mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:14:59 +02:00
Support Web entities in android
This commit is contained in:
parent
0a70e844bf
commit
7e640abb39
3 changed files with 109 additions and 73 deletions
|
@ -1,73 +0,0 @@
|
|||
"use strict";
|
||||
//
|
||||
// clickOverlays.js
|
||||
// scripts/system/+android
|
||||
//
|
||||
// Created by Gabriel Calero & Cristian Duarte on Jun 22, 2018
|
||||
// Copyright 2018 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
(function() { // BEGIN LOCAL_SCOPE
|
||||
|
||||
var logEnabled = false;
|
||||
var touchOverlayID;
|
||||
|
||||
function printd(str) {
|
||||
if (logEnabled)
|
||||
print("[clickOverlays.js] " + str);
|
||||
}
|
||||
|
||||
function touchBegin(event) {
|
||||
var rayIntersection = Overlays.findRayIntersection(Camera.computePickRay(event.x, event.y));
|
||||
if (rayIntersection && rayIntersection.intersects && rayIntersection.overlayID &&
|
||||
Overlays.getOverlayType(rayIntersection.overlayID) == "web3d") {
|
||||
touchOverlayID = rayIntersection.overlayID;
|
||||
} else {
|
||||
touchOverlayID = null;
|
||||
}
|
||||
}
|
||||
|
||||
function touchEnd(event) {
|
||||
var rayIntersection = Overlays.findRayIntersection(Camera.computePickRay(event.x, event.y));
|
||||
if (rayIntersection && rayIntersection.intersects && rayIntersection.overlayID &&
|
||||
touchOverlayID == rayIntersection.overlayID) {
|
||||
var propertiesToGet = {};
|
||||
propertiesToGet[rayIntersection.overlayID] = ['url'];
|
||||
var properties = Overlays.getOverlaysProperties(propertiesToGet);
|
||||
if (properties[rayIntersection.overlayID].url) {
|
||||
Window.openUrl(properties[rayIntersection.overlayID].url);
|
||||
}
|
||||
var overlayObj = Overlays.getOverlayObject(rayIntersection.overlayID);
|
||||
Overlays.sendMousePressOnOverlay(rayIntersection.overlayID, {
|
||||
type: "press",
|
||||
id: 0,
|
||||
pos2D: event
|
||||
});
|
||||
}
|
||||
touchOverlayID = null;
|
||||
}
|
||||
|
||||
function ending() {
|
||||
Controller.touchBeginEvent.disconnect(touchBegin);
|
||||
Controller.touchEndEvent.disconnect(touchEnd);
|
||||
}
|
||||
|
||||
function init() {
|
||||
Controller.touchBeginEvent.connect(touchBegin);
|
||||
Controller.touchEndEvent.connect(touchEnd);
|
||||
|
||||
Script.scriptEnding.connect(function () {
|
||||
ending();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: init,
|
||||
ending: ending
|
||||
}
|
||||
|
||||
}()); // END LOCAL_SCOPE
|
106
scripts/system/+android/clickWeb.js
Normal file
106
scripts/system/+android/clickWeb.js
Normal file
|
@ -0,0 +1,106 @@
|
|||
"use strict";
|
||||
//
|
||||
// clickOverlays.js
|
||||
// scripts/system/+android
|
||||
//
|
||||
// Created by Gabriel Calero & Cristian Duarte on Jun 22, 2018
|
||||
// Copyright 2018 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
(function() { // BEGIN LOCAL_SCOPE
|
||||
|
||||
var logEnabled = false;
|
||||
var touchOverlayID;
|
||||
var touchEntityID;
|
||||
|
||||
function printd(str) {
|
||||
if (logEnabled)
|
||||
print("[clickOverlays.js] " + str);
|
||||
}
|
||||
|
||||
|
||||
function findOverlayIDRayIntersection(pickRay) {
|
||||
// Check 3D overlays and entities. Argument is an object with origin and direction.
|
||||
var rayIntersection = Overlays.findRayIntersection(pickRay);
|
||||
if (rayIntersection && rayIntersection.intersects && rayIntersection.overlayID &&
|
||||
Overlays.getOverlayType(rayIntersection.overlayID) == "web3d") {
|
||||
return rayIntersection.overlayID;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function findEntityIDRayIntersection(pickRay) {
|
||||
// Check 3D overlays and entities. Argument is an object with origin and direction.
|
||||
var rayIntersection = Entities.findRayIntersection(pickRay, true);
|
||||
if (rayIntersection.entityID) {
|
||||
var properties = Entities.getEntityProperties(rayIntersection.entityID, ["type", "sourceUrl"]);
|
||||
if (properties.type && properties.type == "Web" && properties.sourceUrl) {
|
||||
return rayIntersection.entityID;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function touchBegin(event) {
|
||||
var overlayID = findOverlayIDRayIntersection(Camera.computePickRay(event.x, event.y));
|
||||
if (overlayID) {
|
||||
touchOverlayID = overlayID;
|
||||
touchEntityID = null;
|
||||
return;
|
||||
}
|
||||
var entityID = findEntityIDRayIntersection(Camera.computePickRay(event.x, event.y));
|
||||
if (entityID) {
|
||||
touchEntityID = entityID;
|
||||
touchOverlayID = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function touchEnd(event) {
|
||||
var overlayID = findOverlayIDRayIntersection(Camera.computePickRay(event.x, event.y));
|
||||
if (touchOverlayID && overlayID == touchOverlayID) {
|
||||
var propertiesToGet = {};
|
||||
propertiesToGet[overlayID] = ['url'];
|
||||
var properties = Overlays.getOverlaysProperties(propertiesToGet);
|
||||
if (properties[overlayID].url) {
|
||||
Window.openUrl(properties[overlayID].url);
|
||||
}
|
||||
}
|
||||
|
||||
var entityID = findEntityIDRayIntersection(Camera.computePickRay(event.x, event.y));
|
||||
if (touchEntityID && entityID == touchEntityID) {
|
||||
var properties = Entities.getEntityProperties(entityID, ["sourceUrl"]);
|
||||
if (properties.sourceUrl) {
|
||||
Window.openUrl(properties.sourceUrl);
|
||||
}
|
||||
}
|
||||
|
||||
touchOverlayID = null;
|
||||
touchEntityID = null;
|
||||
}
|
||||
|
||||
function ending() {
|
||||
Controller.touchBeginEvent.disconnect(touchBegin);
|
||||
Controller.touchEndEvent.disconnect(touchEnd);
|
||||
}
|
||||
|
||||
function init() {
|
||||
Controller.touchBeginEvent.connect(touchBegin);
|
||||
Controller.touchEndEvent.connect(touchEnd);
|
||||
|
||||
Script.scriptEnding.connect(function () {
|
||||
ending();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: init,
|
||||
ending: ending
|
||||
}
|
||||
|
||||
}()); // END LOCAL_SCOPE
|
|
@ -29,6 +29,7 @@ var logEnabled = false;
|
|||
var radar = Script.require('./radar.js');
|
||||
var uniqueColor = Script.require('./uniqueColor.js');
|
||||
var displayNames = Script.require('./displayNames.js');
|
||||
var clickWeb = Script.require('./clickWeb.js');
|
||||
|
||||
function printd(str) {
|
||||
if (logEnabled) {
|
||||
|
@ -97,9 +98,11 @@ function switchToMode(newMode) {
|
|||
if (currentMode == MODE_RADAR) {
|
||||
radar.startRadarMode();
|
||||
displayNames.ending();
|
||||
clickWeb.ending();
|
||||
} else if (currentMode == MODE_MY_VIEW) {
|
||||
// nothing to do yet
|
||||
displayNames.init();
|
||||
clickWeb.init();
|
||||
} else {
|
||||
printd("Unknown view mode " + currentMode);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue