2013-03-23 32 views
0

我没有更新我的系统中的three.js库。今天,我更新了three.js文件。但是我遇到了这个错误:“Uncaught TypeError:Object#has no method'traverseHierarchy'”。Three.js SceneUtils没有遍历层次!它在哪里?

我已经用它检测路口: 在线代码是在这里:https://dl.dropbox.com/u/44791710/test/simple2.html

function Intersect(event) { 
    event.preventDefault(); 
    var mousex = (event.clientX/window.innerWidth) * 2 - 1; 
    var mousey = -(event.clientY/window.innerHeight) * 2 + 1; 
    var vector = new THREE.Vector3(mousex, mousey, 1); 

    var toIntersect = []; 
    THREE.SceneUtils.traverseHierarchy(scene, function (child) { 
     if (child instanceof THREE.Mesh) { 
      toIntersect.push(child); 
     } 
    }); 
    var projector = new THREE.Projector(); 
    projector.unprojectVector(vector, camera); 
    var ray = new THREE.Raycaster(camera.position,vector.sub(camera.position).normalize()); 
    var intersects = ray.intersectObjects(toIntersect); 
    if (intersects.length > 0) { 
     for (var j = 0; j < intersects.length ; j++){ 
       target = intersects[j].object; 
       console.log('Intersects at ' + mouse.x + '/' + mouse.y + ':'); 
       for(var i = 0, m = intersects.length; i<m; i++){ 
        console.log(intersects[i].object.id, intersects[i]); 
       } 
     } 
    } 
} 

我需要做什么样的变化? 谢谢。

+0

它被称为traverse()挂在Object3D上。 – gaitat 2013-03-23 07:25:31

+0

我是新手,并不明白你的意思!你能否详细说明一下?!我检查了THREE.SceneUtils和THREE.Object3D,但没有任何遍历()!谢谢。 – mbehnaam 2013-03-23 07:56:40

+0

如果您查看http://mrdoob.github.com/three.js/docs/57/#Reference/Core/Object3D上的文档,您将在那里看到traverse()函数作为方法。 – gaitat 2013-03-23 08:37:01

回答

6

,就应该替换由scene.traverse(function (child) {scene.traverse(scene, function (child) {(我不能添加评论,所以我创建了一个答案,而不是)。

+0

非常感谢。问题解决了!!! – mbehnaam 2013-03-26 00:19:28

1

作为Migration导向状态,在R51 - > R52:

Replaced SceneUtils.traverseHierarchy with object.traverse.

object指任何THREE.Object3D实例,例如THREE.MeshTHREE.Scene。因此,而不是THREE.SceneUtils.traverseHierarchy,请尝试scene.traverse

+0

我替换了THREE.SceneUtils.traverseHierarchy,BY scene.traverse。但是我得到了这个错误! Uncaught TypeError:对象不是一个函数!请看看这里的在线代码https://dl.dropbox.com/u/44791710/test/simple2.html非常感谢! – mbehnaam 2013-03-24 04:29:02

+0

@mbehnaam由于它是一个成员函数,所以不会将场景作为参数传递,只能传递回调。查看问题评论中链接的API文档步骤。 – Tapio 2013-03-24 13:45:46

+0

谢谢Tapio ... – mbehnaam 2013-03-26 03:42:49