@babylonjs/core 7.27.1 → 7.27.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/Animations/animatable.core.d.ts +198 -0
  2. package/Animations/animatable.core.js +893 -0
  3. package/Animations/animatable.core.js.map +1 -0
  4. package/Animations/animatable.d.ts +4 -213
  5. package/Animations/animatable.js +5 -886
  6. package/Animations/animatable.js.map +1 -1
  7. package/Animations/animationGroup.d.ts +1 -1
  8. package/Animations/animationGroup.js.map +1 -1
  9. package/Animations/runtimeAnimation.d.ts +1 -0
  10. package/Animations/runtimeAnimation.js +25 -1
  11. package/Animations/runtimeAnimation.js.map +1 -1
  12. package/Audio/audioSceneComponent.d.ts +0 -4
  13. package/Audio/audioSceneComponent.js.map +1 -1
  14. package/Behaviors/Cameras/bouncingBehavior.js.map +1 -1
  15. package/Behaviors/Cameras/framingBehavior.js.map +1 -1
  16. package/Bones/skeleton.d.ts +1 -1
  17. package/Bones/skeleton.js.map +1 -1
  18. package/Culling/ray.core.d.ts +328 -0
  19. package/Culling/ray.core.js +934 -0
  20. package/Culling/ray.core.js.map +1 -0
  21. package/Culling/ray.d.ts +1 -220
  22. package/Culling/ray.js +12 -791
  23. package/Culling/ray.js.map +1 -1
  24. package/Engines/abstractEngine.js +2 -2
  25. package/Engines/abstractEngine.js.map +1 -1
  26. package/FlowGraph/Blocks/Execution/Animation/flowGraphPauseAnimationBlock.d.ts +1 -1
  27. package/FlowGraph/Blocks/Execution/Animation/flowGraphPauseAnimationBlock.js.map +1 -1
  28. package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.d.ts +1 -1
  29. package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.js.map +1 -1
  30. package/FlowGraph/Blocks/Execution/Animation/flowGraphStopAnimationBlock.d.ts +1 -1
  31. package/FlowGraph/Blocks/Execution/Animation/flowGraphStopAnimationBlock.js.map +1 -1
  32. package/Inputs/scene.inputManager.js +1 -1
  33. package/Inputs/scene.inputManager.js.map +1 -1
  34. package/Layers/effectLayerSceneComponent.d.ts +0 -6
  35. package/Layers/effectLayerSceneComponent.js +0 -1
  36. package/Layers/effectLayerSceneComponent.js.map +1 -1
  37. package/Layers/layerSceneComponent.d.ts +0 -9
  38. package/Layers/layerSceneComponent.js +0 -1
  39. package/Layers/layerSceneComponent.js.map +1 -1
  40. package/LensFlares/lensFlareSystemSceneComponent.d.ts +0 -5
  41. package/LensFlares/lensFlareSystemSceneComponent.js +0 -1
  42. package/LensFlares/lensFlareSystemSceneComponent.js.map +1 -1
  43. package/Lights/light.js.map +1 -1
  44. package/Materials/Textures/Procedurals/proceduralTextureSceneComponent.d.ts +0 -10
  45. package/Materials/Textures/Procedurals/proceduralTextureSceneComponent.js +0 -1
  46. package/Materials/Textures/Procedurals/proceduralTextureSceneComponent.js.map +1 -1
  47. package/Materials/effectRenderer.d.ts +1 -0
  48. package/Materials/effectRenderer.js +2 -0
  49. package/Materials/effectRenderer.js.map +1 -1
  50. package/Meshes/mesh.d.ts +7 -0
  51. package/Meshes/mesh.js +15 -0
  52. package/Meshes/mesh.js.map +1 -1
  53. package/Misc/assetsManager.d.ts +1 -1
  54. package/Misc/assetsManager.js.map +1 -1
  55. package/Misc/tools.js +1 -13
  56. package/Misc/tools.js.map +1 -1
  57. package/Sprites/spriteSceneComponent.d.ts +1 -1
  58. package/Sprites/spriteSceneComponent.js +4 -4
  59. package/Sprites/spriteSceneComponent.js.map +1 -1
  60. package/assetContainer.d.ts +1 -1
  61. package/assetContainer.js.map +1 -1
  62. package/node.d.ts +1 -1
  63. package/node.js.map +1 -1
  64. package/package.json +1 -1
  65. package/scene.d.ts +45 -4
  66. package/scene.js +81 -54
  67. package/scene.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"effectRenderer.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/effectRenderer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE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,OAAO,EACP,SAAS,EACT,eAAe,CAAC,UAAU,EAC1B,SAAS,EACT,SAAS,EACT,SAAS,EACT,eAAe,CAAC,cAAc,EAC9B,eAAe,CAAC,yBAAyB,CAC5C,CAAC;YAEF,IAAI,CAAC,0BAA0B,GAAG,eAAe,CAAC,MAAM,CAAC,2BAA2B,CAAC,GAAG,CAAC,GAAG,EAAE;gBAC1F,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC,oHAAoH;gBACzJ,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;YACjC,CAAC,CAAC,CAAC;SACN;IACL,CAAC;IAED;;;OAGG;IACI,OAAO,CAAC,WAAoB,KAAK;QACpC,IAAI,IAAI,CAAC,0BAA0B,EAAE;YACjC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,2BAA2B,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;YAC5F,IAAI,CAAC,0BAA0B,GAAG,IAAI,CAAC;SAC1C;QACD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { Viewport } from \"../Maths/math.viewport\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { Effect } from \"./effect\";\r\nimport type { DataBuffer } from \"../Buffers/dataBuffer\";\r\nimport { DrawWrapper } from \"./drawWrapper\";\r\nimport type { IRenderTargetTexture, RenderTargetWrapper } from \"../Engines/renderTargetWrapper\";\r\nimport type { ShaderLanguage } from \"./shaderLanguage\";\r\n\r\n/**\r\n * Effect Render Options\r\n */\r\nexport interface IEffectRendererOptions {\r\n /**\r\n * Defines the vertices positions.\r\n */\r\n positions?: number[];\r\n /**\r\n * Defines the indices.\r\n */\r\n indices?: number[];\r\n}\r\n\r\n// Fullscreen quad buffers by default.\r\nconst defaultOptions = {\r\n positions: [1, 1, -1, 1, -1, -1, 1, -1],\r\n indices: [0, 1, 2, 0, 2, 3],\r\n};\r\n\r\n/**\r\n * Helper class to render one or more effects.\r\n * You can access the previous rendering in your shader by declaring a sampler named textureSampler\r\n */\r\nexport class EffectRenderer {\r\n /**\r\n * The engine the effect renderer has been created for.\r\n */\r\n public readonly engine: AbstractEngine;\r\n\r\n private _vertexBuffers: { [key: string]: VertexBuffer };\r\n private _indexBuffer: DataBuffer;\r\n\r\n private _fullscreenViewport = new Viewport(0, 0, 1, 1);\r\n private _onContextRestoredObserver: Nullable<Observer<AbstractEngine>>;\r\n\r\n private _savedStateDepthTest: boolean;\r\n private _savedStateStencilTest: boolean;\r\n\r\n /**\r\n * Creates an effect renderer\r\n * @param engine the engine to use for rendering\r\n * @param options defines the options of the effect renderer\r\n */\r\n constructor(engine: AbstractEngine, options: IEffectRendererOptions = defaultOptions) {\r\n const positions = options.positions ?? defaultOptions.positions;\r\n const indices = options.indices ?? defaultOptions.indices;\r\n\r\n this.engine = engine;\r\n this._vertexBuffers = {\r\n [VertexBuffer.PositionKind]: new VertexBuffer(engine, positions, VertexBuffer.PositionKind, false, false, 2),\r\n };\r\n this._indexBuffer = engine.createIndexBuffer(indices);\r\n\r\n this._onContextRestoredObserver = engine.onContextRestoredObservable.add(() => {\r\n this._indexBuffer = engine.createIndexBuffer(indices);\r\n\r\n for (const key in this._vertexBuffers) {\r\n const vertexBuffer = this._vertexBuffers[key];\r\n vertexBuffer._rebuild();\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Sets the current viewport in normalized coordinates 0-1\r\n * @param viewport Defines the viewport to set (defaults to 0 0 1 1)\r\n */\r\n public setViewport(viewport = this._fullscreenViewport): void {\r\n this.engine.setViewport(viewport);\r\n }\r\n\r\n /**\r\n * Binds the embedded attributes buffer to the effect.\r\n * @param effect Defines the effect to bind the attributes for\r\n */\r\n public bindBuffers(effect: Effect): void {\r\n this.engine.bindBuffers(this._vertexBuffers, this._indexBuffer, effect);\r\n }\r\n\r\n /**\r\n * Sets the current effect wrapper to use during draw.\r\n * The effect needs to be ready before calling this api.\r\n * This also sets the default full screen position attribute.\r\n * @param effectWrapper Defines the effect to draw with\r\n */\r\n public applyEffectWrapper(effectWrapper: EffectWrapper): void {\r\n this.engine.setState(true);\r\n this.engine.depthCullingState.depthTest = false;\r\n this.engine.stencilState.stencilTest = false;\r\n this.engine.enableEffect(effectWrapper._drawWrapper);\r\n this.bindBuffers(effectWrapper.effect);\r\n effectWrapper.onApplyObservable.notifyObservers({});\r\n }\r\n\r\n /**\r\n * Saves engine states\r\n */\r\n public saveStates(): void {\r\n this._savedStateDepthTest = this.engine.depthCullingState.depthTest;\r\n this._savedStateStencilTest = this.engine.stencilState.stencilTest;\r\n }\r\n\r\n /**\r\n * Restores engine states\r\n */\r\n public restoreStates(): void {\r\n this.engine.depthCullingState.depthTest = this._savedStateDepthTest;\r\n this.engine.stencilState.stencilTest = this._savedStateStencilTest;\r\n }\r\n\r\n /**\r\n * Draws a full screen quad.\r\n */\r\n public draw(): void {\r\n this.engine.drawElementsType(Constants.MATERIAL_TriangleFillMode, 0, 6);\r\n }\r\n\r\n private _isRenderTargetTexture(texture: RenderTargetWrapper | IRenderTargetTexture): texture is IRenderTargetTexture {\r\n return (texture as IRenderTargetTexture).renderTarget !== undefined;\r\n }\r\n\r\n /**\r\n * renders one or more effects to a specified texture\r\n * @param effectWrapper the effect to renderer\r\n * @param outputTexture texture to draw to, if null it will render to the screen.\r\n */\r\n public render(effectWrapper: EffectWrapper, outputTexture: Nullable<RenderTargetWrapper | IRenderTargetTexture> = null) {\r\n // Ensure effect is ready\r\n if (!effectWrapper.effect.isReady()) {\r\n return;\r\n }\r\n\r\n this.saveStates();\r\n\r\n // Reset state\r\n this.setViewport();\r\n\r\n const out = outputTexture === null ? null : this._isRenderTargetTexture(outputTexture) ? outputTexture.renderTarget! : outputTexture;\r\n\r\n if (out) {\r\n this.engine.bindFramebuffer(out);\r\n }\r\n\r\n this.applyEffectWrapper(effectWrapper);\r\n\r\n this.draw();\r\n\r\n if (out) {\r\n this.engine.unBindFramebuffer(out);\r\n }\r\n\r\n this.restoreStates();\r\n }\r\n\r\n /**\r\n * Disposes of the effect renderer\r\n */\r\n dispose() {\r\n const vertexBuffer = this._vertexBuffers[VertexBuffer.PositionKind];\r\n if (vertexBuffer) {\r\n vertexBuffer.dispose();\r\n delete this._vertexBuffers[VertexBuffer.PositionKind];\r\n }\r\n\r\n if (this._indexBuffer) {\r\n this.engine._releaseBuffer(this._indexBuffer);\r\n }\r\n\r\n if (this._onContextRestoredObserver) {\r\n this.engine.onContextRestoredObservable.remove(this._onContextRestoredObserver);\r\n this._onContextRestoredObserver = null;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Options to create an EffectWrapper\r\n */\r\ninterface EffectWrapperCreationOptions {\r\n /**\r\n * Engine to use to create the effect\r\n */\r\n engine: AbstractEngine;\r\n /**\r\n * Fragment shader for the effect\r\n */\r\n fragmentShader: string;\r\n /**\r\n * Use the shader store instead of direct source code\r\n */\r\n useShaderStore?: boolean;\r\n /**\r\n * Vertex shader for the effect\r\n */\r\n vertexShader?: string;\r\n /**\r\n * Attributes to use in the shader\r\n */\r\n attributeNames?: Array<string>;\r\n /**\r\n * Uniforms to use in the shader\r\n */\r\n uniformNames?: Array<string>;\r\n /**\r\n * Texture sampler names to use in the shader\r\n */\r\n samplerNames?: Array<string>;\r\n /**\r\n * Defines to use in the shader\r\n */\r\n defines?: Array<string>;\r\n /**\r\n * Callback when effect is compiled\r\n */\r\n onCompiled?: Nullable<(effect: Effect) => void>;\r\n /**\r\n * The friendly name of the effect displayed in Spector.\r\n */\r\n name?: string;\r\n /**\r\n * The language the shader is written in (default: GLSL)\r\n */\r\n shaderLanguage?: ShaderLanguage;\r\n /**\r\n * Additional async code to run before preparing the effect\r\n */\r\n extraInitializationsAsync?: () => Promise<void>;\r\n}\r\n\r\n/**\r\n * Wraps an effect to be used for rendering\r\n */\r\nexport class EffectWrapper {\r\n /**\r\n * Event that is fired right before the effect is drawn (should be used to update uniforms)\r\n */\r\n public onApplyObservable = new Observable<{}>();\r\n /**\r\n * The underlying effect\r\n */\r\n public get effect(): Effect {\r\n return this._drawWrapper.effect!;\r\n }\r\n\r\n public set effect(effect: Effect) {\r\n this._drawWrapper.effect = effect;\r\n }\r\n\r\n /** @internal */\r\n public _drawWrapper: DrawWrapper;\r\n\r\n private _onContextRestoredObserver: Nullable<Observer<AbstractEngine>>;\r\n\r\n /**\r\n * Creates an effect to be renderer\r\n * @param creationOptions options to create the effect\r\n */\r\n constructor(creationOptions: EffectWrapperCreationOptions) {\r\n let shaderPath: any;\r\n const uniformNames = creationOptions.uniformNames || [];\r\n\r\n if (creationOptions.vertexShader) {\r\n shaderPath = {\r\n fragmentSource: creationOptions.fragmentShader,\r\n vertexSource: creationOptions.vertexShader,\r\n spectorName: creationOptions.name || \"effectWrapper\",\r\n };\r\n } else {\r\n // Default scale to use in post process vertex shader.\r\n uniformNames.push(\"scale\");\r\n\r\n shaderPath = {\r\n fragmentSource: creationOptions.fragmentShader,\r\n vertex: \"postprocess\",\r\n spectorName: creationOptions.name || \"effectWrapper\",\r\n };\r\n\r\n // Sets the default scale to identity for the post process vertex shader.\r\n this.onApplyObservable.add(() => {\r\n this.effect.setFloat2(\"scale\", 1, 1);\r\n });\r\n }\r\n\r\n const defines = creationOptions.defines ? creationOptions.defines.join(\"\\n\") : \"\";\r\n this._drawWrapper = new DrawWrapper(creationOptions.engine);\r\n\r\n if (creationOptions.useShaderStore) {\r\n shaderPath.fragment = shaderPath.fragmentSource;\r\n if (!shaderPath.vertex) {\r\n shaderPath.vertex = shaderPath.vertexSource;\r\n }\r\n\r\n delete shaderPath.fragmentSource;\r\n delete shaderPath.vertexSource;\r\n\r\n this.effect = creationOptions.engine.createEffect(\r\n shaderPath,\r\n creationOptions.attributeNames || [\"position\"],\r\n uniformNames,\r\n creationOptions.samplerNames,\r\n defines,\r\n undefined,\r\n creationOptions.onCompiled,\r\n undefined,\r\n undefined,\r\n creationOptions.shaderLanguage,\r\n creationOptions.extraInitializationsAsync\r\n );\r\n } else {\r\n this.effect = new Effect(\r\n shaderPath,\r\n creationOptions.attributeNames || [\"position\"],\r\n uniformNames,\r\n creationOptions.samplerNames,\r\n creationOptions.engine,\r\n defines,\r\n undefined,\r\n creationOptions.onCompiled,\r\n undefined,\r\n undefined,\r\n undefined,\r\n creationOptions.shaderLanguage,\r\n creationOptions.extraInitializationsAsync\r\n );\r\n\r\n this._onContextRestoredObserver = creationOptions.engine.onContextRestoredObservable.add(() => {\r\n this.effect._pipelineContext = null; // because _prepareEffect will try to dispose this pipeline before recreating it and that would lead to webgl errors\r\n this.effect._prepareEffect();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the effect wrapper\r\n * @param _ignored kept for backward compatibility\r\n */\r\n public dispose(_ignored: boolean = false) {\r\n if (this._onContextRestoredObserver) {\r\n this.effect.getEngine().onContextRestoredObservable.remove(this._onContextRestoredObserver);\r\n this._onContextRestoredObserver = null;\r\n }\r\n this.effect.dispose();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"effectRenderer.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/effectRenderer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI5C,sCAAsC;AACtC,OAAO,+BAA+B,CAAC;AAgBvC,sCAAsC;AACtC,MAAM,cAAc,GAAG;IACnB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AAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;YACjC,CAAC,CAAC,CAAC;SACN;IACL,CAAC;IAED;;;OAGG;IACI,OAAO,CAAC,WAAoB,KAAK;QACpC,IAAI,IAAI,CAAC,0BAA0B,EAAE;YACjC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,2BAA2B,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;YAC5F,IAAI,CAAC,0BAA0B,GAAG,IAAI,CAAC;SAC1C;QACD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { Viewport } from \"../Maths/math.viewport\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { Effect } from \"./effect\";\r\nimport type { DataBuffer } from \"../Buffers/dataBuffer\";\r\nimport { DrawWrapper } from \"./drawWrapper\";\r\nimport type { IRenderTargetTexture, RenderTargetWrapper } from \"../Engines/renderTargetWrapper\";\r\nimport type { ShaderLanguage } from \"./shaderLanguage\";\r\n\r\n// Prevents ES6 issue if not imported.\r\nimport \"../Shaders/postprocess.vertex\";\r\n\r\n/**\r\n * Effect Render Options\r\n */\r\nexport interface IEffectRendererOptions {\r\n /**\r\n * Defines the vertices positions.\r\n */\r\n positions?: number[];\r\n /**\r\n * Defines the indices.\r\n */\r\n indices?: number[];\r\n}\r\n\r\n// Fullscreen quad buffers by default.\r\nconst defaultOptions = {\r\n positions: [1, 1, -1, 1, -1, -1, 1, -1],\r\n indices: [0, 1, 2, 0, 2, 3],\r\n};\r\n\r\n/**\r\n * Helper class to render one or more effects.\r\n * You can access the previous rendering in your shader by declaring a sampler named textureSampler\r\n */\r\nexport class EffectRenderer {\r\n /**\r\n * The engine the effect renderer has been created for.\r\n */\r\n public readonly engine: AbstractEngine;\r\n\r\n private _vertexBuffers: { [key: string]: VertexBuffer };\r\n private _indexBuffer: DataBuffer;\r\n\r\n private _fullscreenViewport = new Viewport(0, 0, 1, 1);\r\n private _onContextRestoredObserver: Nullable<Observer<AbstractEngine>>;\r\n\r\n private _savedStateDepthTest: boolean;\r\n private _savedStateStencilTest: boolean;\r\n\r\n /**\r\n * Creates an effect renderer\r\n * @param engine the engine to use for rendering\r\n * @param options defines the options of the effect renderer\r\n */\r\n constructor(engine: AbstractEngine, options: IEffectRendererOptions = defaultOptions) {\r\n const positions = options.positions ?? defaultOptions.positions;\r\n const indices = options.indices ?? defaultOptions.indices;\r\n\r\n this.engine = engine;\r\n this._vertexBuffers = {\r\n [VertexBuffer.PositionKind]: new VertexBuffer(engine, positions, VertexBuffer.PositionKind, false, false, 2),\r\n };\r\n this._indexBuffer = engine.createIndexBuffer(indices);\r\n\r\n this._onContextRestoredObserver = engine.onContextRestoredObservable.add(() => {\r\n this._indexBuffer = engine.createIndexBuffer(indices);\r\n\r\n for (const key in this._vertexBuffers) {\r\n const vertexBuffer = this._vertexBuffers[key];\r\n vertexBuffer._rebuild();\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Sets the current viewport in normalized coordinates 0-1\r\n * @param viewport Defines the viewport to set (defaults to 0 0 1 1)\r\n */\r\n public setViewport(viewport = this._fullscreenViewport): void {\r\n this.engine.setViewport(viewport);\r\n }\r\n\r\n /**\r\n * Binds the embedded attributes buffer to the effect.\r\n * @param effect Defines the effect to bind the attributes for\r\n */\r\n public bindBuffers(effect: Effect): void {\r\n this.engine.bindBuffers(this._vertexBuffers, this._indexBuffer, effect);\r\n }\r\n\r\n /**\r\n * Sets the current effect wrapper to use during draw.\r\n * The effect needs to be ready before calling this api.\r\n * This also sets the default full screen position attribute.\r\n * @param effectWrapper Defines the effect to draw with\r\n */\r\n public applyEffectWrapper(effectWrapper: EffectWrapper): void {\r\n this.engine.setState(true);\r\n this.engine.depthCullingState.depthTest = false;\r\n this.engine.stencilState.stencilTest = false;\r\n this.engine.enableEffect(effectWrapper._drawWrapper);\r\n this.bindBuffers(effectWrapper.effect);\r\n effectWrapper.onApplyObservable.notifyObservers({});\r\n }\r\n\r\n /**\r\n * Saves engine states\r\n */\r\n public saveStates(): void {\r\n this._savedStateDepthTest = this.engine.depthCullingState.depthTest;\r\n this._savedStateStencilTest = this.engine.stencilState.stencilTest;\r\n }\r\n\r\n /**\r\n * Restores engine states\r\n */\r\n public restoreStates(): void {\r\n this.engine.depthCullingState.depthTest = this._savedStateDepthTest;\r\n this.engine.stencilState.stencilTest = this._savedStateStencilTest;\r\n }\r\n\r\n /**\r\n * Draws a full screen quad.\r\n */\r\n public draw(): void {\r\n this.engine.drawElementsType(Constants.MATERIAL_TriangleFillMode, 0, 6);\r\n }\r\n\r\n private _isRenderTargetTexture(texture: RenderTargetWrapper | IRenderTargetTexture): texture is IRenderTargetTexture {\r\n return (texture as IRenderTargetTexture).renderTarget !== undefined;\r\n }\r\n\r\n /**\r\n * renders one or more effects to a specified texture\r\n * @param effectWrapper the effect to renderer\r\n * @param outputTexture texture to draw to, if null it will render to the screen.\r\n */\r\n public render(effectWrapper: EffectWrapper, outputTexture: Nullable<RenderTargetWrapper | IRenderTargetTexture> = null) {\r\n // Ensure effect is ready\r\n if (!effectWrapper.effect.isReady()) {\r\n return;\r\n }\r\n\r\n this.saveStates();\r\n\r\n // Reset state\r\n this.setViewport();\r\n\r\n const out = outputTexture === null ? null : this._isRenderTargetTexture(outputTexture) ? outputTexture.renderTarget! : outputTexture;\r\n\r\n if (out) {\r\n this.engine.bindFramebuffer(out);\r\n }\r\n\r\n this.applyEffectWrapper(effectWrapper);\r\n\r\n this.draw();\r\n\r\n if (out) {\r\n this.engine.unBindFramebuffer(out);\r\n }\r\n\r\n this.restoreStates();\r\n }\r\n\r\n /**\r\n * Disposes of the effect renderer\r\n */\r\n dispose() {\r\n const vertexBuffer = this._vertexBuffers[VertexBuffer.PositionKind];\r\n if (vertexBuffer) {\r\n vertexBuffer.dispose();\r\n delete this._vertexBuffers[VertexBuffer.PositionKind];\r\n }\r\n\r\n if (this._indexBuffer) {\r\n this.engine._releaseBuffer(this._indexBuffer);\r\n }\r\n\r\n if (this._onContextRestoredObserver) {\r\n this.engine.onContextRestoredObservable.remove(this._onContextRestoredObserver);\r\n this._onContextRestoredObserver = null;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Options to create an EffectWrapper\r\n */\r\ninterface EffectWrapperCreationOptions {\r\n /**\r\n * Engine to use to create the effect\r\n */\r\n engine: AbstractEngine;\r\n /**\r\n * Fragment shader for the effect\r\n */\r\n fragmentShader: string;\r\n /**\r\n * Use the shader store instead of direct source code\r\n */\r\n useShaderStore?: boolean;\r\n /**\r\n * Vertex shader for the effect\r\n */\r\n vertexShader?: string;\r\n /**\r\n * Attributes to use in the shader\r\n */\r\n attributeNames?: Array<string>;\r\n /**\r\n * Uniforms to use in the shader\r\n */\r\n uniformNames?: Array<string>;\r\n /**\r\n * Texture sampler names to use in the shader\r\n */\r\n samplerNames?: Array<string>;\r\n /**\r\n * Defines to use in the shader\r\n */\r\n defines?: Array<string>;\r\n /**\r\n * Callback when effect is compiled\r\n */\r\n onCompiled?: Nullable<(effect: Effect) => void>;\r\n /**\r\n * The friendly name of the effect displayed in Spector.\r\n */\r\n name?: string;\r\n /**\r\n * The language the shader is written in (default: GLSL)\r\n */\r\n shaderLanguage?: ShaderLanguage;\r\n /**\r\n * Additional async code to run before preparing the effect\r\n */\r\n extraInitializationsAsync?: () => Promise<void>;\r\n}\r\n\r\n/**\r\n * Wraps an effect to be used for rendering\r\n */\r\nexport class EffectWrapper {\r\n /**\r\n * Event that is fired right before the effect is drawn (should be used to update uniforms)\r\n */\r\n public onApplyObservable = new Observable<{}>();\r\n /**\r\n * The underlying effect\r\n */\r\n public get effect(): Effect {\r\n return this._drawWrapper.effect!;\r\n }\r\n\r\n public set effect(effect: Effect) {\r\n this._drawWrapper.effect = effect;\r\n }\r\n\r\n /** @internal */\r\n public _drawWrapper: DrawWrapper;\r\n\r\n private _onContextRestoredObserver: Nullable<Observer<AbstractEngine>>;\r\n\r\n /**\r\n * Creates an effect to be renderer\r\n * @param creationOptions options to create the effect\r\n */\r\n constructor(creationOptions: EffectWrapperCreationOptions) {\r\n let shaderPath: any;\r\n const uniformNames = creationOptions.uniformNames || [];\r\n\r\n if (creationOptions.vertexShader) {\r\n shaderPath = {\r\n fragmentSource: creationOptions.fragmentShader,\r\n vertexSource: creationOptions.vertexShader,\r\n spectorName: creationOptions.name || \"effectWrapper\",\r\n };\r\n } else {\r\n // Default scale to use in post process vertex shader.\r\n uniformNames.push(\"scale\");\r\n\r\n shaderPath = {\r\n fragmentSource: creationOptions.fragmentShader,\r\n vertex: \"postprocess\",\r\n spectorName: creationOptions.name || \"effectWrapper\",\r\n };\r\n\r\n // Sets the default scale to identity for the post process vertex shader.\r\n this.onApplyObservable.add(() => {\r\n this.effect.setFloat2(\"scale\", 1, 1);\r\n });\r\n }\r\n\r\n const defines = creationOptions.defines ? creationOptions.defines.join(\"\\n\") : \"\";\r\n this._drawWrapper = new DrawWrapper(creationOptions.engine);\r\n\r\n if (creationOptions.useShaderStore) {\r\n shaderPath.fragment = shaderPath.fragmentSource;\r\n if (!shaderPath.vertex) {\r\n shaderPath.vertex = shaderPath.vertexSource;\r\n }\r\n\r\n delete shaderPath.fragmentSource;\r\n delete shaderPath.vertexSource;\r\n\r\n this.effect = creationOptions.engine.createEffect(\r\n shaderPath,\r\n creationOptions.attributeNames || [\"position\"],\r\n uniformNames,\r\n creationOptions.samplerNames,\r\n defines,\r\n undefined,\r\n creationOptions.onCompiled,\r\n undefined,\r\n undefined,\r\n creationOptions.shaderLanguage,\r\n creationOptions.extraInitializationsAsync\r\n );\r\n } else {\r\n this.effect = new Effect(\r\n shaderPath,\r\n creationOptions.attributeNames || [\"position\"],\r\n uniformNames,\r\n creationOptions.samplerNames,\r\n creationOptions.engine,\r\n defines,\r\n undefined,\r\n creationOptions.onCompiled,\r\n undefined,\r\n undefined,\r\n undefined,\r\n creationOptions.shaderLanguage,\r\n creationOptions.extraInitializationsAsync\r\n );\r\n\r\n this._onContextRestoredObserver = creationOptions.engine.onContextRestoredObservable.add(() => {\r\n this.effect._pipelineContext = null; // because _prepareEffect will try to dispose this pipeline before recreating it and that would lead to webgl errors\r\n this.effect._prepareEffect();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the effect wrapper\r\n * @param _ignored kept for backward compatibility\r\n */\r\n public dispose(_ignored: boolean = false) {\r\n if (this._onContextRestoredObserver) {\r\n this.effect.getEngine().onContextRestoredObservable.remove(this._onContextRestoredObserver);\r\n this._onContextRestoredObserver = null;\r\n }\r\n this.effect.dispose();\r\n }\r\n}\r\n"]}
