2015-08-16 7 views
5

node.js ve three.js ile sunucuda import OBJ (farklı çalıştı) çalışıyorum - Ayrıştırma dosyasından sonra bu hatayı aldım. Bu benim geometri içe nasıl geçerli kod: Burada three.js TypeError: undefined özelliği 'center' özelliği okunamıyor

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); 

çağrı yığını:

this.center.copy(sphere.center); 
TypeError: Cannot read property 'center' of undefined 
at THREE.Sphere.copy (eval at <anonymous> (/lib/three.js:32:3), <anonymous>:6074:27) 
at THREE.Frustum.intersectsObject (eval at <anonymous> (/lib/three.js:32:3), <anonymous>:6253:11) 
at eval (eval at <anonymous> (/lib/three.js:32:3), <anonymous>:36578:53) 
at THREE.Object3D.traverseVisible (eval at <anonymous> (/lib/three.js:32:3), <anonymous>:7943:3) 
at THREE.Object3D.traverseVisible (eval at <anonymous> (/lib/three.js:32:3), <anonymous>:7947:23) 
at projectScene (eval at <anonymous> (/lib/three.js:32:3), <anonymous>:36568:9) 
at render (eval at <anonymous> (/lib/three.js:32:3), <anonymous>:35449:28) 

Ben bu sorunu https://github.com/mrdoob/three.js/pull/3748 bilindiğini biliyorum, ama bu hatayı düzeltmek için nasıl düşündüm olamaz.

+0

Model malzeme kullanmadan yüklenmiş mi? Bu durumda, model kodunuzda bir sorun yoksa – mrapsogos

+0

@mrapsogos Model sadece geometridir (http://pastebin.com/6gAkVmE0) 3dsmax tarafından oluşturulur ve bu yüzden tamam olmalıdır. – Destrosvet

cevap

10

OBJLoader tarafından yüklenen nesnelerin zaten bir THREE.Mesh örneği olduğunu keşfettiğimden beri aynı soruna sahibim.

Yani muhtemelen bunu olmalıdır:

var loader = new THREE.OBJLoader(); 
loader.load(modelPath, function(object) { 

    // if you want to add your 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; 
     } 
    }); 

    // then directly add the object 
    scene.add(object); 
}); 

Ayrıca this question ve this example on the three.js website bakın.