Currently I am working on another 3D product configurator.
The idea is to import a base 3D object to the scene, and move certain vertices an x amount according to the dimensions provided by the customer.
First I thought to import an .obj file, use Blender to get the vertex indices and work from there.
However it seems that after importing the .obj file the vertex indices don’t match the indices from Blender anymore, even the amount of vertices is differrent (higher) then the amount of vertices in Blender.
So now I am thinking to import the obj first.
Then add a couple of bounding boxes to select the vertex indexes and store them.
Remove the bounding boxes again.
So now I am thinking to import the obj first.
Then add a couple of bounding boxes to select the vertex indexes and store them.
Remove the bounding boxes again.
Any thoughts or ideas on this?
This seems to work fine, dumping some code on how I did this for future souls who want to do the same:
// the box containing the vertices to select
const boxMaterial = new MeshPhongMaterial({
color: new Color(0xaaaaaa).convertSRGBToLinear()
});
const boxGeometry = new BoxBufferGeometry(20, 10, 20);
const boxMesh = new Mesh(boxGeometry, boxMaterial);
boxMesh.position.set(9, 0, 0);
const boxHelper = new BoxHelper(boxMesh, 0xffff00);
boxHelper.geometry.computeBoundingBox();
const boundingBox = boxHelper.geometry.boundingBox;
const inBoundingBoxVertexIndices = [];
for (let vertexIndex = 0; vertexIndex <= chimney3DObject.current.geometry.userData.originalVertexPositions.count; vertexIndex ++) {
const x = chimney3DObject.current.geometry.userData.originalVertexPositions.getX(vertexIndex);
const y = chimney3DObject.current.geometry.userData.originalVertexPositions.getY(vertexIndex);
const z = chimney3DObject.current.geometry.userData.originalVertexPositions.getZ(vertexIndex);
if (x > boundingBox.min.x && x < boundingBox.max.x
&& y > boundingBox.min.y && y < boundingBox.max.y
&& z > boundingBox.min.z && z < boundingBox.max.z
) {
inBoundingBoxVertexIndices.push(vertexIndex);
}
}