2018-03-24 17:16:36 +01:00
|
|
|
if (!this.entityLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.initialized) {
|
2018-03-24 17:29:10 +01:00
|
|
|
|
|
|
|
this.camera = this.entityLoaded.camera;
|
|
|
|
this.buttons = this.entityLoaded.buttons;
|
|
|
|
this.raycaster = this.entityLoaded.raycaster;
|
2018-03-24 18:24:12 +01:00
|
|
|
this.canvasHUD = this.entityLoaded.canvasHUD;
|
2018-03-24 17:29:10 +01:00
|
|
|
|
2018-03-24 17:16:36 +01:00
|
|
|
this.initialized = true;
|
|
|
|
}
|
2018-03-24 17:22:36 +01:00
|
|
|
|
2018-03-24 17:24:03 +01:00
|
|
|
var mouse = {
|
2018-03-24 18:44:39 +01:00
|
|
|
x : (data.event.offsetX / data.event.target.clientWidth ) * 2 - 1,
|
|
|
|
y : -(data.event.offsetY / data.event.target.clientHeight) * 2 + 1
|
2018-03-24 17:24:03 +01:00
|
|
|
}
|
|
|
|
|
2018-03-24 19:02:37 +01:00
|
|
|
//console.log('mouse ' + mouse.x + ', ' + mouse.y);
|
2018-03-24 18:36:34 +01:00
|
|
|
|
2018-03-24 17:35:30 +01:00
|
|
|
this.raycaster.setFromCamera(
|
|
|
|
mouse,
|
|
|
|
this.camera
|
|
|
|
);
|
2018-03-24 17:22:36 +01:00
|
|
|
|
2018-03-24 18:34:27 +01:00
|
|
|
var intersects = this.raycaster.getIntersectedObjects(this.buttons);
|
|
|
|
|
|
|
|
if (intersects.length === 0) {
|
2018-03-24 19:02:37 +01:00
|
|
|
//console.log('nothing');
|
2018-03-24 18:34:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
intersects.map(
|
2018-03-24 17:35:30 +01:00
|
|
|
function(intersect) {
|
2018-03-24 17:58:36 +01:00
|
|
|
|
2018-03-24 18:12:05 +01:00
|
|
|
var x = Math.round(intersect.uv.x * 256);
|
2018-03-24 19:00:59 +01:00
|
|
|
|
|
|
|
var y = Math.round(intersect.uv.y * 256);
|
|
|
|
|
2018-03-24 19:02:11 +01:00
|
|
|
var pixel = intersect.mesh.materials[0].diffuseMap.image.alphas[(256 * y) + x];
|
2018-03-24 18:00:36 +01:00
|
|
|
|
2018-03-24 18:42:00 +01:00
|
|
|
if (pixel === 255) {
|
2018-03-24 18:39:10 +01:00
|
|
|
console.log(intersect.mesh.name + ' : ' + pixel);
|
2018-03-24 18:42:00 +01:00
|
|
|
}
|
2018-03-24 18:14:08 +01:00
|
|
|
|
2018-03-24 17:35:30 +01:00
|
|
|
}
|
|
|
|
);
|
2018-03-24 17:15:24 +01:00
|
|
|
//@ sourceURL=mouseDown.js
|