Pārlūkot izejas kodu

BufferAttribute: add gpuType (#26084)

* Docs: add BufferAttribute.gpuType

* BufferAttribute: add gpuType to base class

* Docs: clarify gpuType behavior for floats

* Examples: use gpuType in integer attribute example
Cody Bennett 2 gadi atpakaļ
vecāks
revīzija
b67384c280

+ 7 - 0
docs/api/en/core/BufferAttribute.html

@@ -63,6 +63,13 @@
 			or color), then this will count the number of such vectors stored.
 			or color), then this will count the number of such vectors stored.
 		</p>
 		</p>
 
 
+		<h3>[property:Number gpuType]</h3>
+		<p>
+			Configures the bound GPU type for use in shaders. Either [page:BufferAttribute THREE.FloatType] or [page:BufferAttribute THREE.IntType], default is [page:BufferAttribute THREE.FloatType].
+
+			Note: this only has an effect for integer arrays and is not configurable for float arrays. For lower precision float types, see [page:BufferAttributeTypes THREE.Float16BufferAttribute].
+		</p>
+
 		<h3>[property:Boolean isBufferAttribute]</h3>
 		<h3>[property:Boolean isBufferAttribute]</h3>
 		<p>Read-only flag to check if a given object is of type [name].</p>
 		<p>Read-only flag to check if a given object is of type [name].</p>
 
 

+ 7 - 0
docs/api/fr/core/BufferAttribute.html

@@ -55,6 +55,13 @@
 		cela comptera alors le nombre de ces vecteurs stockés.
 		cela comptera alors le nombre de ces vecteurs stockés.
 		</p>
 		</p>
 
 
+		<h3>[property:Number gpuType]</h3>
+		<p>
+			Configures the bound GPU type for use in shaders. Either [page:BufferAttribute THREE.FloatType] or [page:BufferAttribute THREE.IntType], default is [page:BufferAttribute THREE.FloatType].
+
+			Note: this only has an effect for integer arrays and is not configurable for float arrays. For lower precision float types, see [page:BufferAttributeTypes THREE.Float16BufferAttribute].
+		</p>
+
 		<h3>[property:Boolean isBufferAttribute]</h3>
 		<h3>[property:Boolean isBufferAttribute]</h3>
 		<p>
 		<p>
 		Booléen en lecture seule pour vérifier si un objet donné est de type[name].
 		Booléen en lecture seule pour vérifier si un objet donné est de type[name].

+ 7 - 0
docs/api/it/core/BufferAttribute.html

@@ -53,6 +53,13 @@
       questo conterà il numero dei vettori memorizzati.
       questo conterà il numero dei vettori memorizzati.
 		</p>
 		</p>
 
 
+		<h3>[property:Number gpuType]</h3>
+		<p>
+			Configures the bound GPU type for use in shaders. Either [page:BufferAttribute THREE.FloatType] or [page:BufferAttribute THREE.IntType], default is [page:BufferAttribute THREE.FloatType].
+
+			Note: this only has an effect for integer arrays and is not configurable for float arrays. For lower precision float types, see [page:BufferAttributeTypes THREE.Float16BufferAttribute].
+		</p>
+
 		<h3>[property:Boolean isBufferAttribute]</h3>
 		<h3>[property:Boolean isBufferAttribute]</h3>
 		<p>
 		<p>
       Flag di sola lettura per verificare se un dato oggetto è di tipo [name].
       Flag di sola lettura per verificare se un dato oggetto è di tipo [name].

+ 7 - 0
docs/api/ko/core/BufferAttribute.html

@@ -59,6 +59,13 @@
 		저장된 벡터들의 수를 계산합니다.
 		저장된 벡터들의 수를 계산합니다.
 		</p>
 		</p>
 
 
+		<h3>[property:Number gpuType]</h3>
+		<p>
+			Configures the bound GPU type for use in shaders. Either [page:BufferAttribute THREE.FloatType] or [page:BufferAttribute THREE.IntType], default is [page:BufferAttribute THREE.FloatType].
+
+			Note: this only has an effect for integer arrays and is not configurable for float arrays. For lower precision float types, see [page:BufferAttributeTypes THREE.Float16BufferAttribute].
+		</p>
+
 		<h3>[property:Boolean isBufferAttribute]</h3>
 		<h3>[property:Boolean isBufferAttribute]</h3>
 		<p>
 		<p>
 			Read-only flag to check if a given object is of type [name].
 			Read-only flag to check if a given object is of type [name].

+ 7 - 0
docs/api/zh/core/BufferAttribute.html

