babylon.material.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. "use strict";
  2. var BABYLON = BABYLON || {};
  3. (function () {
  4. BABYLON.Material = function (name, scene) {
  5. this.name = name;
  6. this.id = name;
  7. this._scene = scene;
  8. scene.materials.push(this);
  9. };
  10. // Members
  11. BABYLON.Material.prototype.checkReadyOnEveryCall = true;
  12. BABYLON.Material.prototype.checkReadyOnlyOnce = false;
  13. BABYLON.Material.prototype.alpha = 1.0;
  14. BABYLON.Material.prototype.wireframe = false;
  15. BABYLON.Material.prototype.backFaceCulling = true;
  16. BABYLON.Material.prototype._effect = null;
  17. BABYLON.Material.prototype._wasPreviouslyReady = false;
  18. // Events
  19. BABYLON.Effect.prototype.onCompiled = null;
  20. BABYLON.Effect.prototype.onError = null;
  21. BABYLON.Material.prototype.onDispose = null;
  22. // Properties
  23. BABYLON.Material.prototype.isReady = function (mesh) {
  24. return true;
  25. };
  26. BABYLON.Material.prototype.getEffect = function () {
  27. return this._effect;
  28. };
  29. BABYLON.Material.prototype.needAlphaBlending = function () {
  30. return (this.alpha < 1.0);
  31. };
  32. BABYLON.Material.prototype.needAlphaTesting = function () {
  33. return false;
  34. };
  35. // Methods
  36. BABYLON.Material.prototype.trackCreation = function (onCompiled, onError) {
  37. };
  38. BABYLON.Material.prototype._preBind = function () {
  39. var engine = this._scene.getEngine();
  40. engine.enableEffect(this._effect);
  41. engine.setState(this.backFaceCulling);
  42. };
  43. BABYLON.Material.prototype.bind = function (world, mesh) {
  44. };
  45. BABYLON.Material.prototype.unbind = function () {
  46. };
  47. BABYLON.Material.prototype.baseDispose = function (forceDisposeEffect) {
  48. // Remove from scene
  49. var index = this._scene.materials.indexOf(this);
  50. this._scene.materials.splice(index, 1);
  51. // Shader are kept in cache for further use but we can get rid of this by using forceDisposeEffect
  52. if (forceDisposeEffect && this._effect) {
  53. this._scene.getEngine()._releaseEffect(this._effect);
  54. this._effect = null;
  55. }
  56. // Callback
  57. if (this.onDispose) {
  58. this.onDispose();
  59. }
  60. };
  61. BABYLON.Material.prototype.dispose = function (forceDisposeEffect) {
  62. this.baseDispose(forceDisposeEffect);
  63. };
  64. })();