vendor/GLTFExporter.js
function processBufferView(attribute, componentType, start, count, target) {
      if (!outputJSON.bufferViews) {
        outputJSON.bufferViews = [];
      }

      // Create a new dataview and dump the attribute's array into it

      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;

      for (var i = start; i < start + count; i++) {
        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];

          if (componentType === WEBGL_CONSTANTS.FLOAT) {
            dataView.setFloat32(offset, value, true);
          } else if (componentType === WEBGL_CONSTANTS.UNSIGNED_INT) {
            dataView.setUint32(offset, value, true);
          } else if (componentType === WEBGL_CONSTANTS.UNSIGNED_SHORT) {
            dataView.setUint16(offset, value, true);
          } else if (componentType === WEBGL_CONSTANTS.UNSIGNED_BYTE) {
            dataView.setUint8(offset, value);
          }

          offset += componentSize;
        }
      }

      var gltfBufferView = {
        buffer: processBuffer(dataView.buffer),
        byteOffset: byteOffset,
        byteLength: byteLength
      };

      if (target !== undefined) gltfBufferView.target = target;

      if (target === WEBGL_CONSTANTS.ARRAY_BUFFER) {
        // Only define byteStride for vertex attributes.
        gltfBufferView.byteStride = attribute.itemSize * componentSize;
      }

      byteOffset += byteLength;

      outputJSON.bufferViews.push(gltfBufferView);

      // @TODO Merge bufferViews where possible.
      var output = {
        id: outputJSON.bufferViews.length - 1,
        byteLength: 0
      };

      return output;
    }
function processBufferView(attribute, componentType, start, count, target) {
      if (!outputJSON.bufferViews) {
        outputJSON.bufferViews = [];
      }

      // Create a new dataview and dump the attribute's array into it

      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;

      for (var i = start; i < start + count; i++) {
        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];

          if (componentType === WEBGL_CONSTANTS.FLOAT) {
            dataView.setFloat32(offset, value, true);
          } else if (componentType === WEBGL_CONSTANTS.UNSIGNED_INT) {
            dataView.setUint32(offset, value, true);
          } else if (componentType === WEBGL_CONSTANTS.UNSIGNED_SHORT) {
            dataView.setUint16(offset, value, true);
          } else if (componentType === WEBGL_CONSTANTS.UNSIGNED_BYTE) {
            dataView.setUint8(offset, value);
          }

          offset += componentSize;
        }
      }

      var gltfBufferView = {
        buffer: processBuffer(dataView.buffer),
        byteOffset: byteOffset,
        byteLength: byteLength
      };

      if (target !== undefined) gltfBufferView.target = target;

      if (target === WEBGL_CONSTANTS.ARRAY_BUFFER) {
        // Only define byteStride for vertex attributes.
        gltfBufferView.byteStride = attribute.itemSize * componentSize;
      }

      byteOffset += byteLength;

      outputJSON.bufferViews.push(gltfBufferView);

      // @TODO Merge bufferViews where possible.
      var output = {
        id: outputJSON.bufferViews.length - 1,
        byteLength: 0
      };

      return output;
    }
function processBufferView ( attribute , componentType , start , count , target ) { if ( ! outputJSON . bufferViews ) { outputJSON . bufferViews = [ ] ; } // Create a new dataview and dump the attribute's array into it 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 ; for ( var i = start ; i < start + count ; i ++ ) { 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 ] ; if ( componentType === WEBGL_CONSTANTS . FLOAT ) { dataView . setFloat32 ( offset , value , true ) ; } else if ( componentType === WEBGL_CONSTANTS . UNSIGNED_INT ) { dataView . setUint32 ( offset , value , true ) ; } else if ( componentType === WEBGL_CONSTANTS . UNSIGNED_SHORT ) { dataView . setUint16 ( offset , value , true ) ; } else if ( componentType === WEBGL_CONSTANTS . UNSIGNED_BYTE ) { dataView . setUint8 ( offset , value ) ; } offset += componentSize ; } } var gltfBufferView = { buffer : processBuffer ( dataView . buffer ) , byteOffset : byteOffset , byteLength : byteLength } ; if ( target !== undefined ) gltfBufferView . target = target ; if ( target === WEBGL_CONSTANTS . ARRAY_BUFFER ) { // Only define byteStride for vertex attributes. gltfBufferView . byteStride = attribute . itemSize * componentSize ; } byteOffset += byteLength ; outputJSON . bufferViews . push ( gltfBufferView ) ; // @TODO Merge bufferViews where possible. var output = { id : outputJSON . bufferViews . length - 1 , byteLength : 0 } ; return output ; }
Process and generate a BufferView
@param  {THREE.BufferAttribute} attribute
@param  {number} componentType
@param  {number} start
@param  {number} count
@param  {number} target (Optional) Target usage of the BufferView
@return {Object}
Process and generate a BufferView