107 lines
4.2 KiB
Vue
107 lines
4.2 KiB
Vue
<script setup lang="ts">
|
|
import { Vector3 } from 'three';
|
|
//@ts-ignore
|
|
import { useGLTF, } from '@tresjs/cientos'
|
|
import type { OrbitControlsProps } from '@tresjs/cientos/dist/core/controls/OrbitControls.vue.js';
|
|
|
|
const section_count = use_section_count()
|
|
const extra_section = use_extra_section()
|
|
const lamelles_count = use_lamelles_count()
|
|
const lamelle_height = use_lamelle_height()
|
|
const fence_section = use_fence_section()
|
|
const open_calc = use_open_calc()
|
|
const goto_cam = use_goto_camera()
|
|
const goto_target = use_goto_target()
|
|
|
|
const { scene, controls, camera } = useTresContext()
|
|
const { seek, seekAll } = useSeek()
|
|
|
|
const { scene: model_pillar_top } = await useGLTF('/models_one/pillar/top.glb')
|
|
const { scene: model_pillar_center } = await useGLTF('/models_one/pillar/center.glb')
|
|
const { scene: model_pillar_bottom } = await useGLTF('/models_one/pillar/bottom.glb')
|
|
const { scene: model_pillar_inner } = await useGLTF('/models_one/pillar/inner.glb')
|
|
const { scene: model_pillar_brace } = await useGLTF('/models_one/pillar/brace.glb')
|
|
|
|
const { scene: model_fastening_top_center } = await useGLTF('/models_one/fastening/top_center.glb');
|
|
const { scene: model_fastening_top_right } = await useGLTF('/models_one/fastening/top_right.glb');
|
|
const { scene: model_fastening_side } = await useGLTF('/models_one/fastening/side.glb');
|
|
const { scene: top_model } = await useGLTF('/models_one/top_100.glb', { draco: true })
|
|
const { scene: lamelle_model } = await useGLTF('/models_one/lamel_100.glb', { draco: true });
|
|
|
|
const top = ref(top_model)
|
|
const pillar_center = ref(model_pillar_center)
|
|
const pillar_top = ref(model_pillar_top)
|
|
const pillar_bottom = ref(model_pillar_bottom)
|
|
const pillar_inner = ref(model_pillar_inner)
|
|
const pillar_brace = ref(model_pillar_brace)
|
|
const fastening_top_center = ref(model_fastening_top_center)
|
|
const fastening_top_right = ref(model_fastening_top_right)
|
|
const fastening_side = ref(model_fastening_side)
|
|
const lamelle = ref(lamelle_model)
|
|
|
|
const total = ref((section_count.value + ~~(!!extra_section.value)))
|
|
const size = ref(Math.ceil(total.value / 4))
|
|
const count = ref((total.value >= 4) ? size.value : total.value)
|
|
|
|
watch(() => [section_count.value, extra_section.value], () => {
|
|
total.value = (section_count.value + ~~(!!extra_section.value))
|
|
size.value = Math.ceil(total.value / 4);
|
|
count.value = (total.value >= 4) ? size.value : total.value;
|
|
|
|
const lines_count = (total.value >= 4) ? 4 : 1
|
|
const base = seek(scene.value, 'name', 'base')
|
|
if (base?.children && base.children.length !== lines_count) {
|
|
base.children = [...base?.children.slice(0, lines_count)]
|
|
}
|
|
|
|
const lines = seekAll(scene.value, 'name', 'line')
|
|
lines.forEach(line => {
|
|
let n = size.value
|
|
if (lines_count == 1) {
|
|
n = total.value
|
|
}
|
|
if (line.name.endsWith('_4')) {
|
|
n = total.value - size.value * 3
|
|
if (n < 0) {
|
|
n = 0
|
|
}
|
|
}
|
|
const inner = seek(line, 'name', line.name + '_inner');
|
|
if (inner?.children && n < inner?.children.length) {
|
|
inner.children = [...inner?.children.slice(0, n)]
|
|
}
|
|
});
|
|
})
|
|
const setTarget = (smooth = false) => {
|
|
let f = fence_section.value * lamelles_count.value * lamelle_height.value * 0.75
|
|
if (f < 3) f = 3
|
|
const target = new Vector3(0, lamelles_count.value * lamelle_height.value * 0.5, 0);
|
|
if (smooth) {
|
|
goto_target.value = target
|
|
goto_cam.value = new Vector3(f, f, f)
|
|
} else {
|
|
(controls.value as OrbitControlsProps).target = target
|
|
camera.value?.position.set(f, f, f)
|
|
}
|
|
}
|
|
setTarget()
|
|
watch([lamelles_count, fence_section], () => setTarget(false))
|
|
|
|
watch(open_calc, () => {
|
|
if (Object.keys(open_calc.value).length == 0) {
|
|
setTarget(true)
|
|
}
|
|
})
|
|
</script>
|
|
<template>
|
|
<TresGroup name="base">
|
|
<template v-for="line in (total >= 4) ? 4 : 1" :key="`${line}_${count}`">
|
|
<ModelLine :models="{
|
|
top,
|
|
pillar_center, pillar_top, pillar_bottom, pillar_inner, pillar_brace,
|
|
fastening_top_center, fastening_top_right, fastening_side,
|
|
lamelle
|
|
}" :number="line" :count="count" />
|
|
</template>
|
|
</TresGroup>
|
|
</template> |