getBinaryAccessor.js 1.4 KB

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