diff --git a/QPanda3D/__pycache__/Panda3DWorld.cpython-312.pyc b/QPanda3D/__pycache__/Panda3DWorld.cpython-312.pyc index 10ce1618..381d3105 100644 Binary files a/QPanda3D/__pycache__/Panda3DWorld.cpython-312.pyc and b/QPanda3D/__pycache__/Panda3DWorld.cpython-312.pyc differ diff --git a/__pycache__/main.cpython-312.pyc b/__pycache__/main.cpython-312.pyc index eb2db67b..54a5c0f5 100644 Binary files a/__pycache__/main.cpython-312.pyc and b/__pycache__/main.cpython-312.pyc differ diff --git a/core/__pycache__/selection.cpython-312.pyc b/core/__pycache__/selection.cpython-312.pyc index 095a7f8e..6269ce7a 100644 Binary files a/core/__pycache__/selection.cpython-312.pyc and b/core/__pycache__/selection.cpython-312.pyc differ diff --git a/core/__pycache__/world.cpython-312.pyc b/core/__pycache__/world.cpython-312.pyc index c02a0d70..c67c8f15 100644 Binary files a/core/__pycache__/world.cpython-312.pyc and b/core/__pycache__/world.cpython-312.pyc differ diff --git a/scene/__pycache__/scene_manager.cpython-312.pyc b/scene/__pycache__/scene_manager.cpython-312.pyc index 3a452c57..bd4f9587 100644 Binary files a/scene/__pycache__/scene_manager.cpython-312.pyc and b/scene/__pycache__/scene_manager.cpython-312.pyc differ diff --git a/scene/__pycache__/util.cpython-312.pyc b/scene/__pycache__/util.cpython-312.pyc index 5fd59c44..307623b1 100644 Binary files a/scene/__pycache__/util.cpython-312.pyc and b/scene/__pycache__/util.cpython-312.pyc differ diff --git a/ui/__pycache__/interface_manager.cpython-312.pyc b/ui/__pycache__/interface_manager.cpython-312.pyc index cd1f489c..6e592b09 100644 Binary files a/ui/__pycache__/interface_manager.cpython-312.pyc and b/ui/__pycache__/interface_manager.cpython-312.pyc differ diff --git a/ui/__pycache__/property_panel.cpython-312.pyc b/ui/__pycache__/property_panel.cpython-312.pyc index 84e451b7..25abb18f 100644 Binary files a/ui/__pycache__/property_panel.cpython-312.pyc and b/ui/__pycache__/property_panel.cpython-312.pyc differ diff --git a/ui/__pycache__/widgets.cpython-312.pyc b/ui/__pycache__/widgets.cpython-312.pyc index 006a12cc..8b12b4d5 100644 Binary files a/ui/__pycache__/widgets.cpython-312.pyc and b/ui/__pycache__/widgets.cpython-312.pyc differ diff --git a/ui/interface_manager.py b/ui/interface_manager.py index eb4fc379..d786dcb9 100644 --- a/ui/interface_manager.py +++ b/ui/interface_manager.py @@ -142,20 +142,121 @@ class InterfaceManager: lightItem = QTreeWidgetItem(sceneRoot,['灯光']) - BLACK_LIST={'','**','temp','collision'} - - def should_skip(node): - name = node.getName() - return name in BLACK_LIST or name.startswith('__') - - def addNodeToTree(node,parentItem,force=False): - if not force and should_skip(node): + # 用于跟踪已添加的节点,避免重复 + added_nodes = set() + + # 检查是否有图标配置 + if not hasattr(self, 'item_icons'): + self.item_icons = { + 'model': None, + 'geometry': None, + 'empty': None, + 'default': None + } + + def _add_children_recursive(parent_item, node_path): + """递归添加子节点到树项 - 使用用户提供的有效方法""" + # 防止重复添加 + node_id = id(node_path) + if node_id in added_nodes: + print(f"⚠️ 跳过重复节点: {node_path.getName()}") return - nodeItem = QTreeWidgetItem(parentItem, [node.getName()]) - nodeItem.setData(0,Qt.UserRole,node) - - for child in node.getChildren(): - addNodeToTree(child,nodeItem,force=False) + added_nodes.add(node_id) + + # 获取所有子节点 + children = node_path.getChildren() + + for i in range(children.getNumPaths()): + child_node = children.getPath(i) + + # 跳过黑名单节点 + child_name = child_node.getName() + if child_name in {'', '**', 'temp', 'collision'} or child_name.startswith('__'): + continue + + # 创建子项 + child_item = QTreeWidgetItem(parent_item) + display_name = child_name or f"Child_{i}" + child_item.setText(0, display_name) + + # 检查是否是几何节点并设置图标 + if child_node.find("**/+GeomNode").isEmpty(): + # 不是几何节点 + if hasattr(self, 'item_icons') and self.item_icons.get('model'): + child_item.setIcon(0, self.item_icons.get('model', self.item_icons['default'])) + display_name += " 📦" # 模型节点标记 + else: + # 是几何节点 + if hasattr(self, 'item_icons') and self.item_icons.get('empty'): + child_item.setIcon(0, self.item_icons.get('empty', self.item_icons['default'])) + display_name += " 🔷" # 几何节点标记 + + # 更新显示名称 + child_item.setText(0, display_name) + + # 存储NodePath引用 + child_item.setData(0, Qt.UserRole, child_node) + + # 添加节点信息到提示 + node_info = [] + if hasattr(child_node, 'node') and child_node.node(): + node_info.append(f"类型: {type(child_node.node()).__name__}") + if child_node.getNumChildren() > 0: + node_info.append(f"子节点: {child_node.getNumChildren()}") + if hasattr(child_node, 'getTags') and child_node.getTags(): + tags = [f"{k}:{v}" for k, v in child_node.getTags().items()] + node_info.append(f"标签: {', '.join(tags)}") + + if node_info: + child_item.setToolTip(0, "\n".join(node_info)) + + print(f"+ 添加节点: {display_name}") + + # 递归处理子节点的子节点 + if child_node.getNumChildren() > 0: + _add_children_recursive(child_item, child_node) + + def addNodeToTree(node, parentItem, force=True): + """添加单个节点到树 - 包装函数""" + node_id = id(node) + if node_id in added_nodes: + print(f"⚠️ 跳过重复根节点: {node.getName()}") + return + added_nodes.add(node_id) + + # 创建根节点项 + display_name = node.getName() or "" + + # 检查是否为GLB模型 + is_glb_model = False + if hasattr(node, 'getTags'): + tags = node.getTags() if hasattr(node, 'getTags') else {} + is_glb_model = any('glb' in str(v).lower() or 'gltf' in str(v).lower() for v in tags.values()) + if not is_glb_model: + node_name = node.getName().lower() if node.getName() else "" + is_glb_model = '.glb' in node_name or '.gltf' in node_name + + if is_glb_model: + display_name += " 🎯 GLB" + print(f"🎯 GLB模型检测到: {display_name}") + else: + display_name += " 📦" + print(f"📦 常规模型: {display_name}") + + nodeItem = QTreeWidgetItem(parentItem, [display_name]) + nodeItem.setData(0, Qt.UserRole, node) + + # 添加根节点信息 + node_info = [] + if hasattr(node, 'node') and node.node(): + node_info.append(f"类型: {type(node.node()).__name__}") + if node.getNumChildren() > 0: + node_info.append(f"子节点: {node.getNumChildren()}") + if node_info: + nodeItem.setToolTip(0, "\n".join(node_info)) + + # 使用改进的递归方法处理子节点 + _add_children_recursive(nodeItem, node) # 递归添加节点及其子节点 # def addNodeToTree(node, parentItem): @@ -177,9 +278,16 @@ class InterfaceManager: # else: # print(f"跳过节点: {child.getName()}") + # 清空去重集合 + added_nodes.clear() + # 添加所有模型及其子节点 - for model in self.world.models: - addNodeToTree(model, modelsItem,force=True) + print(f"\n=== 开始处理 {len(self.world.models)} 个模型 ===") + for i, model in enumerate(self.world.models): + model_name = model.getName() or f"Model_{i}" + print(f"\n--- 处理模型 {i+1}: {model_name} ---") + addNodeToTree(model, modelsItem, force=True) + print("=== 模型处理完成 ===") # 添加所有GUI元素 for gui_element in self.world.gui_elements: @@ -191,10 +299,15 @@ class InterfaceManager: guiElementItem.setData(0, Qt.UserRole, gui_element) print(f"添加GUI元素: {display_name}") - for light_element in self.world.Spotlight: - addNodeToTree(light_element,lightItem) - for light_element in self.world.Pointlight: - addNodeToTree(light_element,lightItem) + # 添加聚光灯 + if hasattr(self.world, 'Spotlight'): + for light_element in self.world.Spotlight: + addNodeToTree(light_element, lightItem, force=True) + + # 添加点光源 + if hasattr(self.world, 'Pointlight'): + for light_element in self.world.Pointlight: + addNodeToTree(light_element, lightItem, force=True) # 添加地板节点 if hasattr(self.world, 'ground'):