babylon.material.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. module BABYLON {
  2. export class Material {
  3. private static _TriangleFillMode = 0;
  4. private static _WireFrameFillMode = 1;
  5. private static _PointFillMode = 2;
  6. public static get TriangleFillMode(): number {
  7. return Material._TriangleFillMode;
  8. }
  9. public static get WireFrameFillMode(): number {
  10. return Material._WireFrameFillMode;
  11. }
  12. public static get PointFillMode(): number {
  13. return Material._PointFillMode;
  14. }
  15. public id: string;
  16. public checkReadyOnEveryCall = true;
  17. public checkReadyOnlyOnce = false;
  18. public state = "";
  19. public alpha = 1.0;
  20. public backFaceCulling = true;
  21. public onCompiled: (effect: Effect) => void;
  22. public onError: (effect: Effect, errors: string) => void;
  23. public onDispose: () => void;
  24. public getRenderTargetTextures: () => SmartArray<RenderTargetTexture>;
  25. public _effect: Effect;
  26. public _wasPreviouslyReady = false;
  27. private _scene: Scene;
  28. private _fillMode = Material.TriangleFillMode;
  29. public pointSize = 1.0;
  30. public get wireframe(): boolean {
  31. return this._fillMode === Material.WireFrameFillMode;
  32. }
  33. public set wireframe(value:boolean) {
  34. this._fillMode = (value ? Material.WireFrameFillMode : Material.TriangleFillMode);
  35. }
  36. public get pointsCloud(): boolean {
  37. return this._fillMode === Material.PointFillMode;
  38. }
  39. public set pointsCloud(value: boolean) {
  40. this._fillMode = (value ? Material.PointFillMode : Material.TriangleFillMode);
  41. }
  42. public get fillMode(): number {
  43. return this._fillMode;
  44. }
  45. public set fillMode(value: number) {
  46. this._fillMode = value;
  47. }
  48. constructor(public name: string, scene: Scene, doNotAdd?: boolean) {
  49. this.id = name;
  50. this._scene = scene;
  51. if (!doNotAdd) {
  52. scene.materials.push(this);
  53. }
  54. }
  55. public isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean {
  56. return true;
  57. }
  58. public getEffect(): Effect {
  59. return this._effect;
  60. }
  61. public getScene(): Scene {
  62. return this._scene;
  63. }
  64. public needAlphaBlending(): boolean {
  65. return (this.alpha < 1.0);
  66. }
  67. public needAlphaTesting(): boolean {
  68. return false;
  69. }
  70. public getAlphaTestTexture(): BaseTexture {
  71. return null;
  72. }
  73. public trackCreation(onCompiled: (effect: Effect) => void, onError: (effect: Effect, errors: string) => void) {
  74. }
  75. public _preBind(): void {
  76. var engine = this._scene.getEngine();
  77. engine.enableEffect(this._effect);
  78. engine.setState(this.backFaceCulling);
  79. }
  80. public bind(world: Matrix, mesh: Mesh): void {
  81. }
  82. public bindOnlyWorldMatrix(world: Matrix): void {
  83. }
  84. public unbind(): void {
  85. }
  86. public dispose(forceDisposeEffect?: boolean): void {
  87. // Remove from scene
  88. var index = this._scene.materials.indexOf(this);
  89. this._scene.materials.splice(index, 1);
  90. // Shader are kept in cache for further use but we can get rid of this by using forceDisposeEffect
  91. if (forceDisposeEffect && this._effect) {
  92. this._scene.getEngine()._releaseEffect(this._effect);
  93. this._effect = null;
  94. }
  95. // Callback
  96. if (this.onDispose) {
  97. this.onDispose();
  98. }
  99. }
  100. }
  101. }