package/Meshes/mesh.d.ts CHANGED
@@ -770,6 +770,13 @@ export declare class Mesh extends AbstractMesh implements IGetSetVerticesData {
770
770
  * @returns the current mesh
771
771
  */
772
772
  renderWithRenderPassId(renderPassId?: number, enableAlphaMode?: boolean, effectiveMeshReplacement?: AbstractMesh, subMesh?: SubMesh, checkFrustumCulling?: boolean): this;
773
+ /**
774
+ * Render a complete mesh by going through all submeshes
775
+ * @returns the current mesh
776
+ * #5SPY1V#2: simple test
777
+ * #5SPY1V#5: perf test
778
+ */
779
+ directRender(): Mesh;
773
780
  /**
774
781
  * Triggers the draw call for the mesh. Usually, you don't need to call this method by your own because the mesh rendering is handled by the scene rendering manager
775
782
  * @param subMesh defines the subMesh to render
package/Meshes/mesh.js CHANGED
@@ -1871,6 +1871,21 @@ export class Mesh extends AbstractMesh {
1871
1871
  }
1872
1872
  return this;
1873
1873
  }
1874
+ /**
1875
+ * Render a complete mesh by going through all submeshes
1876
+ * @returns the current mesh
1877
+ * #5SPY1V#2: simple test
1878
+ * #5SPY1V#5: perf test
1879
+ */
1880
+ directRender() {
1881
+ if (!this.subMeshes) {
1882
+ return this;
1883
+ }
1884
+ for (const submesh of this.subMeshes) {
1885
+ this.render(submesh, false);
1886
+ }
1887
+ return this;
1888
+ }
1874
1889
  /**
1875
1890
  * Triggers the draw call for the mesh. Usually, you don't need to call this method by your own because the mesh rendering is handled by the scene rendering manager
1876
1891
  * @param subMesh defines the subMesh to render