Dear community,
I’m having trouble exporting a scene as an STL and I’m really hoping for your support after lots of trial and error.
Export STL doesn’t represent the scene correctly
The glTF file is stored in Dropbox: TestGLB.glb
Tested with three.js editor
It doesn’t work with the implementation either:
const glbfoader = new GLTFLoader();
glbfoader.load('TestGLB.glb', function(glb){
scene.add(glb.scene);
})
//one of many solutions that unfortunately didn't work ^^ from https://github.com/mrdoob/three.js/issues/18572
function createMeshesFromInstancedMesh ( instancedMesh ) {
var group = new THREE.Group();
var count = instancedMesh.count;
var geometry = instancedMesh.geometry;
console.log(instancedMesh)
for ( var i = 0; i < count; i ++ ) {
console.log("Instance: ", i , " von ", count)
var material = instancedMesh.material.clone();
instancedMesh.getColorAt( i, material.color );
var mesh = new THREE.Mesh( geometry, material );
instancedMesh.getMatrixAt( i, mesh.matrix );
mesh.matrix.decompose( mesh.position, mesh.quaternion, mesh.scale );
group.add( mesh );
}
group.copy( instancedMesh );
group.updateMatrixWorld(); // ensure correct world matrices of meshes
return group;
};
//https://threejs.org/docs/#examples/en/exporters/STLExporter
function exportBinary() {
console.log("test test")
const sceneExport = createMeshesFromInstancedMesh(scene)
//const result = exporter.parse( scene, { binary: true } );
const result = exporter.parse( sceneExport, { binary: true } );
saveArrayBuffer( result, 'box.stl' );
}
What ideas do you have for creating an STL export from TestGLB.glb file?
Thank you very much for all suggestions!
Best wishes
Kikki