Просмотр исходного кода

WebGPURenderer: Respect TypedArray in StorageInstancedBufferAttribute (#30218)

* WebGPURenderer: Respect TypedArray in StorageInstancedBufferAttribute

* Update NodeUtils.js

---------

Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
Renaud Rohlinger 1 год назад
Родитель
Сommit
d24a6b48de
2 измененных файлов с 38 добавлено и 3 удалено
  1. 5 3
      src/nodes/accessors/Arrays.js
  2. 33 0
      src/nodes/core/NodeUtils.js

+ 5 - 3
src/nodes/accessors/Arrays.js

@@ -1,7 +1,7 @@
 import StorageInstancedBufferAttribute from '../../renderers/common/StorageInstancedBufferAttribute.js';
 import StorageInstancedBufferAttribute from '../../renderers/common/StorageInstancedBufferAttribute.js';
 import StorageBufferAttribute from '../../renderers/common/StorageBufferAttribute.js';
 import StorageBufferAttribute from '../../renderers/common/StorageBufferAttribute.js';
 import { storage } from './StorageBufferNode.js';
 import { storage } from './StorageBufferNode.js';
-import { getLengthFromType } from '../core/NodeUtils.js';
+import { getLengthFromType, getTypedArrayFromType } from '../core/NodeUtils.js';
 
 
 /** @module Arrays **/
 /** @module Arrays **/
 
 
@@ -16,8 +16,9 @@ import { getLengthFromType } from '../core/NodeUtils.js';
 export const attributeArray = ( count, type = 'float' ) => {
 export const attributeArray = ( count, type = 'float' ) => {
 
 
 	const itemSize = getLengthFromType( type );
 	const itemSize = getLengthFromType( type );
+	const typedArray = getTypedArrayFromType( type );
 
 
-	const buffer = new StorageBufferAttribute( count, itemSize );
+	const buffer = new StorageBufferAttribute( count, itemSize, typedArray );
 	const node = storage( buffer, type, count );
 	const node = storage( buffer, type, count );
 
 
 	return node;
 	return node;
@@ -35,8 +36,9 @@ export const attributeArray = ( count, type = 'float' ) => {
 export const instancedArray = ( count, type = 'float' ) => {
 export const instancedArray = ( count, type = 'float' ) => {
 
 
 	const itemSize = getLengthFromType( type );
 	const itemSize = getLengthFromType( type );
+	const typedArray = getTypedArrayFromType( type );
 
 
-	const buffer = new StorageInstancedBufferAttribute( count, itemSize );
+	const buffer = new StorageInstancedBufferAttribute( count, itemSize, typedArray );
 	const node = storage( buffer, type, count );
 	const node = storage( buffer, type, count );
 
 
 	return node;
 	return node;

+ 33 - 0
src/nodes/core/NodeUtils.js

@@ -183,6 +183,39 @@ export function getTypeFromLength( length ) {
 
 
 }
 }
 
 
+/**
+ * Returns the typed array for the given data type.
+ *
+ * @method
+ * @param {String} type - The data type.
+ * @return {TypedArray} The typed array.
+ */
+export function getTypedArrayFromType( type ) {
+
+	// Handle component type for vectors and matrices
+	if ( /[iu]?vec\d/.test( type ) ) {
+
+		// Handle int vectors
+		if ( type.startsWith( 'ivec' ) ) return Int32Array;
+		// Handle uint vectors
+		if ( type.startsWith( 'uvec' ) ) return Uint32Array;
+		// Default to float vectors
+		return Float32Array;
+
+	}
+
+	// Handle matrices (always float)
+	if ( /mat\d/.test( type ) ) return Float32Array;
+
+	// Basic types
+	if ( /float/.test( type ) ) return Float32Array;
+	if ( /uint/.test( type ) ) return Uint32Array;
+	if ( /int/.test( type ) ) return Int32Array;
+
+	throw new Error( `THREE.NodeUtils: Unsupported type: ${type}` );
+
+}
+
 /**
 /**
  * Returns the length for the given data type.
  * Returns the length for the given data type.
  *
  *

粤ICP备19079148号