fix(rendering): complete character visual regression fixes
This commit is contained in:
@@ -238,7 +238,7 @@ func _build_stage() -> void:
|
||||
root.add_child(we)
|
||||
|
||||
_pivot = Node3D.new()
|
||||
_pivot.rotation.y = -PI * 0.5
|
||||
_pivot.rotation.y = PI * 0.5
|
||||
root.add_child(_pivot)
|
||||
|
||||
_cam = Camera3D.new()
|
||||
@@ -254,10 +254,20 @@ func _frame_model() -> void:
|
||||
return
|
||||
var aabb := AABB()
|
||||
var first := true
|
||||
# GPU skinning happens in the vertex shader, so MeshInstance3D's mesh AABB
|
||||
# remains in bind pose. Prefer the extension's matching deformed bounds for
|
||||
# the main body; accessories continue through their own mesh bounds below.
|
||||
if _pv.model and _pv.model.has_method("get_visual_aabb"):
|
||||
var posed: AABB = _pv.model.call("get_visual_aabb")
|
||||
if posed.size.length_squared() > 0.0:
|
||||
aabb = (_pv.model as Node3D).global_transform * posed
|
||||
first = false
|
||||
for mi in (_pv as Node).find_children("*", "MeshInstance3D", true, false):
|
||||
var m := mi as MeshInstance3D
|
||||
if m.mesh == null:
|
||||
continue
|
||||
if m.get_parent() == _pv.model and m.name == "MeshInstance3D":
|
||||
continue # already covered by Metin2Model.get_visual_aabb()
|
||||
var wb: AABB = m.get_global_transform() * m.get_aabb()
|
||||
aabb = wb if first else aabb.merge(wb)
|
||||
first = false
|
||||
@@ -274,6 +284,13 @@ func _frame_model() -> void:
|
||||
_cam.position = target + Vector3(0, dist * sin(deg_to_rad(6.0)), dist * cos(deg_to_rad(6.0)))
|
||||
_cam.look_at(target, Vector3.UP)
|
||||
|
||||
# Metin2AnimPlayer enables the optional GPU skin path on its first animation
|
||||
# sample. Its material/mesh swap changes the MeshInstance AABB after the
|
||||
# initial CPU framing pass, so frame again after the extension confirms it.
|
||||
func _on_model_visual_bounds_changed(pv: Node) -> void:
|
||||
if pv == _pv and is_instance_valid(pv):
|
||||
call_deferred("_frame_model")
|
||||
|
||||
func _rebuild_model() -> void:
|
||||
if _pivot == null:
|
||||
return
|
||||
@@ -290,6 +307,8 @@ func _rebuild_model() -> void:
|
||||
_pivot.add_child(pv)
|
||||
if pv.build(_assets, job, pump):
|
||||
_pv = pv
|
||||
if pv.model and pv.model.has_signal("visual_bounds_changed"):
|
||||
pv.model.visual_bounds_changed.connect(_on_model_visual_bounds_changed.bind(pv))
|
||||
if _proto == null and ClassDB.class_exists("Metin2Proto"):
|
||||
_proto = ClassDB.instantiate("Metin2Proto")
|
||||
add_child(_proto)
|
||||
|
||||
Reference in New Issue
Block a user