test-model-console.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // 测试模型加载的控制台脚本
  2. console.log('=== 开始测试模型加载 ===');
  3. // 检查 Three.js 是否加载
  4. if (typeof THREE === 'undefined') {
  5. console.error('Three.js 未加载');
  6. } else {
  7. console.log('Three.js 已加载,版本:', THREE.REVISION);
  8. }
  9. // 检查 GLTFLoader 是否加载
  10. if (typeof GLTFLoader === 'undefined') {
  11. console.error('GLTFLoader 未加载');
  12. } else {
  13. console.log('GLTFLoader 已加载');
  14. }
  15. // 检查 Cesium 是否加载
  16. if (typeof window.viewer === 'undefined') {
  17. console.error('Cesium viewer 未初始化');
  18. } else {
  19. console.log('Cesium viewer 已初始化');
  20. }
  21. // 测试模型加载
  22. function testModelLoad() {
  23. console.log('开始测试模型加载');
  24. if (typeof THREE === 'undefined' || typeof GLTFLoader === 'undefined') {
  25. console.error('Three.js 或 GLTFLoader 未加载');
  26. return;
  27. }
  28. const loader = new GLTFLoader();
  29. console.log('GLTFLoader 实例创建成功');
  30. loader.load(
  31. '/models/启闭机.glb',
  32. function (gltf) {
  33. console.log('模型加载成功:', gltf);
  34. console.log('模型场景:', gltf.scene);
  35. console.log('模型部件数量:', gltf.scene.children.length);
  36. },
  37. function (xhr) {
  38. const percent = (xhr.loaded / xhr.total * 100).toFixed(0);
  39. console.log(`加载进度: ${percent}%`);
  40. },
  41. function (error) {
  42. console.error('模型加载失败:', error);
  43. }
  44. );
  45. }
  46. // 导出测试函数
  47. window.testModelLoad = testModelLoad;
  48. console.log('=== 测试脚本加载完成 ===');
  49. console.log('请在控制台中执行 testModelLoad() 来测试模型加载');