test-coordinate.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>坐标系转换测试</title>
  7. <style>
  8. body {
  9. font-family: Arial, sans-serif;
  10. margin: 20px;
  11. background-color: #f5f5f5;
  12. }
  13. .test-container {
  14. max-width: 800px;
  15. margin: 0 auto;
  16. background: white;
  17. padding: 20px;
  18. border-radius: 8px;
  19. box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  20. }
  21. .test-item {
  22. margin: 15px 0;
  23. padding: 15px;
  24. border-left: 4px solid #2196F3;
  25. background: #f9f9f9;
  26. }
  27. .test-item h3 {
  28. margin: 0 0 10px 0;
  29. color: #333;
  30. }
  31. .code-block {
  32. background: #263238;
  33. color: #aed581;
  34. padding: 15px;
  35. border-radius: 4px;
  36. font-family: 'Courier New', monospace;
  37. overflow-x: auto;
  38. margin: 10px 0;
  39. }
  40. .status-info {
  41. color: #2196F3;
  42. font-weight: bold;
  43. }
  44. </style>
  45. </head>
  46. <body>
  47. <div class="test-container">
  48. <h1>🔄 坐标系转换测试</h1>
  49. <p>测试时间: <span id="test-time"></span></p>
  50. <div class="test-item">
  51. <h3>📋 坐标系说明</h3>
  52. <p><strong>Three.js 默认坐标系 (Y-up):</strong></p>
  53. <ul>
  54. <li>Y轴: 朝上 (垂直方向)</li>
  55. <li>Z轴: 朝前 (视线方向)</li>
  56. <li>X轴: 朝右 (水平方向)</li>
  57. </ul>
  58. <p><strong>GLB模型坐标系 (Z-up):</strong></p>
  59. <ul>
  60. <li>Z轴: 朝上 (垂直方向)</li>
  61. <li>Y轴: 朝前 (视线方向)</li>
  62. <li>X轴: 朝右 (水平方向)</li>
  63. </ul>
  64. </div>
  65. <div class="test-item">
  66. <h3>🔧 转换方法</h3>
  67. <p>将 Z-up 坐标系转换为 Y-up 坐标系:</p>
  68. <div class="code-block">
  69. // 方法1: 直接旋转模型
  70. model.rotation.x = -Math.PI / 2
  71. // 方法2: 使用转换工具
  72. import { convertCoordinateSystem } from '../utils/coordinateConverter'
  73. const convertedModel = convertCoordinateSystem(model, 'z-up', 'y-up')
  74. </div>
  75. </div>
  76. <div class="test-item">
  77. <h3>✅ 已实现的功能</h3>
  78. <p>✓ 坐标系转换工具函数 (<code>coordinateConverter.ts</code>)</p>
  79. <p>✓ 自动检测模型坐标系</p>
  80. <p>✓ 支持多种坐标系转换</p>
  81. <p>✓ 坐标系参考轴可视化</p>
  82. <p>✓ 在 Map3DScene.vue 中应用转换</p>
  83. </div>
  84. <div class="test-item">
  85. <h3>📊 使用示例</h3>
  86. <div class="code-block">
  87. // 在模型加载后应用坐标系转换
  88. async function loadModel() {
  89. const loader = new GLTFLoader()
  90. const gltf = await loader.loadAsync(props.modelUrl)
  91. const model = gltf.scene
  92. // 计算包围盒并居中
  93. const box = new THREE.Box3().setFromObject(model)
  94. const center = box.getCenter(new THREE.Vector3())
  95. model.position.sub(center)
  96. // 坐标系转换:Z-up → Y-up
  97. const convertedModel = convertCoordinateSystem(model, 'z-up', 'y-up')
  98. const group = new THREE.Group()
  99. group.add(convertedModel)
  100. map.add(group)
  101. }
  102. </div>
  103. </div>
  104. <div class="test-item">
  105. <h3>🎯 测试建议</h3>
  106. <p>1. 运行开发服务器查看模型显示效果</p>
  107. <p>2. 检查模型方向是否正确</p>
  108. <p>3. 如需调试,可取消注释坐标系参考轴</p>
  109. <p>4. 使用变换面板调整模型位置和旋转</p>
  110. <p class="status-info">💡 提示:如果模型方向仍不正确,可能需要调整旋转角度</p>
  111. </div>
  112. </div>
  113. <script>
  114. document.getElementById('test-time').textContent = new Date().toLocaleString('zh-CN');
  115. console.log('坐标系转换测试页面加载完成');
  116. </script>
  117. </body>
  118. </html>