lamelle as instance mesh
This commit is contained in:
parent
dcdd269368
commit
a115e6e31b
|
@ -1,5 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { BufferGeometry, InstancedBufferGeometry, Matrix4, MeshNormalMaterial } from 'three';
|
import { BufferGeometry, Matrix4, Vector3 } from 'three';
|
||||||
|
|
||||||
const props = defineProps(['index', 'models'])
|
const props = defineProps(['index', 'models'])
|
||||||
|
|
||||||
|
@ -37,31 +37,33 @@ if (extra.value) {
|
||||||
pillar_two_pos.value = (extra.value as number) * 0.5 + pillar_size + bSize - 0.01
|
pillar_two_pos.value = (extra.value as number) * 0.5 + pillar_size + bSize - 0.01
|
||||||
}
|
}
|
||||||
|
|
||||||
const instancedMesh = shallowRef();
|
const instanced_lamelle = shallowRef();
|
||||||
watch(instancedMesh, (mesh) => {
|
const instanced_lamelle_geometry = Object.assign(new BufferGeometry, props.models.lamelle.children[0].geometry)
|
||||||
console.log('rr')
|
const instanced_lamelle_material = props.models.lamelle.children[0].material
|
||||||
for (let i = 0; i < 4; i++) {
|
const instanced_lamelle_count = 24
|
||||||
instancedMesh.value.setMatrixAt(
|
const instanced_v = [instanced_lamelle_geometry, instanced_lamelle_material, instanced_lamelle_count]
|
||||||
i,
|
watch([instanced_lamelle, fence_section, extra_section, lamelles_count], (mesh) => {
|
||||||
new Matrix4().makeTranslation(i, 1, 1)
|
for (let i = 0; i < instanced_lamelle_count; i++) {
|
||||||
);
|
if (instanced_lamelle.value) {
|
||||||
}
|
const scale_x = (((extra.value as number) || fence_section.value) * 10)
|
||||||
// mesh.instanceMatrix.setUsage(DynamicDrawUsage);
|
const pos_x = pillar_size * 0.5
|
||||||
});
|
const pos_y = (lSize * i)
|
||||||
onMounted(() => {
|
const pos_z = -0.02
|
||||||
for (let i = 0; i < 4; i++) {
|
const newmatrix = new Matrix4().fromArray([
|
||||||
const elapsed = 1
|
scale_x, 0, 0, 0,
|
||||||
const x = Math.sin(elapsed + i * 0.3) * 3.5;
|
0, 1, 0, 0,
|
||||||
const y = Math.cos(elapsed + i * 0.5) * 4;
|
0, 0, 1, 0,
|
||||||
const z = Math.cos(elapsed + i * 0.3) * 3.5;
|
pos_x, pos_y, pos_z, 1
|
||||||
if (instancedMesh.value) {
|
])
|
||||||
instancedMesh.value.setMatrixAt(
|
instanced_lamelle.value.setMatrixAt(i, newmatrix);
|
||||||
i,
|
|
||||||
new Matrix4().makeTranslation(x, y, z)
|
if (i >= lamelles_count.value) {
|
||||||
);
|
instanced_lamelle.value.setMatrixAt(i, new Matrix4().makeTranslation(new Vector3(0,0,-2)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
instanced_lamelle.value.instanceMatrix.needsUpdate = true
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
watch([section_count, fence_section, extra_section], () => {
|
watch([section_count, fence_section, extra_section], () => {
|
||||||
extra.value = (extra_section.value && props.index == (section_count.value + 1)) ? extra_section.value * 0.001 : false
|
extra.value = (extra_section.value && props.index == (section_count.value + 1)) ? extra_section.value * 0.001 : false
|
||||||
if (extra_section && props.index == (section_count.value + 1)) {
|
if (extra_section && props.index == (section_count.value + 1)) {
|
||||||
|
@ -109,18 +111,14 @@ watch([section_count, fence_section, extra_section], () => {
|
||||||
</TresGroup>
|
</TresGroup>
|
||||||
|
|
||||||
<TresGroup name="lamelles">
|
<TresGroup name="lamelles">
|
||||||
<template v-for="(n, i) in lamelles_count">
|
<template v-for="(n, i) in lamelles_count" v-if=false>
|
||||||
<TresGroup :position="[pillar_size * 0.5, (lSize * i), 0.02]"
|
<TresGroup :position="[pillar_size * 0.5, (lSize * i), 0.02]"
|
||||||
:scale-x="((extra as number) || fence_section) * 10">
|
:scale-x="((extra as number) || fence_section) * 10">
|
||||||
<TresObject3D v-bind="props.models.lamelle.children[0]" />
|
<TresObject3D v-bind="props.models.lamelle.children[0]" />
|
||||||
</TresGroup>
|
</TresGroup>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<TresInstancedMesh ref="instancedMesh" :args="[props.models.lamelle.children[0].geometry, null!, 4]"
|
<TresInstancedMesh ref="instanced_lamelle" :args="instanced_v" cast-shadow />
|
||||||
:scale-x="((extra as number) || fence_section) * 10" v-if=false>
|
|
||||||
<TresBufferGeometry v-bind="props.models.lamelle.children[0].geometry" />
|
|
||||||
<TresMeshBasicMaterial color="red" />
|
|
||||||
</TresInstancedMesh>
|
|
||||||
</TresGroup>
|
</TresGroup>
|
||||||
<TresGroup name="lam_fastening_one">
|
<TresGroup name="lam_fastening_one">
|
||||||
<template v-for="(n, i) in lamelles_count">
|
<template v-for="(n, i) in lamelles_count">
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Color, MeshStandardMaterial } from "three"
|
||||||
|
|
||||||
const set_metaril_func = (scene: any, material: any) => {
|
const set_metaril_func = (scene: any, material: any) => {
|
||||||
scene.children.forEach((el: any) => {
|
scene.children.forEach((el: any) => {
|
||||||
if (el.isMesh) {
|
if (el.isMesh && !el.isInstancedMesh) {
|
||||||
el.castShadow = true
|
el.castShadow = true
|
||||||
el.receiveShadow = true
|
el.receiveShadow = true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue