diff --git a/RenderPipelineFile/config/daytime.yaml b/RenderPipelineFile/config/daytime.yaml index 140ea957..af9861ed 100644 --- a/RenderPipelineFile/config/daytime.yaml +++ b/RenderPipelineFile/config/daytime.yaml @@ -17,7 +17,7 @@ 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.6666666667]]] + sun_azimuth: [[[0.5000000000,0.5000000000]]] sun_altitude: [[[0.5000000000,1.0000000000]]] extinction: [[[0.4913294798,0.6378830084]]] volumetrics: diff --git a/__pycache__/main.cpython-312.pyc b/__pycache__/main.cpython-312.pyc index e35aa17c..c1b6b806 100644 Binary files a/__pycache__/main.cpython-312.pyc and b/__pycache__/main.cpython-312.pyc differ diff --git a/core/__pycache__/CustomMouseController.cpython-312.pyc b/core/__pycache__/CustomMouseController.cpython-312.pyc index 4c3504de..3005ff4f 100644 Binary files a/core/__pycache__/CustomMouseController.cpython-312.pyc and b/core/__pycache__/CustomMouseController.cpython-312.pyc differ diff --git a/core/__pycache__/selection.cpython-312.pyc b/core/__pycache__/selection.cpython-312.pyc index da8b40dd..68ef7ea4 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 31895cc1..ebe521bc 100644 Binary files a/core/__pycache__/world.cpython-312.pyc and b/core/__pycache__/world.cpython-312.pyc differ diff --git a/core/selection.py b/core/selection.py index 8f2c020c..d1c62a24 100644 --- a/core/selection.py +++ b/core/selection.py @@ -1187,44 +1187,32 @@ class SelectionSystem: # 检查目标节点是否有父节点 parent_node = self.gizmoTarget.getParent() - # 确定轴向量的变换上下文 - if parent_node and parent_node != self.world.render: - # 子节点:使用父节点的局部坐标系 - print(f"子节点拖拽 - 父节点: {parent_node.getName()}, 父节点旋转: {parent_node.getHpr()}") - transform_context = parent_node - else: - # 顶级模型:使用世界坐标系 - print(f"顶级模型拖拽 - 使用世界坐标系") - transform_context = self.world.render - # 计算轴向量在正确坐标系中的方向 if self.dragGizmoAxis == "x": - # 在变换上下文中的X轴方向 + # 在局部坐标系中的X轴方向 local_axis_vector = Vec3(1, 0, 0) elif self.dragGizmoAxis == "y": - # 在变换上下文中的Y轴方向 + # 在局部坐标系中的Y轴方向 local_axis_vector = Vec3(0, 1, 0) elif self.dragGizmoAxis == "z": - # 在变换上下文中的Z轴方向 + # 在局部坐标系中的Z轴方向 local_axis_vector = Vec3(0, 0, 1) else: print(f"拖拽更新失败: 未知轴类型 {self.dragGizmoAxis}") return - # 将局部轴向量转换到世界坐标系(用于屏幕投影) - if transform_context != self.world.render: - # 获取变换矩阵并应用到轴向量上 - transform_mat = transform_context.getMat(self.world.render) - # 只旋转向量,不平移 + # 确定轴向量的变换上下文 + if parent_node and parent_node != self.world.render: + # 子节点:使用父节点的局部坐标系 + # print(f"子节点拖拽 - 父节点: {parent_node.getName()}, 父节点旋转: {parent_node.getHpr()}") + # transform_context = parent_node + transform_mat = parent_node.getMat(self.world.render) world_axis_vector = transform_mat.xformVec(local_axis_vector) - world_axis_vector.normalize() # 归一化 - print(f"转换后的轴向量: {local_axis_vector} -> {world_axis_vector}") else: - # 顶级节点,直接使用世界轴向量 world_axis_vector = local_axis_vector - print(f"世界轴向量: {world_axis_vector}") - - # 计算轴的端点位置(用于屏幕投影) + # 顶级模型:使用世界坐标系 + # print(f"顶级模型拖拽 - 使用世界坐标系") + # transform_context = self.world.render axis_end = gizmo_world_pos + world_axis_vector # 投影到屏幕空间 @@ -1279,83 +1267,62 @@ class SelectionSystem: projected_distance = (mouseDeltaX * screen_axis_dir[0] + mouseDeltaY * screen_axis_dir[1]) - # 计算动态比例因子,基于相机距离和视野角度 - cam_pos = self.world.cam.getPos() - distance_to_object = (cam_pos - gizmo_world_pos).length() + scale_adjustment = 1.0 + if parent_node and parent_node!= self.world.render: + current_node = parent_node + total_scale = 1.0 + while current_node and current_node != self.world.render: + node_scale = current_node.getScale() + avg_scale = (node_scale.x+node_scale.y + node_scale.z)/3.0 + total_scale *= avg_scale + current_node = current_node.getParent() + if total_scale>0: + scale_adjustment = 1.0 / total_scale + # parent_scale = parent_node.getScale() + # avg_scale = (parent_scale.x+parent_scale.y+parent_scale.z)/3.0 + # if avg_scale>0: + # scale_adjustment = 1.0 / avg_scale - # 获取相机的视野角度 - fov = self.world.cam.node().getLens().getFov()[0] # 水平视野角度 - fov_radians = math.radians(fov) - # 获取窗口尺寸 - winWidth, winHeight = self.world.getWindowSize() + fixed_pixel_to_world_ratio = 0.01 # 1像素 = 0.01世界单位 + scale_factor = fixed_pixel_to_world_ratio * scale_adjustment - # 计算一个像素在世界坐标系中的大小(在目标物体的距离处) - # 使用透视投影公式:world_size = screen_size * distance * tan(fov/2) / (screen_width/2) - pixel_to_world_ratio = distance_to_object * math.tan(fov_radians / 2) / (winWidth / 2) - - # 【改进修复】:智能缩放补偿,区分继承缩放和本体缩放 - # 计算父节点链的累积缩放(不包括目标节点本身) - parent_cumulative_scale = 1.0 - current_node = self.gizmoTarget.getParent() - while current_node and current_node != self.world.render: - node_scale = current_node.getScale() - # 使用缩放的几何平均值作为累积因子 - scale_magnitude = (abs(node_scale.x) * abs(node_scale.y) * abs(node_scale.z)) ** (1.0/3.0) - parent_cumulative_scale *= scale_magnitude - current_node = current_node.getParent() - - # 获取目标节点自身的缩放 - target_scale = self.gizmoTarget.getScale() - target_scale_magnitude = (abs(target_scale.x) * abs(target_scale.y) * abs(target_scale.z)) ** (1.0/3.0) - - # 智能补偿策略: - # 1. 只对父节点链的小缩放进行完全补偿(这通常是单位转换导致的) - # 2. 对目标节点自身的缩放进行部分补偿(避免大模型缩小后移动过快) - parent_compensation = 1.0 / parent_cumulative_scale if parent_cumulative_scale > 0 else 1.0 - - # 对目标节点自身的缩放使用平方根补偿,减少过度补偿 - target_compensation = 1.0 / math.sqrt(target_scale_magnitude) if target_scale_magnitude > 0 else 1.0 - - # 限制目标补偿的最大值,避免移动过快 - target_compensation = min(target_compensation, 10.0) # 最大10倍补偿 - - # 综合补偿因子 - total_compensation = parent_compensation * target_compensation - scale_factor = pixel_to_world_ratio * 0.5*total_compensation - - # 【关键修复】:在正确的坐标系中计算移动向量 - # 计算移动距离(标量) movement_distance = projected_distance * scale_factor - - # 在正确的坐标系中计算移动向量 - if transform_context != self.world.render: - # 子节点:在父节点的局部坐标系中移动 - if self.dragGizmoAxis == "x": - movement_local = Vec3(movement_distance, 0, 0) - elif self.dragGizmoAxis == "y": - movement_local = Vec3(0, movement_distance, 0) - elif self.dragGizmoAxis == "z": - movement_local = Vec3(0, 0, movement_distance) - - # 将局部移动向量转换到父节点的坐标系中 - # 由于我们要应用到目标节点上,而目标节点相对于父节点,我们直接使用局部移动 - movement = movement_local - print(f"子节点移动向量(局部): {movement}") + # 获取当前位置并只修改选中轴的坐标 + currentPos = self.gizmoTargetStartPos + + # 根据拖拽的轴,只修改对应的坐标分量 + if self.dragGizmoAxis == "x": + newPos = Vec3(currentPos.x + movement_distance, currentPos.y, currentPos.z) + print(f"X轴移动:{currentPos.x} -> {newPos.x}") + elif self.dragGizmoAxis == "y": + newPos = Vec3(currentPos.x, currentPos.y + movement_distance, currentPos.z) + print(f"Y轴移动:{currentPos.y} -> {newPos.y}") + elif self.dragGizmoAxis == "z": + newPos = Vec3(currentPos.x, currentPos.y, currentPos.z + movement_distance) + print(f"Z轴移动:{currentPos.z} -> {newPos.z}") else: - # 顶级模型:在世界坐标系中移动 - if self.dragGizmoAxis == "x": - movement = Vec3(movement_distance, 0, 0) - elif self.dragGizmoAxis == "y": - movement = Vec3(0, movement_distance, 0) - elif self.dragGizmoAxis == "z": - movement = Vec3(0, 0, movement_distance) - print(f"顶级模型移动向量(世界): {movement}") - - # 应用移动到目标节点 - newPos = self.gizmoTargetStartPos + movement - self.gizmoTarget.setPos(newPos) + print(f"未知轴: {self.dragGizmoAxis}") + return + + # 应用新位置到目标节点 + light_object = self.gizmoTarget.getPythonTag("rp_light_object") + if light_object: + light_object.pos = newPos + self.gizmoTarget.setPos(newPos) + else: + self.gizmoTarget.setPos(newPos) + + # 更新坐标轴位置 - 计算新的中心位置 + minPoint = Point3() + maxPoint = Point3() + if self.gizmoTarget.calcTightBounds(minPoint, maxPoint, self.world.render): + center = Point3((minPoint.x + maxPoint.x) * 0.5, + (minPoint.y + maxPoint.y) * 0.5, + (minPoint.z + maxPoint.z) * 0.5) + self.gizmo.setPos(center) + # 实时更新属性面板 self.world.property_panel.refreshModelValues(self.gizmoTarget) # 每次拖拽都输出调试信息(但限制频率) @@ -1365,18 +1332,9 @@ class SelectionSystem: import time current_time = time.time() if current_time - self._last_drag_debug_time > 0.1: # 每0.1秒最多输出一次 - print(f"拖拽更新成功 - 轴:{self.dragGizmoAxis}, 距离:{distance_to_object:.2f}, 比例:{scale_factor:.6f}, 投影:{projected_distance:.2f}") + print(f"拖拽更新成功 - 轴:{self.dragGizmoAxis}, 比例:{scale_factor:.6f}, 投影:{projected_distance:.2f}") self._last_drag_debug_time = current_time - newPos = self.gizmoTargetStartPos + movement - light_object = self.gizmoTarget.getPythonTag("rp_light_object") - if light_object: - light_object.pos = newPos - self.gizmoTarget.setPos(newPos) - else: - self.gizmoTarget.setPos(newPos) - self.gizmo.setPos(newPos) - except Exception as e: print(f"更新坐标轴拖拽失败: {str(e)}") import traceback diff --git a/scene/__pycache__/scene_manager.cpython-312.pyc b/scene/__pycache__/scene_manager.cpython-312.pyc index 4bded081..17a23d1f 100644 Binary files a/scene/__pycache__/scene_manager.cpython-312.pyc and b/scene/__pycache__/scene_manager.cpython-312.pyc differ diff --git a/ui/main_window.py b/ui/main_window.py index 53cc3e35..a853f494 100644 --- a/ui/main_window.py +++ b/ui/main_window.py @@ -405,7 +405,8 @@ class MainWindow(QMainWindow): self.createPointLight.clicked.connect(lambda :self.world.createPointLight()) # 连接树节点点击信号 - self.treeWidget.itemClicked.connect(self.world.onTreeItemClicked) + # self.treeWidget.itemClicked.connect(self.world.onTreeItemClicked) + self.treeWidget.itemSelectionChanged.connect(lambda :self.world.onTreeItemClicked(self.treeWidget.currentItem(), 0)) print("已连接点击信号") # 连接工具切换信号 diff --git a/ui/property_panel.py b/ui/property_panel.py index 6fcfb4aa..6905826b 100644 --- a/ui/property_panel.py +++ b/ui/property_panel.py @@ -877,7 +877,7 @@ class PropertyPanelManager: print(f"材质基础颜色: {base_color}") # 基础颜色标题 - color_row = 2 if material_status != "标准PBR材质" else 0 + color_row = 2 if material_status != "标准PBR材质" else 1 material_layout.addWidget(QLabel("基础颜色"), color_row, 0) # R, G, B 标签 @@ -3870,20 +3870,15 @@ class PropertyPanelManager: azimuth, altitude = presets[preset_name] # 更新滑块和数值框 - self.sun_azimuth_slider.blockSignals(True) - self.sun_azimuth_spinbox.blockSignals(True) - self.sun_altitude_slider.blockSignals(True) - self.sun_altitude_spinbox.blockSignals(True) + # 更新滑块和数值框 + self.azimuthSpinBox.blockSignals(True) + self.altitudeSpinBox.blockSignals(True) - self.sun_azimuth_slider.setValue(azimuth) - self.sun_azimuth_spinbox.setValue(azimuth) - self.sun_altitude_slider.setValue(altitude) - self.sun_altitude_spinbox.setValue(altitude) + self.azimuthSpinBox.setValue(azimuth) + self.altitudeSpinBox.setValue(altitude) - self.sun_azimuth_slider.blockSignals(False) - self.sun_azimuth_spinbox.blockSignals(False) - self.sun_altitude_slider.blockSignals(False) - self.sun_altitude_spinbox.blockSignals(False) + self.azimuthSpinBox.blockSignals(False) + self.altitudeSpinBox.blockSignals(False) # 应用设置 - 优先使用Day Time Editor azimuth_success = self._updateDayTimeEditorSetting("scattering", "sun_azimuth", azimuth)