babylon.vertexBuffer.js 5.3 KB

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