我已经完成了一个简单的html来使用three.js及其gltfloader.js加载gltf模型,它在Mozilla上完美运行,但即使没有错误也没有在ie11上显示。我曾尝试使用es6-promise pollyfill,但似乎无法正常工作。我需要它才能在Internet Explorer上工作。我将代码放在此处,主要是示例代码中的复制粘贴。
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>My first three.js app</title>
<style>
body { margin: 0; }
canvas { width: 100%; height: 100% }
</style>
</head>
<body>
<script src="js/three.js"></script>
<script src="js/GLTFLoader.js"></script>
<script src="js/OrbitControl.js"></script>
<script src="js/es6-promise.min.js"></script>
<script src="js/es6-promise.js"></script>
<script src="js/es6-promise.auto.js"></script>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );
var controls = new THREE.OrbitControls( camera );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
controls.screenSpacePanning = true;
scene.background = new THREE.Color( 0xefe3a7 );
camera.position.z = 5;
controls.update();
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
var cube = new THREE.Mesh( geometry, material );
scene.add( cube );
var animate = function () {
requestAnimationFrame( animate );
renderer.render( scene, camera );
};
light = new THREE.HemisphereLight( 0xbbbbff, 0x444422 );
light.position.set( 0, 1, 0 );
scene.add( light );
// Instantiate a loader
var loader = new THREE.GLTFLoader();
// Load a glTF resource
loader.load(
// resource URL
'DUCK/Duck.gltf',
// called when the resource is loaded
function ( gltf ) {
scene.add( gltf.scene );
gltf.animations; // Array<THREE.AnimationClip>
gltf.scene; // THREE.Scene
gltf.scenes; // Array<THREE.Scene>
gltf.cameras; // Array<THREE.Camera>
gltf.asset; // Object
},
// 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' );
}
);
animate();
</script>
</body>
</html>
编辑:该框仅供参考,表明只有gltf模型不起作用,该框在ie11上显示正常。
编辑2 :Threejs网站上的gltf loader example在ie11上也不起作用。这是否意味着加载程序与ie11不兼容?
答案 0 :(得分:0)
这是我的解决方法:
在html中导入ES6支持polyfill
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js"></script>
如果您的页面仍未显示gltf模型,则可能需要执行以下操作: 更改GLTFLoader.js中的功能 parse
var json = JSON.parse(content)
到
var json = eval('('+content+')')
myBrowser:IE 11.0.9600.17843IS