babylon.vertexBuffer.js 2.6 KB

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