mns-mini-zabor/components/model/parametric.vue

81 lines
2.9 KiB
Vue

<script setup lang="ts">
import { Mesh, Object3D } from 'three';
//@ts-ignore
import { useGLTF, } from '@tresjs/cientos'
const section_count = use_section_count()
const extra_section = use_extra_section()
const { scene } = useTresContext()
const { seek, seekAll } = useSeek()
const { scene: top_model } = await useGLTF('/models_one/verh_100.glb', { draco: true })
const { scene: model_fence_top } = await useGLTF('/fence_one/top.glb')
const { scene: model_fence_center } = await useGLTF('/fence_one/center.glb')
const { scene: model_fence_bottom } = await useGLTF('/fence_one/bottom.glb')
const { scene: model_fence_inner } = await useGLTF('/fence_one/inner.glb')
const { scene: fastening_model } = await useGLTF('/models_one/krepleniye_planok.glb', { draco: true });
const { scene: lamelle_model } = await useGLTF('/models_one/lamel_100.glb', { draco: true });
[model_fence_top, model_fence_bottom].map((sc: Object3D) =>
sc.traverse((child: Object3D) => {
if (child instanceof Mesh) {
child.position.z = 0
}
})
)
const top = ref(top_model)
const fence = ref(model_fence_center)
const fence_top = ref(model_fence_top)
const fence_bottom = ref(model_fence_bottom)
const fence_inner = ref(model_fence_inner)
const fastening = ref(fastening_model)
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)]
}
});
})
</script>
<template>
<TresGroup name="base">
<template v-for="line in (total >= 4) ? 4 : 1" :key="`${line}_${count}`">
<ModelLine :models="{ top, fence, fence_top, fence_bottom, fence_inner, fastening, lamelle }" :number="line"
:count="count" />
</template>
</TresGroup>
<Suspense>
<ModelRecolor :models="{ top, fence, fence_top, fence_bottom, fence_inner, fastening, lamelle }" />
</Suspense>
</template>