At last, I successfully merged all cubes into a single geometry.
Prior to this update, I was handling cube intersection with mouse clicks.
I attempted to resolve the issue with the following code snippet, but it did not yield the desired outcome:
Code snippet for adding geometry merge and array with all mesh:
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 );
...
Double Click Mouse Event
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
};
};
};
};