three.js TypeError: Cannot read property 'center' of undefined -
i trying import obj (tried different) on server node.js , three.js - got error after parse file. current code how import geometry:
var loader = new three.objloader(); loader.load(modelpath, function (geometryobj) { var materialobj = new three.meshbasicmaterial( { vertexcolors: three.facecolors, overdraw: 0.5 } ); mesh = new three.mesh(geometryobj, materialobj); scene.add(mesh);
here call stack:
this.center.copy( sphere.center ); typeerror: cannot read property 'center' of undefined @ three.sphere.copy (eval @ <anonymous> (/lib/three.js:32:3), <anonymous>:6074:27) @ three.frustum.intersectsobject (eval @ <anonymous> (/lib/three.js:32:3), <anonymous>:6253:11) @ eval (eval @ <anonymous> (/lib/three.js:32:3), <anonymous>:36578:53) @ three.object3d.traversevisible (eval @ <anonymous> (/lib/three.js:32:3), <anonymous>:7943:3) @ three.object3d.traversevisible (eval @ <anonymous> (/lib/three.js:32:3), <anonymous>:7947:23) @ projectscene (eval @ <anonymous> (/lib/three.js:32:3), <anonymous>:36568:9) @ render (eval @ <anonymous> (/lib/three.js:32:3), <anonymous>:35449:28)
i know known issue https://github.com/mrdoob/three.js/pull/3748 , cannot figured out how fix error.
i've got same problem since discovered objects loaded objloader three.mesh instance.
so should :
var loader = new three.objloader(); loader.load(modelpath, function(object) { // if want add custom material var materialobj = new three.meshbasicmaterial({ vertexcolors: three.facecolors, overdraw: 0.5 }); object.traverse(function(child) { if (child instanceof three.mesh) { child.material = materialobj; } }); // directly add object scene.add(object); });
also see this question , this example on three.js website.
Comments
Post a Comment