InstanceAttributeSemantic.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import Check from "../Core/Check.js";
  2. /**
  3. * An enum describing the built-in instance attribute semantics.
  4. *
  5. * @enum {String}
  6. *
  7. * @private
  8. */
  9. const InstanceAttributeSemantic = {
  10. /**
  11. * Per-instance translation.
  12. *
  13. * @type {String}
  14. * @constant
  15. */
  16. TRANSLATION: "TRANSLATION",
  17. /**
  18. * Per-instance rotation.
  19. *
  20. * @type {String}
  21. * @constant
  22. */
  23. ROTATION: "ROTATION",
  24. /**
  25. * Per-instance scale.
  26. *
  27. * @type {String}
  28. * @constant
  29. */
  30. SCALE: "SCALE",
  31. /**
  32. * Per-instance feature ID.
  33. *
  34. * @type {String}
  35. * @constant
  36. */
  37. FEATURE_ID: "_FEATURE_ID",
  38. };
  39. /**
  40. * Gets the instance attribute semantic matching the glTF attribute semantic.
  41. *
  42. * @returns {InstanceAttributeSemantic} The instance attribute semantic, or undefined if there is no match.
  43. *
  44. * @private
  45. */
  46. InstanceAttributeSemantic.fromGltfSemantic = function (gltfSemantic) {
  47. //>>includeStart('debug', pragmas.debug);
  48. Check.typeOf.string("gltfSemantic", gltfSemantic);
  49. //>>includeEnd('debug')
  50. let semantic = gltfSemantic;
  51. // Strip the set index from the semantic
  52. const setIndexRegex = /^(\w+)_\d+$/;
  53. const setIndexMatch = setIndexRegex.exec(gltfSemantic);
  54. if (setIndexMatch !== null) {
  55. semantic = setIndexMatch[1];
  56. }
  57. switch (semantic) {
  58. case "TRANSLATION":
  59. return InstanceAttributeSemantic.TRANSLATION;
  60. case "ROTATION":
  61. return InstanceAttributeSemantic.ROTATION;
  62. case "SCALE":
  63. return InstanceAttributeSemantic.SCALE;
  64. case "_FEATURE_ID":
  65. return InstanceAttributeSemantic.FEATURE_ID;
  66. }
  67. return undefined;
  68. };
  69. export default Object.freeze(InstanceAttributeSemantic);