From b2fd557c33733e390e15d546a2b61ce504486902 Mon Sep 17 00:00:00 2001 From: alvarosabu Date: Mon, 17 Apr 2023 21:08:35 +0200 Subject: [PATCH] feat: add disable render prop for postprocessing --- docs/api/renderer.md | 1 + src/components/TresCanvas.ts | 2 ++ src/components/TresScene.ts | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/api/renderer.md b/docs/api/renderer.md index 7a2287b1a..cf148bf18 100644 --- a/docs/api/renderer.md +++ b/docs/api/renderer.md @@ -82,6 +82,7 @@ renderer.shadowMap.type: PCFSoftShadowMap | **preserveDrawingBuffer** | Whether to preserve the buffers until manually cleared or overwritten.. | `false` | | **clearColor** | The color the renderer will use to clear the canvas. | `#000000` | | **windowSize** | Whether to use the window size as the canvas size or the parent element. | `false` | +| **disableRender** | Disable render on requestAnimationFrame, usefull for PostProcessing | `false` | ## Defaults diff --git a/src/components/TresCanvas.ts b/src/components/TresCanvas.ts index 7be20d821..165e9fbd3 100644 --- a/src/components/TresCanvas.ts +++ b/src/components/TresCanvas.ts @@ -18,6 +18,7 @@ export interface TresCanvasProps { clearColor?: string windowSize?: boolean preset?: RendererPresetsType + disableRender?: boolean } /** * Vue component for rendering a Tres component. @@ -39,6 +40,7 @@ export const TresCanvas = defineComponent({ 'clearColor', 'windowSize', 'preset', + 'disableRender', ] as unknown as undefined, setup(props, { slots, expose }) { const tres = useTresProvider() diff --git a/src/components/TresScene.ts b/src/components/TresScene.ts index aeb0c9523..2776ff870 100644 --- a/src/components/TresScene.ts +++ b/src/components/TresScene.ts @@ -23,6 +23,7 @@ export interface TresSceneProps { clearColor?: string windowSize?: boolean preset?: RendererPresetsType + disableRender?: boolean } /** * Vue component for rendering a Tres component. @@ -46,6 +47,7 @@ export const TresScene = defineComponent({ 'clearColor', 'windowSize', 'preset', + 'disableRender', ] as unknown as undefined, setup(props, { slots, expose }) { if (props.physicallyCorrectLights === true) { @@ -89,7 +91,7 @@ export const TresScene = defineComponent({ }) onLoop(() => { - if (activeCamera.value) renderer.value?.render(scene, activeCamera.value) + if (activeCamera.value && props.disableRender === true) renderer.value?.render(scene, activeCamera.value) if (raycaster.value) { const intersects = raycaster.value.intersectObjects(scene.children)