2

我想使用 collada 对象中的射线检测相交,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;
}
4

1 回答 1

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

}
于 2021-04-16T01:58:08.113 回答