2015-08-16 32 views
5

Ich versuche OBJ (versucht anders) auf Server mit node.js und three.js zu importieren - Ich habe diesen Fehler nach Analysedatei. Dies ist aktuelle Code, wie ich Geometrie importieren:three.js TypeError: Eigenschaft 'center' von undefined kann nicht gelesen werden

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

Hier ist Call-Stack:

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) 

Ich weiß, dass dieses Problem bekannt war https://github.com/mrdoob/three.js/pull/3748, aber ich kann nicht herausgefunden, wie diese Fehler zu beheben.

+0

Wird das Modell ohne Verwendung von Material geladen? Wenn nicht, dann ist etwas falsch mit Ihrem Modellcode – mrapsogos

+0

@mrapsogos Modell ist nur Geometrie (http://pastebin.com/6gAkVmE0) von 3dsmax generieren, so sollte es in Ordnung sein. – Destrosvet

Antwort

10

Ich habe das gleiche Problem seit ich entdeckt, dass Objekte von OBJLoader geladen sind bereits eine THREE.Mesh-Instanz.

So sollten Sie wahrscheinlich das tun:

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

Auch this question und this example on the three.js website sehen.

Verwandte Themen