dev #84

Merged
ksenia_mikhailova merged 141 commits from dev into main 2024-10-03 15:30:24 +03:00
2 changed files with 47 additions and 13 deletions
Showing only changes of commit a3687808ea - Show all commits

View File

@ -183,5 +183,9 @@ watch([instanced_lamelle, lamelle_color], setLamellesColor)
<template v-for="item in fastening"> <template v-for="item in fastening">
<TresObject3D v-bind="item.clone()" /> <TresObject3D v-bind="item.clone()" />
</template> </template>
<TresMesh :position="[0, 0, 0]">
<TresBoxGeometry :args="[0.1, 0.1, 0.1]" />
<TresMeshBasicMaterial color="violet" />
</TresMesh>
</TresGroup> </TresGroup>
</template> </template>

View File

@ -2,12 +2,42 @@ import { Color, DataTexture, DoubleSide, MeshBasicMaterial, MeshStandardMaterial
import { useLoader, type TresLoader } from '@tresjs/core' import { useLoader, type TresLoader } from '@tresjs/core'
import { getFilename, patterns, type patternTypes } from "~/components/pattern" import { getFilename, patterns, type patternTypes } from "~/components/pattern"
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 && !el.isInstancedMesh) { if (el.isMesh && !el.isInstancedMesh) {
el.castShadow = true el.castShadow = true
el.receiveShadow = true el.receiveShadow = true
} }
if (el.material) {
// Получите UV-координаты
const uvAttribute = el.geometry.getAttribute('uv');
const uvs = [];
for (let i = 0; i < uvAttribute.count; i++) {
uvs.push(uvAttribute.getX(i), uvAttribute.getY(i));
}
// Вычисление минимальных и максимальных UV
const minU = Math.min(...uvs.filter((_, index) => index % 2 === 0)); // X координаты
const maxU = Math.max(...uvs.filter((_, index) => index % 2 === 0));
const minV = Math.min(...uvs.filter((_, index) => index % 2 === 1)); // Y координаты
const maxV = Math.max(...uvs.filter((_, index) => index % 2 === 1));
// Определите размеры текстуры на поверхности
const surfaceWidth = maxU - minU;
const surfaceHeight = (maxV - minV) * el.scale.y;
material.normalMap.wrapS = RepeatWrapping;
material.normalMap.wrapT = RepeatWrapping;
material.normalMap.repeat.set(surfaceWidth, surfaceHeight);
material.normalMap.needsUpdate = true
console.log(`Ширина текстуры на поверхности: ${surfaceWidth * 128}`);
console.log(`Высота текстуры на поверхности: ${surfaceHeight * 128}`);
}
if (el.material) el.material = material if (el.material) el.material = material
set_metaril_func(el, material) set_metaril_func(el, material)
}) })