Skip to content

export mesh as .STL file? #1160

Answered by donmccurdy
rawwerks asked this question in Q&A
Nov 8, 2023 · 2 comments · 8 replies
Discussion options

You must be logged in to vote

glTF Transform doesn't read or write any other formats, but you could use it to obtain the vertex positions and normals you'd need to serialize an STL file with other libraries. I used stl for this example, but you could do the same with three.js by constructing BufferGeometries.

import { NodeIO } from '@gltf-transform/core';
import { KHRONOS_EXTENSIONS } from '@gltf-transform/extensions';
import { normals, unweld } from '@gltf-transform/functions';
import stl from 'stl';
import { writeFile } from 'node:fs/promises';

const io = new NodeIO().registerExtensions(KHRONOS_EXTENSIONS);
const document = await io.read('./assets/input.glb');
await document.transform(normals({ overwrite: true }), u…

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
8 replies
@rawwerks
Comment options

@donmccurdy
Comment options

@rawwerks
Comment options

@rawwerks
Comment options

@donmccurdy
Comment options

Answer selected by rawwerks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants