""" 高级骨骼动画系统插件 完整的骨骼动画解决方案,包含动画播放、混合、IK、压缩、网络同步等高级功能 """ from plugins.plugin_manager import BasePlugin from direct.showbase.DirectObject import DirectObject # 导入核心模块 from .core import SkeletalAnimationCore from .network import AnimationNetworkSync from .advanced import AnimationStateMachine, AnimationCurveEditor, PhysicsAnimationIntegration from .optimization import AnimationCompressor, AnimationLODSystem, AnimationCacheManager from .tools import AnimationAnalyzer, AnimationEditor, DebugVisualizer, AnimationProfiler class AdvancedSkeletalAnimationPlugin(BasePlugin): """ 高级骨骼动画系统插件 提供完整的骨骼动画支持,包括加载、播放、控制、混合等高级功能 """ def __init__(self, plugin_manager, name): """ 初始化高级骨骼动画插件 :param plugin_manager: 插件管理器 :param name: 插件名称 """ super().__init__(plugin_manager, name) self.config = { "version": "1.0.0", "author": "Advanced Animation Team", "description": "高级骨骼动画系统,支持模型动画加载、播放控制、混合、IK、压缩、网络同步等高级功能" } # 核心系统组件 self.core_system = None self.network_system = None self.lod_system = None self.cache_manager = None self.is_enabled = False self.update_task = None print(f"高级骨骼动画插件初始化: {self.name}") def initialize(self) -> bool: """ 初始化插件 :return: 是否初始化成功 """ try: world = self.plugin_manager.world # 创建核心动画系统 self.core_system = SkeletalAnimationCore(world) # 创建网络同步系统 self.network_system = AnimationNetworkSync(world, self.core_system) # 创建LOD系统 self.lod_system = AnimationLODSystem(world) # 创建缓存管理器 self.cache_manager = AnimationCacheManager() print(f"高级骨骼动画插件初始化成功: {self.name}") return True except Exception as e: print(f"高级骨骼动画插件初始化失败: {e}") import traceback traceback.print_exc() return False def enable(self) -> bool: """ 启用插件 :return: 是否启用成功 """ if not super().enable(): return False if self.is_enabled: print(f"高级骨骼动画插件已启用: {self.name}") return True try: # 启动核心系统更新 self.core_system.start_updating() # 启动网络同步 self.network_system.start_sync_task() # 启动更新任务 self.update_task = self.plugin_manager.world.taskMgr.add( self._update_task, f"advanced_skeletal_animation_update_{self.name}", sort=30 ) # 标记为已启用 self.is_enabled = True print(f"高级骨骼动画插件启用成功: {self.name}") return True except Exception as e: print(f"高级骨骼动画插件启用失败: {e}") import traceback traceback.print_exc() return False def disable(self) -> bool: """ 禁用插件 :return: 是否禁用成功 """ if not super().disable(): return False if not self.is_enabled: print(f"高级骨骼动画插件已禁用: {self.name}") return True try: # 停止更新任务 if self.update_task: self.plugin_manager.world.taskMgr.remove(self.update_task) self.update_task = None # 停止核心系统更新 self.core_system.stop_updating() # 停止网络同步 self.network_system.stop_sync_task() # 标记为已禁用 self.is_enabled = False print(f"高级骨骼动画插件禁用成功: {self.name}") return True except Exception as e: print(f"高级骨骼动画插件禁用失败: {e}") import traceback traceback.print_exc() return False def finalize(self) -> None: """ 清理插件资源 """ print(f"清理高级骨骼动画插件资源: {self.name}") try: # 停止更新任务 if self.update_task: self.plugin_manager.world.taskMgr.remove(self.update_task) self.update_task = None # 停止核心系统 if self.core_system: self.core_system.stop_updating() # 停止网络同步 if self.network_system: self.network_system.stop_sync_task() # 清理资源 self.core_system = None self.network_system = None self.lod_system = None self.cache_manager = None print(f"高级骨骼动画插件资源清理完成: {self.name}") except Exception as e: print(f"清理高级骨骼动画插件资源失败: {e}") import traceback traceback.print_exc() def _update_task(self, task) -> int: """ 插件更新任务 :param task: 任务对象 :return: 任务状态 """ try: dt = globalClock.getDt() # 更新核心系统 if self.core_system: self.core_system.update(dt) # 更新LOD系统 if self.lod_system and self.core_system: self.lod_system.update_lod_levels(self.core_system.actors) # 更新网络同步 # (网络同步有独立的任务) except Exception as e: print(f"插件更新任务出错: {e}") return task.cont # 核心系统访问方法 def get_core_system(self): """ 获取核心动画系统 :return: SkeletalAnimationCore实例 """ return self.core_system def get_network_system(self): """ 获取网络同步系统 :return: AnimationNetworkSync实例 """ return self.network_system def get_lod_system(self): """ 获取LOD系统 :return: AnimationLODSystem实例 """ return self.lod_system def get_cache_manager(self): """ 获取缓存管理器 :return: AnimationCacheManager实例 """ return self.cache_manager def get_analyzer(self): """ 获取动画分析器 :return: AnimationAnalyzer实例 """ return self.core_system.get_analyzer() if self.core_system else None def get_editor(self): """ 获取动画编辑器 :return: AnimationEditor实例 """ return self.core_system.get_editor() if self.core_system else None def get_visualizer(self): """ 获取调试可视化工具 :return: DebugVisualizer实例 """ return self.core_system.get_visualizer() if self.core_system else None def get_profiler(self): """ 获取性能分析器 :return: AnimationProfiler实例 """ return self.core_system.get_profiler() if self.core_system else None # 兼容性接口 Plugin = AdvancedSkeletalAnimationPlugin __all__ = [ 'AdvancedSkeletalAnimationPlugin', 'Plugin', 'SkeletalAnimationCore', 'AnimationNetworkSync', 'AnimationStateMachine', 'AnimationCurveEditor', 'PhysicsAnimationIntegration', 'AnimationCompressor', 'AnimationLODSystem', 'AnimationCacheManager', 'AnimationAnalyzer', 'AnimationEditor', 'DebugVisualizer', 'AnimationProfiler' ]