小游戏中用threejs加载gltf模型问题
如果将模型放在小游戏项目下一起打包,在真机上可以正常加载。 但是,如果把模型文件放在远端服务器,下载回来放入wx.env.USER_DATA_PATH目录后就无法加载。 [图片] var loader = new THREE.GLTFLoader(); // Load a glTF resource loader.load( // resource URL wx.env.USER_DATA_PATH + '/res/penguin.gltf', // called when the resource is loaded function ( gltf ) { let gltfScene : THREE.Scene = gltf.scene; let gltfMesh = gltfScene.children[0].children[1] as THREE.Mesh; PGeometry = gltfMesh; console.log(gltf); Anim = gltf.animations[0] as THREE.AnimationClip; RootBone = gltfScene.children[0] as THREE.Bone; RootBone.scale.set(3, 3, 3); RootBone.position.set(0,0,-5); scene.add(RootBone); mixer = new THREE.AnimationMixer(RootBone); let action = mixer.clipAction(Anim); action.play(); }, // called while loading is progressing function ( xhr ) { console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' ); }, // called when loading has errors function ( error ) { console.log( 'An error happened: ' + error ); } ); }