Created
November 29, 2023 16:12
-
-
Save OlafHaag/75e83ffb7ac97bfb243ddfd29e2c0db7 to your computer and use it in GitHub Desktop.
Using https://gltf.report and switching to the script tab (<> symbol on the left), the following script can be used to identify what kind of data the accessors from the error message hold.
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
const root = document.getRoot(); | |
// Get all accessors in the document | |
const accessors = document.getRoot().listAccessors(); | |
// Loop through each accessor | |
for (let accessorIndex = 0; accessorIndex < accessors.length; accessorIndex++) { | |
const accessor = accessors[accessorIndex]; | |
// Find where the accessor is used | |
const usedAs = findAccessorUsage(accessor); | |
// Log information about the accessor | |
console.log(`Accessor ${accessorIndex}:`); | |
console.log(`- Data Type: ${accessor.getType()}`); | |
console.log(`- Component Type: ${accessor.getComponentType()}`); | |
console.log(`- Count: ${accessor.getCount()}`); | |
if (Object.keys(usedAs).length > 0 && usedAs.constructor === Object) { | |
console.log('- Used in:'); | |
for (const [key, purpose] of Object.entries(usedAs)) { | |
console.log(` - ${key}: ${purpose}`); | |
} | |
} else { | |
console.log('- Usage not identified.'); | |
} | |
//console.log(accessor) // Uncomment for debugging | |
console.log(''); // Add a newline for better readability | |
} | |
// Function to find where an accessor is used | |
function findAccessorUsage(accessor) { | |
const usedAs = {}; | |
const meshes = root.listMeshes(); | |
for (const mesh of meshes) { | |
// Assume single primitive | |
const prim0 = mesh.listPrimitives()[0]; | |
const indices = prim0.getIndices(); | |
if (indices.equals(accessor)) { | |
usedAs[`Mesh ${mesh.getName()}`] = 'Vertex indices to form triangles'; | |
break; | |
} | |
const attributes = prim0.listAttributes(); | |
const semantics = prim0.listSemantics(); // matches attributes' order | |
for (let attributeIdx = 0; attributeIdx < attributes.length; attributeIdx++) { | |
if (attributes[attributeIdx].equals(accessor)) { | |
usedAs[`Mesh ${mesh.getName()}`] = semantics[attributeIdx]; | |
} | |
} | |
} | |
const animations = root.listAnimations(); | |
for (const animation of animations) { | |
const sampler = animation.listSamplers().find(s => s.getInput().equals(accessor) || s.getOutput().equals(accessor)); | |
if (sampler) { | |
usedAs[`Animation ${animation.getName()}`] = 'sampler'; | |
} | |
} | |
const skins = root.listSkins(); | |
for (const skin of skins) { | |
if (skin.getInverseBindMatrices().equals(accessor)) { | |
usedAs['Skin'] = 'InverseBindMatrices for skinning'; | |
} | |
} | |
return usedAs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment