test-rotation.html 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 #ff9800;
  25. background: #f9f9f9;
  26. }
  27. .test-item h3 {
  28. margin: 0 0 10px 0;
  29. color: #333;
  30. }
  31. .rotation-controls {
  32. display: grid;
  33. grid-template-columns: 1fr 1fr;
  34. gap: 15px;
  35. margin: 15px 0;
  36. }
  37. .control-group {
  38. background: #e3f2fd;
  39. padding: 15px;
  40. border-radius: 4px;
  41. }
  42. .control-group h4 {
  43. margin: 0 0 10px 0;
  44. color: #1976d2;
  45. }
  46. .rotation-value {
  47. font-family: monospace;
  48. background: #263238;
  49. color: #aed581;
  50. padding: 5px 10px;
  51. border-radius: 3px;
  52. margin: 5px 0;
  53. }
  54. .test-button {
  55. background: #ff9800;
  56. color: white;
  57. border: none;
  58. padding: 10px 20px;
  59. border-radius: 4px;
  60. cursor: pointer;
  61. margin: 5px;
  62. font-size: 14px;
  63. }
  64. .test-button:hover {
  65. background: #f57c00;
  66. }
  67. .test-button.active {
  68. background: #4CAF50;
  69. }
  70. .info-box {
  71. background: #fff3e0;
  72. border-left: 4px solid #ff9800;
  73. padding: 10px;
  74. margin: 10px 0;
  75. }
  76. </style>
  77. </head>
  78. <body>
  79. <div class="test-container">
  80. <h1>🔄 模型旋转调试</h1>
  81. <p>测试时间: <span id="test-time"></span></p>
  82. <div class="test-item">
  83. <h3>📋 问题描述</h3>
  84. <p>模型上下颠倒,需要找到正确的旋转角度来修正方向。</p>
  85. <div class="info-box">
  86. <strong>当前情况:</strong> 模型显示上下颠倒
  87. <br><strong>可能原因:</strong> 坐标系转换旋转方向错误
  88. </div>
  89. </div>
  90. <div class="test-item">
  91. <h3>🔧 旋转调试控制</h3>
  92. <div class="rotation-controls">
  93. <div class="control-group">
  94. <h4>绕X轴旋转</h4>
  95. <div class="rotation-value">当前: <span id="rot-x">0</span>°</div>
  96. <button class="test-button" onclick="rotateX(90)">+90°</button>
  97. <button class="test-button" onclick="rotateX(-90)">-90°</button>
  98. <button class="test-button" onclick="rotateX(180)">+180°</button>
  99. <button class="test-button" onclick="resetRotation('x')">重置</button>
  100. </div>
  101. <div class="control-group">
  102. <h4>绕Y轴旋转</h4>
  103. <div class="rotation-value">当前: <span id="rot-y">0</span>°</div>
  104. <button class="test-button" onclick="rotateY(90)">+90°</button>
  105. <button class="test-button" onclick="rotateY(-90)">-90°</button>
  106. <button class="test-button" onclick="rotateY(180)">+180°</button>
  107. <button class="test-button" onclick="resetRotation('y')">重置</button>
  108. </div>
  109. <div class="control-group">
  110. <h4>绕Z轴旋转</h4>
  111. <div class="rotation-value">当前: <span id="rot-z">0</span>°</div>
  112. <button class="test-button" onclick="rotateZ(90)">+90°</button>
  113. <button class="test-button" onclick="rotateZ(-90)">-90°</button>
  114. <button class="test-button" onclick="rotateZ(180)">+180°</button>
  115. <button class="test-button" onclick="resetRotation('z')">重置</button>
  116. </div>
  117. <div class="control-group">
  118. <h4>预设旋转</h4>
  119. <button class="test-button" onclick="applyPreset('z-up-to-y-up')">Z-up → Y-up</button>
  120. <button class="test-button" onclick="applyPreset('y-up-to-z-up')">Y-up → Z-up</button>
  121. <button class="test-button" onclick="applyPreset('flip-x')">翻转X轴</button>
  122. <button class="test-button" onclick="applyPreset('flip-y')">翻转Y轴</button>
  123. </div>
  124. </div>
  125. </div>
  126. <div class="test-item">
  127. <h3>📊 旋转矩阵</h3>
  128. <div class="rotation-value" id="matrix-display">
  129. [1, 0, 0, 0]<br>
  130. [0, 1, 0, 0]<br>
  131. [0, 0, 1, 0]<br>
  132. [0, 0, 0, 1]
  133. </div>
  134. </div>
  135. <div class="test-item">
  136. <h3>🎯 推荐解决方案</h3>
  137. <p>根据你的描述(模型上下颠倒),最可能的解决方案是:</p>
  138. <div class="info-box">
  139. <strong>方案1:</strong> 绕X轴旋转 +90° (Math.PI/2)
  140. <br><strong>方案2:</strong> 绕X轴旋转 -90° (-Math.PI/2)
  141. <br><strong>方案3:</strong> 绕X轴旋转 180° (Math.PI)
  142. </div>
  143. <p>点击上面的按钮测试不同的旋转效果。</p>
  144. </div>
  145. <div class="test-item">
  146. <h3>📝 代码示例</h3>
  147. <div style="background: #263238; color: #aed581; padding: 15px; border-radius: 4px; font-family: monospace;">
  148. // 在模型加载后应用旋转<br>
  149. model.rotation.x = Math.PI / 2; // +90度<br>
  150. // 或者<br>
  151. model.rotation.x = -Math.PI / 2; // -90度<br>
  152. // 或者<br>
  153. model.rotation.x = Math.PI; // 180度
  154. </div>
  155. </div>
  156. </div>
  157. <script>
  158. let currentRotation = { x: 0, y: 0, z: 0 };
  159. function updateDisplay() {
  160. document.getElementById('rot-x').textContent = Math.round(currentRotation.x * 180 / Math.PI);
  161. document.getElementById('rot-y').textContent = Math.round(currentRotation.y * 180 / Math.PI);
  162. document.getElementById('rot-z').textContent = Math.round(currentRotation.z * 180 / Math.PI);
  163. // 更新矩阵显示
  164. const cosX = Math.cos(currentRotation.x);
  165. const sinX = Math.sin(currentRotation.x);
  166. const cosY = Math.cos(currentRotation.y);
  167. const sinY = Math.sin(currentRotation.y);
  168. const cosZ = Math.cos(currentRotation.z);
  169. const sinZ = Math.sin(currentRotation.z);
  170. document.getElementById('matrix-display').innerHTML =
  171. `[${cosY*cosZ.toFixed(2)}, ${-cosY*sinZ.toFixed(2)}, ${sinY.toFixed(2)}, 0]<br>` +
  172. `[${(sinX*sinY*cosZ + cosX*sinZ).toFixed(2)}, ${(-sinX*sinY*sinZ + cosX*cosZ).toFixed(2)}, ${-sinX*cosY.toFixed(2)}, 0]<br>` +
  173. `[${(-cosX*sinY*cosZ + sinX*sinZ).toFixed(2)}, ${(cosX*sinY*sinZ + sinX*cosZ).toFixed(2)}, ${cosX*cosY.toFixed(2)}, 0]<br>` +
  174. `[0, 0, 0, 1]`;
  175. }
  176. function rotateX(angle) {
  177. currentRotation.x += angle * Math.PI / 180;
  178. updateDisplay();
  179. }
  180. function rotateY(angle) {
  181. currentRotation.y += angle * Math.PI / 180;
  182. updateDisplay();
  183. }
  184. function rotateZ(angle) {
  185. currentRotation.z += angle * Math.PI / 180;
  186. updateDisplay();
  187. }
  188. function resetRotation(axis) {
  189. currentRotation[axis] = 0;
  190. updateDisplay();
  191. }
  192. function applyPreset(preset) {
  193. switch(preset) {
  194. case 'z-up-to-y-up':
  195. currentRotation.x = Math.PI / 2;
  196. break;
  197. case 'y-up-to-z-up':
  198. currentRotation.x = -Math.PI / 2;
  199. break;
  200. case 'flip-x':
  201. currentRotation.x = Math.PI;
  202. break;
  203. case 'flip-y':
  204. currentRotation.y = Math.PI;
  205. break;
  206. }
  207. updateDisplay();
  208. }
  209. // 初始化
  210. document.getElementById('test-time').textContent = new Date().toLocaleString('zh-CN');
  211. updateDisplay();
  212. console.log('旋转调试页面加载完成');
  213. console.log('当前旋转角度:', currentRotation);
  214. </script>
  215. </body>
  216. </html>