pcace
October 14, 2022, 12:21pm
1
hey there, i am trying to export a babylonjs scene as stl / gltf. i basically works by:
STLExport.CreateSTL(scene.meshes as Mesh[], true, fileName, true, true, true)
But: there are two Problems:
it seems to mutate the original scene! → at least after using the function, meshes get copied all over the place.
it seems to not export the meshes with its global positions/rotations → some of the exported meshes are rotated, some are at an other position.
whats a quick way around this? i just want to save the whole scene as i see it in the viewport as stl / obj / gltf…
Cheers and thank you so much!
PS.: is this the Problem? scene.meshes as Mesh[],
? scene.meshes is a AbstractMesh
Pryme8
October 14, 2022, 4:03pm
3
bake the transforms into each mesh before exporting the whole thing.
STL do not have transformation matrices and are just vertex arrays that have the positions.
I wrote the exporter a long while ago and forget if I had it take the transformations into account or not.
but quick and dirty would be
meshes.forEach((m)=>{
m.bakeCurrentTransformIntoVertices()
})
then do your stl export
2 Likes
pcace
October 18, 2022, 8:48am
4
Hi,
i am doing it like this now:
const exportMeshes = scene.meshes
.map(mesh => {
if (mesh.id !== 'filterbla' && mesh.id !== 'filterbla' && mesh.id !== 'filterbla') {
return
}
return new Mesh('exportSTLMesh', scene, null, mesh as Mesh, true)
.flipFaces()
.bakeCurrentTransformIntoVertices()
})
.filter(x => x) as Mesh[]
STLExport.CreateSTL(exportMeshes, true, fileName, true, true, true)
exportMeshes.map(mesh => mesh?.dispose())
But it still mutates the original mesh (the Meshes in the viewport get changed (flipFaces) + when i open the STL (in rhino for example) it is flipped.
Why?
Cheers and thanks!
EDIT: another try - with the same result → scene.meshes get mutated. But why, even with cloning the whole thing!!!
const rootMesh = new Mesh('rootMesh')
const scenarioMesh = scene.meshes
.filter(mesh => mesh.id == 'bla')
.map(mesh => {
const clonedMesh = new Mesh('clonedMesh', scene, rootMesh, mesh as Mesh)
return clonedMesh
})
scenarioMesh.map(bla => bla.flipFaces())
STLExport.CreateSTL([...scenarioMesh], true, fileName)
Pryme8
October 18, 2022, 3:38pm
5
I don’t know Rhino but it sounds like it might have a different handiness. Can you place them all into a parent transform and set its z scaling to -1?
1 Like