diff --git a/core/selection.py b/core/selection.py index e2a3c639..cb706e2b 100644 --- a/core/selection.py +++ b/core/selection.py @@ -16,7 +16,6 @@ from panda3d.core import (Vec3, Point3, Point2, LineSegs, ColorAttrib, RenderSta from direct.task.TaskManagerGlobal import taskMgr import math - class SelectionSystem: """选择和变换系统类""" @@ -125,9 +124,6 @@ class SelectionSystem: def createSelectionBox(self, nodePath): """为选中的节点创建选择框""" try: - #print(f" 开始创建选择框,目标节点: {nodePath.getName()}") - - # 如果已有选择框,先移除 if self.selectionBox: print(" 移除现有选择框") self.selectionBox.removeNode() @@ -137,21 +133,12 @@ class SelectionSystem: print(" 目标节点为空,取消创建") return - # 创建选择框作为render的子节点,但会实时跟踪目标节点 self.selectionBox = self.world.render.attachNewNode("selectionBox") - self.selectionBoxTarget = nodePath # 保存目标节点引用 - #print(f" 选择框节点创建完成: {self.selectionBox}") + self.selectionBoxTarget = nodePath - # 启动选择框更新任务 taskMgr.add(self.updateSelectionBoxTask, "updateSelectionBox") - #print(" 选择框更新任务已启动") - - # 初始更新选择框 - #print(" 开始初始化选择框几何体...") self.updateSelectionBoxGeometry() - #print(f" ✓ 为节点 {nodePath.getName()} 创建了选择框") - except Exception as e: print(f" ✗ 创建选择框失败: {str(e)}") import traceback @@ -2298,7 +2285,7 @@ class SelectionSystem: view_direction.normalize() # 计算合适的观察距离 - optimal_distance = max(size * 2.0, 5.0) + optimal_distance = max(size * 1, 1.0) # 计算目标摄像机位置 target_cam_pos = center + (view_direction * optimal_distance) diff --git a/core/world.py b/core/world.py index 0f4ec28a..b6fabf41 100644 --- a/core/world.py +++ b/core/world.py @@ -323,8 +323,8 @@ class CoreWorld(Panda3DWorld): self.ground.setP(-90) self.ground.setZ(-1.0) self.ground.setColor(0.8, 0.8, 0.8, 1) - # self.ground.setTag("is_scene_element", "1") - # self.ground.setTag("tree_item_type", "SCENE_NODE") + self.ground.setTag("is_scene_element", "1") + self.ground.setTag("tree_item_type", "SCENE_NODE") # 创建支持贴图的材质 mat = Material() @@ -343,6 +343,8 @@ class CoreWorld(Panda3DWorld): self.ground2.setZ(49) # 在X轴方向偏移 self.ground2.setColor(0.8, 0.8, 0.8, 1) self.ground2.set_material(mat) + self.ground2.setTag("is_scene_element", "1") + self.ground2.setTag("tree_item_type", "SCENE_NODE") # 创建第三个相同的地面,位置在另一个方向 self.ground3 = self.render.attachNewNode(cm.generate()) @@ -352,6 +354,8 @@ class CoreWorld(Panda3DWorld): self.ground3.setZ(49) # 在X轴负方向偏移 self.ground3.setColor(0.8, 0.8, 0.8, 1) self.ground3.set_material(mat) + self.ground3.setTag("is_scene_element", "1") + self.ground3.setTag("tree_item_type", "SCENE_NODE") self.ground4 = self.render.attachNewNode(cm.generate()) # self.ground3.setR(90) @@ -360,6 +364,8 @@ class CoreWorld(Panda3DWorld): self.ground4.setZ(49) # 在X轴负方向偏移 self.ground4.setColor(0.8, 0.8, 0.8, 1) self.ground4.set_material(mat) + self.ground4.setTag("is_scene_element", "1") + self.ground4.setTag("tree_item_type", "SCENE_NODE") self.ground5 = self.render.attachNewNode(cm.generate()) self.ground5.setP(180) @@ -368,6 +374,8 @@ class CoreWorld(Panda3DWorld): self.ground5.setZ(49) # 在X轴负方向偏移 self.ground5.setColor(0.8, 0.8, 0.8, 1) self.ground5.set_material(mat) + self.ground5.setTag("is_scene_element", "1") + self.ground5.setTag("tree_item_type", "SCENE_NODE") self.ground6 = self.render.attachNewNode(cm.generate()) self.ground6.setP(90) @@ -375,6 +383,8 @@ class CoreWorld(Panda3DWorld): self.ground6.setZ(99) # 在X轴负方向偏移 self.ground6.setColor(0.8, 0.8, 0.8, 1) self.ground6.set_material(mat) + self.ground6.setTag("is_scene_element", "1") + self.ground6.setTag("tree_item_type", "SCENE_NODE") # 应用默认PBR效果,确保支持贴图 try: diff --git a/ui/interface_manager.py b/ui/interface_manager.py index e5e0c626..08a8284a 100644 --- a/ui/interface_manager.py +++ b/ui/interface_manager.py @@ -339,6 +339,23 @@ class InterfaceManager: groundItem.setData(0, Qt.UserRole, self.world.ground) groundItem.setData(0,Qt.UserRole + 1, "SCENE_NODE") + ground_nodes = [ + ('ground2','地板2'), + ('ground3','地板3'), + ('ground4','地板4'), + ('ground5','地板5'), + ('ground6','地板6') + ] + + for attr_name,display_name in ground_nodes: + if hasattr(self.world,attr_name): + ground_node = getattr(self.world,attr_name) + if ground_node: + extraGroundItem = QTreeWidgetItem(sceneRoot,[display_name]) + extraGroundItem.setData(0,Qt.UserRole,ground_node) + extraGroundItem.setData(0,Qt.UserRole+1,"SCENE_NODE") + + #添加灯光节点 for light in self.world.Spotlight: if light: