4

我正在尝试对使用BufferGeometry. 但它似乎不支持光线投射?

BufferGeometry如此处所示启动时,光线投射不适用于此对象

但是当我BufferGeometry用光线投射替换时Geometry效果很好。

var geometry = new THREE.Geometry();
var lines = new THREE.Object3D();

for ( var i = 0; i <array.length; i++) {
   x = ( Math.random() - 0.5 ) * 30;
   y = ( Math.random() - 0.5 ) * 30;
   z = ( Math.random() - 0.5 ) * 30;
   geometry.vertices.push(new THREE.Vector3(x,y,z));
}

var line = new THREE.Line( geometry, new THREE.LineBasicMaterial( { color: 0x9999FF, opacity: 0.5 } ) );
lines.add(line);
scene.add(lines);

我也试过换BufferGeometryObject3D,不影响结果。如何对BufferGeometry线进行光线投射?

编辑

摆弄 BufferGeometry

摆弄几何

4

1 回答 1

0

我在您的 BufferGeometry 示例上做了一些工作,现在它可以工作了

http://jsfiddle.net/eviltoad/s9fsds19/11/

material.originalColor = material.color;
// line
lines = new THREE.Object3D();
line = new THREE.Line( geometry,  material );
lines.add(line);
scene.add(lines);

document.onmousemove = function(event){
    mousePosition.x = 2 * (event.clientX / window.innerWidth) - 1;
    mousePosition.y = 1 - 2 * ( event.clientY / window.innerHeight);
    mousePosition.unproject(camera);
    var raycaster = new THREE.Raycaster(camera.position,mousePosition.sub(camera.position).normalize());
    console.log(lines.children);
    var intersections = raycaster.intersectObjects(lines.children);
    console.log(intersections);
    lines.children.forEach(function( child ) {
        child.material.color = child.material.originalColor;
    });
    for( var j = 0; j < intersections.length;j++ ) {
        var intersection = intersections[j];
        var object = intersection.object;
        object.material.color = new THREE.Color("#FFFFFF");
    }
};
于 2015-07-21T10:38:43.267 回答