babylon.vertexBuffer.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var VertexBuffer = (function () {
  4. function VertexBuffer(mesh, data, kind, updatable, engine) {
  5. this._mesh = mesh;
  6. this._engine = engine || mesh.getScene().getEngine();
  7. this._updatable = updatable;
  8. if (updatable) {
  9. this._buffer = this._engine.createDynamicVertexBuffer(data.length * 4);
  10. this._engine.updateDynamicVertexBuffer(this._buffer, data);
  11. } else {
  12. this._buffer = this._engine.createVertexBuffer(data);
  13. }
  14. this._data = data;
  15. this._kind = kind;
  16. switch (kind) {
  17. case VertexBuffer.PositionKind:
  18. this._strideSize = 3;
  19. if (this._mesh) {
  20. this._mesh._resetPointsArrayCache();
  21. }
  22. break;
  23. case VertexBuffer.NormalKind:
  24. this._strideSize = 3;
  25. break;
  26. case VertexBuffer.UVKind:
  27. this._strideSize = 2;
  28. break;
  29. case VertexBuffer.UV2Kind:
  30. this._strideSize = 2;
  31. break;
  32. case VertexBuffer.ColorKind:
  33. this._strideSize = 3;
  34. break;
  35. case VertexBuffer.MatricesIndicesKind:
  36. this._strideSize = 4;
  37. break;
  38. case VertexBuffer.MatricesWeightsKind:
  39. this._strideSize = 4;
  40. break;
  41. }
  42. }
  43. // Properties
  44. VertexBuffer.prototype.isUpdatable = function () {
  45. return this._updatable;
  46. };
  47. VertexBuffer.prototype.getData = function () {
  48. return this._data;
  49. };
  50. VertexBuffer.prototype.getBuffer = function () {
  51. return this._buffer;
  52. };
  53. VertexBuffer.prototype.getStrideSize = function () {
  54. return this._strideSize;
  55. };
  56. // Methods
  57. VertexBuffer.prototype.update = function (data) {
  58. if (!this._updatable) {
  59. console.log("You cannot update a non-updatable vertex buffer");
  60. return;
  61. }
  62. this._engine.updateDynamicVertexBuffer(this._buffer, data);
  63. this._data = data;
  64. if (this._kind === BABYLON.VertexBuffer.PositionKind && this._mesh) {
  65. this._mesh._resetPointsArrayCache();
  66. }
  67. };
  68. VertexBuffer.prototype.dispose = function () {
  69. this._engine._releaseBuffer(this._buffer);
  70. };
  71. VertexBuffer.PositionKind = "position";
  72. VertexBuffer.NormalKind = "normal";
  73. VertexBuffer.UVKind = "uv";
  74. VertexBuffer.UV2Kind = "uv2";
  75. VertexBuffer.ColorKind = "color";
  76. VertexBuffer.MatricesIndicesKind = "matricesIndices";
  77. VertexBuffer.MatricesWeightsKind = "matricesWeights";
  78. return VertexBuffer;
  79. })();
  80. BABYLON.VertexBuffer = VertexBuffer;
  81. })(BABYLON || (BABYLON = {}));
  82. //# sourceMappingURL=babylon.vertexBuffer.js.map