0

对不起我的英语:我加载了几个对象。Json 和我使用 Ray 选择它们并相交以使它们改变颜色。但我想知道在运行时选择了哪个加载的对象。当前并使用下面的代码,输出为: [object Object] $ var intersects = ray.intersectObjects(scene.children);

            if ( intersects.length > 0 ) {

                if ( INTERSECTED != intersects[ 0 ].object ) {


                    var aux = intersects[ 0 ].object;

                    if ( INTERSECTED ) INTERSECTED.material.emissive.setHex( INTERSECTED.currentHex );


                    INTERSECTED = intersects[ 0 ].object;

                    INTERSECTED.currentHex = INTERSECTED.material.emissive.getHex();
                    INTERSECTED.material.emissive.setHex( 0xffff00 );


                        console.debug("name:,"+aux);

                }

            } else {

                if ( INTERSECTED ) INTERSECTED.material.emissive.setHex( INTERSECTED.currentHex );

                INTERSECTED = null;


            }
4

1 回答 1

0

id您可以在创建每个网格时为其添加唯一的。

mesh = new THREE.Mesh( geometry, material );
mesh.id = some_unique_id;
scene.add( mesh );

然后在你的相交逻辑中:

if ( intersects.length > 0 ) {

    alert( intersects[0].object.id );

}
于 2013-01-21T14:21:22.040 回答