getBinaryAccessor.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. var ComponentsPerAttribute = {
  9. SCALAR : 1,
  10. VEC2 : 2,
  11. VEC3 : 3,
  12. VEC4 : 4,
  13. MAT2 : 4,
  14. MAT3 : 9,
  15. MAT4 : 16
  16. };
  17. var 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. var componentType = accessor.componentType;
  31. var componentDatatype;
  32. if (typeof componentType === 'string') {
  33. componentDatatype = ComponentDatatype.fromName(componentType);
  34. } else {
  35. componentDatatype = componentType;
  36. }
  37. var componentsPerAttribute = ComponentsPerAttribute[accessor.type];
  38. var classType = ClassPerType[accessor.type];
  39. return {
  40. componentsPerAttribute : componentsPerAttribute,
  41. classType : classType,
  42. createArrayBufferView : function(buffer, byteOffset, length) {
  43. return ComponentDatatype.createArrayBufferView(componentDatatype, buffer, byteOffset, componentsPerAttribute * length);
  44. }
  45. };
  46. }
  47. export default getBinaryAccessor;