-
-
Save unitycoder/ccd0ed50020f8c8b77687d12bc19f9ab to your computer and use it in GitHub Desktop.
Revisions
-
donmccurdy created this gist
Mar 18, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ import { Document, NodeIO, Primitive } from '@gltf-transform/core'; const document = new Document(); const buffer = document.createBuffer(); const position = document.createAccessor() .setType('VEC3') .setBuffer(buffer) .setArray(new Float32Array([ 0, 0, 0, // ax,ay,az 0, 0, 1, // bx,by,bz 0, 1, 0, // ... 1, 0, 0, ])); const color = document.createAccessor() .setType('VEC4') .setBuffer(buffer) .setNormalized(true) .setArray(new Uint8Array([ 0, 0, 0, 255, 0, 0, 255, 255, 0, 255, 0, 255, 255, 0, 0, 255, ])); const prim = document .createPrimitive() .setMode(Primitive.Mode.POINTS) .setAttribute('POSITION', position) .setAttribute('COLOR_0', color); const mesh = document.createMesh().addPrimitive(prim); const node = document.createNode().setMesh(mesh); const scene = document.createScene().addChild(node); document.getRoot().setDefaultScene(scene); const io = new NodeIO(); await io.write('./points.glb', document);