Three.js Raycaster没有与我的自定义网格相交

时间:2016-11-17 12:58:54

标签: javascript three.js

我是Three.js的新手。 Raycaster可以找到导入的对象,但是当我按如下方式创建自定义网格时它不起作用:

        var geom = new THREE.Geometry(); 
        var v1 = new THREE.Vector3(0,0,0);
        var v2 = new THREE.Vector3(0,500,0);
        var v3 = new THREE.Vector3(-400,-500,50);

        geom.vertices.push(v1);
        geom.vertices.push(v2);
        geom.vertices.push(v3);

        geom.faces.push( new THREE.Face3( 0, 1, 2 ) );
        geom.computeFaceNormals();

        meshFrame = new THREE.Mesh( geom, new THREE.MeshNormalMaterial() );

        meshFrame.position.z = 20;
        meshFrame.rotation.y = 0;
        meshFrame.verticesNeedUpdate = true;
        scene.add(meshFrame);   

您认为问题可能是什么?光线在三角形中传递,但仍然intersectObjects返回空。在这里,我的光线投射代码:

        var ever = bver.clone();

        ever.setComponent(2,ever.z+150);

        var geometryF = new THREE.Geometry();
        geometryF.vertices.push(
            bver,
            ever
        );

        var bray = new THREE.Ray(bver, new THREE.Vector3(0 ,0, 0));
        bray.lookAt(ever);

        var raycaster = new THREE.Raycaster();
        raycaster.set( bray.origin, bray.direction);            

        var intersects = raycaster.intersectObjects( [meshFrame] );

        var x = [scene.getObjectByName( "meshFrame" )];
        print(meshFrame.geometry.vertices);

        console.log(intersects);

        var lineF = new THREE.Line( geometryF, materialF );
        scene.add( lineF ); 

非常感谢你的帮助。

1 个答案:

答案 0 :(得分:0)

好的,我解决了这个问题。显然面部朝向是问题所在。当我颠倒它时,它就开始起作用了。