test-simple-rotation.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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: 600px;
  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. .solution {
  22. margin: 20px 0;
  23. padding: 15px;
  24. border-left: 4px solid #4CAF50;
  25. background: #f9f9f9;
  26. }
  27. .solution h3 {
  28. margin: 0 0 10px 0;
  29. color: #333;
  30. }
  31. .code {
  32. background: #263238;
  33. color: #aed581;
  34. padding: 15px;
  35. border-radius: 4px;
  36. font-family: monospace;
  37. margin: 10px 0;
  38. }
  39. .status {
  40. padding: 10px;
  41. margin: 10px 0;
  42. border-radius: 4px;
  43. }
  44. .status.info {
  45. background: #e3f2fd;
  46. border-left: 4px solid #2196F3;
  47. }
  48. .status.warning {
  49. background: #fff3e0;
  50. border-left: 4px solid #ff9800;
  51. }
  52. </style>
  53. </head>
  54. <body>
  55. <div class="test-container">
  56. <h1>🔄 简单旋转测试</h1>
  57. <p>测试时间: <span id="test-time"></span></p>
  58. <div class="status info">
  59. <strong>问题:</strong>模型上下颠倒
  60. <br><strong>原因:</strong>GLB模型是Z轴朝上,Three.js是Y轴朝上
  61. </div>
  62. <div class="solution">
  63. <h3>✅ 推荐解决方案</h3>
  64. <p>在模型加载后添加以下代码:</p>
  65. <div class="code">
  66. // 方法1:绕X轴旋转 -90度(最常用)<br>
  67. model.rotation.x = -Math.PI / 2;<br><br>
  68. // 方法2:绕X轴旋转 +90度<br>
  69. model.rotation.x = Math.PI / 2;<br><br>
  70. // 方法3:绕X轴旋转 180度<br>
  71. model.rotation.x = Math.PI;
  72. </div>
  73. </div>
  74. <div class="solution">
  75. <h3>🔧 在项目中的具体修改</h3>
  76. <p>编辑文件:<code>src/scenes/Map3DScene.vue</code></p>
  77. <p>找到模型加载部分,添加旋转代码:</p>
  78. <div class="code">
  79. // 在 model.position.sub(center) 之后添加:<br>
  80. model.rotation.x = -Math.PI / 2; // 或者尝试 +Math.PI / 2
  81. </div>
  82. </div>
  83. <div class="solution">
  84. <h3>📋 完整代码示例</h3>
  85. <div class="code">
  86. async function loadModel() {<br>
  87. const loader = new GLTFLoader()<br>
  88. const gltf = await loader.loadAsync(props.modelUrl)<br>
  89. const model = gltf.scene<br><br>
  90. // 计算包围盒并居中<br>
  91. const box = new THREE.Box3().setFromObject(model)<br>
  92. const center = box.getCenter(new THREE.Vector3())<br>
  93. model.position.sub(center)<br><br>
  94. // 修复上下颠倒问题<br>
  95. model.rotation.x = -Math.PI / 2;<br><br>
  96. const group = new THREE.Group()<br>
  97. group.add(model)<br>
  98. group.position.set(0, 0, 0)<br>
  99. group.rotation.y = THREE.MathUtils.degToRad(5)<br>
  100. map.add(group)<br>
  101. modelGroup = group<br>
  102. }
  103. </div>
  104. </div>
  105. <div class="status warning">
  106. <strong>提示:</strong>如果 -90度 不正确,请尝试 +90度 或 180度。
  107. <br>不同的模型可能需要不同的旋转角度。
  108. </div>
  109. <div class="solution">
  110. <h3>🎯 测试步骤</h3>
  111. <ol>
  112. <li>修改 <code>Map3DScene.vue</code> 添加旋转代码</li>
  113. <li>运行开发服务器 <code>npm run dev</code></li>
  114. <li>查看模型方向是否正确</li>
  115. <li>如不正确,尝试其他旋转角度</li>
  116. </ol>
  117. </div>
  118. </div>
  119. <script>
  120. document.getElementById('test-time').textContent = new Date().toLocaleString('zh-CN');
  121. console.log('简单旋转测试页面加载完成');
  122. </script>
  123. </body>
  124. </html>