All files / engine/Source/Scene getBinaryAccessor.js

90% Statements 9/10
50% Branches 1/2
100% Functions 2/2
90% Lines 9/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                1x                   1x                           335x   335x 335x         335x 335x 335x       335x                    
import Cartesian2 from "../Core/Cartesian2.js";
import Cartesian3 from "../Core/Cartesian3.js";
import Cartesian4 from "../Core/Cartesian4.js";
import ComponentDatatype from "../Core/ComponentDatatype.js";
import Matrix2 from "../Core/Matrix2.js";
import Matrix3 from "../Core/Matrix3.js";
import Matrix4 from "../Core/Matrix4.js";
 
const ComponentsPerAttribute = {
  SCALAR: 1,
  VEC2: 2,
  VEC3: 3,
  VEC4: 4,
  MAT2: 4,
  MAT3: 9,
  MAT4: 16,
};
 
const ClassPerType = {
  SCALAR: undefined,
  VEC2: Cartesian2,
  VEC3: Cartesian3,
  VEC4: Cartesian4,
  MAT2: Matrix2,
  MAT3: Matrix3,
  MAT4: Matrix4,
};
 
/**
 * @private
 */
function getBinaryAccessor(accessor) {
  const componentType = accessor.componentType;
  let componentDatatype;
  if (typeof componentType === "string") {
    componentDatatype = ComponentDatatype.fromName(componentType);
  } else E{
    componentDatatype = componentType;
  }
 
  const componentsPerAttribute = ComponentsPerAttribute[accessor.type];
  const classType = ClassPerType[accessor.type];
  return {
    componentsPerAttribute: componentsPerAttribute,
    classType: classType,
    createArrayBufferView: function (buffer, byteOffset, length) {
      return ComponentDatatype.createArrayBufferView(
        componentDatatype,
        buffer,
        byteOffset,
        componentsPerAttribute * length,
      );
    },
  };
}
export default getBinaryAccessor;