babylon.material.js 4.6 KB

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