three.js射线交叉路口r58

时间:2013-04-27 19:35:44

标签: three.js webgl raycasting

我想在collada对象中使用ray检测交集,three.js r58但是

var intersects = target.intersectObjects(ai);

不为我工作有人解决这个问题吗? Ray是不支持r58中的intersectObjects()方法还是代码中有任何错误?什么是替代而不是Raycasting?

    var sphereMaterial = new t.MeshBasicMaterial({color: 0x333333});
    var sphereGeo = new t.SphereGeometry(2, 6, 6);
    var target;

    function createBullet(obj) {
        if (obj === undefined) {
            obj = cam;
        }
        var sphere = new t.Mesh(sphereGeo, sphereMaterial);
        sphere.position.set(obj.position.x, obj.position.y * 0.8, obj.position.z);

        if (obj instanceof t.Camera) {
            var vector = new t.Vector3(mouse.x, mouse.y, 1);
            projector.unprojectVector(vector, obj);
            target=new t.Ray(obj.position, vector.sub(obj.position).normalize());
        sphere.ray= target;
        }
        else {
            var vector = cam.position.clone();
        target=new t.Ray(obj.position, vector.sub( obj.position ).normalize());
sphere.ray= target;     
}



    sphere.owner = obj;

    bullets.push(sphere);
    scene.add(sphere);

    return sphere;
}

1 个答案:

答案 0 :(得分:-1)

var sphereMaterialc = new t.MeshBasicMaterial({color: 0x0099FF});
var sphereGeoc = new t.SphereGeometry(5, 5, 5);
function createBullet3(obj) {
    var obj = cam;
    var spherec = new t.Mesh(sphereGeoc, sphereMaterialc);
    spherec.position.set(obj.position.x, obj.position.y, obj.position.z);

   
     
        var vector = new t.Vector3(mouse.x, mouse.y, 1);
        projector.unprojectVector(vector, obj);

        spherec.ray = new t.Ray(
                obj.position,
                vector.subSelf(obj.position).normalize()
        );
    
    

    
    spherec.id = 'player';
    spherec.owner = 'player';
    spherec.health = 100;
    spherec.lastfive = Date.now();


    bullets.push(spherec);
    scene.add(spherec);
    
    return spherec;

}