render: extract animated M2 materializer

This commit is contained in:
2026-07-18 01:48:55 +04:00
parent 9ab4c0762d
commit 456f3e2334
16 changed files with 725 additions and 78 deletions
+32 -49
View File
@@ -78,8 +78,8 @@ const M2_ANIMATION_LOAD_PIPELINE_STATE_SCRIPT := preload(
const M2_ANIMATED_SCENE_FINALIZER_SCRIPT := preload(
"res://src/render/m2/m2_animated_scene_finalizer.gd"
)
const M2_ANIMATION_PLAYBACK_CONTROLLER_SCRIPT := preload(
"res://src/render/m2/m2_animation_playback_controller.gd"
const M2_ANIMATED_INSTANCE_MATERIALIZER_SCRIPT := preload(
"res://src/render/m2/m2_animated_instance_materializer.gd"
)
const M2_MESH_RESOURCE_CACHE_STATE_SCRIPT := preload(
"res://src/render/m2/m2_mesh_resource_cache_state.gd"
@@ -281,7 +281,7 @@ var _m2_mesh_resource_extractor := M2_MESH_RESOURCE_EXTRACTOR_SCRIPT.new()
var _m2_mesh_load_pipeline_state := M2_MESH_LOAD_PIPELINE_STATE_SCRIPT.new()
var _m2_animation_load_pipeline_state := M2_ANIMATION_LOAD_PIPELINE_STATE_SCRIPT.new()
var _m2_animated_scene_finalizer := M2_ANIMATED_SCENE_FINALIZER_SCRIPT.new()
var _m2_animation_playback_controller := M2_ANIMATION_PLAYBACK_CONTROLLER_SCRIPT.new()
var _m2_animated_instance_materializer := M2_ANIMATED_INSTANCE_MATERIALIZER_SCRIPT.new()
var _wmo_build_jobs: Dictionary = {}
var _wmo_build_queue: Array = []
var _tile_loading_tasks: Dictionary = {}
@@ -4429,53 +4429,36 @@ func _materialize_m2_animated_batch(
start: int,
count: int,
serial: int) -> void:
if transforms.is_empty() or count <= 0 or prototype == null:
var materialization := _m2_animated_instance_materializer.materialize_batch(
m2_root,
rel_path,
prototype,
transforms,
start,
count,
serial,
m2_visibility_range,
CHUNK_SIZE,
m2_cast_shadows,
M2_NATIVE_ANIMATOR_SCRIPT,
debug_streaming
)
if materialization.is_empty():
return
var batch_root := Node3D.new()
batch_root.name = "%s_anim_%d" % [rel_path.get_file().get_basename(), serial]
for i in count:
var instance := prototype.duplicate(Node.DUPLICATE_SIGNALS | Node.DUPLICATE_GROUPS | Node.DUPLICATE_SCRIPTS) as Node3D
if instance == null:
continue
instance.name = "%s_%d" % [rel_path.get_file().get_basename(), start + i]
instance.transform = transforms[start + i]
_apply_visibility_range_recursive(instance, m2_visibility_range)
_apply_shadow_cast_recursive(instance, m2_cast_shadows)
_m2_animation_playback_controller.copy_native_animator_data(
prototype,
instance,
M2_NATIVE_ANIMATOR_SCRIPT
)
batch_root.add_child(instance)
var animation_players := _m2_animated_scene_finalizer.animation_players_in_subtree(
instance
)
var native_diagnostics := _m2_animation_playback_controller.start_instance_playback(
instance,
rel_path,
start + i,
M2_NATIVE_ANIMATOR_SCRIPT,
animation_players,
debug_streaming
)
if debug_streaming:
for state in native_diagnostics:
print("M2_NATIVE_ANIMATOR path=%s instance=%d prepared=%s processing=%s mesh=%s bones=%d surfaces=%d length=%.2f" % [
_normalize_m2_rel_path(rel_path),
start + i,
str(state.get("prepared", false)),
str(state.get("processing", false)),
str(state.get("has_mesh", false)),
int(state.get("bones", 0)),
int(state.get("surfaces", 0)),
float(state.get("length", 0.0)),
])
if batch_root.get_child_count() <= 0:
batch_root.queue_free()
return
m2_root.add_child(batch_root)
if debug_streaming:
for diagnostic_entry in materialization.get("native_diagnostics", []):
var state: Dictionary = diagnostic_entry.get("state", {})
print("M2_NATIVE_ANIMATOR path=%s instance=%d prepared=%s processing=%s mesh=%s bones=%d surfaces=%d length=%.2f" % [
_normalize_m2_rel_path(rel_path),
int(diagnostic_entry.get("instance_index", -1)),
str(state.get("prepared", false)),
str(state.get("processing", false)),
str(state.get("has_mesh", false)),
int(state.get("bones", 0)),
int(state.get("surfaces", 0)),
float(state.get("length", 0.0)),
])
var batch_root: Node3D = materialization.get("batch_root", null)
_set_editor_owner_recursive(batch_root)