问题
I'm trying to follow the examples in that book in order to learn the Three.js library "Learning Three.js: The JavaScript 3D Library for WebGL" and I also have the example sets downloaded from that github link https://github.com/josdirksen/learning-threejs. Most of the examples are runing fine but some of them raises an error especially the one which loads Wavefront objects with OBJLoader.js file. It raises the following error in run time
Uncaught TypeError: undefined is not a function VM12649 OBJLoader.js:66
Corresponding portion of OBJLoader.js is
function meshN( meshName, materialName ) {
if ( geometry.vertices.length > 0 ) {
geometry.mergeVertices();
geometry.computeCentroids(); //EXCEPTION RASED HERE !!!!!
geometry.computeFaceNormals();
geometry.computeBoundingSphere();
object.add( mesh );
geometry = new THREE.Geometry();
mesh = new THREE.Mesh( geometry, material );
verticesCount = 0;
}
回答1:
You have downloaded the latest version of the three.js library (probably r68) but the examples are written against version r63 so somethings have changed.
As you can see at https://github.com/mrdoob/three.js/releases in r67 the method computeCentroids
was removed from the Geometry
.
来源:https://stackoverflow.com/questions/26322640/error-in-objloader-of-three-js-lilbrary