babylon.vertexBuffer.js 2.9 KB

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