diff --git a/components/model/bench-table.vue b/components/model/bench-table.vue index 7b09302..75e1c06 100644 --- a/components/model/bench-table.vue +++ b/components/model/bench-table.vue @@ -2,37 +2,28 @@ //@ts-ignore import { useGLTF } from '@tresjs/cientos' import { useTresContext } from '@tresjs/core' -import { Vector3 } from 'three' -import { ref, onMounted } from 'vue' +import { degToRad } from 'three/src/math/MathUtils.js' const { camera, controls } = useTresContext() -const { scene: obj } = await useGLTF('/models/bench2_export-v1.glb') -const scale = ref(1) // Масштаб объекта - -onMounted(() => { - if (obj && camera.value && controls.value) { - const distance = 10 - const cameraOffset = { x: 1, y: 0.75, z: -1.25 } // Смещение камеры - - // Вычисляем масштаб и позицию камеры - const { scale: objectScale } = calculateScaleToFit( - obj, - camera.value as any, - controls.value as any, - distance, - cameraOffset - ) - - scale.value = objectScale +const { scene } = await useGLTF('/models/table.glb') +const object = calculateScaleToFit( + scene, + camera, + controls, + 3, + { + x: Math.sin(degToRad(-30)), // Смещение по оси X + y: 1, // Нет смещения по оси Y + z: -Math.cos(degToRad(0)) // Смещение по оси Z } -}) +) \ No newline at end of file + diff --git a/components/model/bench.vue b/components/model/bench.vue index b82fa0c..6a600fa 100644 --- a/components/model/bench.vue +++ b/components/model/bench.vue @@ -2,37 +2,28 @@ //@ts-ignore import { useGLTF } from '@tresjs/cientos' import { useTresContext } from '@tresjs/core' -import { Vector3 } from 'three' -import { ref, onMounted } from 'vue' +import { degToRad } from 'three/src/math/MathUtils.js' const { camera, controls } = useTresContext() -const { scene: obj } = await useGLTF('/models/bench_export-v1.glb') -const scale = ref(1) // Масштаб объекта - -onMounted(() => { - if (obj && camera.value && controls.value) { - const distance = 10 - const cameraOffset = { x: -1, y: 0.75, z: -1.25 } // Смещение камеры - - // Вычисляем масштаб и позицию камеры - const { scale: objectScale } = calculateScaleToFit( - obj, - camera.value as any, - controls.value as any, - distance, - cameraOffset - ) - - scale.value = objectScale +const { scene } = await useGLTF('/models/bench.glb') +const object = calculateScaleToFit( + scene, + camera, + controls, + 2, + { + x: Math.sin(degToRad(30)), // Смещение по оси X + y: 1, // Нет смещения по оси Y + z: -Math.cos(degToRad(0)) // Смещение по оси Z } -}) +) \ No newline at end of file + diff --git a/components/model/env.vue b/components/model/env.vue index c4bd86b..5b727a1 100644 --- a/components/model/env.vue +++ b/components/model/env.vue @@ -1,11 +1,12 @@ - \ No newline at end of file + diff --git a/components/model/scene.vue b/components/model/scene.vue index 8e2b29c..63044df 100644 --- a/components/model/scene.vue +++ b/components/model/scene.vue @@ -14,15 +14,26 @@ const props = defineProps({ } }) +const camera = ref() +const controls = ref() + const controlsState = reactive({ - // minDistance: 2, - // maxDistance: 10, - enablePan: false, - enableZoom: false, - maxPolarAngle: Math.PI / 2 - 0.2 + minDistance: 2, + maxDistance: 20, + enablePan: false + // enableZoom: false, + // maxPolarAngle: Math.PI / 2 - 0.2 }) const toggleModal = () => {} + +const changeDistance = (v = 1) => { + if (camera.value && controls.value) { + const distance = camera.value.position.distanceTo(new Vector3(0, 0, 0)) + const r = distance + v + camera.value.position.normalize().multiplyScalar(r) + } +}