jscad-to-gltf
v0.0.6
Published
To install dependencies:
Readme
jscad-to-gltf
To install dependencies:
bun installTo run:
bun run index.tsUsage
From JSCAD model
import * as jscad from "@jscad/modeling"
import { convertJscadModelToGltf } from "jscad-to-gltf"
const model = jscad.csg.union(
jscad.csg.cube({ size: [5, 5, 5] }),
jscad.csg.cube({ size: [5, 5, 5] }).translate([10, 0, 0])
)
const result = await convertJscadModelToGltf(model, {
format: "glb", // or "gltf"
meshName: "MyAssembly",
prettyJson: false,
axisTransform: "jscad_y+ -> gltf_z+", // Makes objects lie flat
})
await Bun.write(`model.${result.format}`, result.data)From JSON jscad plan
import { convertJscadPlanToGltf, convertJscadModelToGltf } from "jscad-to-gltf"
const result = await convertJscadPlanToGltf(plan, {
format: "glb", // or "gltf"
meshName: "MyAssembly",
prettyJson: false,
axisTransform: "jscad_y+ -> gltf_z+", // Makes objects lie flat
})
await Bun.write(`model.${result.format}`, result.data)planis anyJscadOperationfromjscad-planner. UseconvertJscadModelToGltf(model, options)if you already rendered aJscadRenderedModel.- The converter preserves per-vertex colors when provided and falls back to white.
Options
format: output as binaryglb(default) or JSONgltf.meshName: base name used for generated meshes and nodes ("JSCADMesh"by default).prettyJson: pretty-print the.gltfJSON for readability.axisTransform: axis transformation to apply (default:"none"). Available options:"none": No transformation (keeps original JSCAD orientation)"jscad_y+ -> gltf_z+": Transforms JSCAD Y-up coordinate system to glTF Z-up (makes objects lie flat when viewed in glTF viewers)
Result
data: anArrayBufferforglbor a stringified JSON document forgltf.mimeType:model/gltf-binaryormodel/gltf+jsonfor serving the result.byteLength: number of bytes in the returned data.
This project was created using bun init in bun v1.2.23. Bun is a fast all-in-one JavaScript runtime.
