对不起我的英文:我加载了几个对象。 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;
}
答案 0 :(得分: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 );
}