bx-1316-refactoring #14

Merged
ksenia_mikhailova merged 46 commits from bx-1316-refactoring into dev 2024-08-28 15:06:52 +03:00
3 changed files with 22 additions and 20 deletions
Showing only changes of commit 927ec74faa - Show all commits

View File

@ -251,23 +251,6 @@ onAfterRender(() => {
} }
}) })
const openSidebar = (id: number) => {
sidebar.open(id);
const clickable = useClickable()
const target = clickable.list.find(el => el.id == id)
if (!target) return
const el = seekByName(scene.value, `${id}_clickable`);
if (el) {
(controls.value as any).maxDistance = 10;
(controls.value as any).minDistance = 1;
const target_vector = new Vector3();
el.getWorldPosition(target_vector);
(controls.value as any).target = target_vector;
}
}
loadModels() loadModels()
watch(() => props.source, () => { watch(() => props.source, () => {
const loaded = seekByName(scene.value, 'loaded') const loaded = seekByName(scene.value, 'loaded')
@ -278,12 +261,27 @@ watch(() => props.source, () => {
loadModels() loadModels()
}) })
watch(() => sidebar.is_open, () => { watch(() => sidebar, () => {
if (sidebar.is_open == false) { if (sidebar.is_open == false) {
(controls.value as any).minDistance = mobileAndTabletCheck() ? def_distance.min * 0.5 : def_distance.min; (controls.value as any).minDistance = mobileAndTabletCheck() ? def_distance.min * 0.5 : def_distance.min;
(controls.value as any).maxDistance = def_distance.max; (controls.value as any).maxDistance = def_distance.max;
} }
}) if (sidebar.is_open && sidebar.id_clickable) {
const clickable = useClickable()
const target = clickable.list.find(el => el.id == sidebar.id_clickable)
if (!target) return
const el = seekByName(scene.value, `${sidebar.id_clickable}_clickable`);
if (el) {
(controls.value as any).maxDistance = 10;
(controls.value as any).minDistance = 1;
const target_vector = new Vector3();
el.getWorldPosition(target_vector);
target_vector.y = 0;
(controls.value as any).target = target_vector;
}
}
}, { deep: true })
onMounted(() => { onMounted(() => {
document.addEventListener('click', clickEvent) document.addEventListener('click', clickEvent)
@ -330,7 +328,7 @@ const clickEvent = (event: MouseEvent) => {
const intersects = raycaster.value.intersectObjects(clickable_objects); const intersects = raycaster.value.intersectObjects(clickable_objects);
const names = intersects.map(el => (el.object.parent ? el.object.parent.name : el.object.name) ?? false).filter(Boolean) const names = intersects.map(el => (el.object.parent ? el.object.parent.name : el.object.name) ?? false).filter(Boolean)
if (names.length) { if (names.length) {
openSidebar(parseInt(names[0].replace('_clickable', ''))) sidebar.open(parseInt(names[0].replace('_clickable', '')))
} }
} }
</script> </script>

View File

@ -60,6 +60,7 @@ interface PromoSidebarData {
target_name?: string target_name?: string
} }
interface PromoSidebar extends PromoSidebarData { interface PromoSidebar extends PromoSidebarData {
id_clickable?: number
loading: boolean loading: boolean
is_open: boolean is_open: boolean
} }

View File

@ -4,6 +4,7 @@ import { useClickable } from './clickable'
export const usePromoSidebar = defineStore('promo_sidebar', { export const usePromoSidebar = defineStore('promo_sidebar', {
state: () => { state: () => {
return { return {
id_clickable: undefined,
title: undefined, title: undefined,
description: undefined, description: undefined,
target: undefined, target: undefined,
@ -19,6 +20,8 @@ export const usePromoSidebar = defineStore('promo_sidebar', {
const target = clickable.list.find(el => el.id == id) const target = clickable.list.find(el => el.id == id)
if (!target) return if (!target) return
const sidebar_data = { const sidebar_data = {
id_clickable: id,
target_id: target.id,
title: target.name, title: target.name,
description: target.description description: target.description
} as PromoSidebarData } as PromoSidebarData