babylon.vertexBuffer.js 5.3 KB

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