small refactor

This commit is contained in:
Kseninia Mikhaylova 2024-09-03 12:34:52 +03:00
parent d986562a2b
commit 1b5c510de0
1 changed files with 42 additions and 36 deletions

View File

@ -36,12 +36,13 @@ let sidebar_clickable = [] as PromoScene[]
let sidebar_visible = [] as PromoScene[]
const COUNT = 100
const controls_targetto = ref() as Ref<Vector3 | undefined>;
const controls_targetto_count = ref(COUNT)
const camera_moveto = ref() as Ref<Vector3 | undefined>;
const camera_moveto_count = ref(COUNT)
const camera_rotatetoto = ref() as Ref<Quaternion | undefined>;
const camera_rotatetoto_count = ref(COUNT)
type smooth = {
value: Vector3 | Quaternion | undefined,
count: number
}
const smooth_target = reactive({}) as smooth
const smooth_move = reactive({}) as smooth
const smooth_rotate = reactive({}) as smooth
const vis_target = ref()
@ -58,6 +59,13 @@ const pointerTexture = await useTexture({
map: '/pointer_texture.png'
})
const set_moveto = (obj: smooth, value: Vector3 | Quaternion | undefined) => {
obj.value = value
if (obj.value == undefined) {
obj.count = COUNT
}
}
const setEnv = async () => {
envVars.focus = raw_dataStore.data.max_distance * 0.5
if (raw_dataStore.data.env) {
@ -223,12 +231,12 @@ const loadModels = async () => {
const gotoCenterAndDistance = () => {
targetDistance.min = mobileAndTabletCheck() ? raw_dataStore.data.min_distance * 0.5 : raw_dataStore.data.min_distance;
targetDistance.max = raw_dataStore.data.max_distance;
controls_targetto.value = new Vector3(0, 0, 0);
camera_moveto.value = new Vector3(
set_moveto(smooth_target, new Vector3(0, 0, 0))
set_moveto(smooth_move, new Vector3(
raw_dataStore.data.max_distance * 0.5,
raw_dataStore.data.max_distance * 0.5,
raw_dataStore.data.max_distance * 0.5
);
))
}
watch(() => props.source, () => {
@ -266,17 +274,18 @@ watch(() => sidebar.is_open && sidebar.id_clickable, () => {
target_vector.y = raw_dataStore.data.min_distance > 50 ? raw_dataStore.data.min_distance / 10 : 1;
const quaternion = new Quaternion();
quaternion.setFromEuler(new Euler(
-45 * 1 * (Math.PI / 180),
35 * 1 * (Math.PI / 180),
35 * 1 * (Math.PI / 180)
));
// quaternion.setFromEuler(new Euler(
// -45 * 1 * (Math.PI / 180),
// 35 * 1 * (Math.PI / 180),
// 35 * 1 * (Math.PI / 180)
// ));
quaternion.setFromEuler(new Euler(0, 0, 0).setFromVector3(target_vector))
// quaternion.setFromAxisAngle(new Vector3(0, 1, 0).normalize(), 45 * 4 * (Math.PI / 180));
// quaternion.setFromAxisAngle(new Vector3(0, 0, 1).normalize(), -45 * 4 * (Math.PI / 180));
camera_rotatetoto.value = quaternion
controls_targetto.value = target_vector;
camera_moveto.value = target_vector;
set_moveto(smooth_rotate, quaternion)
set_moveto(smooth_target, target_vector)
set_moveto(smooth_move, target_vector)
vis_target.value = target_vector;
}
}
@ -297,33 +306,30 @@ onAfterRender(() => {
}
})
const koef = 0.02
if (controls_targetto.value) {
if (smooth_target.value) {
timer.stopTimer();
(controls.value as any).target.lerp(controls_targetto.value, koef);
controls_targetto_count.value -= 1
if (controls_targetto_count.value == 0) {
controls_targetto_count.value = COUNT;
controls_targetto.value = undefined;
(controls.value as any).target.lerp(smooth_target.value, koef);
smooth_target.count -= 1
if (smooth_target.count == 0) {
set_moveto(smooth_target, undefined)
}
}
if (camera_moveto.value) {
if (smooth_move.value) {
timer.stopTimer();
camera.value?.position.lerp(camera_moveto.value, koef);
camera_moveto_count.value -= 1
if (camera_moveto_count.value == 0) {
camera.value?.lookAt(camera_moveto.value)
camera_moveto.value = undefined;
camera_moveto_count.value = COUNT;
camera.value?.position.lerp(smooth_move.value, koef);
smooth_move.count -= 1
if (smooth_move.count == 0) {
// camera.value?.lookAt(camera_moveto.value)
set_moveto(smooth_move, undefined)
}
}
if (camera_rotatetoto.value) {
if (smooth_rotate.value) {
timer.stopTimer();
camera.value?.quaternion.slerp(camera_rotatetoto.value, koef);
camera.value?.quaternion.slerp(smooth_rotate.value as Quaternion, koef);
camera.value?.quaternion.normalize()
camera_rotatetoto_count.value -= 1;
if (camera_rotatetoto_count.value == 0) {
camera_rotatetoto_count.value = COUNT;
camera_rotatetoto.value = undefined
smooth_rotate.count -= 1;
if (smooth_rotate.count == 0) {
set_moveto(smooth_rotate, undefined)
}
camera.value?.updateMatrixWorld()
}