Created
June 9, 2024 00:55
-
-
Save yacineMTB/d28a67da85ed65583726cbc9ec9fe61f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'fs'; | |
import path from 'path'; | |
import {exportModels} from './worker'; | |
import Module from './built/manifold'; | |
export const manifoldModule = await Module(); | |
manifoldModule.setup(); | |
const {cube, sphere} = manifoldModule.Manifold; | |
const defaults = { roughness: 0.2, metallic: 1, baseColorFactor: [1, 1, 0], alpha: 1, unlit: false, animationLength: 1, animationMode: 'loop' }; | |
async function runAndSave() { | |
const box = cube([100, 100, 100], true); | |
const ball = sphere(60, 100); | |
const result = await exportModels(defaults as any, box.subtract(ball)); | |
if (result) { | |
const response = await fetch(result.glbURL); | |
const buffer = await response.arrayBuffer(); | |
const outputPath = path.join('./', `out.glb`); | |
fs.writeFileSync(outputPath, Buffer.from(buffer)); | |
console.log(`GLB file saved to ${outputPath}`); | |
} | |
} | |
runAndSave(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment