babylon.vertexBuffer.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var VertexBuffer = (function () {
  4. function VertexBuffer(engine, data, kind, updatable, postponeInternalCreation) {
  5. if (engine instanceof BABYLON.Mesh) {
  6. this._engine = engine.getScene().getEngine();
  7. } else {
  8. this._engine = engine;
  9. }
  10. this._updatable = updatable;
  11. this._data = data;
  12. if (!postponeInternalCreation) {
  13. this.create();
  14. }
  15. this._kind = kind;
  16. switch (kind) {
  17. case VertexBuffer.PositionKind:
  18. this._strideSize = 3;
  19. break;
  20. case VertexBuffer.NormalKind:
  21. this._strideSize = 3;
  22. break;
  23. case VertexBuffer.UVKind:
  24. this._strideSize = 2;
  25. break;
  26. case VertexBuffer.UV2Kind:
  27. this._strideSize = 2;
  28. break;
  29. case VertexBuffer.ColorKind:
  30. this._strideSize = 3;
  31. break;
  32. case VertexBuffer.MatricesIndicesKind:
  33. this._strideSize = 4;
  34. break;
  35. case VertexBuffer.MatricesWeightsKind:
  36. this._strideSize = 4;
  37. break;
  38. }
  39. }
  40. // Properties
  41. VertexBuffer.prototype.isUpdatable = function () {
  42. return this._updatable;
  43. };
  44. VertexBuffer.prototype.getData = function () {
  45. return this._data;
  46. };
  47. VertexBuffer.prototype.getBuffer = function () {
  48. return this._buffer;
  49. };
  50. VertexBuffer.prototype.getStrideSize = function () {
  51. return this._strideSize;
  52. };
  53. // Methods
  54. VertexBuffer.prototype.create = function (data) {
  55. if (!data && this._buffer) {
  56. return;
  57. }
  58. data = data || this._data;
  59. if (!this._buffer) {
  60. if (this._updatable) {
  61. this._buffer = this._engine.createDynamicVertexBuffer(data.length * 4);
  62. } else {
  63. this._buffer = this._engine.createVertexBuffer(data);
  64. }
  65. }
  66. if (this._updatable) {
  67. this._engine.updateDynamicVertexBuffer(this._buffer, data);
  68. this._data = data;
  69. }
  70. };
  71. VertexBuffer.prototype.update = function (data) {
  72. this.create(data);
  73. };
  74. VertexBuffer.prototype.dispose = function () {
  75. if (!this._buffer) {
  76. return;
  77. }
  78. if (this._engine._releaseBuffer(this._buffer)) {
  79. this._buffer = null;
  80. }
  81. };
  82. Object.defineProperty(VertexBuffer, "PositionKind", {
  83. get: function () {
  84. return VertexBuffer._PositionKind;
  85. },
  86. enumerable: true,
  87. configurable: true
  88. });
  89. Object.defineProperty(VertexBuffer, "NormalKind", {
  90. get: function () {
  91. return VertexBuffer._NormalKind;
  92. },
  93. enumerable: true,
  94. configurable: true
  95. });
  96. Object.defineProperty(VertexBuffer, "UVKind", {
  97. get: function () {
  98. return VertexBuffer._UVKind;
  99. },
  100. enumerable: true,
  101. configurable: true
  102. });
  103. Object.defineProperty(VertexBuffer, "UV2Kind", {
  104. get: function () {
  105. return VertexBuffer._UV2Kind;
  106. },
  107. enumerable: true,
  108. configurable: true
  109. });
  110. Object.defineProperty(VertexBuffer, "ColorKind", {
  111. get: function () {
  112. return VertexBuffer._ColorKind;
  113. },
  114. enumerable: true,
  115. configurable: true
  116. });
  117. Object.defineProperty(VertexBuffer, "MatricesIndicesKind", {
  118. get: function () {
  119. return VertexBuffer._MatricesIndicesKind;
  120. },
  121. enumerable: true,
  122. configurable: true
  123. });
  124. Object.defineProperty(VertexBuffer, "MatricesWeightsKind", {
  125. get: function () {
  126. return VertexBuffer._MatricesWeightsKind;
  127. },
  128. enumerable: true,
  129. configurable: true
  130. });
  131. VertexBuffer._PositionKind = "position";
  132. VertexBuffer._NormalKind = "normal";
  133. VertexBuffer._UVKind = "uv";
  134. VertexBuffer._UV2Kind = "uv2";
  135. VertexBuffer._ColorKind = "color";
  136. VertexBuffer._MatricesIndicesKind = "matricesIndices";
  137. VertexBuffer._MatricesWeightsKind = "matricesWeights";
  138. return VertexBuffer;
  139. })();
  140. BABYLON.VertexBuffer = VertexBuffer;
  141. })(BABYLON || (BABYLON = {}));
  142. //# sourceMappingURL=babylon.vertexBuffer.js.map