babylon.material.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var Material = (function () {
  4. function Material(name, scene, doNotAdd) {
  5. this.name = name;
  6. this.checkReadyOnEveryCall = true;
  7. this.checkReadyOnlyOnce = false;
  8. this.state = "";
  9. this.alpha = 1.0;
  10. this.backFaceCulling = true;
  11. this._wasPreviouslyReady = false;
  12. this._fillMode = Material.TriangleFillMode;
  13. this.pointSize = 1.0;
  14. this.zOffset = 0;
  15. this.id = name;
  16. this._scene = scene;
  17. if (!doNotAdd) {
  18. scene.materials.push(this);
  19. }
  20. }
  21. Object.defineProperty(Material, "TriangleFillMode", {
  22. get: function () {
  23. return Material._TriangleFillMode;
  24. },
  25. enumerable: true,
  26. configurable: true
  27. });
  28. Object.defineProperty(Material, "WireFrameFillMode", {
  29. get: function () {
  30. return Material._WireFrameFillMode;
  31. },
  32. enumerable: true,
  33. configurable: true
  34. });
  35. Object.defineProperty(Material, "PointFillMode", {
  36. get: function () {
  37. return Material._PointFillMode;
  38. },
  39. enumerable: true,
  40. configurable: true
  41. });
  42. Object.defineProperty(Material.prototype, "wireframe", {
  43. get: function () {
  44. return this._fillMode === Material.WireFrameFillMode;
  45. },
  46. set: function (value) {
  47. this._fillMode = (value ? Material.WireFrameFillMode : Material.TriangleFillMode);
  48. },
  49. enumerable: true,
  50. configurable: true
  51. });
  52. Object.defineProperty(Material.prototype, "pointsCloud", {
  53. get: function () {
  54. return this._fillMode === Material.PointFillMode;
  55. },
  56. set: function (value) {
  57. this._fillMode = (value ? Material.PointFillMode : Material.TriangleFillMode);
  58. },
  59. enumerable: true,
  60. configurable: true
  61. });
  62. Object.defineProperty(Material.prototype, "fillMode", {
  63. get: function () {
  64. return this._fillMode;
  65. },
  66. set: function (value) {
  67. this._fillMode = value;
  68. },
  69. enumerable: true,
  70. configurable: true
  71. });
  72. Material.prototype.isReady = function (mesh, useInstances) {
  73. return true;
  74. };
  75. Material.prototype.getEffect = function () {
  76. return this._effect;
  77. };
  78. Material.prototype.getScene = function () {
  79. return this._scene;
  80. };
  81. Material.prototype.needAlphaBlending = function () {
  82. return (this.alpha < 1.0);
  83. };
  84. Material.prototype.needAlphaTesting = function () {
  85. return false;
  86. };
  87. Material.prototype.getAlphaTestTexture = function () {
  88. return null;
  89. };
  90. Material.prototype.trackCreation = function (onCompiled, onError) {
  91. };
  92. Material.prototype._preBind = function () {
  93. var engine = this._scene.getEngine();
  94. engine.enableEffect(this._effect);
  95. engine.setState(this.backFaceCulling, this.zOffset);
  96. };
  97. Material.prototype.bind = function (world, mesh) {
  98. this._scene._cachedMaterial = this;
  99. if (this.onBind) {
  100. this.onBind(this);
  101. }
  102. };
  103. Material.prototype.bindOnlyWorldMatrix = function (world) {
  104. };
  105. Material.prototype.unbind = function () {
  106. };
  107. Material.prototype.dispose = function (forceDisposeEffect) {
  108. // Remove from scene
  109. var index = this._scene.materials.indexOf(this);
  110. this._scene.materials.splice(index, 1);
  111. // Shader are kept in cache for further use but we can get rid of this by using forceDisposeEffect
  112. if (forceDisposeEffect && this._effect) {
  113. this._scene.getEngine()._releaseEffect(this._effect);
  114. this._effect = null;
  115. }
  116. // Callback
  117. if (this.onDispose) {
  118. this.onDispose();
  119. }
  120. };
  121. Material._TriangleFillMode = 0;
  122. Material._WireFrameFillMode = 1;
  123. Material._PointFillMode = 2;
  124. return Material;
  125. })();
  126. BABYLON.Material = Material;
  127. })(BABYLON || (BABYLON = {}));
  128. //# sourceMappingURL=babylon.material.js.map