babylon.vertexBuffer.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.updateDirectly = function (data) {
  75. if (!this._buffer) {
  76. return;
  77. }
  78. if (this._updatable) {
  79. this._engine.updateDynamicVertexBuffer(this._buffer, data);
  80. this._data = null;
  81. }
  82. };
  83. VertexBuffer.prototype.dispose = function () {
  84. if (!this._buffer) {
  85. return;
  86. }
  87. if (this._engine._releaseBuffer(this._buffer)) {
  88. this._buffer = null;
  89. }
  90. };
  91. Object.defineProperty(VertexBuffer, "PositionKind", {
  92. get: function () {
  93. return VertexBuffer._PositionKind;
  94. },
  95. enumerable: true,
  96. configurable: true
  97. });
  98. Object.defineProperty(VertexBuffer, "NormalKind", {
  99. get: function () {
  100. return VertexBuffer._NormalKind;
  101. },
  102. enumerable: true,
  103. configurable: true
  104. });
  105. Object.defineProperty(VertexBuffer, "UVKind", {
  106. get: function () {
  107. return VertexBuffer._UVKind;
  108. },
  109. enumerable: true,
  110. configurable: true
  111. });
  112. Object.defineProperty(VertexBuffer, "UV2Kind", {
  113. get: function () {
  114. return VertexBuffer._UV2Kind;
  115. },
  116. enumerable: true,
  117. configurable: true
  118. });
  119. Object.defineProperty(VertexBuffer, "ColorKind", {
  120. get: function () {
  121. return VertexBuffer._ColorKind;
  122. },
  123. enumerable: true,
  124. configurable: true
  125. });
  126. Object.defineProperty(VertexBuffer, "MatricesIndicesKind", {
  127. get: function () {
  128. return VertexBuffer._MatricesIndicesKind;
  129. },
  130. enumerable: true,
  131. configurable: true
  132. });
  133. Object.defineProperty(VertexBuffer, "MatricesWeightsKind", {
  134. get: function () {
  135. return VertexBuffer._MatricesWeightsKind;
  136. },
  137. enumerable: true,
  138. configurable: true
  139. });
  140. VertexBuffer._PositionKind = "position";
  141. VertexBuffer._NormalKind = "normal";
  142. VertexBuffer._UVKind = "uv";
  143. VertexBuffer._UV2Kind = "uv2";
  144. VertexBuffer._ColorKind = "color";
  145. VertexBuffer._MatricesIndicesKind = "matricesIndices";
  146. VertexBuffer._MatricesWeightsKind = "matricesWeights";
  147. return VertexBuffer;
  148. })();
  149. BABYLON.VertexBuffer = VertexBuffer;
  150. })(BABYLON || (BABYLON = {}));
  151. //# sourceMappingURL=babylon.vertexBuffer.js.map