render: add M2 build resource snapshot

This commit is contained in:
2026-07-18 02:47:10 +04:00
parent 0decd10e09
commit ec1b90f1e4
14 changed files with 655 additions and 52 deletions
+25 -17
View File
@@ -63,6 +63,9 @@ const M2_BUILD_BATCH_PLANNER_SCRIPT := preload(
const M2_BUILD_DISPATCH_PLANNER_SCRIPT := preload(
"res://src/render/m2/m2_build_dispatch_planner.gd"
)
const M2_BUILD_RESOURCE_SNAPSHOT_SCRIPT := preload(
"res://src/render/m2/m2_build_resource_snapshot.gd"
)
const M2_BUILD_QUEUE_SCRIPT := preload("res://src/render/m2/m2_build_queue.gd")
const M2_STATIC_BATCH_MATERIALIZER_SCRIPT := preload(
"res://src/render/m2/m2_static_batch_materializer.gd"
@@ -4350,31 +4353,38 @@ func _process_m2_build_jobs() -> void:
enable_m2_animated_instances
and _m2_animation_load_pipeline_state.has_request(normalized_rel)
)
var resource_snapshot: RefCounted = M2_BUILD_RESOURCE_SNAPSHOT_SCRIPT.new(
normalized_rel,
animated_prototype,
animation_request_pending
)
var batch_plan: Dictionary = {}
var batch_count := 0
var static_mesh: Mesh = null
var static_model_missing := false
if not animation_request_pending:
if not bool(resource_snapshot.call("animation_request_pending")):
batch_plan = _m2_build_batch_planner.plan_batch(
transforms.size(),
offset,
animated_prototype != null,
bool(resource_snapshot.call("has_animated_prototype")),
m2_animated_instances_per_tick,
m2_multimesh_batch_size
)
batch_count = int(batch_plan["batch_count"])
if batch_count > 0 and animated_prototype == null:
static_mesh = _get_m2_mesh_or_request(rel_path)
static_model_missing = (
static_mesh == null
and _m2_prototype_cache_state.is_model_missing(normalized_rel)
if (
batch_count > 0
and not bool(resource_snapshot.call("has_animated_prototype"))
):
var static_mesh := _get_m2_mesh_or_request(rel_path)
resource_snapshot.call(
"adopt_static_observation",
static_mesh,
(
static_mesh == null
and _m2_prototype_cache_state.is_model_missing(normalized_rel)
)
)
var dispatch_plan: Dictionary = _m2_build_dispatch_planner.plan_step(
batch_count,
animation_request_pending,
animated_prototype != null,
static_mesh != null,
static_model_missing
resource_snapshot
)
if bool(dispatch_plan["rotate_queue"]):
_m2_build_queue_state.rotate_front()
@@ -4392,7 +4402,7 @@ func _process_m2_build_jobs() -> void:
_materialize_m2_animated_batch(
root as Node3D,
rel_path,
animated_prototype,
resource_snapshot.call("animated_prototype") as Node3D,
transforms,
offset,
batch_count,
@@ -4405,7 +4415,7 @@ func _process_m2_build_jobs() -> void:
_materialize_m2_group_batch(
root as Node3D,
rel_path,
static_mesh,
resource_snapshot.call("static_mesh") as Mesh,
transforms,
offset,
batch_count,
@@ -4431,8 +4441,6 @@ func _process_m2_build_jobs() -> void:
if next_group_index >= group_keys.size():
_finish_m2_build_job(key)
_m2_build_queue_state.pop_front()
func _materialize_m2_group_batch(
m2_root: Node3D,
rel_path: String,