shaogen1995 5 月之前
父节点
当前提交
066a7f9047
共有 2 个文件被更改,包括 10 次插入10 次删除
  1. 1 1
      package.json
  2. 9 9
      src/pages/A1home/index.tsx

+ 1 - 1
package.json

@@ -68,4 +68,4 @@
     "react-app-rewired": "^2.2.1"
   },
   "homepage": "."
-}
+}

+ 9 - 9
src/pages/A1home/index.tsx

@@ -40,15 +40,14 @@ function A1home() {
     // 获取地址栏参数
     const fileName = window.location.href.split('?m=')[1]
 
-    if (!fileName) return alert('参数错误')
-
     const rgbeLoader = new RGBELoader().setPath('./modelFile/')
 
     const usdzLoader = new USDZLoader1().setPath('./modelFile/')
 
     let textureProgress = 0,
       modelProgress = 0
-    try {
+
+    if (fileName.endsWith('.usdz')) {
       camera.current.position.set(0, 0.75, -3.5)
 
       // 加载资源(改用回调形式)
@@ -98,9 +97,8 @@ function A1home() {
       model.position.y = 0.25
       model.position.z = -0.25
       scene.current.add(model)
-    } catch (error) {
-      console.log(123, error)
-      if (1 + 1 === 2) return
+    } else if (fileName.endsWith('.glb')) {
+      // if (1 + 1 === 2) return
       console.log('usdz是二进制,转成glb格式')
 
       camera.current.position.set(0, 0.75, 0.75)
@@ -117,14 +115,16 @@ function A1home() {
       // 加载管理器与进度处理
       const loadingManager = new THREE.LoadingManager()
       loadingManager.onProgress = (url, loaded, total) => {
-        setLoding((loaded / total) * 100)
+        if ((loaded / total) * 100 >= 100) {
+          setLoding((loaded / total) * 100)
+        }
       }
       loadingManager.onLoad = () => {}
 
       // 加载GLB模型
       const loader = new GLTFLoader(loadingManager)
       loader.load(
-        `./modelFile/${fileName.replace('usdz', 'glb')}`,
+        `./modelFile/${fileName}`,
         (gltf: any) => {
           const model = gltf.scene
           scene.current.add(model)
@@ -148,7 +148,7 @@ function A1home() {
         // (xhr: any) => console.log('加载进度:', xhr.loaded / xhr.total),
         // (error: any) => console.error('加载失败:', error)
       )
-    }
+    } else alert('参数错误')
 
     // renderer