add touch support for interactive 360
This commit is contained in:
parent
1ed7aa9c5b
commit
da973da1ce
2 changed files with 66 additions and 48 deletions
|
|
@ -1,23 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'debug' => true,
|
'debug' => true,
|
||||||
'smartypants' => true,
|
'smartypants' => true,
|
||||||
'locale' => 'fr_FR.utf-8',
|
'locale' => 'fr_FR.utf-8',
|
||||||
'date' => [
|
'date' => [
|
||||||
'handler' => 'intl'
|
'handler' => 'intl',
|
||||||
],
|
],
|
||||||
'api' => [
|
'api' => [
|
||||||
'basicAuth' => true,
|
'basicAuth' => true,
|
||||||
// Enable api access without SSL. To disable in production.
|
// Enable api access without SSL. To disable in production.
|
||||||
'allowInsecure' => true
|
'allowInsecure' => true,
|
||||||
],
|
],
|
||||||
'panel' => [
|
'panel' => [
|
||||||
'language' => 'fr',
|
'language' => 'fr',
|
||||||
'css' => 'assets/css/panel.css',
|
'css' => 'assets/css/panel.css',
|
||||||
'js' => 'assets/js/panel.js',
|
'js' => 'assets/js/panel.js',
|
||||||
'favicon' => 'favicon.svg',
|
'favicon' => 'favicon.svg',
|
||||||
'menu' => require(__DIR__ . '/menu.php'),
|
'menu' => require(__DIR__ . '/menu.php'),
|
||||||
],
|
],
|
||||||
'routes' => [
|
'routes' => [
|
||||||
require(__DIR__ . '/routes/logout.php'),
|
require(__DIR__ . '/routes/logout.php'),
|
||||||
|
|
@ -32,7 +32,7 @@ return [
|
||||||
require(__DIR__ . '/routes/request-optimization-appointment.php'),
|
require(__DIR__ . '/routes/request-optimization-appointment.php'),
|
||||||
],
|
],
|
||||||
'hooks' => [
|
'hooks' => [
|
||||||
'page.create:after' => require_once(__DIR__ . '/hooks/create-steps.php'),
|
'page.create:after' => require_once(__DIR__ . '/hooks/create-steps.php'),
|
||||||
'page.delete:before' => require_once(__DIR__ . '/hooks/delete-steps.php'),
|
'page.delete:before' => require_once(__DIR__ . '/hooks/delete-steps.php'),
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
<figure>
|
<figure>
|
||||||
<div
|
<div
|
||||||
@mousedown="enableDragToRotate"
|
@mousedown="enableDragToRotate"
|
||||||
|
@touchstart="enableDragToRotate"
|
||||||
class="drag-zone"
|
class="drag-zone"
|
||||||
:class="{ grabbing: isDragToRotateEnabled }"
|
:class="{ grabbing: isDragToRotateEnabled }"
|
||||||
></div>
|
></div>
|
||||||
|
|
@ -48,18 +49,16 @@ const isHelperHidden = ref(localStorage.getItem('isHelperHidden'));
|
||||||
localStorage.setItem('isHelperHidden', true);
|
localStorage.setItem('isHelperHidden', true);
|
||||||
|
|
||||||
// Grab interaction
|
// Grab interaction
|
||||||
const yMax = computed(() => {
|
const yMax = computed(() =>
|
||||||
return parseInt(
|
parseInt(activeTrack.files[activeTrack.files.length - 1].name.split('_')[0])
|
||||||
activeTrack.files[activeTrack.files.length - 1].name.split('_')[0]
|
);
|
||||||
);
|
const xMax = computed(() =>
|
||||||
});
|
parseInt(
|
||||||
const xMax = computed(() => {
|
|
||||||
return parseInt(
|
|
||||||
activeTrack.files[activeTrack.files.length - 1].name
|
activeTrack.files[activeTrack.files.length - 1].name
|
||||||
.split('_')[1]
|
.split('_')[1]
|
||||||
.split('.')[0]
|
.split('.')[0]
|
||||||
);
|
)
|
||||||
});
|
);
|
||||||
|
|
||||||
const frontXView = (xMax.value + 1) / 2;
|
const frontXView = (xMax.value + 1) / 2;
|
||||||
const currentX = ref(frontXView);
|
const currentX = ref(frontXView);
|
||||||
|
|
@ -68,74 +67,86 @@ const currentFileIndex = computed(() => currentY.value + '_' + currentX.value);
|
||||||
const currentFile = computed(() =>
|
const currentFile = computed(() =>
|
||||||
activeTrack.files.find((file) => file.name.includes(currentFileIndex.value))
|
activeTrack.files.find((file) => file.name.includes(currentFileIndex.value))
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
currentFile,
|
currentFile,
|
||||||
() => {
|
() => {
|
||||||
virtualSampleStore.currentFile = currentFile.value;
|
virtualSampleStore.currentFile = currentFile.value;
|
||||||
openedFile.value = currentFile.value;
|
openedFile.value = currentFile.value;
|
||||||
},
|
},
|
||||||
{
|
{ immediate: true }
|
||||||
immediate: true,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Rotation
|
||||||
function rotateX(direction) {
|
function rotateX(direction) {
|
||||||
if (direction == 'left') {
|
if (direction === 'left') {
|
||||||
currentX.value = currentX.value === 0 ? xMax.value : currentX.value - 1;
|
currentX.value = currentX.value === 0 ? xMax.value : currentX.value - 1;
|
||||||
}
|
} else if (direction === 'right') {
|
||||||
if (direction == 'right') {
|
|
||||||
currentX.value = currentX.value === xMax.value ? 0 : currentX.value + 1;
|
currentX.value = currentX.value === xMax.value ? 0 : currentX.value + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isDragToRotateEnabled = ref(false);
|
const isDragToRotateEnabled = ref(false);
|
||||||
window.addEventListener('mouseup', disableDragToRotate);
|
|
||||||
function enableDragToRotate() {
|
|
||||||
isDragToRotateEnabled.value = true;
|
|
||||||
}
|
|
||||||
function disableDragToRotate() {
|
|
||||||
isDragToRotateEnabled.value = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let previousMouseXPos;
|
let previousMouseXPos;
|
||||||
let previousMouseYPos;
|
let previousMouseYPos;
|
||||||
const DRAG_STEP = 20;
|
const DRAG_STEP = 20;
|
||||||
|
|
||||||
|
function enableDragToRotate(event) {
|
||||||
|
if (event.type.startsWith('touch')) event.preventDefault();
|
||||||
|
const isTouch = event.type.startsWith('touch');
|
||||||
|
|
||||||
|
isDragToRotateEnabled.value = true;
|
||||||
|
const clientX = isTouch ? event.touches[0].clientX : event.clientX;
|
||||||
|
const clientY = isTouch ? event.touches[0].clientY : event.clientY;
|
||||||
|
|
||||||
|
previousMouseXPos = clientX;
|
||||||
|
previousMouseYPos = clientY;
|
||||||
|
}
|
||||||
|
|
||||||
|
function disableDragToRotate() {
|
||||||
|
isDragToRotateEnabled.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
function dragToRotate(event) {
|
function dragToRotate(event) {
|
||||||
handleHorizontalRotation(event);
|
if (event.type.startsWith('touch')) event.preventDefault();
|
||||||
handleVerticalRotation(event);
|
const isTouch = event.type.startsWith('touch');
|
||||||
|
const clientX = isTouch ? event.touches[0].clientX : event.clientX;
|
||||||
|
const clientY = isTouch ? event.touches[0].clientY : event.clientY;
|
||||||
|
|
||||||
|
handleHorizontalRotation(clientX);
|
||||||
|
handleVerticalRotation(clientY);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleHorizontalRotation(event) {
|
function handleHorizontalRotation(clientX) {
|
||||||
if (previousMouseXPos === undefined) {
|
if (previousMouseXPos === undefined) {
|
||||||
previousMouseXPos = event.clientX;
|
previousMouseXPos = clientX;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.clientX > previousMouseXPos + DRAG_STEP) {
|
if (clientX > previousMouseXPos + DRAG_STEP) {
|
||||||
rotateX('left');
|
rotateX('left');
|
||||||
previousMouseXPos = event.clientX;
|
previousMouseXPos = clientX;
|
||||||
} else if (event.clientX < previousMouseXPos - DRAG_STEP) {
|
} else if (clientX < previousMouseXPos - DRAG_STEP) {
|
||||||
rotateX('right');
|
rotateX('right');
|
||||||
previousMouseXPos = event.clientX;
|
previousMouseXPos = clientX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleVerticalRotation(event) {
|
function handleVerticalRotation(clientY) {
|
||||||
if (previousMouseYPos === undefined) {
|
if (previousMouseYPos === undefined) {
|
||||||
previousMouseYPos = event.clientY;
|
previousMouseYPos = clientY;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.clientY > previousMouseYPos + DRAG_STEP) {
|
if (clientY > previousMouseYPos + DRAG_STEP) {
|
||||||
if (currentY.value < yMax.value) {
|
if (currentY.value < yMax.value) {
|
||||||
currentY.value++;
|
currentY.value++;
|
||||||
previousMouseYPos = event.clientY;
|
previousMouseYPos = clientY;
|
||||||
}
|
}
|
||||||
} else if (event.clientY < previousMouseYPos - DRAG_STEP) {
|
} else if (clientY < previousMouseYPos - DRAG_STEP) {
|
||||||
if (currentY.value > 0) {
|
if (currentY.value > 0) {
|
||||||
currentY.value--;
|
currentY.value--;
|
||||||
previousMouseYPos = event.clientY;
|
previousMouseYPos = clientY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -150,13 +161,20 @@ const throttledDragToRotate = throttle(dragToRotate, 50);
|
||||||
watch(isDragToRotateEnabled, (newValue) => {
|
watch(isDragToRotateEnabled, (newValue) => {
|
||||||
if (newValue) {
|
if (newValue) {
|
||||||
window.addEventListener('mousemove', throttledDragToRotate);
|
window.addEventListener('mousemove', throttledDragToRotate);
|
||||||
|
window.addEventListener('touchmove', throttledDragToRotate, {
|
||||||
|
passive: false,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
window.removeEventListener('mousemove', throttledDragToRotate);
|
window.removeEventListener('mousemove', throttledDragToRotate);
|
||||||
|
window.removeEventListener('touchmove', throttledDragToRotate);
|
||||||
previousMouseXPos = undefined;
|
previousMouseXPos = undefined;
|
||||||
previousMouseYPos = undefined;
|
previousMouseYPos = undefined;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.addEventListener('mouseup', disableDragToRotate);
|
||||||
|
window.addEventListener('touchend', disableDragToRotate);
|
||||||
|
|
||||||
const { isLoopAnimationEnabled } = storeToRefs(useVirtualSampleStore());
|
const { isLoopAnimationEnabled } = storeToRefs(useVirtualSampleStore());
|
||||||
|
|
||||||
function loopAnimation() {
|
function loopAnimation() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue