EG/demo/quick_selection_test.py
2025-07-10 09:19:51 +08:00

94 lines
2.6 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
快速选择功能测试
测试修复后的选择功能是否能正确工作
"""
import sys
import os
sys.path.append('..')
from direct.showbase.ShowBase import ShowBase
from panda3d.core import CardMaker, Vec3, Point3, Material, ModelRoot
from PyQt5.QtWidgets import QApplication
def main():
"""运行完整的主程序进行测试"""
print("启动选择功能修复测试...")
# 直接运行主程序
from main import MyWorld
from ui.main_window import setup_main_window
world = MyWorld()
app, main_window = setup_main_window(world)
# 创建一个简单的测试立方体
print("创建测试立方体...")
cm = CardMaker('test_cube')
cm.setFrame(-2, 2, -2, 2)
model_root = world.render.attachNewNode(ModelRoot("TestCube"))
# 创建6个面
for i, (x, y, z, rx, ry, rz) in enumerate([
(0, 0, 2, 0, 0, 0), # 前面
(0, 0, -2, 0, 180, 0), # 后面
(2, 0, 0, 0, 90, 0), # 右面
(-2, 0, 0, 0, -90, 0), # 左面
(0, 2, 0, 90, 0, 0), # 顶面
(0, -2, 0, -90, 0, 0), # 底面
]):
face = model_root.attachNewNode(cm.generate())
face.setPos(x, y, z)
face.setHpr(rx, ry, rz)
# 设置位置和颜色
model_root.setPos(0, 10, 3)
model_root.setColor(0.8, 0.3, 0.3, 1.0)
# 创建材质
material = Material()
material.setDiffuse((0.8, 0.3, 0.3, 1.0))
material.setAmbient((0.2, 0.1, 0.1, 1.0))
material.setSpecular((0.5, 0.5, 0.5, 1.0))
material.setShininess(32.0)
model_root.setMaterial(material)
# 设置标签
model_root.setTag("file", "TestCube")
model_root.setTag("is_model_root", "1")
# 添加到场景管理器
world.scene_manager.models.append(model_root)
# 设置碰撞检测
world.scene_manager.setupCollision(model_root)
# 更新场景树
world.scene_manager.updateSceneTree()
print("✓ 测试立方体创建完成")
print("\n=== 测试说明 ===")
print("1. 点击红色立方体测试选择功能")
print("2. 观察控制台输出,确认选择过程")
print("3. 检查是否显示选择框和坐标轴")
print("4. 检查左侧树形控件是否高亮")
print("5. 尝试拖拽坐标轴移动物体")
print("================")
# 启用射线显示用于调试
world.setRayDisplay(True)
print("射线显示已启用")
# 显示窗口
main_window.show()
# 运行应用
sys.exit(app.exec_())
if __name__ == "__main__":
main()