GLTFLoader error: Cannot read property 'itemStart' of undefined
为了节省12兆字节,我只需要从OBJloader切换到GLTFLoader,就得到了错误:
Uncaught TypeError: Cannot read property 'itemStart' of undefined
html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | <script src="https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/loaders/GLTFLoader.js"> ... // Load the creature function load_creature() { // creature loader var images = [ "./textures/00.jpg", ]; var texture = new THREE.TextureLoader().load( images[0] ); // var loader = new THREE.OBJLoader(); var loader = new THREE.GLTFLoader(); // var creature = './obj/trex.obj' var creature = './gltf/trex.gltf' // Load a glTF resource loader.load( // resource URL './gltf/rex.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' ); } ); // Load creature var trex = load_creature(); |
我是three.js的新手,我看不到哪里出了问题。有什么想法吗?
在项目中打开控制台时,您可以在第一行看到ThreeJS版本:
THREE.WebGLRenderer 96
确保您的GLTFLoader具有相同的版本。因此,在我的情况下为96。
https://rawcdn.githack.com/mrdoob/three.js/r96/examples/js/loaders/GLTFLoader.js
确保将URL的粗体部分修改为ThreeJS版本,以获取正确的代码。
感谢Mugen87提供的信息,我只是想总结一下。
请确保您的