pushMaterial.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { Matrix } from "../Maths/math.vector.js";
  2. import { Material } from "../Materials/material.js";
  3. /**
  4. * Base class of materials working in push mode in babylon JS
  5. * @internal
  6. */
  7. export class PushMaterial extends Material {
  8. constructor(name, scene, storeEffectOnSubMeshes = true) {
  9. super(name, scene);
  10. this._normalMatrix = new Matrix();
  11. this._storeEffectOnSubMeshes = storeEffectOnSubMeshes;
  12. }
  13. getEffect() {
  14. return this._storeEffectOnSubMeshes ? this._activeEffect : super.getEffect();
  15. }
  16. isReady(mesh, useInstances) {
  17. if (!mesh) {
  18. return false;
  19. }
  20. if (!this._storeEffectOnSubMeshes) {
  21. return true;
  22. }
  23. if (!mesh.subMeshes || mesh.subMeshes.length === 0) {
  24. return true;
  25. }
  26. return this.isReadyForSubMesh(mesh, mesh.subMeshes[0], useInstances);
  27. }
  28. _isReadyForSubMesh(subMesh) {
  29. const defines = subMesh.materialDefines;
  30. if (!this.checkReadyOnEveryCall && subMesh.effect && defines) {
  31. if (defines._renderId === this.getScene().getRenderId()) {
  32. return true;
  33. }
  34. }
  35. return false;
  36. }
  37. /**
  38. * Binds the given world matrix to the active effect
  39. *
  40. * @param world the matrix to bind
  41. */
  42. bindOnlyWorldMatrix(world) {
  43. this._activeEffect.setMatrix("world", world);
  44. }
  45. /**
  46. * Binds the given normal matrix to the active effect
  47. *
  48. * @param normalMatrix the matrix to bind
  49. */
  50. bindOnlyNormalMatrix(normalMatrix) {
  51. this._activeEffect.setMatrix("normalMatrix", normalMatrix);
  52. }
  53. bind(world, mesh) {
  54. if (!mesh) {
  55. return;
  56. }
  57. this.bindForSubMesh(world, mesh, mesh.subMeshes[0]);
  58. }
  59. _afterBind(mesh, effect = null, subMesh) {
  60. super._afterBind(mesh, effect, subMesh);
  61. this.getScene()._cachedEffect = effect;
  62. if (subMesh) {
  63. subMesh._drawWrapper._forceRebindOnNextCall = false;
  64. }
  65. else {
  66. this._drawWrapper._forceRebindOnNextCall = false;
  67. }
  68. }
  69. _mustRebind(scene, effect, subMesh, visibility = 1) {
  70. return subMesh._drawWrapper._forceRebindOnNextCall || scene.isCachedMaterialInvalid(this, effect, visibility);
  71. }
  72. dispose(forceDisposeEffect, forceDisposeTextures, notBoundToMesh) {
  73. this._activeEffect = undefined;
  74. super.dispose(forceDisposeEffect, forceDisposeTextures, notBoundToMesh);
  75. }
  76. }
  77. //# sourceMappingURL=pushMaterial.js.map