2

我没有更新系统中的 three.js 库。今天更新了three.js文件。但是我遇到了这个错误:“Uncaught TypeError: Object # has no method 'traverseHierarchy'”。

我用它来检测交叉点:在线代码在这里: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]);
                }
        }
    }
}

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

4

2 回答 2

7

您应该替换scene.traverse(scene, function (child) {scene.traverse(function (child) {(我无法添加评论,所以我创建了一个答案)。

于 2013-03-25T20:09:12.603 回答
2

正如迁移指南所述,在 r51 -> r52 中:

将 SceneUtils.traverseHierarchy 替换为 object.traverse。

object表示任何THREE.Object3D实例,例如THREE.MeshTHREE.Scene。所以,而不是THREE.SceneUtils.traverseHierarchy,尝试scene.traverse

于 2013-03-23T09:04:31.963 回答