babylon.pushMaterial.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. module BABYLON {
  2. export class PushMaterial extends Material {
  3. protected _activeEffect: Effect;
  4. protected _normalMatrix : Matrix = new Matrix();
  5. constructor(name: string, scene: Scene) {
  6. super(name, scene);
  7. this.storeEffectOnSubMeshes = true;
  8. }
  9. public getEffect(): Effect {
  10. return this._activeEffect;
  11. }
  12. public isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean {
  13. if (!mesh) {
  14. return false;
  15. }
  16. if (!mesh.subMeshes || mesh.subMeshes.length === 0) {
  17. return true;
  18. }
  19. return this.isReadyForSubMesh(mesh, mesh.subMeshes[0], useInstances);
  20. }
  21. /**
  22. * Binds the given world matrix to the active effect
  23. *
  24. * @param world the matrix to bind
  25. */
  26. public bindOnlyWorldMatrix(world: Matrix): void {
  27. this._activeEffect.setMatrix("world", world);
  28. }
  29. /**
  30. * Binds the given normal matrix to the active effect
  31. *
  32. * @param normalMatrix the matrix to bind
  33. */
  34. public bindOnlyNormalMatrix(normalMatrix: Matrix): void {
  35. this._activeEffect.setMatrix("normalMatrix", normalMatrix);
  36. }
  37. public bind(world: Matrix, mesh?: Mesh): void {
  38. if (!mesh) {
  39. return;
  40. }
  41. this.bindForSubMesh(world, mesh, mesh.subMeshes[0]);
  42. }
  43. protected _afterBind(mesh: Mesh, effect: Nullable<Effect> = null): void {
  44. super._afterBind(mesh);
  45. this.getScene()._cachedEffect = effect;
  46. }
  47. protected _mustRebind(scene: Scene, effect: Effect, visibility: number = 1) {
  48. return scene.isCachedMaterialInvalid(this, effect, visibility);
  49. }
  50. }
  51. }