Skip to content

Commit

Permalink
Add support for changing the attribute buffer type for TypedBackedArray
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Aug 29, 2023
1 parent 8eb0bce commit 194e5e8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/core/TypeBackedArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class TypeBackedArray {

if ( this.length !== 0 ) {

throw new Error();
throw new Error( 'TypeBackedArray: Cannot change the type while there is used data in the buffer.' );

}

Expand All @@ -38,7 +38,7 @@ export class TypeBackedArray {

setSize( size ) {

if ( size === this.array.length ) {
if ( this.array && size === this.array.length ) {

return;

Expand Down
12 changes: 11 additions & 1 deletion src/core/TypedAttributeData.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,17 @@ export class TypedAttributeData {

if ( referenceAttr.type !== type ) {

throw new Error( `TypedAttributeData: Array ${ name } already initialized with a different type.` );
for ( let i = 0, l = groupAttributes.length; i < l; i ++ ) {

groupAttributes[ i ][ name ].setType( type );

}

// } else {

// throw new Error( `TypedAttributeData: Array ${ name } already initialized with a different type.` );

// }

}

Expand Down
3 changes: 2 additions & 1 deletion tests/BVH.Evaluator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ describe( 'Evaluator', () => {
const result1 = evaluator.evaluate( brush1A, brush1B, SUBTRACTION );
const result2 = evaluator.evaluate( brush2A, brush2B, SUBTRACTION );

expect( result1.geometry.attributes.uv.array.constructor ).toBe( Float32Array );
expect( result2.geometry.attributes.uv.array.constructor ).toBe( Uint8Array );

} );


} );
5 changes: 5 additions & 0 deletions tests/Utils.TypeBackedArray.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe( 'TypeBackedArray', () => {

it.todo( 'make tests' );

} );
5 changes: 5 additions & 0 deletions tests/Utils.TypedAttributeData.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe( 'TypedAttributeData', () => {

it.todo( 'make tests' );

} );

0 comments on commit 194e5e8

Please sign in to comment.