Second light

This commit is contained in:
Kseninia Mikhaylova 2024-09-18 16:29:45 +03:00
parent f022fab129
commit c6b97830fa
3 changed files with 25 additions and 19 deletions

View File

@ -3,6 +3,7 @@ import { TresCanvas } from '@tresjs/core'
import { OrbitControls } from '@tresjs/cientos' import { OrbitControls } from '@tresjs/cientos'
//@ts-ignore //@ts-ignore
import { useGLTF } from '@tresjs/cientos' import { useGLTF } from '@tresjs/cientos'
import { degToRad, radToDeg } from 'three/src/math/MathUtils.js';
const fence_section = use_fence_section() const fence_section = use_fence_section()
const section_count = use_section_count() const section_count = use_section_count()
@ -11,11 +12,12 @@ const max_size = use_max_size()
const controlsState = reactive({ const controlsState = reactive({
distance: section_count.value, distance: section_count.value,
minDistance: 7, minDistance: 10,
maxDistance: 20, maxDistance: 10,
position: { x: 0, y: 0, z: 0 }, position: { x: 0, y: 0, z: 0 },
enablePan: false, enablePan: false,
maxPolarAngle: (Math.PI / 2) - 0.2, minPolarAngle: degToRad(30),
maxPolarAngle: degToRad(90),
}) })
const cameraStat = reactive({ const cameraStat = reactive({
position: [-4, 2, 8], position: [-4, 2, 8],
@ -26,18 +28,19 @@ const cameraStat = reactive({
const pointLight = ref() const pointLight = ref()
const loadAll = async () => { const loadAll = async () => {
const { scene: light } = await useGLTF('/models_light/zabor_so_svetom.glb') const { scene: light } = await useGLTF('/models_light/zabor_so_svetom.glb')
pointLight.value = light.children[2] pointLight.value = light.children[2].clone()
pointLight.value.color = '#f0dea9' pointLight.value.intensity = pointLight.value.intensity * 0.05
pointLight.value.intensity = pointLight.value.intensity * 0.1
pointLight.value.shadow.camera.near = 50
pointLight.value.shadow.bias = -0.002 pointLight.value.shadow.bias = -0.002
const j = 4 const j = 4
pointLight.value.shadow.mapSize.x = 512 * j pointLight.value.shadow.mapSize.x = 512 * j
pointLight.value.shadow.mapSize.y = 512 * j pointLight.value.shadow.mapSize.y = 512 * j
const k = 3 const k = 1
// pointLight.value.position.x = pointLight.value.position.x * k
// pointLight.value.position.y = pointLight.value.position.y * k
// pointLight.value.position.z = pointLight.value.position.z * k
pointLight.value.position.x = pointLight.value.position.x * k pointLight.value.position.x = pointLight.value.position.x * k
pointLight.value.position.y = pointLight.value.position.y * k pointLight.value.position.y = pointLight.value.position.z * k
pointLight.value.position.z = pointLight.value.position.z * k pointLight.value.position.z = pointLight.value.position.z * k
} }
const camera = ref("camera") const camera = ref("camera")
@ -62,7 +65,7 @@ watch([section_count, extra_section], () => {
</div> </div>
</template> </template>
<Loader /> <Loader />
<TresCanvas> <TresCanvas clear-color="#ccc">
<TresPerspectiveCamera v-bind="cameraStat" ref="camera" /> <TresPerspectiveCamera v-bind="cameraStat" ref="camera" />
<OrbitControls v-bind="controlsState" make-default /> <OrbitControls v-bind="controlsState" make-default />
<TresGroup :position-x="Math.min(section_count, max_size) * fence_section * -1" :position-y="-3"> <TresGroup :position-x="Math.min(section_count, max_size) * fence_section * -1" :position-y="-3">
@ -76,8 +79,11 @@ watch([section_count, extra_section], () => {
</TresMesh> </TresMesh>
<template v-if="pointLight"> <template v-if="pointLight">
<TresPointLight v-bind="pointLight" cast-shadow /> <TresPointLight v-bind="pointLight.clone()" cast-shadow />
<TresPointLight v-bind="pointLight.clone()" :position-x="pointLight.position.x * -1"
:position-z="pointLight.position.z * -1" cast-shadow />
</template> </template>
<TresAmbientLight intensity="10" />
</TresCanvas> </TresCanvas>
</ClientOnly> </ClientOnly>
</div> </div>

View File

@ -114,12 +114,12 @@ onMounted(async () => {
if (renderer.value && camera.value) { if (renderer.value && camera.value) {
renderer.value.render(scene.value, camera.value) renderer.value.render(scene.value, camera.value)
} }
scene.value.environment = result.renderTarget.texture // scene.value.environment = result.renderTarget.texture
scene.value.background = result.renderTarget.texture // scene.value.background = result.renderTarget.texture
scene.value.background.mapping = EquirectangularReflectionMapping // scene.value.background.mapping = EquirectangularReflectionMapping
scene.value.backgroundRotation = new Euler(0, 10, 0) // scene.value.backgroundRotation = new Euler(0, 10, 0)
scene.value.backgroundIntensity = 1.5 // scene.value.backgroundIntensity = 1.5
scene.value.backgroundBlurriness = 0.06 // scene.value.backgroundBlurriness = 0.06
result.renderTarget.texture.dispose(); result.renderTarget.texture.dispose();
}) })

View File

@ -1,5 +1,5 @@
import { Color, DoubleSide, MeshBasicMaterial, MeshStandardMaterial, RepeatWrapping, TextureLoader, Vector2 } from "three" import { Color, DoubleSide, MeshBasicMaterial, MeshStandardMaterial, RepeatWrapping, TextureLoader, Vector2 } from "three"
import { useLoader } from '@tresjs/core' import { useLoader, type TresLoader } from '@tresjs/core'
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) => {
@ -31,7 +31,7 @@ export const set_material = (scene: any, color: any, count: number | undefined =
color: new Color(c || '#9c9c00'), color: new Color(c || '#9c9c00'),
alphaMap: count ? texture : null, alphaMap: count ? texture : null,
transparent: true, transparent: true,
opacity: 0.75, opacity: 1,
// roughness: 0.5, // roughness: 0.5,
// metalness: 0, // metalness: 0,
side: DoubleSide, side: DoubleSide,