Skip to content

Commit adfa0d8

Browse files
committed
BufferAttribute TypeArray support and normalized clean up.
1 parent 26d1c78 commit adfa0d8

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

src/core/BufferAttribute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ THREE.BufferAttribute = function ( array, itemSize, normalized ) {
1313
this.updateRange = { offset: 0, count: - 1 };
1414

1515
this.version = 0;
16-
this.normalized = normalized ? true : false;
16+
this.normalized = normalized === true;
1717

1818
};
1919

src/loaders/BufferGeometryLoader.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ THREE.BufferGeometryLoader.prototype = {
5656

5757
var attribute = attributes[ key ];
5858
var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
59-
var normalized = attribute.normalized || false;
60-
geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize , normalized) );
59+
geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize , attribute.normalized ) );
6160

6261
}
6362

src/renderers/WebGLRenderer.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,8 @@ THREE.WebGLRenderer = function ( parameters ) {
831831

832832
}
833833

834+
//
835+
834836
var index = geometry.index;
835837
var position = geometry.attributes.position;
836838

@@ -865,6 +867,8 @@ THREE.WebGLRenderer = function ( parameters ) {
865867

866868
}
867869

870+
//
871+
868872
var dataStart = 0;
869873
var dataCount = Infinity;
870874

@@ -996,48 +1000,44 @@ THREE.WebGLRenderer = function ( parameters ) {
9961000

9971001
if ( geometryAttribute !== undefined ) {
9981002

999-
var dataType = _gl.FLOAT;
1000-
var normalized = geometryAttribute.normalized;
1003+
var type = _gl.FLOAT;
10011004
var array = geometryAttribute.array;
1005+
var normalized = geometryAttribute.normalized;
1006+
10021007
if ( array instanceof Float32Array ) {
10031008

1004-
dataType = _gl.FLOAT;
1009+
type = _gl.FLOAT;
10051010

10061011
} else if ( array instanceof Float64Array ) {
10071012

10081013
console.warn("Unsupported data buffer format: Float64Array");
10091014

10101015
} else if ( array instanceof Uint16Array ) {
10111016

1012-
dataType = _gl.UNSIGNED_SHORT;
1013-
1017+
type = _gl.UNSIGNED_SHORT;
1018+
10141019
} else if ( array instanceof Int16Array ) {
10151020

1016-
dataType = _gl.SHORT;
1021+
type = _gl.SHORT;
10171022

10181023
} else if ( array instanceof Uint32Array ) {
10191024

1020-
dataType = _gl.UNSIGNED_INT;
1025+
type = _gl.UNSIGNED_INT;
10211026

10221027
} else if ( array instanceof Int32Array ) {
10231028

1024-
dataType = _gl.INT;
1029+
type = _gl.INT;
10251030

10261031
} else if ( array instanceof Int8Array ) {
10271032

1028-
dataType = _gl.BYTE;
1033+
type = _gl.BYTE;
10291034

10301035
} else if ( array instanceof Uint8Array ) {
10311036

1032-
dataType = _gl.UNSIGNED_BYTE;
1033-
1034-
} else
1035-
{
1036-
1037-
dataType = _gl.FLOAT;
1037+
type = _gl.UNSIGNED_BYTE;
10381038

10391039
}
1040-
1040+
10411041
var size = geometryAttribute.itemSize;
10421042
var buffer = objects.getAttributeBuffer( geometryAttribute );
10431043

@@ -1064,7 +1064,7 @@ THREE.WebGLRenderer = function ( parameters ) {
10641064
}
10651065

10661066
_gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
1067-
_gl.vertexAttribPointer( programAttribute, size, dataType, normalized, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
1067+
_gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
10681068

10691069
} else {
10701070

@@ -1085,7 +1085,7 @@ THREE.WebGLRenderer = function ( parameters ) {
10851085
}
10861086

10871087
_gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
1088-
_gl.vertexAttribPointer( programAttribute, size, dataType, normalized, 0, startIndex * size * geometryAttribute.array.BYTES_PER_ELEMENT );
1088+
_gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * geometryAttribute.array.BYTES_PER_ELEMENT );
10891089

10901090
}
10911091

0 commit comments

Comments
 (0)