为了节省12兆字节,我只需要从OBJloader切换到GLTFLoader即可得到错误:
未捕获的TypeError:无法读取未定义的属性'itemStart'
html
<script src="https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/loaders/GLTFLoader.js"></script>
...
// 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的新手,我看不到哪里出了问题。有什么想法吗?
答案 0 :(得分:3)
在项目中打开控制台时,您可以在第一行看到ThreeJS版本:
THREE.WebGLRenderer 96
确保您的GLTFLoader具有相同的版本。以我为例,是96。
https://rawcdn.githack.com/mrdoob/three.js/r96/examples/js/loaders/GLTFLoader.js
确保将URL的粗体部分修改为ThreeJS版本,以获取正确的代码。
感谢Mugen87提供的信息,我只是想总结一下。
答案 1 :(得分:2)
请确保您的struct Human {
id: i32,
alive: bool,
salary: i32,
}
struct Dog {
id: i32,
alive: bool,
has_fur: bool,
}
库文件和外部示例文件(例如three.js
)来自同一版本。不久前,我们在GLTFLoader
forum中遇到了完全相同的问题,根本原因是所使用文件的版本不匹配。
three.js