From 88b3651415e450f7d1197043fee7c09948fdbdbb Mon Sep 17 00:00:00 2001 From: Kseninia Mikhaylova Date: Thu, 20 Mar 2025 12:15:28 +0300 Subject: [PATCH] debouncing --- components/calc/models.vue | 24 ++++++++-- components/expDiagram.vue | 77 ++++++++++++++++++++----------- components/model/env.vue | 20 ++++---- composables/useSceneVisibility.ts | 57 +++++++++++++++++++++++ nuxt.config.ts | 4 +- pages/index.vue | 4 +- 6 files changed, 144 insertions(+), 42 deletions(-) create mode 100644 composables/useSceneVisibility.ts diff --git a/components/calc/models.vue b/components/calc/models.vue index 6d34d93..4192dbe 100644 --- a/components/calc/models.vue +++ b/components/calc/models.vue @@ -3,6 +3,9 @@ import { TresCanvas } from '@tresjs/core' import { Stats, OrbitControls } from '@tresjs/cientos' import { degToRad } from 'three/src/math/MathUtils.js'; +const container = ref(null); +const { isIntersecting, startObserver, stopObserver } = useSceneVisibility(); + const controlsState = reactive({ position: { x: 0, y: 0, z: 0 }, enablePan: false, @@ -17,9 +20,21 @@ const cameraStat = reactive({ aspect: 1920 / 600, // fov: 40, }) +const renderMode = computed(() => (isIntersecting.value ? 'always' : 'manual')); + +onMounted(async () => { + if (container.value) { + await nextTick() + startObserver(container.value); + } +}); + +onBeforeUnmount(() => { + stopObserver(); +}); \ No newline at end of file diff --git a/components/expDiagram.vue b/components/expDiagram.vue index e303764..59e4c55 100644 --- a/components/expDiagram.vue +++ b/components/expDiagram.vue @@ -3,6 +3,9 @@ import { TresCanvas } from '@tresjs/core' import { OrbitControls } from '@tresjs/cientos' import { Vector3 } from 'three'; +const container = ref(null); +const { isIntersecting, startObserver, stopObserver } = useSceneVisibility(); + const camera = ref() const controls = ref() const controlsState = reactive({ @@ -25,36 +28,56 @@ const changeDistance = (v = 1) => { camera.value.position.normalize().multiplyScalar(r) } } + +const renderMode = computed(() => (isIntersecting.value ? 'always' : 'manual')); + +onMounted(async () => { + if (container.value) { + await nextTick() + startObserver(container.value); + } +}); + +onBeforeUnmount(() => { + stopObserver(); +});