135 lines
4.7 KiB
Python
135 lines
4.7 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
|
||
"""
|
||
坐标轴中心位置测试脚本
|
||
|
||
测试坐标轴是否正确显示在实体中心,并且不被实体遮挡
|
||
"""
|
||
|
||
import sys
|
||
import os
|
||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
|
||
from main import MyWorld
|
||
from PyQt5.QtWidgets import QApplication
|
||
|
||
def test_center_gizmo():
|
||
"""测试坐标轴中心位置显示"""
|
||
|
||
print("=== 坐标轴中心位置测试 ===")
|
||
|
||
# 创建应用程序
|
||
app = QApplication.instance()
|
||
if app is None:
|
||
app = QApplication(sys.argv)
|
||
|
||
# 创建世界
|
||
world = MyWorld()
|
||
|
||
print("\n1. 测试导入模型...")
|
||
|
||
# 查找FBX测试文件
|
||
fbx_files = []
|
||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||
for filename in os.listdir(current_dir):
|
||
if filename.lower().endswith('.fbx'):
|
||
fbx_files.append(os.path.join(current_dir, filename))
|
||
|
||
if not fbx_files:
|
||
print("× 没有找到FBX测试文件")
|
||
return
|
||
|
||
# 导入第一个找到的FBX文件
|
||
test_file = fbx_files[0]
|
||
print(f"导入测试文件: {test_file}")
|
||
|
||
model = world.scene_manager.importModel(test_file)
|
||
if not model:
|
||
print("× 模型导入失败")
|
||
return
|
||
|
||
print("✓ 模型导入成功")
|
||
|
||
print("\n2. 测试选择模型...")
|
||
|
||
# 模拟选择模型
|
||
world.selection.updateSelection(model)
|
||
|
||
if world.selection.selectedNode:
|
||
print("✓ 模型选择成功")
|
||
|
||
# 检查坐标轴是否创建
|
||
if world.selection.gizmo:
|
||
print("✓ 坐标轴创建成功")
|
||
|
||
# 获取模型边界和坐标轴位置
|
||
bounds = model.getBounds()
|
||
if bounds and not bounds.isEmpty():
|
||
center = bounds.getCenter()
|
||
gizmo_pos = world.selection.gizmo.getPos()
|
||
|
||
print(f"\n3. 位置验证:")
|
||
print(f" 模型边界中心: {center}")
|
||
print(f" 坐标轴位置: {gizmo_pos}")
|
||
|
||
# 验证坐标轴是否在中心位置(允许小的浮点误差)
|
||
pos_diff = abs(gizmo_pos.x - center.x) + abs(gizmo_pos.y - center.y) + abs(gizmo_pos.z - center.z)
|
||
if pos_diff < 0.1: # 允许0.1的误差
|
||
print("✓ 坐标轴位置正确设置在实体中心")
|
||
else:
|
||
print(f"× 坐标轴位置不在中心,偏差: {pos_diff}")
|
||
|
||
# 检查渲染设置
|
||
print(f"\n4. 渲染设置验证:")
|
||
print(f" 坐标轴渲染bin: {world.selection.gizmo.getBin()}")
|
||
print(f" 坐标轴深度测试: {world.selection.gizmo.getDepthTest()}")
|
||
print(f" 坐标轴深度写入: {world.selection.gizmo.getDepthWrite()}")
|
||
|
||
if world.selection.gizmoXAxis:
|
||
print(f" X轴渲染bin: {world.selection.gizmoXAxis.getBin()}")
|
||
print(f" X轴深度测试: {world.selection.gizmoXAxis.getDepthTest()}")
|
||
|
||
if world.selection.gizmoYAxis:
|
||
print(f" Y轴渲染bin: {world.selection.gizmoYAxis.getBin()}")
|
||
print(f" Y轴深度测试: {world.selection.gizmoYAxis.getDepthTest()}")
|
||
|
||
if world.selection.gizmoZAxis:
|
||
print(f" Z轴渲染bin: {world.selection.gizmoZAxis.getBin()}")
|
||
print(f" Z轴深度测试: {world.selection.gizmoZAxis.getDepthTest()}")
|
||
|
||
print("✓ 渲染设置已应用")
|
||
else:
|
||
print("× 坐标轴创建失败")
|
||
else:
|
||
print("× 模型选择失败")
|
||
|
||
print("\n5. 测试说明:")
|
||
print(" - 坐标轴现在应该显示在实体的几何中心")
|
||
print(" - 即使部分坐标轴在实体内部,也应该完全可见")
|
||
print(" - 坐标轴具有最高的渲染优先级,不会被任何实体遮挡")
|
||
print(" - 三个轴有独立的渲染优先级:X(201), Y(202), Z(203)")
|
||
|
||
print("\n=== 测试完成 ===")
|
||
|
||
# 启动交互模式让用户查看结果
|
||
print("\n按任意键查看3D场景...")
|
||
input()
|
||
|
||
# 显示3D窗口
|
||
try:
|
||
from ui.main_window import setup_main_window
|
||
app, main_window = setup_main_window(world)
|
||
main_window.show()
|
||
|
||
print("✓ 3D窗口已打开,请验证:")
|
||
print(" 1. 坐标轴是否显示在实体中心")
|
||
print(" 2. 坐标轴是否完全可见(不被实体遮挡)")
|
||
print(" 3. 可以正常点击和拖拽坐标轴")
|
||
|
||
app.exec_()
|
||
except Exception as e:
|
||
print(f"显示3D窗口时出错: {e}")
|
||
|
||
if __name__ == "__main__":
|
||
test_center_gizmo() |