ModelMesh.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*global define*/
  2. define([
  3. '../Core/defineProperties'
  4. ], function(
  5. defineProperties) {
  6. "use strict";
  7. /**
  8. * A model's mesh and its materials.
  9. * <p>
  10. * Use {@link Model#getMesh} to create an instance.
  11. * </p>
  12. *
  13. * @alias ModelMesh
  14. * @internalConstructor
  15. *
  16. * @see Model#getMesh
  17. */
  18. var ModelMesh = function(mesh, runtimeMaterialsById, id) {
  19. var materials = [];
  20. var primitives = mesh.primitives;
  21. var length = primitives.length;
  22. for (var i = 0; i < length; ++i) {
  23. var p = primitives[i];
  24. materials[i] = runtimeMaterialsById[p.material];
  25. }
  26. this._name = mesh.name;
  27. this._materials = materials;
  28. this._id = id;
  29. };
  30. defineProperties(ModelMesh.prototype, {
  31. /**
  32. * The value of the <code>name</code> property of this mesh. This is the
  33. * name assigned by the artist when the asset is created. This can be
  34. * different than the name of the mesh property ({@link ModelMesh#id}),
  35. * which is internal to glTF.
  36. *
  37. * @memberof ModelMesh.prototype
  38. *
  39. * @type {String}
  40. * @readonly
  41. */
  42. name : {
  43. get : function() {
  44. return this._name;
  45. }
  46. },
  47. /**
  48. * The name of the glTF JSON property for this mesh. This is guaranteed
  49. * to be unique among all meshes. It may not match the mesh's <code>
  50. * name</code> property (@link ModelMesh#name), which is assigned by
  51. * the artist when the asset is created.
  52. *
  53. * @memberof ModelMesh.prototype
  54. *
  55. * @type {String}
  56. * @readonly
  57. */
  58. id : {
  59. get : function() {
  60. return this._id;
  61. }
  62. },
  63. /**
  64. * An array of {@link ModelMaterial} instances indexed by the mesh's
  65. * primitive indices.
  66. *
  67. * @memberof ModelMesh.prototype
  68. *
  69. * @type {ModelMaterial[]}
  70. * @readonly
  71. */
  72. materials : {
  73. get : function() {
  74. return this._materials;
  75. }
  76. }
  77. });
  78. return ModelMesh;
  79. });