init
This commit is contained in:
7
js/controls/dimensions.js
Executable file
7
js/controls/dimensions.js
Executable file
@@ -0,0 +1,7 @@
|
||||
let _w = window.innerWidth;
|
||||
let _h = window.innerHeight;
|
||||
|
||||
export default {
|
||||
"w": _w,
|
||||
"h": _h
|
||||
};
|
116
js/controls/initDesktopEventListeners.js
Executable file
116
js/controls/initDesktopEventListeners.js
Executable file
@@ -0,0 +1,116 @@
|
||||
import dims from "./dimensions";
|
||||
|
||||
export default function (scope) {
|
||||
|
||||
"use strict";
|
||||
|
||||
let downX = 0;
|
||||
let downY = 0;
|
||||
|
||||
window.addEventListener("mousemove", function (ev) {
|
||||
|
||||
if (this.type !== "anim") {
|
||||
|
||||
scope.nm[0] = ev.clientX / dims.w * 2 - 1;
|
||||
scope.nm[1] = ev.clientY / dims.h * -2 + 1;
|
||||
|
||||
}
|
||||
}.bind(scope), false);
|
||||
|
||||
scope.domElement.addEventListener("mousedown", function (ev) {
|
||||
|
||||
downX = ev.clientX / dims.w * 2 - 1;
|
||||
downY = ev.clientY / dims.h * -2 + 1;
|
||||
|
||||
scope.mouseArray = [
|
||||
[downX, downY],
|
||||
[downX, downY],
|
||||
[downX, downY],
|
||||
[downX, downY],
|
||||
[downX, downY],
|
||||
[downX, downY],
|
||||
[downX, downY],
|
||||
[downX, downY],
|
||||
[downX, downY],
|
||||
[downX, downY]
|
||||
]
|
||||
|
||||
this.dragMultiplier = 1;
|
||||
this.pressed = true;
|
||||
|
||||
}.bind(scope), false);
|
||||
|
||||
scope.domElement.addEventListener("mouseup", function (ev) {
|
||||
|
||||
this.pressed = false;
|
||||
|
||||
if (Math.abs(downX - scope.nm[0]) + Math.abs(downY - scope.nm[1]) < 0.05) {
|
||||
|
||||
//If we have an intersect object
|
||||
if (this.intersects) {
|
||||
|
||||
//If the name of the object under the cursor === floor then set controls to FP, translate to Cursor pos
|
||||
if (this.intersects.object.name === "floor") {
|
||||
this.setFP(this.intersects);
|
||||
this.activeObject.uuid = undefined;
|
||||
}
|
||||
|
||||
//If the object under the cursor is clickable &
|
||||
//not the activeObject & the camera is not animating translate the Camera to it
|
||||
else if (
|
||||
this.intersects.object.userData.clickable === true &&
|
||||
this.intersects.object.uuid !== this.activeObject.uuid &&
|
||||
this.type !== "anim") {
|
||||
this.setOrbit(this.intersects.object);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
this.dragMultiplier = 1.1;
|
||||
|
||||
this.dragVector.x = (scope.mouseArray[9][1] - scope.mouseArray[7][1]) * -1;
|
||||
this.dragVector.y = scope.mouseArray[9][0] - scope.mouseArray[7][0];
|
||||
|
||||
}
|
||||
|
||||
if (this.saveCamTransform) {
|
||||
localStorage.camTransform = [
|
||||
this.target.position.x,
|
||||
this.target.position.y,
|
||||
this.target.position.z,
|
||||
this.target.rotation.x,
|
||||
this.target.rotation.y,
|
||||
this.target.rotation.z
|
||||
];
|
||||
}
|
||||
|
||||
}.bind(scope), false);
|
||||
|
||||
scope.domElement.addEventListener("mouseleave", function () {
|
||||
this.pressed = false;
|
||||
}.bind(scope), false);
|
||||
|
||||
window.addEventListener("keydown", function (e) {
|
||||
switch (e.key) {
|
||||
case "Escape":
|
||||
|
||||
if (this.type === "orbit" && this.activeObject.uuid) {
|
||||
this.setFP({
|
||||
point: {
|
||||
x: this.savePosition.x,
|
||||
y: 0,
|
||||
z: this.savePosition.z
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}.bind(scope), false);
|
||||
}
|
94
js/controls/initMobileEventListeners.js
Executable file
94
js/controls/initMobileEventListeners.js
Executable file
@@ -0,0 +1,94 @@
|
||||
export default function i(scope) {
|
||||
|
||||
"use strict";
|
||||
|
||||
let downX = 0;
|
||||
let downY = 0;
|
||||
|
||||
scope.domElement.addEventListener("touchmove", function (ev) {
|
||||
|
||||
if (this.type !== "anim") {
|
||||
|
||||
nm[0] = ev.touches[0].clientX / w * 2 - 1;
|
||||
nm[1] = ev.touches[0].clientY / h * -2 + 1;
|
||||
|
||||
}
|
||||
}.bind(scope), false);
|
||||
|
||||
scope.domElement.addEventListener("touchstart", function (ev) {
|
||||
|
||||
downX = ev.touches[0].clientX / w * 2 - 1;
|
||||
downY = ev.touches[0].clientY / h * -2 + 1;
|
||||
|
||||
scope.mouseArray = [
|
||||
[downX, downY],
|
||||
[downX, downY],
|
||||
[downX, downY],
|
||||
[downX, downY],
|
||||
[downX, downY],
|
||||
[downX, downY],
|
||||
[downX, downY],
|
||||
[downX, downY],
|
||||
[downX, downY],
|
||||
[downX, downY]
|
||||
]
|
||||
|
||||
this.dragMultiplier = 1;
|
||||
this.pressed = true;
|
||||
|
||||
}.bind(scope), false);
|
||||
|
||||
scope.domElement.addEventListener("touchend", function (ev) {
|
||||
|
||||
this.pressed = false;
|
||||
|
||||
if (Math.abs(downX - nm[0]) + Math.abs(downY - nm[1]) < 0.05) {
|
||||
|
||||
//If we have an intersect object
|
||||
if (this.intersects) {
|
||||
|
||||
//If the name of the object under the cursor === floor then set controls to FP, translate to Cursor pos
|
||||
if (this.intersects.object.name === "floor") {
|
||||
this.setFP(this.intersects);
|
||||
this.activeObject.uuid = undefined;
|
||||
}
|
||||
|
||||
//If the object under the cursor is clickable &
|
||||
//not the activeObject & the camera is not animating translate the Camera to it
|
||||
else if (
|
||||
this.intersects.object.userData.clickable === true &&
|
||||
this.intersects.object.uuid !== this.activeObject.uuid &&
|
||||
this.type !== "anim") {
|
||||
this.setOrbit(this.intersects.object);
|
||||
this.outlineObject.visible = false;
|
||||
this.activeObject.uuid = this.intersects.object.uuid;
|
||||
this.activeObject.name = this.intersects.object.name;
|
||||
this.activeObject.text = this.intersects.object.userData.text;
|
||||
overlayInfo.animIn(this.activeObject.name, this.activeObject.text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
this.dragMultiplier = 1.1;
|
||||
|
||||
this.dragVector.x = (mouseArray[9][1] - mouseArray[7][1]) * -1;
|
||||
this.dragVector.y = mouseArray[9][0] - mouseArray[7][0];
|
||||
|
||||
}
|
||||
|
||||
if (this.saveCamTransform) {
|
||||
localStorage.camTransform = [
|
||||
this.target.position.x,
|
||||
this.target.position.y,
|
||||
this.target.position.z,
|
||||
this.target.rotation.x,
|
||||
this.target.rotation.y,
|
||||
this.target.rotation.z
|
||||
];
|
||||
}
|
||||
|
||||
}.bind(scope), false);
|
||||
|
||||
}
|
Reference in New Issue
Block a user