refactor(M03): extract raw M2 model repository

This commit is contained in:
2026-07-17 15:53:20 +04:00
parent e4bb10cee7
commit b608a81766
12 changed files with 479 additions and 66 deletions
+17 -44
View File
@@ -63,6 +63,9 @@ const M2_BUILD_BATCH_PLANNER_SCRIPT := preload(
const M2_RUNTIME_MESH_FINALIZER_SCRIPT := preload(
"res://src/render/m2/m2_runtime_mesh_finalizer.gd"
)
const M2_RAW_MODEL_REPOSITORY_SCRIPT := preload(
"res://src/render/m2/m2_raw_model_repository.gd"
)
const M2_MESH_LOAD_PIPELINE_STATE_SCRIPT := preload(
"res://src/render/m2/m2_mesh_load_pipeline_state.gd"
)
@@ -259,6 +262,7 @@ var _m2_placement_transform_resolver := M2_PLACEMENT_TRANSFORM_RESOLVER_SCRIPT.n
var _m2_placement_grouper := M2_PLACEMENT_GROUPER_SCRIPT.new()
var _m2_build_batch_planner := M2_BUILD_BATCH_PLANNER_SCRIPT.new()
var _m2_runtime_mesh_finalizer := M2_RUNTIME_MESH_FINALIZER_SCRIPT.new()
var _m2_raw_model_repository := M2_RAW_MODEL_REPOSITORY_SCRIPT.new()
var _m2_mesh_resource_cache_state := M2_MESH_RESOURCE_CACHE_STATE_SCRIPT.new()
var _m2_mesh_resource_extractor := M2_MESH_RESOURCE_EXTRACTOR_SCRIPT.new()
var _m2_mesh_load_pipeline_state := M2_MESH_LOAD_PIPELINE_STATE_SCRIPT.new()
@@ -4653,7 +4657,10 @@ func _prepare_m2_mesh_for_runtime(normalized_rel: String, mesh: Mesh) -> Mesh:
return null
if not _m2_runtime_mesh_finalizer.requires_raw_data_for_refresh(mesh):
return mesh
var data := _load_m2_raw_data_for_refresh(normalized_rel)
var data := _m2_raw_model_repository.load_static_model_data(
extracted_dir,
normalized_rel
)
return _m2_runtime_mesh_finalizer.finalize_mesh(
normalized_rel,
mesh,
@@ -4673,19 +4680,6 @@ func _prepare_m2_node_for_runtime(normalized_rel: String, root: Node3D) -> void:
mesh_instance.mesh = prepared
func _load_m2_raw_data_for_refresh(normalized_rel: String) -> Dictionary:
if normalized_rel.is_empty() or not ClassDB.class_exists("M2Loader"):
return {}
var abs_path := ProjectSettings.globalize_path(extracted_dir.path_join(normalized_rel))
if not FileAccess.file_exists(abs_path):
return {}
var loader = ClassDB.instantiate("M2Loader")
if loader == null:
return {}
var data: Variant = loader.call("load_m2", abs_path)
return data if data is Dictionary else {}
func _get_or_load_m2_mesh(rel_path: String) -> Mesh:
var normalized_rel := _normalize_m2_rel_path(rel_path)
if _m2_mesh_resource_cache_state.has_mesh(normalized_rel):
@@ -4868,18 +4862,11 @@ func _get_or_load_m2_prototype(rel_path: String) -> Node3D:
return node as Node3D
break
# Fall back to raw M2Loader
if not ClassDB.class_exists("M2Loader"):
_m2_missing_cache[normalized_rel] = true
return null
var abs_path := ProjectSettings.globalize_path(extracted_dir.path_join(normalized_rel))
if not FileAccess.file_exists(abs_path):
_m2_missing_cache[normalized_rel] = true
return null
var loader = ClassDB.instantiate("M2Loader")
var data: Dictionary = loader.call("load_m2", abs_path)
# Fall back to the raw native M2 repository.
var data := _m2_raw_model_repository.load_static_model_data(
extracted_dir,
normalized_rel
)
if data.is_empty():
_m2_missing_cache[normalized_rel] = true
return null
@@ -4901,24 +4888,10 @@ func _get_or_load_m2_native_animated_prototype(rel_path: String) -> Node3D:
return _m2_animated_scene_cache[normalized_rel]
if _m2_static_animation_cache.has(normalized_rel):
return null
if not ClassDB.class_exists("M2Loader"):
_m2_static_animation_cache[normalized_rel] = true
return null
var abs_path := ProjectSettings.globalize_path(extracted_dir.path_join(normalized_rel))
if not FileAccess.file_exists(abs_path):
_m2_static_animation_cache[normalized_rel] = true
return null
var loader = ClassDB.instantiate("M2Loader")
if loader == null:
_m2_static_animation_cache[normalized_rel] = true
return null
if not loader.has_method("load_m2_animated"):
_m2_static_animation_cache[normalized_rel] = true
return null
var data: Dictionary = loader.call("load_m2_animated", abs_path)
var data := _m2_raw_model_repository.load_animated_model_data(
extracted_dir,
normalized_rel
)
var animated_surfaces: Array = data.get("animated_surfaces", [])
if data.is_empty() or animated_surfaces.is_empty():
_m2_static_animation_cache[normalized_rel] = true