I have over 100,000 boxes that I've added to a merged geometry. Occasionally, I need to remove some geometries from this merged structure. Is it possible for me to iterate through the position attributes in increments of either 108 or 72 vertices per cube to extract the positions of these boxes? Or does the merging process also consolidate vertices?
function modifyCubeBlocks(grid, blockModel) {
function findElevation(givenN, givenE, grid) {
var y_grid = Math.floor((grid.metaData.yMax - givenN) / grid.metaData.yStep) + 1;
var x_grid = Math.floor((givenE - grid.metaData.xMin) / grid.metaData.xStep);
var array_pos = Math.round(y_grid * (grid.metaData.nCol + 1) + x_grid);
return isNaN(grid.elevations[array_pos]) ? Infinity : grid.elevations[array_pos];
}
var tempBox = new THREE.BoxBufferGeometry(blockModel.x_step, blockModel.y_step, 2);
var myBlock = scene.getObjectByName('blockModel');
var pointsPerVertex = 3,
verticesPerFace = 4,
facesPerSide = 1,
sidesPerBox = 6;
var pointsPerCube = pointsPerVertex * verticesPerFace * facesPerSide * sidesPerBox;
for (var i = 0, j = myBlock.geometry.attributes.position.array.length; i < j; i += pointsPerCube) {
var above = false,
below = false;
for (var k = i; k < i + pointsPerCube; k += pointsPerVertex) {
var givenN = myBlock.geometry.attributes.position.array[k + 1];
var givenE = myBlock.geometry.attributes.position.array[k + 0];
var zCoord = myBlock.geometry.attributes.position.array[k + 2];
if (zCoord > findElevation(givenN + WEBGLyTranslate, givenE + WEBGLxTranslate, grid))
above = true;
else
below = true;
if (above && below) break;
}
if (above) {
if (below) {
var newBoxGeometry = tempBox.clone();
newBoxGeometry.attributes.position.array = myBlock.geometry.attributes.position.array.slice(i, i + pointsPerCube);
for (var materialGroupIndex = 0, z = myBlock.geometry.groups.length; materialGroupIndex < z; materialGroupIndex++) {
var myGeometryGroup = myBlock.geometry.groups[materialGroupIndex];
if (i >= myGeometryGroup.start && i < myGeometryGroup.start + myGeometryGroup.count) {
var newMaterial = myBlock.material.materials[myGeometryGroup.materialIndex].clone();
var mesh = new THREE.Mesh(newBoxGeometry, newMaterial)
scene.add(mesh);
break;
}
}
}
for (var k = i; k < i + pointsPerCube; k++) {
myBlock.geometry.attributes.position.array[k] = undefined;
}
}
}
myBlock.geometry.attributes.position.needsUpdate = true;
}
I'm seeing inconsistent results. How exactly does the merging operation handle the positioning array — does it combine vertices or simply add them sequentially?