function init() {
camera = new THREE.PerspectiveCamera(45, canvas.width / canvas.height, 0.25, 100);
camera.position.set(-5, 3, 10);
camera.lookAt(new THREE.Vector3(0, 2, 0));
scene = new THREE.Scene();
clock = new THREE.Clock();
// lights
var light = new THREE.HemisphereLight(0xffffff, 0x444444);
light.position.set(0, 20, 0);
scene.add(light);
light = new THREE.DirectionalLight(0xffffff);
light.position.set(0, 20, 10);
scene.add(light);
// model
var loader = new THREE.GLTFLoader();
wx.showLoading({
title: '模型加载中',
mask: true
})
loader.load('https://threejs.org/examples/models/gltf/RobotExpressive/RobotExpressive.glb', function (gltf) {
wx.hideLoading()
console.log('load modal success')
model = gltf.scene;
model.scale.set(4,4,4)
scene.add(model);
createGUI(model, gltf.animations)
}, undefined, function (e) {
console.error(e);
wx.hideLoading()
wx.showToast({
title: '模型加载出错',
icon:'error'
})
});
renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setPixelRatio(wx.getSystemInfoSync().pixelRatio);
renderer.setSize(canvas.width, canvas.height);
renderer.gammaOutput = true;
renderer.gammaFactor = 2.2;
const {
OrbitControls
} = registerOrbit(THREE)
controls = new OrbitControls(camera, renderer.domElement);
camera.position.set(5, 5, 10);
controls.update();
}
以上是主要加载模型代码,在开发者工具是完全正常的,真机(iPhone8 plus)有时候无法显示,有时候打开调试模式,真机就能显示,有时候又不行,社区其他人也反馈过多个类似的问题,盼回复