babylon.material.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. module BABYLON {
  2. export class Material {
  3. public id: string;
  4. public checkReadyOnEveryCall = true;
  5. public checkReadyOnlyOnce = false;
  6. public state = "";
  7. public alpha = 1.0;
  8. public wireframe = false;
  9. public backFaceCulling = true;
  10. public onCompiled: (effect: Effect) => void;
  11. public onError: (effect: Effect, errors: string) => void;
  12. public onDispose: () => void;
  13. public getRenderTargetTextures: () => SmartArray<RenderTargetTexture>;
  14. public _effect: Effect;
  15. public _wasPreviouslyReady = false;
  16. private _scene: Scene;
  17. constructor(public name: string, scene: Scene, doNotAdd?: boolean) {
  18. this.id = name;
  19. this._scene = scene;
  20. if (!doNotAdd) {
  21. scene.materials.push(this);
  22. }
  23. }
  24. public isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean {
  25. return true;
  26. }
  27. public getEffect(): Effect {
  28. return this._effect;
  29. }
  30. public getScene(): Scene {
  31. return this._scene;
  32. }
  33. public needAlphaBlending(): boolean {
  34. return (this.alpha < 1.0);
  35. }
  36. public needAlphaTesting(): boolean {
  37. return false;
  38. }
  39. public getAlphaTestTexture(): BaseTexture {
  40. return null;
  41. }
  42. public trackCreation(onCompiled: (effect: Effect) => void, onError: (effect: Effect, errors: string) => void) {
  43. }
  44. public _preBind(): void {
  45. var engine = this._scene.getEngine();
  46. engine.enableEffect(this._effect);
  47. engine.setState(this.backFaceCulling);
  48. }
  49. public bind(world: Matrix, mesh: Mesh): void {
  50. }
  51. public bindOnlyWorldMatrix(world: Matrix): void {
  52. }
  53. public unbind(): void {
  54. }
  55. public dispose(forceDisposeEffect?: boolean): void {
  56. // Remove from scene
  57. var index = this._scene.materials.indexOf(this);
  58. this._scene.materials.splice(index, 1);
  59. // Shader are kept in cache for further use but we can get rid of this by using forceDisposeEffect
  60. if (forceDisposeEffect && this._effect) {
  61. this._scene.getEngine()._releaseEffect(this._effect);
  62. this._effect = null;
  63. }
  64. // Callback
  65. if (this.onDispose) {
  66. this.onDispose();
  67. }
  68. }
  69. }
  70. }