|
|
|
@@ -321,24 +321,23 @@ func add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false,
|
|
|
|
|
var def_id: String = str(unit.get("cardDefinitionId", ""))
|
|
|
|
|
if not def_id.is_empty():
|
|
|
|
|
unit_registry.unit_def_ids[iid] = def_id
|
|
|
|
|
if def_id.is_empty():
|
|
|
|
|
return
|
|
|
|
|
var def: Dictionary = ContentCache.get_definition(def_id)
|
|
|
|
|
_prime_unit_sfx(def)
|
|
|
|
|
var def: Dictionary = ContentCache.get_definition(def_id) if not def_id.is_empty() else {}
|
|
|
|
|
if not def.is_empty():
|
|
|
|
|
_prime_unit_sfx(def)
|
|
|
|
|
var model_asset: Dictionary = find_model3d_asset(def)
|
|
|
|
|
var model_url: String = str(model_asset.get("cdnUrl", ""))
|
|
|
|
|
var model_etag: String = str(model_asset.get("contentETag", ""))
|
|
|
|
|
var model_url: String = str(unit.get("modelUrl", "")).strip_edges()
|
|
|
|
|
var model_etag: String = ""
|
|
|
|
|
if model_url.is_empty():
|
|
|
|
|
model_url = str(model_asset.get("cdnUrl", "")).strip_edges()
|
|
|
|
|
model_etag = str(model_asset.get("contentETag", ""))
|
|
|
|
|
if model_url.is_empty():
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Asset-level config (model-file specific).
|
|
|
|
|
var facing_dir: String = str(model_asset.get("modelFacingDirection", "south"))
|
|
|
|
|
# Card-level config (visual identity of this card, not the shared mesh file).
|
|
|
|
|
var model_scale: float = float(def.get("modelScale", 1.0))
|
|
|
|
|
var tint_str: String = str(def.get("modelTintColor", ""))
|
|
|
|
|
var model_tint: Color = Color.WHITE
|
|
|
|
|
if not tint_str.is_empty() and tint_str != "null":
|
|
|
|
|
model_tint = Color(tint_str)
|
|
|
|
|
var model_scale: float = _parse_model_scale(def.get("modelScale", 1.0))
|
|
|
|
|
var model_tint: Color = _parse_model_tint(def.get("modelTintColor", ""))
|
|
|
|
|
|
|
|
|
|
# Team-based facing: P1 units face +Z (toward P2), P2 units face -Z (toward P1).
|
|
|
|
|
# Rotate if: (local is P1 AND friendly) OR (local is P2 AND enemy).
|
|
|
|
@@ -694,7 +693,8 @@ func _play_materialize_shader_timed(visual: Node3D, team_color: Color, duration:
|
|
|
|
|
mat.shader = _materialize_shader()
|
|
|
|
|
mat.set_shader_parameter("reveal", 0.0)
|
|
|
|
|
mat.set_shader_parameter("team_color", Color(team_color.r, team_color.g, team_color.b, 1.0))
|
|
|
|
|
mi.material_override = mat
|
|
|
|
|
_configure_materialize_source(mat, entry.get("active_material", null))
|
|
|
|
|
_apply_materialize_override(mi, entry, mat)
|
|
|
|
|
reveal_mats.append(mat)
|
|
|
|
|
|
|
|
|
|
var target_scale: Vector3 = visual.scale
|
|
|
|
@@ -715,7 +715,7 @@ func _play_materialize_shader_timed(visual: Node3D, team_color: Color, duration:
|
|
|
|
|
var mesh_ref: WeakRef = entry["mesh_ref"] as WeakRef
|
|
|
|
|
var mi: MeshInstance3D = mesh_ref.get_ref() as MeshInstance3D if mesh_ref != null else null
|
|
|
|
|
if is_instance_valid(mi):
|
|
|
|
|
mi.material_override = entry["override"]
|
|
|
|
|
_restore_materialize_override(mi, entry)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -741,7 +741,8 @@ func _play_dissolve_shader_timed(visual: Node3D, team_color: Color, duration: fl
|
|
|
|
|
mat.shader = _materialize_shader()
|
|
|
|
|
mat.set_shader_parameter("reveal", 1.0)
|
|
|
|
|
mat.set_shader_parameter("team_color", Color(team_color.r, team_color.g, team_color.b, 1.0))
|
|
|
|
|
mi.material_override = mat
|
|
|
|
|
_configure_materialize_source(mat, entry.get("active_material", null))
|
|
|
|
|
_apply_materialize_override(mi, entry, mat)
|
|
|
|
|
dissolve_mats.append(mat)
|
|
|
|
|
|
|
|
|
|
var tween: Tween = create_tween()
|
|
|
|
@@ -769,14 +770,62 @@ func _exit_tree() -> void:
|
|
|
|
|
func _collect_materialize_surfaces(node: Node, surfaces: Array[Dictionary]) -> void:
|
|
|
|
|
if node is MeshInstance3D:
|
|
|
|
|
var mi: MeshInstance3D = node as MeshInstance3D
|
|
|
|
|
surfaces.append({
|
|
|
|
|
"mesh_ref": weakref(mi),
|
|
|
|
|
"override": mi.material_override
|
|
|
|
|
})
|
|
|
|
|
if mi.material_override != null or mi.mesh == null or mi.mesh.get_surface_count() <= 0:
|
|
|
|
|
var active_material: Material = null
|
|
|
|
|
if mi.mesh != null and mi.mesh.get_surface_count() > 0:
|
|
|
|
|
active_material = mi.get_active_material(0)
|
|
|
|
|
surfaces.append({
|
|
|
|
|
"mesh_ref": weakref(mi),
|
|
|
|
|
"surface_idx": -1,
|
|
|
|
|
"override": mi.material_override,
|
|
|
|
|
"active_material": active_material
|
|
|
|
|
})
|
|
|
|
|
else:
|
|
|
|
|
for i: int in mi.mesh.get_surface_count():
|
|
|
|
|
surfaces.append({
|
|
|
|
|
"mesh_ref": weakref(mi),
|
|
|
|
|
"surface_idx": i,
|
|
|
|
|
"override": mi.get_surface_override_material(i),
|
|
|
|
|
"active_material": mi.get_active_material(i)
|
|
|
|
|
})
|
|
|
|
|
for child: Node in node.get_children():
|
|
|
|
|
_collect_materialize_surfaces(child, surfaces)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _apply_materialize_override(mi: MeshInstance3D, entry: Dictionary, mat: ShaderMaterial) -> void:
|
|
|
|
|
var surface_idx: int = int(entry.get("surface_idx", -1))
|
|
|
|
|
if surface_idx >= 0:
|
|
|
|
|
mi.set_surface_override_material(surface_idx, mat)
|
|
|
|
|
else:
|
|
|
|
|
mi.material_override = mat
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _restore_materialize_override(mi: MeshInstance3D, entry: Dictionary) -> void:
|
|
|
|
|
var surface_idx: int = int(entry.get("surface_idx", -1))
|
|
|
|
|
if surface_idx >= 0:
|
|
|
|
|
mi.set_surface_override_material(surface_idx, entry.get("override", null) as Material)
|
|
|
|
|
else:
|
|
|
|
|
mi.material_override = entry.get("override", null) as Material
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _configure_materialize_source(shader_mat: ShaderMaterial, source: Material) -> void:
|
|
|
|
|
var base_color: Color = Color.WHITE
|
|
|
|
|
var base_texture: Texture2D = null
|
|
|
|
|
var roughness: float = 0.35
|
|
|
|
|
var metallic: float = 0.0
|
|
|
|
|
if source is StandardMaterial3D:
|
|
|
|
|
var standard: StandardMaterial3D = source as StandardMaterial3D
|
|
|
|
|
base_color = standard.albedo_color
|
|
|
|
|
base_texture = standard.albedo_texture
|
|
|
|
|
roughness = standard.roughness
|
|
|
|
|
metallic = standard.metallic
|
|
|
|
|
shader_mat.set_shader_parameter("base_color", base_color)
|
|
|
|
|
shader_mat.set_shader_parameter("base_texture", base_texture)
|
|
|
|
|
shader_mat.set_shader_parameter("has_base_texture", base_texture != null)
|
|
|
|
|
shader_mat.set_shader_parameter("base_roughness", roughness)
|
|
|
|
|
shader_mat.set_shader_parameter("base_metallic", metallic)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _materialize_shader() -> Shader:
|
|
|
|
|
if has_meta("_materialize_shader"):
|
|
|
|
|
return get_meta("_materialize_shader") as Shader
|
|
|
|
@@ -787,6 +836,11 @@ render_mode blend_mix, cull_disabled, depth_draw_opaque;
|
|
|
|
|
|
|
|
|
|
uniform float reveal : hint_range(0.0, 1.0) = 0.0;
|
|
|
|
|
uniform vec4 team_color : source_color = vec4(0.35, 0.5, 1.0, 1.0);
|
|
|
|
|
uniform vec4 base_color : source_color = vec4(1.0);
|
|
|
|
|
uniform sampler2D base_texture : source_color;
|
|
|
|
|
uniform bool has_base_texture = false;
|
|
|
|
|
uniform float base_roughness : hint_range(0.0, 1.0) = 0.35;
|
|
|
|
|
uniform float base_metallic : hint_range(0.0, 1.0) = 0.0;
|
|
|
|
|
|
|
|
|
|
varying vec3 local_pos;
|
|
|
|
|
|
|
|
|
@@ -812,15 +866,20 @@ void fragment() {
|
|
|
|
|
|
|
|
|
|
float edge = 1.0 - smoothstep(0.0, 0.16, abs(bubble_noise - threshold));
|
|
|
|
|
float shimmer = smoothstep(0.72, 1.0, fine_noise) * (1.0 - reveal * 0.45);
|
|
|
|
|
vec4 source = base_color;
|
|
|
|
|
if (has_base_texture) {
|
|
|
|
|
source *= texture(base_texture, UV);
|
|
|
|
|
}
|
|
|
|
|
vec3 black_bubble = vec3(0.012, 0.010, 0.018);
|
|
|
|
|
vec3 final_tint = mix(team_color.rgb * 0.35, team_color.rgb, reveal);
|
|
|
|
|
vec3 final_tint = mix(team_color.rgb * 0.35, source.rgb, reveal);
|
|
|
|
|
vec3 color = mix(black_bubble, final_tint, smoothstep(0.25, 1.0, reveal));
|
|
|
|
|
color += team_color.rgb * (edge * 1.8 + shimmer * 0.9);
|
|
|
|
|
|
|
|
|
|
ALBEDO = color;
|
|
|
|
|
EMISSION = team_color.rgb * (edge * 1.5 + shimmer);
|
|
|
|
|
ROUGHNESS = 0.35;
|
|
|
|
|
ALPHA = 1.0;
|
|
|
|
|
ROUGHNESS = base_roughness;
|
|
|
|
|
METALLIC = base_metallic;
|
|
|
|
|
ALPHA = source.a;
|
|
|
|
|
}
|
|
|
|
|
"""
|
|
|
|
|
set_meta("_materialize_shader", shader)
|
|
|
|
@@ -1064,11 +1123,8 @@ func do_model_retry(iid: String, model_url: String, attempt: int, etag: String =
|
|
|
|
|
# Re-read card config in case ContentCache was refreshed since placement.
|
|
|
|
|
var def_id: String = unit_registry.unit_def_ids.get(iid, "")
|
|
|
|
|
var def: Dictionary = ContentCache.get_definition(def_id)
|
|
|
|
|
var model_scale: float = float(def.get("modelScale", 1.0))
|
|
|
|
|
var tint_str: String = str(def.get("modelTintColor", ""))
|
|
|
|
|
var model_tint: Color = Color.WHITE
|
|
|
|
|
if not tint_str.is_empty() and tint_str != "null":
|
|
|
|
|
model_tint = Color(tint_str)
|
|
|
|
|
var model_scale: float = _parse_model_scale(def.get("modelScale", 1.0))
|
|
|
|
|
var model_tint: Color = _parse_model_tint(def.get("modelTintColor", ""))
|
|
|
|
|
var target_scale: Vector3 = Vector3.ONE * model_scale
|
|
|
|
|
if not is_equal_approx(model_scale, 1.0):
|
|
|
|
|
model_node.scale = target_scale
|
|
|
|
@@ -1089,6 +1145,38 @@ func do_model_retry(iid: String, model_url: String, attempt: int, etag: String =
|
|
|
|
|
|
|
|
|
|
# ── Model helpers ─────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
func _parse_model_scale(value: Variant) -> float:
|
|
|
|
|
var parsed: float = 1.0
|
|
|
|
|
match typeof(value):
|
|
|
|
|
TYPE_FLOAT, TYPE_INT:
|
|
|
|
|
parsed = value
|
|
|
|
|
TYPE_STRING, TYPE_STRING_NAME:
|
|
|
|
|
var text: String = str(value).strip_edges()
|
|
|
|
|
if text.is_valid_float():
|
|
|
|
|
parsed = text.to_float()
|
|
|
|
|
_:
|
|
|
|
|
parsed = 1.0
|
|
|
|
|
if parsed <= 0.0:
|
|
|
|
|
return 1.0
|
|
|
|
|
return parsed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _parse_model_tint(value: Variant) -> Color:
|
|
|
|
|
var text: String = str(value).strip_edges()
|
|
|
|
|
if text.is_empty() or text.to_lower() == "null":
|
|
|
|
|
return Color.WHITE
|
|
|
|
|
if text.to_lower() == "white":
|
|
|
|
|
return Color.WHITE
|
|
|
|
|
if not Color.html_is_valid(text):
|
|
|
|
|
push_warning("[UnitMeshBuilder] Ignoring invalid modelTintColor '%s'" % text)
|
|
|
|
|
return Color.WHITE
|
|
|
|
|
var parsed: Color = Color.html(text)
|
|
|
|
|
if maxf(parsed.r, maxf(parsed.g, parsed.b)) <= 0.02:
|
|
|
|
|
push_warning("[UnitMeshBuilder] Ignoring near-black modelTintColor '%s'; multiplicative tint hides GLB textures" % text)
|
|
|
|
|
return Color.WHITE
|
|
|
|
|
return Color(parsed.r, parsed.g, parsed.b, 1.0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Returns the first Model3D asset dict for a card definition, or {} if none.
|
|
|
|
|
func find_model3d_asset(def: Dictionary) -> Dictionary:
|
|
|
|
|
for asset: Variant in def.get("assets", []):
|
|
|
|
|