Skip to content

Commit

Permalink
Detect buffer attribute types
Browse files Browse the repository at this point in the history
  • Loading branch information
stevinz committed Aug 3, 2022
1 parent 678730f commit a59f656
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
13 changes: 9 additions & 4 deletions build/index.module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/index.module.js.map

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions build/index.umd.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@
attributeList.forEach((attributeName) => {
const attribute = existing.getAttribute(attributeName);
if (! attribute) return;
const attributeArrayType = attribute.array.constructor;

const newTriangles = 4; /* maximum number of new triangles */
const arrayLength = (vertexCount * attribute.itemSize) * newTriangles;
const floatArray = new Float32Array(arrayLength);
const floatArray = new attributeArrayType(arrayLength);

let index = 0;
let step = attribute.itemSize;
Expand Down Expand Up @@ -296,7 +298,7 @@

// Resize Array
const reducedCount = (index * 3) / step;
const reducedArray = new Float32Array(reducedCount);
const reducedArray = new attributeArrayType(reducedCount);
for (let i = 0; i < reducedCount; i++) {
reducedArray[i] = floatArray[i];
}
Expand Down Expand Up @@ -330,9 +332,11 @@
attributeList.forEach((attributeName) => {
const attribute = existing.getAttribute(attributeName);
if (! attribute) return;

const attributeArrayType = attribute.array.constructor;
const newTriangles = 4;
const arrayLength = (vertexCount * attribute.itemSize) * newTriangles;
const floatArray = new Float32Array(arrayLength);
const floatArray = new attributeArrayType(arrayLength);

let index = 0;
let step = attribute.itemSize;
Expand Down Expand Up @@ -423,12 +427,13 @@
///// Build Geometry
attributeList.forEach((attributeName) => {
const existingAttribute = existing.getAttribute(attributeName);
const existingArrayType = existingAttribute.array.constructor;
const flatAttribute = flat.getAttribute(attributeName);
const flatPosition = flat.getAttribute('position');
if (existingAttribute === undefined || flatAttribute === undefined) return;

const arrayLength = (flat.attributes.position.count * flatAttribute.itemSize);
const floatArray = new Float32Array(arrayLength);
const floatArray = new existingArrayType(arrayLength);

let index = 0;
for (let i = 0; i < flat.attributes.position.count; i += 3) {
Expand Down
2 changes: 1 addition & 1 deletion build/index.umd.cjs.map

Large diffs are not rendered by default.

0 comments on commit a59f656

Please sign in to comment.