@@ -56,6 +56,13 @@
 			若缓存存储三元组(例如顶点位置、法向量、颜色值),则该值应等于队列中三元组的个数。
 			若缓存存储三元组(例如顶点位置、法向量、颜色值),则该值应等于队列中三元组的个数。
 		</p>
 		</p>
 
 
+		<h3>[property:Number gpuType]</h3>
+		<p>
+			Configures the bound GPU type for use in shaders. Either [page:BufferAttribute THREE.FloatType] or [page:BufferAttribute THREE.IntType], default is [page:BufferAttribute THREE.FloatType].
+
+			Note: this only has an effect for integer arrays and is not configurable for float arrays. For lower precision float types, see [page:BufferAttributeTypes THREE.Float16BufferAttribute].
+		</p>
+
 		<h3>[property:Boolean isBufferAttribute]</h3>
 		<h3>[property:Boolean isBufferAttribute]</h3>
 		<p>
 		<p>
 			用于判断对象是否为[name]类型的只读标记.
 			用于判断对象是否为[name]类型的只读标记.

+ 2 - 1
examples/webgl2_buffergeometry_attributes_integer.html

@@ -135,7 +135,8 @@
 
 
 				geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( positions, 3 ) );
 				geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( positions, 3 ) );
 				geometry.setAttribute( 'uv', new THREE.Float32BufferAttribute( uvs, 2 ) );
 				geometry.setAttribute( 'uv', new THREE.Float32BufferAttribute( uvs, 2 ) );
-				geometry.setAttribute( 'textureIndex', new THREE.Int32BufferAttribute( textureIndices, 1 ) );
+				geometry.setAttribute( 'textureIndex', new THREE.Int16BufferAttribute( textureIndices, 1 ) );
+				geometry.attributes.textureIndex.gpuType = THREE.IntType;
 
 
 				geometry.computeBoundingSphere();
 				geometry.computeBoundingSphere();
 
 

+ 2 - 48
src/core/BufferAttribute.js

@@ -28,6 +28,7 @@ class BufferAttribute {
 
 
 		this.usage = StaticDrawUsage;
 		this.usage = StaticDrawUsage;
 		this.updateRange = { offset: 0, count: - 1 };
 		this.updateRange = { offset: 0, count: - 1 };
+		this.gpuType = FloatType;
 
 
 		this.version = 0;
 		this.version = 0;
 
 
@@ -58,6 +59,7 @@ class BufferAttribute {
 		this.normalized = source.normalized;
 		this.normalized = source.normalized;
 
 
 		this.usage = source.usage;
 		this.usage = source.usage;
+		this.gpuType = source.gpuType;
 
 
 		return this;
 		return this;
 
 
@@ -378,18 +380,6 @@ class Int8BufferAttribute extends BufferAttribute {
 
 
 		super( new Int8Array( array ), itemSize, normalized );
 		super( new Int8Array( array ), itemSize, normalized );
 
 
-		this.gpuType = FloatType;
-
-	}
-
-	copy( source ) {
-
-		super.copy( source );
-
-		this.gpuType = source.gpuType;
-
-		return this;
-
 	}
 	}
 
 
 }
 }
@@ -400,18 +390,6 @@ class Uint8BufferAttribute extends BufferAttribute {
 
 
 		super( new Uint8Array( array ), itemSize, normalized );
 		super( new Uint8Array( array ), itemSize, normalized );
 
 
-		this.gpuType = FloatType;
-
-	}
-
-	copy( source ) {
-
-		super.copy( source );
-
-		this.gpuType = source.gpuType;
-
-		return this;
-
 	}
 	}
 
 
 }
 }
@@ -432,18 +410,6 @@ class Int16BufferAttribute extends BufferAttribute {
 
 
 		super( new Int16Array( array ), itemSize, normalized );
 		super( new Int16Array( array ), itemSize, normalized );
 
 
-		this.gpuType = FloatType;
-
-	}
-
-	copy( source ) {
-
-		super.copy( source );
-
-		this.gpuType = source.gpuType;
-
-		return this;
-
 	}
 	}
 
 
 }
 }
@@ -454,18 +420,6 @@ class Uint16BufferAttribute extends BufferAttribute {
 
 
 		super( new Uint16Array( array ), itemSize, normalized );
 		super( new Uint16Array( array ), itemSize, normalized );
 
 
-		this.gpuType = FloatType;
-
-	}
-
-	copy( source ) {
-
-		super.copy( source );
-
-		this.gpuType = source.gpuType;
-
-		return this;
-
 	}
 	}
 
 
 }
 }