我的网页中有一个简单的3D对象,由三个js组成,可以完美地在桌面和手机上使用,但不能在平板电脑上使用。这是代码:
<body>
<script src="GLTFLoader.js"></script>
<script src="OrbitControls.js"></script>
<script>
let scene, camera, renderer;
function init() {
scene = new THREE.Scene();
scene.background = new THREE.Color( 0xFFEEEEEE );
camera = new THREE.PerspectiveCamera(8, window.innerWidth / window.innerHeight, 1,50000);
camera.rotation.y = 45 / 180 * Math.PI;
camera.position.x = 800;
camera.position.y = 100;
camera.position.z = 1000;
controls = new THREE.OrbitControls(camera);
controls.addEventListener('change', renderer);
hlight = new THREE.AmbientLight(0x404040, 10);
scene.add(hlight);
renderer = new THREE.WebGLRenderer({
alpha: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
let loader = new THREE.GLTFLoader();
loader.load('assets/scene.gltf', function (gltf) {
car = gltf.scene.children[0]
scene.add(gltf.scene);
animate();
});
}
function animate() {
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
init();
</script>
</body>