最后,我创建了一个与所有立方体的 geoemtry 合并。
在此更改之前,我曾在多维数据集中通过鼠标单击来处理交叉点。
我尝试解决这个问题,但没有奏效:
使用所有网格添加几何合并和数组的代码:
var geometry = new THREE.Geometry();
for( var i = 0; i < voxels.length; i++ ){
var voxel = voxels[i];
color = voxel.color;
texture = textPlaneTexture(voxel.text,color,voxelSize);
material = new THREE.MeshBasicMaterial({ map: texture });
mesh = new THREE.Mesh(new THREE.CubeGeometry(voxelSize, voxelSize, voxelSize, 1, 1, 1, material));
mesh.name = voxel.name;
mesh.position.x = voxel.x * voxelSize + offset_x;
mesh.position.y = voxel.y * voxelSize + offset_y;
mesh.position.z = voxel.z * voxelSize + offset_z;
//
objects.push( mesh );
THREE.GeometryUtils.merge( geometry, mesh );
}
//Add geometry to scene
mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial() );
scene.add( mesh );
...
双击鼠标事件
function onDocumentMouseDoubleClick( event ) {
if (event.target instanceof HTMLCanvasElement) {
event.preventDefault();
mouse2D.x = ( event.clientX / widthChart ) * 2 - 1;
mouse2D.y = - ( (parseInt(event.clientY) - offset_mouse_y) / heightChart ) * 2 + 1;
mouse3D = projector.unprojectVector( mouse2D.clone(), camera );
ray.direction = mouse3D.subSelf( camera.position ).normalize();
var intersects = ray.intersectObjects( objects );
if ( intersects.length > 0 ) {
if ((intersects[ 0 ].object.name != 'undefined') && (intersects[ 0 ].object.name != '')) {
//Object clicked
};
};
};
};