From 194e5e83a3d5fff79936ed2c787ab83a51e6515a Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Tue, 29 Aug 2023 12:19:53 +0900 Subject: [PATCH] Add support for changing the attribute buffer type for TypedBackedArray --- src/core/TypeBackedArray.js | 4 ++-- src/core/TypedAttributeData.js | 12 +++++++++++- tests/BVH.Evaluator.test.js | 3 ++- tests/Utils.TypeBackedArray.test.js | 5 +++++ tests/Utils.TypedAttributeData.test.js | 5 +++++ 5 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 tests/Utils.TypeBackedArray.test.js create mode 100644 tests/Utils.TypedAttributeData.test.js diff --git a/src/core/TypeBackedArray.js b/src/core/TypeBackedArray.js index 0f95ef38..f39c4177 100644 --- a/src/core/TypeBackedArray.js +++ b/src/core/TypeBackedArray.js @@ -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.' ); } @@ -38,7 +38,7 @@ export class TypeBackedArray { setSize( size ) { - if ( size === this.array.length ) { + if ( this.array && size === this.array.length ) { return; diff --git a/src/core/TypedAttributeData.js b/src/core/TypedAttributeData.js index 7c2a77ef..14b67ebd 100644 --- a/src/core/TypedAttributeData.js +++ b/src/core/TypedAttributeData.js @@ -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.` ); + + // } } diff --git a/tests/BVH.Evaluator.test.js b/tests/BVH.Evaluator.test.js index 94e0b7be..1daf20ce 100644 --- a/tests/BVH.Evaluator.test.js +++ b/tests/BVH.Evaluator.test.js @@ -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 ); } ); - } ); diff --git a/tests/Utils.TypeBackedArray.test.js b/tests/Utils.TypeBackedArray.test.js new file mode 100644 index 00000000..d6284381 --- /dev/null +++ b/tests/Utils.TypeBackedArray.test.js @@ -0,0 +1,5 @@ +describe( 'TypeBackedArray', () => { + + it.todo( 'make tests' ); + +} ); diff --git a/tests/Utils.TypedAttributeData.test.js b/tests/Utils.TypedAttributeData.test.js new file mode 100644 index 00000000..f46c33b6 --- /dev/null +++ b/tests/Utils.TypedAttributeData.test.js @@ -0,0 +1,5 @@ +describe( 'TypedAttributeData', () => { + + it.todo( 'make tests' ); + +} );