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(); +});