шейдеры билбордов

This commit is contained in:
2026-07-07 11:33:57 +04:00
parent 44614a79e4
commit f561e52aa9
6 changed files with 320 additions and 6 deletions
+46 -2
View File
@@ -15,6 +15,7 @@ const M2_NATIVE_ANIMATOR_SCRIPT := preload("res://src/scenes/streaming/m2_native
const REQUIRED_BAKED_TILE_FORMAT_VERSION := 4
const REQUIRED_SPLAT_TILE_FORMAT_VERSION := 1
const REQUIRED_CONTROL_SPLAT_TILE_FORMAT_VERSION := 3
const M2_MATERIAL_REFRESH_VERSION := 1
const WMO_MATERIAL_REFRESH_VERSION := 3
const TILE_SIZE := 533.33333
@@ -4400,9 +4401,46 @@ func _request_m2_mesh_load(normalized_rel: String) -> void:
func _prepare_m2_mesh_for_runtime(normalized_rel: String, mesh: Mesh) -> Mesh:
if mesh == null:
return null
if int(mesh.get_meta("wow_m2_material_refresh_version", 0)) >= M2_MATERIAL_REFRESH_VERSION:
return mesh
var rebuilt := _rebuild_m2_mesh_from_raw(normalized_rel)
if rebuilt != null:
return rebuilt
mesh.set_meta("wow_m2_material_refresh_version", M2_MATERIAL_REFRESH_VERSION)
return mesh
func _prepare_m2_node_for_runtime(normalized_rel: String, root: Node3D) -> void:
if root == null:
return
for mesh_instance in _find_mesh_instances_recursive(root):
if mesh_instance == null or mesh_instance.mesh == null:
continue
var prepared := _prepare_m2_mesh_for_runtime(normalized_rel, mesh_instance.mesh)
if prepared != null:
mesh_instance.mesh = prepared
func _rebuild_m2_mesh_from_raw(normalized_rel: String) -> Mesh:
if normalized_rel.is_empty() or not ClassDB.class_exists("M2Loader"):
return null
var abs_path := ProjectSettings.globalize_path(extracted_dir.path_join(normalized_rel))
if not FileAccess.file_exists(abs_path):
return null
var loader = ClassDB.instantiate("M2Loader")
if loader == null:
return null
var data: Dictionary = loader.call("load_m2", abs_path)
if data.is_empty():
return null
var prototype: Node3D = M2_BUILDER_SCRIPT.build(data, extracted_dir)
if prototype == null:
return null
var rebuilt := _find_first_mesh_recursive(prototype)
prototype.free()
return rebuilt
func _extract_first_mesh_from_m2_resource(resource: Resource) -> Mesh:
if resource is Mesh:
return resource as Mesh
@@ -4572,7 +4610,9 @@ func _get_or_load_m2_prototype(rel_path: String) -> Node3D:
if normalized_rel.is_empty():
return null
if _m2_scene_cache.has(normalized_rel):
return _m2_scene_cache[normalized_rel]
var cached: Node3D = _m2_scene_cache[normalized_rel]
_prepare_m2_node_for_runtime(normalized_rel, cached)
return cached
if _m2_missing_cache.has(normalized_rel):
return null
@@ -4586,6 +4626,7 @@ func _get_or_load_m2_prototype(rel_path: String) -> Node3D:
if resource is PackedScene:
var node = (resource as PackedScene).instantiate()
if node is Node3D:
_prepare_m2_node_for_runtime(normalized_rel, node as Node3D)
_m2_scene_cache[normalized_rel] = node as Node3D
return node as Node3D
break
@@ -4768,7 +4809,9 @@ func _get_or_load_m2_material_prototype(normalized_rel: String) -> Node3D:
if normalized_rel.is_empty():
return null
if _m2_scene_cache.has(normalized_rel):
return _m2_scene_cache[normalized_rel]
var cached: Node3D = _m2_scene_cache[normalized_rel]
_prepare_m2_node_for_runtime(normalized_rel, cached)
return cached
for cache_res_path in _get_m2_cache_resource_paths(normalized_rel, [".tscn"]):
if not ResourceLoader.exists(cache_res_path):
@@ -4777,6 +4820,7 @@ func _get_or_load_m2_material_prototype(normalized_rel: String) -> Node3D:
if resource is PackedScene:
var node = (resource as PackedScene).instantiate()
if node is Node3D:
_prepare_m2_node_for_runtime(normalized_rel, node as Node3D)
_m2_scene_cache[normalized_rel] = node as Node3D
return node as Node3D
return null