Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Find duplicate mesh accessors.
const duplicateAccessors = new Map();
for (let i = 0; i < meshAccessorIndices.length; i++) {
if (duplicateAccessors.has(i)) continue;
const iAccessor = container.json.accessors[i];
const iAccessorData = container.getAccessorArray(i).slice().buffer;
for (let j = i + 1; j < meshAccessorIndices.length; j++) {
if (duplicateAccessors.has(j)) continue;
const jAccessor = container.json.accessors[j];
const jAccessorData = container.getAccessorArray(j).slice().buffer;
if (iAccessor.type !== jAccessor.type) continue;
if (iAccessor.componentType !== jAccessor.componentType) continue;
if (iAccessor.count !== jAccessor.count) continue;
if (iAccessor.normalized !== jAccessor.normalized) continue;
if (GLTFUtil.arrayBufferEquals(iAccessorData, jAccessorData)) {
duplicateAccessors.set(j, i);
}
}
}
logger.info(`Duplicates: ${Array.from(duplicateAccessors).length} of ${json.accessors.length}.`);
// Replace accessor references.
json.meshes.forEach((mesh) => {
mesh.primitives.forEach((primitive) => {
for (const semantic in primitive.attributes) {
const index = primitive.attributes[semantic];
if (duplicateAccessors.has(index)) {
primitive.attributes[semantic] = duplicateAccessors.get(index);
}
}
if (primitive.indices && duplicateAccessors.has(primitive.indices)) {