小编hob*_*obs的帖子

Threejs 光线投射点击检测不适用于加载的 3dObject

我加载一个 .obj 文件:

var loader = new THREE.OBJMTLLoader();
loader.load( "../obj/machine.obj", '../obj/machine.mtl',  this.loadObject);
Run Code Online (Sandbox Code Playgroud)

并尝试检测对其的点击:

 click: function(event){
        this.mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
        this.mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
        var vector = new THREE.Vector3( this.mouse.x, this.mouse.y, 1 ).unproject( this.camera );
        this.raycaster.set( this.camera.position, vector.sub( this.camera.position ).normalize() );

        console.log(this.scene.children);
        var intersects = this.raycaster.intersectObjects( this.scene.children );

        if ( intersects.length > 0 ) {

            console.log("hitting something");

        }
    },
Run Code Online (Sandbox Code Playgroud)

这在网格上效果很好,但在加载的 3DObject 上效果不佳,因为它在 this.scene.childeren 中可见:

[THREE.Mesh, THREE.Line, …
Run Code Online (Sandbox Code Playgroud)

javascript three.js raycasting

1
推荐指数
1
解决办法
2531
查看次数

标签 统计

javascript ×1

raycasting ×1

three.js ×1