如果将模型放在小游戏项目下一起打包,在真机上可以正常加载。
但是,如果把模型文件放在远端服务器,下载回来放入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 );
}
);
}
微信小程序开发问题解答
微信小程序开发者回答:
你可以试试使用 FileSystemManager readFile 接口获取文件内容
微信小程序开发者回答:
我修改了适配器里XMLHttpRequest的代码。将wxfile开头的地址改用readFile读取。
本文网址:http://www.91bianli.com/weixinxiaochengxu/35470.html