babylon.vertexBuffer.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. if (updatable) {
  7. this._buffer = this._engine.createDynamicVertexBuffer(data.length * 4);
  8. this._engine.updateDynamicVertexBuffer(this._buffer, data);
  9. } else {
  10. this._buffer = this._engine.createVertexBuffer(data);
  11. }
  12. this._data = data;
  13. this._kind = kind;
  14. switch (kind) {
  15. case BABYLON.VertexBuffer.PositionKind:
  16. this._strideSize = 3;
  17. this._mesh._resetPointsArrayCache();
  18. break;
  19. case BABYLON.VertexBuffer.NormalKind:
  20. this._strideSize = 3;
  21. break;
  22. case BABYLON.VertexBuffer.UVKind:
  23. this._strideSize = 2;
  24. break;
  25. case BABYLON.VertexBuffer.UV2Kind:
  26. this._strideSize = 2;
  27. break;
  28. case BABYLON.VertexBuffer.ColorKind:
  29. this._strideSize = 3;
  30. break;
  31. }
  32. };
  33. // Properties
  34. BABYLON.VertexBuffer.prototype.getData = function() {
  35. return this._data;
  36. };
  37. BABYLON.VertexBuffer.prototype.getStrideSize = function () {
  38. return this._strideSize;
  39. };
  40. // Methods
  41. BABYLON.VertexBuffer.prototype.update = function (data) {
  42. this._engine.updateDynamicVertexBuffer(this._buffer, data);
  43. this._data = data;
  44. if (this._kind === BABYLON.VertexBuffer.PositionKind) {
  45. this._mesh._resetPointsArrayCache();
  46. }
  47. };
  48. BABYLON.VertexBuffer.prototype.dispose = function() {
  49. this._engine._releaseBuffer(this._buffer);
  50. };
  51. // Enums
  52. BABYLON.VertexBuffer.PositionKind = "position";
  53. BABYLON.VertexBuffer.NormalKind = "normal";
  54. BABYLON.VertexBuffer.UVKind = "uv";
  55. BABYLON.VertexBuffer.UV2Kind = "uv2";
  56. BABYLON.VertexBuffer.ColorKind = "color";
  57. })();