2015-08-16 22 views
5

Tôi đang thử nhập OBJ (đã thử khác) trên máy chủ với node.js và three.js - Tôi nhận được lỗi này sau khi tệp phân tích cú pháp. Đây là mã hiện tại làm thế nào tôi nhập hình học:Loại lỗi 3.js: Không thể đọc thuộc tính 'center' của undefined

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

Đây là cuộc gọi 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) 

Tôi biết rằng điều này đã được biết đến vấn đề https://github.com/mrdoob/three.js/pull/3748, nhưng tôi không thể tìm ra cách để sửa lỗi này.

+0

Mô hình có được nạp mà không cần sử dụng tài liệu không? Nếu không thì có điều gì đó sai với mã mô hình của bạn – mrapsogos

+0

@mrapsogos Mô hình chỉ là hình học (http://pastebin.com/6gAkVmE0) tạo bởi 3dsmax nên nó sẽ ổn. – Destrosvet

Trả lời

10

Tôi gặp vấn đề tương tự vì tôi phát hiện ra rằng các đối tượng được nạp bởi OBJLoader đã là một cá thể THREE.Mesh.

Vì vậy, có lẽ bạn nên làm điều đó:

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

Xem thêm this questionthis example on the three.js website.

Các vấn đề liên quan