Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// Bake vertex AO.
const {position, cells} = primitive;
const aoSampler = geoao(position, {cells, resolution, regl});
for (let i = 0; i < samples; i++) aoSampler.sample();
const ao = aoSampler.report();
aoSampler.dispose();
// Write UV set and add AO map.
const numVertices = ao.length;
const uv2Data = new Float32Array(numVertices * 2);
for (let i = 0; i < numVertices; i++) {
uv2Data[i * 2] = uv2Data[i * 2 + 1] = 1 - ao[i];
}
GLTFUtil.addAccessor(
container,
uv2Data,
'VEC2' as GLTF.AccessorType.VEC2,
AccessorComponentType.FLOAT,
numVertices,
BufferViewTarget.ARRAY_BUFFER
);
const accessorIndex = container.json.accessors.length - 1;
primitiveDef.attributes['TEXCOORD_1'] = accessorIndex;
if (primitiveDef.attributes['TEXCOORD_0'] === undefined) {
primitiveDef.attributes['TEXCOORD_0'] = accessorIndex;
}
container.json.materials[primitiveDef.material].occlusionTexture = {index: occlusionTextureIndex};
});