2017-11-09 00:10:48 +01:00
|
|
|
if (!this.entityLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-11 14:46:53 +01:00
|
|
|
if (!this.initialized) {
|
|
|
|
this.initialized = true;
|
|
|
|
}
|
2017-11-09 00:10:48 +01:00
|
|
|
|
2017-11-11 14:46:53 +01:00
|
|
|
this.mouse.x = (event.offsetX / event.target.width ) * 2 - 1;
|
|
|
|
this.mouse.y = -(event.offsetY / event.target.height) * 2 + 1;
|
2017-11-09 00:10:48 +01:00
|
|
|
|
2017-11-11 16:57:21 +01:00
|
|
|
this.camera.lookAt.x = this.mouse.x * 20;
|
|
|
|
this.camera.lookAt.y = this.mouse.y * 20;
|
2017-11-11 17:26:41 +01:00
|
|
|
this.camera.lookAt.z = Math.cos(this.mouse.x) + Math.sin(this.mouse.y);
|
2017-11-11 14:46:53 +01:00
|
|
|
this.camera.updateInstance();
|
2017-11-09 00:10:48 +01:00
|
|
|
|
2017-11-11 16:57:21 +01:00
|
|
|
this.raycaster.setFromCamera(
|
2017-11-11 14:46:53 +01:00
|
|
|
this.mouse,
|
2017-11-11 16:57:21 +01:00
|
|
|
this.camera
|
2017-11-11 14:46:53 +01:00
|
|
|
);
|
2017-11-09 00:10:48 +01:00
|
|
|
|
2017-11-11 17:26:41 +01:00
|
|
|
var distance = - this.camera.position.z / this.raycaster.direction.z;
|
|
|
|
var cursorPosition = this.camera.position.clone().add(
|
|
|
|
this.raycaster.direction.clone().multiply(
|
|
|
|
distance,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
);
|
2017-11-11 16:02:03 +01:00
|
|
|
|
2017-11-11 17:26:41 +01:00
|
|
|
this.cursor.position.x = cursorPosition.x;//this.camera.position.x + this.mouse.x;
|
|
|
|
this.cursor.position.y = cursorPosition.y;//this.camera.position.y + this.mouse.y;
|
|
|
|
this.cursor.position.z = cursorPosition.z;//this.camera.position.z - 1;
|
2017-11-11 14:46:53 +01:00
|
|
|
this.cursor.updateInstance();
|
2017-11-09 00:10:48 +01:00
|
|
|
|
2017-11-11 17:26:41 +01:00
|
|
|
//this.cursor.lookAt.x = this.camera.position.x;
|
|
|
|
//this.cursor.lookAt.y = this.camera.position.y;
|
|
|
|
//this.cursor.lookAt.z = this.camera.position.z;
|
|
|
|
//this.cursor.updateInstance();
|
2017-11-11 16:31:02 +01:00
|
|
|
|
2017-11-11 14:46:53 +01:00
|
|
|
this.thrower.instance.lookAt(
|
2017-11-09 00:10:48 +01:00
|
|
|
new THREE.Vector3(
|
2017-11-11 14:46:53 +01:00
|
|
|
this.cursor.position.x,
|
|
|
|
this.cursor.position.y,
|
|
|
|
this.cursor.position.z
|
2017-11-09 00:10:48 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2017-11-11 15:13:33 +01:00
|
|
|
this.scene.meshes.map(
|
|
|
|
function(mesh) {
|
|
|
|
|
|
|
|
if (mesh.instance.material instanceof Array) {
|
|
|
|
mesh.instance.material.map(
|
|
|
|
function(material) {
|
|
|
|
material.color.setHex(0xffffff);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
mesh.instance.material.color.setHex(0xffffff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2017-11-11 15:09:44 +01:00
|
|
|
var intersects = this.raycaster.getIntersectedObjects(this.scene.meshes);
|
|
|
|
intersects.map(
|
|
|
|
function(intersect) {
|
|
|
|
|
|
|
|
var mesh = intersect.mesh;
|
|
|
|
|
|
|
|
if (mesh.instance.material instanceof Array) {
|
|
|
|
mesh.instance.material.map(
|
|
|
|
function(material) {
|
|
|
|
material.color.setHex(0xff0000);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
mesh.instance.material.color.setHex(0xff0000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2017-11-09 00:10:48 +01:00
|
|
|
//@ sourceURL=mouseMove.js
|