Last active
November 26, 2020 20:02
-
-
Save timknip/f26e96941d158af8e0d37719626f5d5c to your computer and use it in GitHub Desktop.
gltf-transform - draco encoding issue
This file contains 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 { Document, NodeIO } from '@gltf-transform/core'; | |
import { DracoMeshCompression } from '@gltf-transform/extensions'; | |
import * as draco3d from 'draco3dgltf'; | |
export async function draco_extension_issue (useTimeout = false) { | |
const doc = new Document(); | |
const buffer = doc.createBuffer('bin'); | |
const accessor = doc.createAccessor('positions') | |
.setArray(new Float32Array([ | |
0, 0, 0, | |
1, 0, 0, | |
1, 1, 0 | |
])) | |
.setType(Accessor.Type.VEC3) | |
.setBuffer(buffer); | |
const indices = doc.createAccessor('indices') | |
.setArray(new Uint16Array([0, 1, 2])) | |
.setType(Accessor.Type.SCALAR) | |
.setBuffer(buffer); | |
const material = doc.createMaterial('material') | |
.setBaseColorFactor([1, 0, 0, 1]); | |
const primitive = doc.createPrimitive() | |
.setAttribute('POSITION', accessor) | |
.setIndices(indices) | |
.setMaterial(material); | |
const mesh = doc.createMesh('mesh') | |
.addPrimitive(primitive); | |
const node = doc.createNode('node') | |
.setMesh(mesh); | |
const scene = doc.createScene('scene') | |
.addChild(node); | |
doc.createExtension(DracoMeshCompression).setRequired(true); | |
const io = new NodeIO() | |
.registerExtensions([DracoMeshCompression]) | |
.registerDependencies({ | |
'draco3d.decoder': draco3d.createDecoderModule(), | |
'draco3d.encoder': draco3d.createEncoderModule(), | |
}); | |
if (useTimeout) { | |
setTimeout(() => { | |
io.write('draco_extension_issue.glb', doc); | |
}, 1000); | |
} else { | |
// throws: "TypeError: Cannot read property 'apply' of undefined" | |
io.write('draco_extension_issue.glb', doc); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment