test-model-simple.html 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. margin: 0;
  10. font-family: Arial, sans-serif;
  11. }
  12. #info {
  13. padding: 20px;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <div id="info">
  19. <h1>模型加载测试</h1>
  20. <p>测试 GLTFLoader 是否能正常工作</p>
  21. <div id="status">准备测试...</div>
  22. <button onclick="testModelLoad()">测试模型加载</button>
  23. </div>
  24. <script type="importmap">
  25. {
  26. "imports": {
  27. "three": "https://unpkg.com/three@0.160.0/build/three.module.js",
  28. "three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/"
  29. }
  30. }
  31. </script>
  32. <script type="module">
  33. import * as THREE from 'three';
  34. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  35. console.log('Three.js 版本:', THREE.REVISION);
  36. console.log('GLTFLoader 加载:', GLTFLoader);
  37. window.testModelLoad = function() {
  38. const status = document.getElementById('status');
  39. status.innerHTML = '开始加载模型...';
  40. const loader = new GLTFLoader();
  41. console.log('GLTFLoader 实例创建成功');
  42. loader.load(
  43. '/models/启闭机.glb',
  44. function (gltf) {
  45. console.log('模型加载成功:', gltf);
  46. status.innerHTML = '模型加载成功!';
  47. },
  48. function (xhr) {
  49. const percent = (xhr.loaded / xhr.total * 100).toFixed(0);
  50. status.innerHTML = `加载中: ${percent}%`;
  51. console.log(`加载进度: ${percent}%`);
  52. },
  53. function (error) {
  54. console.error('模型加载失败:', error);
  55. status.innerHTML = '模型加载失败: ' + error.message;
  56. }
  57. );
  58. }
  59. </script>
  60. </body>
  61. </html>