babylon.vertexBuffer.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. var BABYLON = BABYLON || {};
  2. (function () {
  3. BABYLON.VertexBuffer = function (mesh, data, kind, updatable) {
  4. this._mesh = mesh;
  5. this._engine = mesh.getScene().getEngine();
  6. this._updatable = updatable;
  7. if (updatable) {
  8. this._buffer = this._engine.createDynamicVertexBuffer(data.length * 4);
  9. this._engine.updateDynamicVertexBuffer(this._buffer, data);
  10. } else {
  11. this._buffer = this._engine.createVertexBuffer(data);
  12. }
  13. this._data = data;
  14. this._kind = kind;
  15. switch (kind) {
  16. case BABYLON.VertexBuffer.PositionKind:
  17. this._strideSize = 3;
  18. this._mesh._resetPointsArrayCache();
  19. break;
  20. case BABYLON.VertexBuffer.NormalKind:
  21. this._strideSize = 3;
  22. break;
  23. case BABYLON.VertexBuffer.UVKind:
  24. this._strideSize = 2;
  25. break;
  26. case BABYLON.VertexBuffer.UV2Kind:
  27. this._strideSize = 2;
  28. break;
  29. case BABYLON.VertexBuffer.ColorKind:
  30. this._strideSize = 3;
  31. break;
  32. case BABYLON.VertexBuffer.MatricesIndicesKind:
  33. this._strideSize = 4;
  34. break;
  35. case BABYLON.VertexBuffer.MatricesWeightsKind:
  36. this._strideSize = 4;
  37. break;
  38. }
  39. };
  40. // Properties
  41. BABYLON.VertexBuffer.prototype.isUpdatable = function () {
  42. return this._updatable;
  43. };
  44. BABYLON.VertexBuffer.prototype.getData = function() {
  45. return this._data;
  46. };
  47. BABYLON.VertexBuffer.prototype.getStrideSize = function () {
  48. return this._strideSize;
  49. };
  50. // Methods
  51. BABYLON.VertexBuffer.prototype.update = function (data) {
  52. this._engine.updateDynamicVertexBuffer(this._buffer, data);
  53. this._data = data;
  54. if (this._kind === BABYLON.VertexBuffer.PositionKind) {
  55. this._mesh._resetPointsArrayCache();
  56. }
  57. };
  58. BABYLON.VertexBuffer.prototype.dispose = function() {
  59. this._engine._releaseBuffer(this._buffer);
  60. };
  61. // Enums
  62. BABYLON.VertexBuffer.PositionKind = "position";
  63. BABYLON.VertexBuffer.NormalKind = "normal";
  64. BABYLON.VertexBuffer.UVKind = "uv";
  65. BABYLON.VertexBuffer.UV2Kind = "uv2";
  66. BABYLON.VertexBuffer.ColorKind = "color";
  67. BABYLON.VertexBuffer.MatricesIndicesKind = "matricesIndices";
  68. BABYLON.VertexBuffer.MatricesWeightsKind = "matricesWeights";
  69. })();