Setting up for locking to camera
This commit is contained in:
parent
2589c0bcc1
commit
6b6ef887ea
1 changed files with 11 additions and 5 deletions
16
src/index.js
16
src/index.js
|
@ -292,6 +292,7 @@ const {selectItem} = (function selectItemFunction() {
|
||||||
function dragItem(THREE, element, offset, camera, depth, mouseInfo) {
|
function dragItem(THREE, element, offset, camera, depth, mouseInfo) {
|
||||||
|
|
||||||
const {x: offsetX, y: offsetY, z: offsetZ} = offset;
|
const {x: offsetX, y: offsetY, z: offsetZ} = offset;
|
||||||
|
const lastCameraRotation = camera.components.camera.camera.rotation.clone();
|
||||||
let lastMouseInfo = mouseInfo;
|
let lastMouseInfo = mouseInfo;
|
||||||
|
|
||||||
function onMouseMove({clientX, clientY}) {
|
function onMouseMove({clientX, clientY}) {
|
||||||
|
@ -319,19 +320,22 @@ function dragItem(THREE, element, offset, camera, depth, mouseInfo) {
|
||||||
element.setAttribute('position', nextPosition);
|
element.setAttribute('position', nextPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onCameraMove({detail}) {
|
function onCameraChange({detail}) {
|
||||||
if (detail.name === 'position' && !deepEqual(detail.oldData, detail.newData)) {
|
if (
|
||||||
|
(detail.name === 'position' || detail.name === 'rotation')
|
||||||
|
&& !deepEqual(detail.oldData, detail.newData)
|
||||||
|
) {
|
||||||
onMouseMove(lastMouseInfo);
|
onMouseMove(lastMouseInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('mousemove', onMouseMove);
|
document.addEventListener('mousemove', onMouseMove);
|
||||||
camera.addEventListener('componentchanged', onCameraMove);
|
camera.addEventListener('componentchanged', onCameraChange);
|
||||||
|
|
||||||
// The "unlisten" function
|
// The "unlisten" function
|
||||||
return _ => {
|
return _ => {
|
||||||
document.removeEventListener('mousemove', onMouseMove);
|
document.removeEventListener('mousemove', onMouseMove);
|
||||||
camera.removeEventListener('componentchanged', onCameraMove);
|
camera.removeEventListener('componentchanged', onCameraChange);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,7 +548,9 @@ export default function aframeDraggableComponent(aframe, componentName = COMPONE
|
||||||
* Draggable component for A-Frame.
|
* Draggable component for A-Frame.
|
||||||
*/
|
*/
|
||||||
aframe.registerComponent(componentName, {
|
aframe.registerComponent(componentName, {
|
||||||
schema: { },
|
schema: {
|
||||||
|
lockToLocalRotation: {default: true},
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called once when component is attached. Generally for initial setup.
|
* Called once when component is attached. Generally for initial setup.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue