diff --git a/RenderPipelineFile/config/daytime.yaml b/RenderPipelineFile/config/daytime.yaml index 0e1455d6..c56e81ec 100644 --- a/RenderPipelineFile/config/daytime.yaml +++ b/RenderPipelineFile/config/daytime.yaml @@ -17,8 +17,8 @@ control_points: scattering: sun_intensity: [[[0.0000000000,0.0000000000],[0.0041666667,0.0000000000],[0.0083333333,0.0000000000],[0.0125000000,0.0000000000],[0.0166666667,0.0000000000],[0.0208333333,0.0000000000],[0.0250000000,0.0000000000],[0.0291666667,0.0000000000],[0.0333333333,0.0000000000],[0.0375000000,0.0000000000],[0.0416666667,0.0000000000],[0.0458333333,0.0000000000],[0.0500000000,0.0000000000],[0.0541666667,0.0000000000],[0.0583333333,0.0000000000],[0.0625000000,0.0000000000],[0.0666666667,0.0000000000],[0.0708333333,0.0000000000],[0.0750000000,0.0000000000],[0.0791666667,0.0000000000],[0.0833333333,0.0000000000],[0.0875000000,0.0000000000],[0.0916666667,0.0000000000],[0.0958333333,0.0000000000],[0.1000000000,0.0000000000],[0.1041666667,0.0000000000],[0.1083333333,0.0000000000],[0.1125000000,0.0000000000],[0.1166666667,0.0000000000],[0.1208333333,0.0000000000],[0.1250000000,0.0000000000],[0.1291666667,0.0000000000],[0.1333333333,0.0000000000],[0.1375000000,0.0000000000],[0.1416666667,0.0000000000],[0.1458333333,0.0000000000],[0.1500000000,0.0000000000],[0.1541666667,0.0000000000],[0.1583333333,0.0000028805],[0.1625000000,0.0003577724],[0.1666666667,0.0013331400],[0.1708333333,0.0029671803],[0.1750000000,0.0052963381],[0.1791666667,0.0083550556],[0.1833333333,0.0121755589],[0.1875000000,0.0167876159],[0.1916666667,0.0222183530],[0.1958333333,0.0284919947],[0.2000000000,0.0356297193],[0.2041666667,0.0436494349],[0.2083333333,0.0525656099],[0.2125000000,0.0623891610],[0.2166666667,0.0731272461],[0.2208333333,0.0847831708],[0.2250000000,0.0973563167],[0.2291666667,0.1108419698],[0.2333333333,0.1252313631],[0.2375000000,0.1405115250],[0.2416666667,0.1566653434],[0.2458333333,0.1736715009],[0.2500000000,0.1915046014],[0.2541666667,0.2101350464],[0.2583333333,0.2295292930],[0.2625000000,0.2496498145],[0.2666666667,0.2704552670],[0.2708333333,0.2919006662],[0.2750000000,0.3139375192],[0.2791666667,0.3365139497],[0.2833333333,0.3595750662],[0.2875000000,0.3830630359],[0.2916666667,0.4069173972],[0.2958333333,0.4310753462],[0.3000000000,0.4554720417],[0.3041666667,0.4800408236],[0.3083333333,0.5047136020],[0.3125000000,0.5294212108],[0.3166666667,0.5540936424],[0.3208333333,0.5786605298],[0.3250000000,0.6030514553],[0.3291666667,0.6271963182],[0.3333333333,0.6510256858],[0.3375000000,0.6744711982],[0.3416666667,0.6974659988],[0.3458333333,0.7199450163],[0.3500000000,0.7418453485],[0.3541666667,0.7631067095],[0.3583333333,0.7836717291],[0.3625000000,0.8034862953],[0.3666666667,0.8224999302],[0.3708333333,0.8406661079],[0.3750000000,0.8579425235],[0.3791666667,0.8742914270],[0.3833333333,0.8896799131],[0.3875000000,0.9040801386],[0.3916666667,0.9174695289],[0.3958333333,0.9298310650],[0.4000000000,0.9411533765],[0.4041666667,0.9514309312],[0.4083333333,0.9606641691],[0.4125000000,0.9688595571],[0.4166666667,0.9760296330],[0.4208333333,0.9821930708],[0.4250000000,0.9873746114],[0.4291666667,0.9916050060],[0.4333333333,0.9949209310],[0.4375000000,0.9973647924],[0.4416666667,0.9989845508],[0.4458333333,0.9998334497],[0.4500000000,0.9999696949],[0.4541666667,0.9994560801],[0.4583333333,0.9983595429],[0.4625000000,0.9967506613],[0.4666666667,0.9947030614],[0.4708333333,0.9922927758],[0.4750000000,0.9895975125],[0.4791666667,0.9866958610],[0.4833333333,0.9836664262],[0.4875000000,0.9805868867],[0.4916666667,0.9775330316],[0.4958333333,0.9745777179],[0.5000000000,0.9717898417],[0.5041666667,0.9692332877],[0.5083333333,0.9669658924],[0.5125000000,0.9650384806],[0.5089595376,0.9690650222],[0.5208333333,0.9623666659],[0.5250000000,0.9616814371],[0.5291666667,0.9614534423],[0.5333333333,0.9616877089],[0.5375000000,0.9623790807],[0.5416666667,0.9635123329],[0.5458333333,0.9650624244],[0.5500000000,0.9669949804],[0.5541666667,0.9692669864],[0.5583333333,0.9718275065],[0.5625000000,0.9746185969],[0.5666666667,0.9775762863],[0.5708333333,0.9806315864],[0.5750000000,0.9837115661],[0.5791666667,0.9867403433],[0.5833333333,0.9896401655],[0.5875000000,0.9923323562],[0.5916666667,0.9947382579],[0.5958333333,0.9967800977],[0.6000000000,0.9983817820],[0.6041666667,0.9994696263],[0.6083333333,0.9999730028],[0.6125000000,0.9998249266],[0.6166666667,0.9989625601],[0.6208333333,0.9973276624],[0.6250000000,0.9948669567],[0.6291666667,0.9915324664],[0.6333333333,0.9872817545],[0.6375000000,0.9820781426],[0.6416666667,0.9758908775],[0.6458333333,0.9686952146],[0.6500000000,0.9604725211],[0.6541666667,0.9512102537],[0.6583333333,0.9409019858],[0.6625000000,0.9295473441],[0.6666666667,0.9171518878],[0.6708333333,0.9037270619],[0.6750000000,0.8892899902],[0.6791666667,0.8738633008],[0.6833333333,0.8574749656],[0.6875000000,0.8401579787],[0.6916666667,0.8219502453],[0.6958333333,0.8028941798],[0.7000000000,0.7830364456],[0.7041666667,0.7624277344],[0.7083333333,0.7411222520],[0.7125000000,0.7191776044],[0.7166666667,0.6966542563],[0.7208333333,0.6736152714],[0.7250000000,0.6501259629],[0.7291666667,0.6262533880],[0.7333333333,0.6020661121],[0.7375000000,0.5776338043],[0.7416666667,0.5530267796],[0.7458333333,0.5283156992],[0.7500000000,0.5035711751],[0.7541666667,0.4788634341],[0.7583333333,0.4542618347],[0.7625000000,0.4298347613],[0.7666666667,0.4056490351],[0.7708333333,0.3817697830],[0.7750000000,0.3582600107],[0.7791666667,0.3351803495],[0.7833333333,0.3125888445],[0.7875000000,0.2905406366],[0.7916666667,0.2690876955],[0.7958333333,0.2482787388],[0.8000000000,0.2281588906],[0.8041666667,0.2087696425],[0.8083333333,0.1901486315],[0.8125000000,0.1723295359],[0.8166666667,0.1553419918],[0.8208333333,0.1392115328],[0.8250000000,0.1239595144],[0.8291666667,0.1096030703],[0.8333333333,0.0961551918],[0.8375000000,0.0836246599],[0.8416666667,0.0720161369],[0.8458333333,0.0613302273],[0.8500000000,0.0515635598],[0.8541666667,0.0427088803],[0.8583333333,0.0347551990],[0.8625000000,0.0276878920],[0.8666666667,0.0214889271],[0.8708333333,0.0161369711],[0.8750000000,0.0116076130],[0.8791666667,0.0078735477],[0.8833333333,0.0049047927],[0.8875000000,0.0026688977],[0.8916666667,0.0011311782],[0.8958333333,0.0002549473],[0.9000000000,0.0000000000],[0.9041666667,0.0000000000],[0.9083333333,0.0000000000],[0.9125000000,0.0000000000],[0.9166666667,0.0000000000],[0.9208333333,0.0000000000],[0.9250000000,0.0000000000],[0.9291666667,0.0000000000],[0.9333333333,0.0000000000],[0.9375000000,0.0000000000],[0.9416666667,0.0000000000],[0.9458333333,0.0000000000],[0.9500000000,0.0000000000],[0.9541666667,0.0000000000],[0.9583333333,0.0000000000],[0.9625000000,0.0000000000],[0.9666666667,0.0000000000],[0.9708333333,0.0000000000],[0.9750000000,0.0000000000],[0.9791666667,0.0000000000],[0.9833333333,0.0000000000],[0.9875000000,0.0000000000],[0.9916666667,0.0000000000],[0.9958333333,0.0000000000]]] sun_color: [[[0.5010435645,0.5818710306],[0.0433100000,0.8999700000],[0.8635787716,0.9130000000],[0.1785000000,0.8973600000],[0.8099800000,0.8651100000],[0.2360800000,0.7712700000],[0.6583432177,0.8485126184],[0.1266806142,0.9648102053],[0.9558541267,0.9090909091],[0.5568400771,0.7353760446]],[[0.5001318426,0.5160300000],[0.0572700000,0.6541600000],[0.2395000000,0.5976800000],[0.8104600000,0.6009000000],[0.6967400000,0.5483900000]],[[0.0862400000,0.4257800000],[0.4955600000,0.4033000000],[0.8234200000,0.4340200000]]] - sun_azimuth: [[[0.5000000000,0.2583333333]]] - sun_altitude: [[[0.5000000000,0.5111111111]]] + sun_azimuth: [[[0.5000000000,0.6138888889]]] + sun_altitude: [[[0.5000000000,0.7111111111]]] extinction: [[[0.4913294798,0.6378830084]]] volumetrics: fog_ramp_size: [[[0.5510597303,0.7409470752]]] diff --git a/core/__pycache__/world.cpython-312.pyc b/core/__pycache__/world.cpython-312.pyc index de54a1b7..aa922f7b 100644 Binary files a/core/__pycache__/world.cpython-312.pyc and b/core/__pycache__/world.cpython-312.pyc differ diff --git a/core/world.py b/core/world.py index 3eb4a53e..969e2d21 100644 --- a/core/world.py +++ b/core/world.py @@ -38,33 +38,6 @@ class CoreWorld(Panda3DWorld): self._setupGround() self._loadFont() - #self.start_day_night_cycle(duration_seconds=300.0) - # self.accept("1", lambda: self.set_daytime("4:00")) # 清晨 - # self.accept("2", lambda: self.set_daytime("6:00")) # 中午 - # self.accept("3", lambda: self.set_daytime("8:00")) # 傍晚 - # self.accept("4", lambda: self.set_daytime("10:00")) # 深夜 - # self.accept("5", lambda: self.set_daytime("12:00")) # 深夜 - # self.accept("6", lambda: self.set_daytime("14:00")) # 深夜 - # self.accept("7", lambda: self.set_daytime("16:00")) # 深夜 - # self.accept("8", lambda: self.set_daytime("18:00")) # 深夜 - # self.accept("9", lambda: self.set_daytime("20:00")) # 深夜 - # self.accept("0", lambda: self.set_daytime("22:00")) # 深夜 - # - #self.createDirectionalLight() - #self._setYCModel() - #self._setArm1() - - # 创建示例材质 - #self.load_test_models_with_materials() - - # 设置材质编辑器网络通信 - #self.setup_material_editor_network() - - # 启动材质编辑器 - #self.launch_material_editor() - - #self.launch_plugin_configurator() - print("✓ 核心世界初始化完成") def _setYCModel(self): @@ -128,11 +101,11 @@ class CoreWorld(Panda3DWorld): # 创建支持贴图的材质 mat = Material() - mat.setName("GroundMaterial") # 设置材质名称,便于材质编辑器识别 - color = LColor(0.7, 0.7, 0.7, 1) # 稍微暗一点的灰色 + mat.setName("GroundMaterial") + color = LColor(1, 1, 1, 0.8) mat.set_base_color(color) mat.set_roughness(0.5) # 设置合适的初始粗糙度 - mat.set_metallic(0.1) # 设置较低的初始金属性 + mat.set_metallic(0.5) # 设置较低的初始金属性 self.ground.set_material(mat) # 应用默认PBR效果,确保支持贴图 diff --git a/nul b/nul deleted file mode 100644 index e69de29b..00000000 diff --git a/scripts/Rotate_P.py b/scripts/Rotate_P.py deleted file mode 100644 index 506ddfeb..00000000 --- a/scripts/Rotate_P.py +++ /dev/null @@ -1,740 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -""" -Rotate_P - 自定义脚本,支持动态挂载其他脚本到模型或子物体 -""" - -from core.script_system import ScriptBase - -class RotateP(ScriptBase): - """自定义脚本类 - 支持脚本挂载功能""" - - def __init__(self): - super().__init__() - # 在这里初始化您的变量 - self.mounted_scripts = {} # 存储已挂载的脚本 {object_name: [script_names]} - self.world = None # 世界对象引用 - - def start(self): - """脚本开始时调用 - 当此脚本被挂载时自动执行挂载其他脚本""" - self.log("Rotate_P 脚本开始运行!") - - # 获取世界对象引用 - if hasattr(self.script_manager, 'world'): - self.world = self.script_manager.world - self.log("✓ 获取世界对象引用成功") - - # 当此脚本被挂载时,自动执行脚本挂载操作 - self.auto_mount_scripts_on_start() - else: - self.log("⚠️ 无法获取世界对象引用") - - def auto_mount_scripts_on_start(self): - """ - 当Rotate_P脚本被挂载时自动执行的脚本挂载操作 - 在这里定义要自动挂载的脚本和目标对象 - """ - self.log("=== 开始自动挂载脚本 ===") - - # 获取当前脚本所挂载的对象 - current_object = self.gameObject - current_object_name = current_object.getName() if current_object else "Unknown" - self.log(f"当前脚本挂载在对象: {current_object_name}") - - # 显示当前对象信息 - self.get_current_object_info() - - # ==================== 配置区域 ==================== - # 请根据您的需求选择以下配置之一,或自定义配置 - - # 配置1:机器人式旋转演示(有停顿) - self.setup_rotation_demo(max_angle=45.0, rotation_speed=25.0, robot_mode=True, pause_duration=0.8) - - # 配置2:工业机器人演示(取消注释以使用) - # self.setup_industrial_robot_demo() - - # 配置3:伺服电机演示(取消注释以使用) - # self.setup_servo_motor_demo() - - # 配置4:机器人手臂演示(取消注释以使用) - # self.setup_robot_arm_demo() - - # 配置5:为指定对象挂载机器人旋转脚本(取消注释并修改) - # self.mount_robot_rotator("arm_joint", max_angle=60.0, rotation_speed=15.0, pause_duration=1.0) - # self.mount_robot_rotator("gripper", max_angle=30.0, rotation_speed=20.0, pause_duration=0.5) - - # 配置6:平滑旋转(无停顿)(取消注释以使用) - # self.mount_smooth_rotator("wheel", max_angle=180.0, rotation_speed=90.0) - - # 配置5:自定义挂载配置(取消注释并修改) - # auto_mount_configs = [ - # ("your_model_name", "RotatorScript"), # 将RotatorScript挂载到指定模型 - # ("child_object_name", "MoverScript"), # 将MoverScript挂载到子物体 - # ("another_object", "ScalerScript"), # 将ScalerScript挂载到另一个对象 - # ] - # if auto_mount_configs: - # success_count = self.batch_mount_scripts(auto_mount_configs) - # self.log(f"✓ 自定义挂载完成,成功挂载 {success_count} 个脚本") - - # ==================== 配置区域结束 ==================== - - # 显示使用说明 - self.show_usage_examples() - - # 列出已挂载的脚本 - self.list_mounted_scripts() - - def mount_script_to_current_object(self, script_name): - """ - 将脚本挂载到当前对象(即Rotate_P脚本所在的对象) - - Args: - script_name: 要挂载的脚本名称 - - Returns: - bool: 挂载是否成功 - """ - if not self.gameObject: - self.log("错误: 无法获取当前对象") - return False - - return self.mount_script_to_object(self.gameObject, script_name) - - def auto_mount_to_all_children(self, script_name): - """ - 自动将脚本挂载到当前对象的所有子物体 - - Args: - script_name: 要挂载的脚本名称 - - Returns: - int: 成功挂载的子物体数量 - """ - if not self.gameObject: - self.log("错误: 无法获取当前对象") - return 0 - - # 获取所有子对象 - children = self.gameObject.getChildren() - success_count = 0 - - self.log(f"开始为当前对象的 {len(children)} 个子物体挂载脚本 '{script_name}'") - - for child in children: - if self.mount_script_to_object(child, script_name): - success_count += 1 - - self.log(f"✓ 成功为 {success_count}/{len(children)} 个子物体挂载脚本 '{script_name}'") - return success_count - - def update(self, dt): - """每帧更新""" - # 在这里编写更新逻辑 - pass - - def on_destroy(self): - """脚本销毁时调用""" - self.log("脚本被销毁") - - # ==================== 脚本挂载功能 ==================== - - def mount_script_to_object(self, target_object, script_name, script_config=None): - """ - 将脚本挂载到指定对象上 - - Args: - target_object: 目标对象(Panda3D NodePath) - script_name: 要挂载的脚本名称(字符串) - script_config: 脚本配置参数(字典),可选 - - Returns: - bool: 挂载是否成功 - """ - if not self.world: - self.log("错误: 世界对象引用不可用") - return False - - try: - # 使用世界对象的addScript方法挂载脚本 - success = self.world.addScript(target_object, script_name) - - if success: - # 记录挂载信息 - obj_name = target_object.getName() - if obj_name not in self.mounted_scripts: - self.mounted_scripts[obj_name] = [] - self.mounted_scripts[obj_name].append(script_name) - - # 如果提供了配置参数,尝试配置脚本 - if script_config and script_name == "RotatorScript": - self.configure_rotator_script(target_object, script_config) - - self.log(f"✓ 成功将脚本 '{script_name}' 挂载到对象 '{obj_name}'") - return True - else: - self.log(f"✗ 挂载脚本 '{script_name}' 失败") - return False - - except Exception as e: - self.log(f"✗ 挂载脚本时出错: {str(e)}") - return False - - def configure_rotator_script(self, target_object, config): - """ - 配置已挂载的RotatorScript脚本 - - Args: - target_object: 目标对象 - config: 配置字典,可包含 max_angle, rotation_speed, robot_mode, pause_duration 等 - """ - try: - # 获取对象上的RotatorScript - scripts = self.world.getScripts(target_object) - for script_component in scripts: - if script_component.script_name == "RotatorScript": - script_instance = script_component.script_instance - - # 配置最大角度 - if 'max_angle' in config: - script_instance.set_max_angle(config['max_angle']) - - # 配置旋转速度 - if 'rotation_speed' in config: - script_instance.set_rotation_speed(config['rotation_speed']) - - # 配置机器人模式 - if 'robot_mode' in config: - script_instance.set_robot_mode(config['robot_mode']) - - # 配置停顿时间 - if 'pause_duration' in config: - script_instance.set_pause_duration(config['pause_duration']) - - # 预设模式 - if 'preset_mode' in config: - preset = config['preset_mode'] - if preset == 'slow_robot': - script_instance.set_slow_robot_mode() - elif preset == 'fast_robot': - script_instance.set_fast_robot_mode() - elif preset == 'smooth': - script_instance.set_smooth_mode() - - self.log(f"✓ 已配置 RotatorScript: {config}") - break - except Exception as e: - self.log(f"✗ 配置 RotatorScript 时出错: {str(e)}") - - def unmount_script_from_object(self, target_object, script_name): - """ - 从指定对象卸载脚本 - - Args: - target_object: 目标对象(Panda3D NodePath) - script_name: 要卸载的脚本名称(字符串) - - Returns: - bool: 卸载是否成功 - """ - if not self.world: - self.log("错误: 世界对象引用不可用") - return False - - try: - # 使用世界对象的removeScript方法卸载脚本 - success = self.world.removeScript(target_object, script_name) - - if success: - # 更新挂载记录 - obj_name = target_object.getName() - if obj_name in self.mounted_scripts and script_name in self.mounted_scripts[obj_name]: - self.mounted_scripts[obj_name].remove(script_name) - if not self.mounted_scripts[obj_name]: # 如果列表为空,删除键 - del self.mounted_scripts[obj_name] - - self.log(f"✓ 成功从对象 '{obj_name}' 卸载脚本 '{script_name}'") - return True - else: - self.log(f"✗ 卸载脚本 '{script_name}' 失败") - return False - - except Exception as e: - self.log(f"✗ 卸载脚本时出错: {str(e)}") - return False - - def mount_script_by_name(self, object_name, script_name): - """ - 通过对象名称挂载脚本 - - Args: - object_name: 目标对象名称(字符串) - script_name: 要挂载的脚本名称(字符串) - - Returns: - bool: 挂载是否成功 - """ - if not self.world: - self.log("错误: 世界对象引用不可用") - return False - - # 查找对象 - target_object = self.find_object_by_name(object_name) - if not target_object: - self.log(f"✗ 未找到名为 '{object_name}' 的对象") - return False - - return self.mount_script_to_object(target_object, script_name) - - def find_object_by_name(self, object_name): - """ - 通过名称查找对象 - - Args: - object_name: 对象名称(字符串) - - Returns: - NodePath: 找到的对象,如果未找到则返回None - """ - if not self.world: - return None - - # 首先尝试使用世界的查找方法 - if hasattr(self.world, 'findModelByName'): - obj = self.world.findModelByName(object_name) - if obj: - return obj - - # 如果没有找到,尝试在render下搜索 - if hasattr(self.world, 'render'): - return self.world.render.find(f"**/{object_name}") - - return None - - def get_available_scripts(self): - """ - 获取所有可用的脚本列表 - - Returns: - list: 可用脚本名称列表 - """ - if not self.world: - self.log("错误: 世界对象引用不可用") - return [] - - try: - return self.world.getAvailableScripts() - except Exception as e: - self.log(f"✗ 获取可用脚本列表时出错: {str(e)}") - return [] - - def get_scripts_on_object(self, target_object): - """ - 获取对象上已挂载的脚本 - - Args: - target_object: 目标对象(Panda3D NodePath) - - Returns: - list: 脚本组件列表 - """ - if not self.world: - self.log("错误: 世界对象引用不可用") - return [] - - try: - return self.world.getScripts(target_object) - except Exception as e: - self.log(f"✗ 获取对象脚本时出错: {str(e)}") - return [] - - def list_mounted_scripts(self): - """ - 列出所有已挂载的脚本信息 - """ - self.log("=== 已挂载脚本列表 ===") - if not self.mounted_scripts: - self.log("暂无已挂载的脚本") - return - - for obj_name, script_names in self.mounted_scripts.items(): - self.log(f"对象 '{obj_name}': {', '.join(script_names)}") - - # ==================== 便捷方法 ==================== - - def mount_rotator_script(self, object_name): - """ - 便捷方法:挂载旋转脚本到指定对象 - - Args: - object_name: 目标对象名称 - - Returns: - bool: 挂载是否成功 - """ - return self.mount_script_by_name(object_name, "RotatorScript") - - def mount_mover_script(self, object_name): - """ - 便捷方法:挂载移动脚本到指定对象 - - Args: - object_name: 目标对象名称 - - Returns: - bool: 挂载是否成功 - """ - return self.mount_script_by_name(object_name, "MoverScript") - - def mount_scaler_script(self, object_name): - """ - 便捷方法:挂载缩放脚本到指定对象 - - Args: - object_name: 目标对象名称 - - Returns: - bool: 挂载是否成功 - """ - return self.mount_script_by_name(object_name, "ScalerScript") - - # ==================== 示例使用方法 ==================== - - def example_mount_scripts(self): - """ - 示例:如何使用脚本挂载功能 - 在start()方法中调用此方法来演示脚本挂载 - """ - self.log("=== 脚本挂载示例 ===") - - # 示例1:挂载旋转脚本到特定对象 - # self.mount_rotator_script("your_model_name") - - # 示例2:挂载多个脚本到同一个对象 - # self.mount_script_by_name("your_model_name", "RotatorScript") - # self.mount_script_by_name("your_model_name", "MoverScript") - - # 示例3:查找并挂载脚本到子物体 - # child_object = self.find_object_by_name("child_object_name") - # if child_object: - # self.mount_script_to_object(child_object, "RotatorScript") - - # 示例4:列出可用脚本 - available_scripts = self.get_available_scripts() - self.log(f"可用脚本: {available_scripts}") - - # 示例5:列出已挂载的脚本 - self.list_mounted_scripts() - - def auto_mount_to_children(self, parent_object_name, script_name): - """ - 自动将脚本挂载到指定父对象的所有子物体 - - Args: - parent_object_name: 父对象名称 - script_name: 要挂载的脚本名称 - - Returns: - int: 成功挂载的子物体数量 - """ - if not self.world: - self.log("错误: 世界对象引用不可用") - return 0 - - # 查找父对象 - parent_object = self.find_object_by_name(parent_object_name) - if not parent_object: - self.log(f"✗ 未找到父对象 '{parent_object_name}'") - return 0 - - # 获取所有子对象 - children = parent_object.getChildren() - success_count = 0 - - for child in children: - if self.mount_script_to_object(child, script_name): - success_count += 1 - - self.log(f"✓ 成功为 {success_count}/{len(children)} 个子物体挂载脚本 '{script_name}'") - return success_count - - def batch_mount_scripts(self, object_script_pairs): - """ - 批量挂载脚本 - - Args: - object_script_pairs: 对象-脚本对列表,格式:[(object_name, script_name), ...] - - Returns: - int: 成功挂载的数量 - """ - success_count = 0 - - for object_name, script_name in object_script_pairs: - if self.mount_script_by_name(object_name, script_name): - success_count += 1 - - self.log(f"✓ 批量挂载完成: {success_count}/{len(object_script_pairs)} 个脚本挂载成功") - return success_count - - # ==================== 预设配置方法 ==================== - - def setup_rotation_demo(self, max_angle=30.0, rotation_speed=30.0, robot_mode=True, pause_duration=0.5): - """ - 预设配置:旋转演示 - 为当前对象及其子物体挂载旋转脚本 - - Args: - max_angle: 最大旋转角度(相对于初始角度) - rotation_speed: 旋转速度(度/秒) - robot_mode: 是否启用机器人模式 - pause_duration: 停顿时间(秒) - """ - self.log("=== 设置旋转演示 ===") - - # 配置参数 - config = { - 'max_angle': max_angle, - 'rotation_speed': rotation_speed, - 'robot_mode': robot_mode, - 'pause_duration': pause_duration - } - - # 为当前对象挂载旋转脚本 - self.mount_script_to_current_object_with_config("RotatorScript", config) - - # 为所有子物体挂载旋转脚本 - self.auto_mount_to_all_children_with_config("RotatorScript", config) - - def setup_animation_combo(self): - """ - 预设配置:动画组合 - 为对象挂载多种动画脚本 - """ - self.log("=== 设置动画组合 ===") - - # 为当前对象挂载多个脚本 - scripts_to_mount = ["RotatorScript", "MoverScript", "ScalerScript"] - - for script_name in scripts_to_mount: - self.mount_script_to_current_object(script_name) - - def setup_child_animation(self, script_name="RotatorScript"): - """ - 预设配置:子物体动画 - 只为子物体挂载脚本,不影响父对象 - - Args: - script_name: 要挂载的脚本名称,默认为RotatorScript - """ - self.log(f"=== 设置子物体动画 ({script_name}) ===") - self.auto_mount_to_all_children(script_name) - - def setup_specific_objects(self, object_names, script_name="RotatorScript"): - """ - 预设配置:为指定的对象列表挂载脚本 - - Args: - object_names: 对象名称列表 - script_name: 要挂载的脚本名称 - """ - self.log(f"=== 为指定对象挂载脚本 ({script_name}) ===") - - for obj_name in object_names: - self.mount_script_by_name(obj_name, script_name) - - def setup_robot_arm_demo(self): - """ - 预设配置:机器人手臂演示 - 为不同关节设置不同的机器人旋转参数 - """ - self.log("=== 设置机器人手臂演示 ===") - - # 为当前对象设置慢速机器人模式 - config = {'preset_mode': 'slow_robot'} - self.mount_script_to_current_object_with_config("RotatorScript", config) - - # 为子物体设置快速机器人模式 - config = {'preset_mode': 'fast_robot'} - self.auto_mount_to_all_children_with_config("RotatorScript", config) - - def setup_industrial_robot_demo(self): - """ - 预设配置:工业机器人演示 - 模拟工业机器人的精确停顿动作 - """ - self.log("=== 设置工业机器人演示 ===") - - # 工业机器人配置:慢速、长停顿 - config = { - 'max_angle': 45.0, - 'rotation_speed': 15.0, - 'robot_mode': True, - 'pause_duration': 1.2 - } - - self.mount_script_to_current_object_with_config("RotatorScript", config) - self.auto_mount_to_all_children_with_config("RotatorScript", config) - - def setup_servo_motor_demo(self): - """ - 预设配置:伺服电机演示 - 模拟伺服电机的快速精确定位 - """ - self.log("=== 设置伺服电机演示 ===") - - # 伺服电机配置:快速、短停顿 - config = { - 'max_angle': 60.0, - 'rotation_speed': 50.0, - 'robot_mode': True, - 'pause_duration': 0.2 - } - - self.mount_script_to_current_object_with_config("RotatorScript", config) - self.auto_mount_to_all_children_with_config("RotatorScript", config) - - # ==================== 使用示例和说明 ==================== - - def show_usage_examples(self): - """ - 显示使用示例和说明 - """ - self.log("=== Rotate_P 脚本使用说明 ===") - self.log("此脚本被挂载时会自动执行脚本挂载操作") - self.log("") - self.log("可用的预设配置方法:") - self.log("1. setup_rotation_demo() - 为当前对象和子物体挂载旋转脚本") - self.log("2. setup_animation_combo() - 为当前对象挂载多种动画脚本") - self.log("3. setup_child_animation() - 只为子物体挂载脚本") - self.log("4. setup_specific_objects() - 为指定对象挂载脚本") - self.log("") - self.log("修改 auto_mount_scripts_on_start() 方法来自定义自动挂载行为") - self.log("=== 使用说明结束 ===") - - def get_current_object_info(self): - """ - 获取当前对象的详细信息 - """ - if not self.gameObject: - self.log("错误: 无法获取当前对象") - return - - obj_name = self.gameObject.getName() - children = self.gameObject.getChildren() - child_names = [child.getName() for child in children] - - self.log("=== 当前对象信息 ===") - self.log(f"对象名称: {obj_name}") - self.log(f"子物体数量: {len(children)}") - if child_names: - self.log(f"子物体名称: {', '.join(child_names)}") - else: - self.log("无子物体") - self.log("=== 对象信息结束 ===") - - # ==================== 带配置的便捷方法 ==================== - - def mount_script_to_current_object_with_config(self, script_name, config=None): - """ - 将脚本挂载到当前对象并配置参数 - - Args: - script_name: 脚本名称 - config: 配置参数字典 - - Returns: - bool: 挂载是否成功 - """ - if not self.gameObject: - self.log("错误: 无法获取当前对象") - return False - - return self.mount_script_to_object(self.gameObject, script_name, config) - - def auto_mount_to_all_children_with_config(self, script_name, config=None): - """ - 自动将脚本挂载到当前对象的所有子物体并配置参数 - - Args: - script_name: 要挂载的脚本名称 - config: 配置参数字典 - - Returns: - int: 成功挂载的子物体数量 - """ - if not self.gameObject: - self.log("错误: 无法获取当前对象") - return 0 - - # 获取所有子对象 - children = self.gameObject.getChildren() - success_count = 0 - - self.log(f"开始为当前对象的 {len(children)} 个子物体挂载脚本 '{script_name}'") - if config: - self.log(f"使用配置: {config}") - - for child in children: - if self.mount_script_to_object(child, script_name, config): - success_count += 1 - - self.log(f"✓ 成功为 {success_count}/{len(children)} 个子物体挂载脚本 '{script_name}'") - return success_count - - def mount_rotator_with_custom_angle(self, object_name, max_angle=45.0, rotation_speed=20.0, robot_mode=True, pause_duration=0.5): - """ - 便捷方法:挂载自定义角度的旋转脚本 - - Args: - object_name: 目标对象名称 - max_angle: 最大旋转角度 - rotation_speed: 旋转速度 - robot_mode: 是否启用机器人模式 - pause_duration: 停顿时间(秒) - - Returns: - bool: 挂载是否成功 - """ - config = { - 'max_angle': max_angle, - 'rotation_speed': rotation_speed, - 'robot_mode': robot_mode, - 'pause_duration': pause_duration - } - - target_object = self.find_object_by_name(object_name) - if not target_object: - self.log(f"✗ 未找到名为 '{object_name}' 的对象") - return False - - return self.mount_script_to_object(target_object, "RotatorScript", config) - - def mount_robot_rotator(self, object_name, max_angle=30.0, rotation_speed=20.0, pause_duration=0.8): - """ - 便捷方法:挂载机器人式旋转脚本 - - Args: - object_name: 目标对象名称 - max_angle: 最大旋转角度 - rotation_speed: 旋转速度 - pause_duration: 停顿时间 - - Returns: - bool: 挂载是否成功 - """ - return self.mount_rotator_with_custom_angle(object_name, max_angle, rotation_speed, True, pause_duration) - - def mount_smooth_rotator(self, object_name, max_angle=45.0, rotation_speed=30.0): - """ - 便捷方法:挂载平滑旋转脚本(无停顿) - - Args: - object_name: 目标对象名称 - max_angle: 最大旋转角度 - rotation_speed: 旋转速度 - - Returns: - bool: 挂载是否成功 - """ - return self.mount_rotator_with_custom_angle(object_name, max_angle, rotation_speed, False, 0.0) diff --git a/scripts/__pycache__/Rotate_P.cpython-312.pyc b/scripts/__pycache__/Rotate_P.cpython-312.pyc deleted file mode 100644 index 7c7e7b98..00000000 Binary files a/scripts/__pycache__/Rotate_P.cpython-312.pyc and /dev/null differ