bx-1140-postprocessing #12

Merged
ksenia_mikhailova merged 18 commits from bx-1140-postprocessing into dev 2024-07-30 09:17:41 +03:00
1 changed files with 26 additions and 31 deletions
Showing only changes of commit 5d79c35439 - Show all commits

View File

@ -42,7 +42,7 @@ const groundTexture = await useTexture({
const timer = ref(10) const timer = ref(10)
renderer.value.capabilities.maxTextures = 4 // renderer.value.capabilities.maxTextures = 4
renderer.value.capabilities.maxTextureSize = 512 renderer.value.capabilities.maxTextureSize = 512
renderer.value.capabilities.precision = 'lowp' renderer.value.capabilities.precision = 'lowp'
@ -188,44 +188,28 @@ const loadModels = async () => {
setInterval(() => { setInterval(() => {
if (timer.value > 0) { if (timer.value > 0) {
timer.value -= 1 timer.value -= 1
} else if (timer.value == 0 && !controls.value.autoRotate) {
camera.value?.position.set(
controls.value.minDistance * 0.5,
controls.value.minDistance * 0.5,
controls.value.minDistance
);
(controls.value as any).autoRotate = true;
(controls.value as any).autoRotateSpeed = 1;
} }
}, 1000) }, 1000)
} }
const { onLoop } = useRenderLoop() const { onAfterRender } = useLoop()
onLoop(() => { onAfterRender(() => {
clickable_refs.value.map(el => { clickable_refs.value.map(el => {
if (el.value[0] && typeof el.value[0].lookAt == 'function') { if (el.value[0] && typeof el.value[0].lookAt == 'function') {
el.value[0].lookAt(camera.value?.position); el.value[0].lookAt(camera.value?.position);
} }
}) })
}) if (controls.value) {
const { onBeforeRender, pause, resume } = useLoop()
let direction = 'plus'
onBeforeRender(() => {
if (camera.value?.rotation) {
if (timer.value == 0) { if (timer.value == 0) {
pause() (controls.value as any).update();
const v = Math.PI * 0.001
if (camera.value.rotation.x > Math.PI * 0.5 && direction == 'plus') {
direction = 'minus'
} else if (camera.value.rotation.x < Math.PI * -0.5 && direction == 'minus') {
direction = 'plus'
}
if (direction == 'plus') {
camera.value.rotation.x += v
camera.value.rotation.y += v
camera.value.rotation.z += v
} else {
camera.value.rotation.x -= v
camera.value.rotation.y -= v
camera.value.rotation.z -= v
}
setTimeout(() => {
resume()
}, 5)
} else {
resume()
} }
} }
}) })
@ -257,14 +241,25 @@ watch(() => props.source, () => {
onMounted(() => { onMounted(() => {
document.addEventListener('click', clickEvent) document.addEventListener('click', clickEvent)
document.addEventListener('click', stopTimer)
document.addEventListener('touchstart', stopTimer)
if (sidebar.is_open) { if (sidebar.is_open) {
sidebar.close() sidebar.close()
} }
}) })
onUnmounted(() => { document.removeEventListener('click', clickEvent) }) onUnmounted(() => {
document.removeEventListener('click', clickEvent)
document.removeEventListener('click', stopTimer)
document.removeEventListener('touchstart', stopTimer)
})
const pointer = reactive({ x: 0, y: 0 }) const pointer = reactive({ x: 0, y: 0 })
const stopTimer = () => {
timer.value = 10;
if (controls.value.autoRotate) {
controls.value.autoRotate = false;
}
}
const clickEvent = (event: MouseEvent) => { const clickEvent = (event: MouseEvent) => {
timer.value = 10
const x = (event.clientX / window.innerWidth) * 2 - 1 const x = (event.clientX / window.innerWidth) * 2 - 1
const y = - (event.clientY / window.innerHeight) * 2 + 1 const y = - (event.clientY / window.innerHeight) * 2 + 1
if (x == pointer.x && y == pointer.y) return if (x == pointer.x && y == pointer.y) return