babylon.vertexBuffer.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. "use strict";
  2. var BABYLON = BABYLON || {};
  3. (function () {
  4. BABYLON.VertexBuffer = function (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 BABYLON.VertexBuffer.PositionKind:
  18. this._strideSize = 3;
  19. if (this._mesh) {
  20. this._mesh._resetPointsArrayCache();
  21. }
  22. break;
  23. case BABYLON.VertexBuffer.NormalKind:
  24. this._strideSize = 3;
  25. break;
  26. case BABYLON.VertexBuffer.UVKind:
  27. this._strideSize = 2;
  28. break;
  29. case BABYLON.VertexBuffer.UV2Kind:
  30. this._strideSize = 2;
  31. break;
  32. case BABYLON.VertexBuffer.ColorKind:
  33. this._strideSize = 3;
  34. break;
  35. case BABYLON.VertexBuffer.MatricesIndicesKind:
  36. this._strideSize = 4;
  37. break;
  38. case BABYLON.VertexBuffer.MatricesWeightsKind:
  39. this._strideSize = 4;
  40. break;
  41. }
  42. };
  43. // Properties
  44. BABYLON.VertexBuffer.prototype.isUpdatable = function () {
  45. return this._updatable;
  46. };
  47. BABYLON.VertexBuffer.prototype.getData = function() {
  48. return this._data;
  49. };
  50. BABYLON.VertexBuffer.prototype.getStrideSize = function () {
  51. return this._strideSize;
  52. };
  53. // Methods
  54. BABYLON.VertexBuffer.prototype.update = function (data) {
  55. this._engine.updateDynamicVertexBuffer(this._buffer, data);
  56. this._data = data;
  57. if (this._kind === BABYLON.VertexBuffer.PositionKind && this._mesh) {
  58. this._mesh._resetPointsArrayCache();
  59. }
  60. };
  61. BABYLON.VertexBuffer.prototype.dispose = function() {
  62. this._engine._releaseBuffer(this._buffer);
  63. };
  64. // Enums
  65. BABYLON.VertexBuffer.PositionKind = "position";
  66. BABYLON.VertexBuffer.NormalKind = "normal";
  67. BABYLON.VertexBuffer.UVKind = "uv";
  68. BABYLON.VertexBuffer.UV2Kind = "uv2";
  69. BABYLON.VertexBuffer.ColorKind = "color";
  70. BABYLON.VertexBuffer.MatricesIndicesKind = "matricesIndices";
  71. BABYLON.VertexBuffer.MatricesWeightsKind = "matricesWeights";
  72. })();