支持不同环境下对同一场景中模型的动画控制

This commit is contained in:
Hector 2025-11-06 11:08:42 +08:00
parent 7270031f25
commit d75d21f0f3
2 changed files with 4541 additions and 4356 deletions

File diff suppressed because it is too large Load Diff

View File

@ -9169,12 +9169,75 @@ class PropertyPanelManager:
def _getActor(self, origin_model):
if origin_model in self._actor_cache:
return self._actor_cache[origin_model]
# 首先检查是否可以直接从内存中的模型创建Actor
if origin_model.hasTag("can_create_actor_from_memory") and origin_model.getTag("can_create_actor_from_memory").lower() == "true":
try:
print(f"[Actor加载] 直接从内存模型创建Actor: {origin_model.getName()}")
# 直接从内存中的模型创建Actor
test_actor = Actor(origin_model)
anims = test_actor.getAnimNames()
test_actor.reparentTo(self.world.render)
self._actor_cache[origin_model] = test_actor
print(f"[Actor加载] 内存创建检测到动画: {anims}")
if anims:
return test_actor
else:
test_actor.cleanup()
test_actor.removeNode()
except Exception as e:
print(f"从内存模型创建Actor失败: {e}")
# 如果不能直接从内存创建,再尝试通过文件路径加载
filepath = origin_model.getTag("model_path")
if not filepath:
return None
print(f"[Actor加载] 尝试加载: {filepath}")
# 处理跨平台路径问题
import os
# 检查路径是否有效,如果无效则尝试修复
if not os.path.exists(filepath):
original_filepath = filepath
# 尝试多种修复策略
fixed = False
# 策略1: 处理Linux风格路径在Windows上的问题
if filepath.startswith('/') and ':' not in filepath:
# 提取文件名并尝试在当前目录查找
filename = os.path.basename(filepath)
potential_path = os.path.join(os.getcwd(), filename)
if os.path.exists(potential_path):
filepath = potential_path
fixed = True
# 策略2: 处理路径分隔符问题
if not fixed:
# 尝试规范化路径
normalized_path = os.path.normpath(filepath)
if os.path.exists(normalized_path):
filepath = normalized_path
fixed = True
# 策略3: 在Resources目录中查找
if not fixed:
# 尝试在Resources目录中查找文件
resources_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "Resources")
filename = os.path.basename(filepath)
potential_path = os.path.join(resources_path, filename)
if os.path.exists(potential_path):
filepath = potential_path
fixed = True
if fixed:
print(f"路径修复: {original_filepath} -> {filepath}")
# 更新模型标签
origin_model.setTag("model_path", filepath)
else:
print(f"[警告] 模型文件不存在: {filepath}")
return None
# 检查是否是 FBX 文件,如果是,使用专门的 FBX 动画加载器
if filepath.lower().endswith('.fbx'):
pass