浏览代码

Merge pull request #13650 from takahirox/GLTFExporterUint8

GLTFExporter: Support Uint8BufferAttribute
Mr.doob 7 年之前
父节点
当前提交
a39c258cb5
共有 1 个文件被更改,包括 25 次插入1 次删除
  1. 25 1
      examples/js/exporters/GLTFExporter.js

+ 25 - 1
examples/js/exporters/GLTFExporter.js

@@ -290,7 +290,23 @@ THREE.GLTFExporter.prototype = {
 			}
 
 			// Create a new dataview and dump the attribute's array into it
-			var componentSize = componentType === WEBGL_CONSTANTS.UNSIGNED_SHORT ? 2 : 4;
+
+			var componentSize;
+
+			if ( componentType === WEBGL_CONSTANTS.UNSIGNED_BYTE ) {
+
+				componentSize = 1;
+
+			} else if ( componentType === WEBGL_CONSTANTS.UNSIGNED_SHORT ) {
+
+				componentSize = 2;
+
+			} else {
+
+				componentSize = 4;
+
+			}
+
 			var byteLength = getPaddedBufferSize( count * attribute.itemSize * componentSize );
 			var dataView = new DataView( new ArrayBuffer( byteLength ) );
 			var offset = 0;
@@ -315,6 +331,10 @@ THREE.GLTFExporter.prototype = {
 
 						dataView.setUint16( offset, value, true );
 
+					} else if ( componentType === WEBGL_CONSTANTS.UNSIGNED_BYTE ) {
+
+						dataView.setUint8( offset, value );
+
 					}
 
 					offset += componentSize;
@@ -436,6 +456,10 @@ THREE.GLTFExporter.prototype = {
 
 				componentType = WEBGL_CONSTANTS.UNSIGNED_SHORT;
 
+			} else if ( attribute.array.constructor === Uint8Array ) {
+
+				componentType = WEBGL_CONSTANTS.UNSIGNED_BYTE;
+
 			} else {
 
 				throw new Error( 'THREE.GLTFExporter: Unsupported bufferAttribute component type.' );