浏览代码

GLTFExporter: Add ability to process interleaved buffer attributes.

Mugen87 5 年之前
父节点
当前提交
39fbd2c3d0
共有 2 个文件被更改,包括 32 次插入6 次删除
  1. 16 3
      examples/js/exporters/GLTFExporter.js
  2. 16 3
      examples/jsm/exporters/GLTFExporter.js

+ 16 - 3
examples/js/exporters/GLTFExporter.js

@@ -506,9 +506,22 @@ THREE.GLTFExporter.prototype = {
 
 				for ( var a = 0; a < attribute.itemSize; a ++ ) {
 
-					// @TODO Fails on InterleavedBufferAttribute, and could probably be
-					// optimized for normal BufferAttribute.
-					var value = attribute.array[ i * attribute.itemSize + a ];
+					var value;
+
+					if ( attribute.itemSize > 3 ) {
+
+						 // no support for interleaved data for itemSize > 3
+
+						value = attribute.array[ i * attribute.itemSize + a ];
+
+					} else {
+
+						if ( a === 0 ) value = attribute.getX( i );
+						if ( a === 1 ) value = attribute.getY( i );
+						if ( a === 2 ) value = attribute.getZ( i );
+						if ( a === 3 ) value = attribute.getW( i );
+
+					}
 
 					if ( componentType === WEBGL_CONSTANTS.FLOAT ) {
 

+ 16 - 3
examples/jsm/exporters/GLTFExporter.js

@@ -528,9 +528,22 @@ GLTFExporter.prototype = {
 
 				for ( var a = 0; a < attribute.itemSize; a ++ ) {
 
-					// @TODO Fails on InterleavedBufferAttribute, and could probably be
-					// optimized for normal BufferAttribute.
-					var value = attribute.array[ i * attribute.itemSize + a ];
+					var value;
+
+					if ( attribute.itemSize > 3 ) {
+
+						 // no support for interleaved data for itemSize > 3
+
+						value = attribute.array[ i * attribute.itemSize + a ];
+
+					} else {
+
+						if ( a === 0 ) value = attribute.getX( i );
+						if ( a === 1 ) value = attribute.getY( i );
+						if ( a === 2 ) value = attribute.getZ( i );
+						if ( a === 3 ) value = attribute.getW( i );
+
+					}
 
 					if ( componentType === WEBGL_CONSTANTS.FLOAT ) {