Load a new STL as geometry will change existed mesh objects
Hi, I’m learning threejs and having a problem now.
I want to load STL files and use THREE.TransformControls to move and rotate.
But after loading several STLs, the pickers of TransformControls will be changed into the newly loaded geometry.
Here is how it happens:
-
Load my first cube from STL. Everything seems ok.
-
The red picker for rotating around X became a cylinder after loading the 4th STL(a cylinder).
-
The green picker for rotating around Y became a cone after loading the 6th STL(a cone).
-
Finally the blue picker for Z became a cube after loading the 8th STL(a cube).
Here is my loader:
const THREE = require("three")
class GeometryLoader {
static loadSTLAsGeometry(buffer) {
const numberOfFaces = buffer.readUInt32LE(80, true)
const dataOffset = 84;
const faceLength = 12 * 4 + 2;
const geometry = new THREE.Geometry();
for (let face = 0; face < numberOfFaces; face++) {
const start = dataOffset + face * faceLength;
const normalX = buffer.readFloatLE(start, true);
const normalY = buffer.readFloatLE(start + 4, true);
const normalZ = buffer.readFloatLE(start + 8, true);
for (let i = 1; i <= 3; i++) {
const vertexstart = start + i * 12;
geometry.vertices.push(new THREE.Vector3(
buffer.readFloatLE(vertexstart, true),
buffer.readFloatLE(vertexstart + 4, true),
buffer.readFloatLE(vertexstart + 8, true)
))
}
const normal = new THREE.Vector3(normalX, normalY, normalZ)
geometry.faces.push(new THREE.Face3(face * 3 + 0, face * 3 + 1, face * 3 + 2, normal))
}
geometry.computeBoundingBox()
geometry.mergeVertices()
return geometry;
}
}
How could I fix it? Any help would be appreciated!