diff --git a/cmake/macros/TargetNvtt.cmake b/cmake/macros/TargetNvtt.cmake index 7134df292d..b8198c0cf0 100644 --- a/cmake/macros/TargetNvtt.cmake +++ b/cmake/macros/TargetNvtt.cmake @@ -1,6 +1,3 @@ -if (NOT ANDROID) -endif() - # # Copyright 2015 High Fidelity, Inc. # Created by Bradley Austin Davis on 2015/10/10 diff --git a/libraries/render-utils/src/forward_model.slf b/libraries/render-utils/src/forward_model.slf index de721e9c2e..9241503902 100644 --- a/libraries/render-utils/src/forward_model.slf +++ b/libraries/render-utils/src/forward_model.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// forward_model_specular_map.frag +// forward_model.frag // fragment shader // // Created by Sam Gateau on 2/15/2016. diff --git a/libraries/render-utils/src/forward_model_normal_map.slf b/libraries/render-utils/src/forward_model_normal_map.slf index ba482cf909..b32ed862d6 100644 --- a/libraries/render-utils/src/forward_model_normal_map.slf +++ b/libraries/render-utils/src/forward_model_normal_map.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// forward_model_normal_specular_map.frag +// forward_model_normal_map.frag // fragment shader // // Created by Sam Gateau on 2/15/2016. diff --git a/libraries/render-utils/src/model_fade.slf b/libraries/render-utils/src/model_fade.slf index be8f003d63..577324f97a 100644 --- a/libraries/render-utils/src/model_fade.slf +++ b/libraries/render-utils/src/model_fade.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// model_specular_map_fade.frag +// model_fade.frag // fragment shader // // Created by Olivier Prat on 06/05/17. diff --git a/libraries/render-utils/src/model_lightmap_fade.slf b/libraries/render-utils/src/model_lightmap_fade.slf index 36e1d8acea..1dfc6a1b9e 100644 --- a/libraries/render-utils/src/model_lightmap_fade.slf +++ b/libraries/render-utils/src/model_lightmap_fade.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// model_lightmap_specular_map_fade.frag +// model_lightmap_fade.frag // fragment shader // // Created by Olivier Prat on 06/05/17. diff --git a/libraries/render-utils/src/model_lightmap_normal_map.slf b/libraries/render-utils/src/model_lightmap_normal_map.slf index 1a52ffe368..8734ea74b8 100644 --- a/libraries/render-utils/src/model_lightmap_normal_map.slf +++ b/libraries/render-utils/src/model_lightmap_normal_map.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// model_lightmap_normal_specular_map.frag +// model_lightmap_normal_map.frag // fragment shader // // Created by Samuel Gateau on 11/19/14. diff --git a/libraries/render-utils/src/model_lightmap_normal_map_fade.slf b/libraries/render-utils/src/model_lightmap_normal_map_fade.slf index ea187cfbf7..e6cb35ec4f 100644 --- a/libraries/render-utils/src/model_lightmap_normal_map_fade.slf +++ b/libraries/render-utils/src/model_lightmap_normal_map_fade.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// model_lightmap_normal_specular_map_fade.frag +// model_lightmap_normal_map_fade.frag // fragment shader // // Created by Olivier Prat on 06/05/17. diff --git a/libraries/ui/src/QmlFragmentClass.cpp b/libraries/ui/src/QmlFragmentClass.cpp index ff67022305..c4cac73b2d 100644 --- a/libraries/ui/src/QmlFragmentClass.cpp +++ b/libraries/ui/src/QmlFragmentClass.cpp @@ -20,9 +20,8 @@ std::mutex QmlFragmentClass::_mutex; std::map QmlFragmentClass::_fragments; -QmlFragmentClass::QmlFragmentClass(QString id) : - qml(id) { -} +QmlFragmentClass::QmlFragmentClass(QString id) : qml(id) { } + // Method called by Qt scripts to create a new bottom menu bar in Android QScriptValue QmlFragmentClass::constructor(QScriptContext* context, QScriptEngine* engine) { diff --git a/scripts/system/+android/radar.js b/scripts/system/+android/radar.js index 9fa07178f6..9b9bd9c473 100644 --- a/scripts/system/+android/radar.js +++ b/scripts/system/+android/radar.js @@ -1,21 +1,23 @@ "use strict"; // -// radar.js -// scripts/system/+android/ +// radar.js +// scripts/system/+android/ // -// Created by Cristian Duarte & Gabriel Calero on 31 Jan 2018 -// Copyright 2018 High Fidelity, Inc. +// Created by Cristian Duarte & Gabriel Calero on 31 Jan 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 +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or +// http://www.apache.org/licenses/LICENSE-2.0.html // var radarModeInterface = {}; var logEnabled = true; function printd(str) { - if (logEnabled) + if (logEnabled) { print("[radar.js] " + str); + } } var radar = false; @@ -31,8 +33,12 @@ var PINCH_INCREMENT_FIRST = 0.4; // 0.1 meters zoom in - out var PINCH_INCREMENT = 0.4; // 0.1 meters zoom in - out var RADAR_HEIGHT_MAX_PLUS_AVATAR = 40; var RADAR_HEIGHT_MIN_PLUS_AVATAR = 2; -var RADAR_CAMERA_DISTANCE_TO_ICONS = 0.5; // Icons are near the camera to prevent the LOD manager dismissing them -var RADAR_ICONS_APPARENT_DISTANCE_TO_AVATAR_BASE = 1; // How much above the avatar base should the icon appear +var RADAR_CAMERA_DISTANCE_TO_ICONS = 0.5; // Icons are near the camera to + // prevent the LOD manager + // dismissing them +var RADAR_ICONS_APPARENT_DISTANCE_TO_AVATAR_BASE = 1; // How much above the + // avatar base should + // the icon appear var AVATAR_DISPLAY_NAME_HEIGHT = 38; var AVATAR_DISPLAY_NAME_CHAR_WIDTH = 18; var lastDragAt; @@ -43,43 +49,70 @@ var uniqueColor; function moveTo(position) { if (radar) { MyAvatar.position = position; - Camera.position = Vec3.sum(MyAvatar.position, {x:0, y: radarHeight, z: 0}); + Camera.position = Vec3.sum(MyAvatar.position, { + x : 0, + y : radarHeight, + z : 0 + }); } } function keyPressEvent(event) { if (radar) { - switch(event.text) { - case "UP": - moveTo(Vec3.sum(MyAvatar.position, {x:0.0, y: 0, z: -1 * MOVE_BY})); - break; - case "DOWN": - moveTo(Vec3.sum(MyAvatar.position, {x:0, y: 0, z: MOVE_BY})); - break; - case "LEFT": - moveTo(Vec3.sum(MyAvatar.position, {x:-1 * MOVE_BY, y: 0, z: 0})); - break; - case "RIGHT": - moveTo(Vec3.sum(MyAvatar.position, {x:MOVE_BY, y: 0, z: 0})); - break; + switch (event.text) { + case "UP": + moveTo(Vec3.sum(MyAvatar.position, { + x : 0.0, + y : 0, + z : -1 * MOVE_BY + })); + break; + case "DOWN": + moveTo(Vec3.sum(MyAvatar.position, { + x : 0, + y : 0, + z : MOVE_BY + })); + break; + case "LEFT": + moveTo(Vec3.sum(MyAvatar.position, { + x : -1 * MOVE_BY, + y : 0, + z : 0 + })); + break; + case "RIGHT": + moveTo(Vec3.sum(MyAvatar.position, { + x : MOVE_BY, + y : 0, + z : 0 + })); + break; } } } function actionOnObjectFromEvent(event) { - var rayIntersection = findRayIntersection(Camera.computePickRay(event.x, event.y)); - if (rayIntersection && rayIntersection.intersects && rayIntersection.overlayID) { + var rayIntersection = findRayIntersection(Camera.computePickRay(event.x, + event.y)); + if (rayIntersection && rayIntersection.intersects + && rayIntersection.overlayID) { printd("found overlayID touched " + rayIntersection.overlayID); if (entitiesByOverlayID[rayIntersection.overlayID]) { - var entity = Entities.getEntityProperties(entitiesByOverlayID[rayIntersection.overlayID], ["sourceUrl"]); + var entity = Entities.getEntityProperties( + entitiesByOverlayID[rayIntersection.overlayID], + [ "sourceUrl" ]); App.openUrl(entity.sourceUrl); return true; } } - if (rayIntersection && rayIntersection.intersects && rayIntersection.entityID && rayIntersection.properties) { - printd("found " + rayIntersection.entityID + " of type " + rayIntersection.properties.type) ; + if (rayIntersection && rayIntersection.intersects + && rayIntersection.entityID && rayIntersection.properties) { + printd("found " + rayIntersection.entityID + " of type " + + rayIntersection.properties.type); if (rayIntersection.properties.type == "Web") { - printd("found web element to " + rayIntersection.properties.sourceUrl); + printd("found web element to " + + rayIntersection.properties.sourceUrl); App.openUrl(rayIntersection.properties.sourceUrl); return true; } @@ -102,7 +135,9 @@ function mousePressOrTouchEnd(event) { return; } if (radar) { - if (actionOnObjectFromEvent(event)) return; + if (actionOnObjectFromEvent(event)) { + return; + } } } @@ -116,38 +151,44 @@ function toggleRadarMode() { function fakeDoubleTap(event) { // CLD - temporarily disable toggling mode through double tap - // * As we have a new UI for toggling between modes, it may be discarded completely in the future. + // * As we have a new UI for toggling between modes, it may be discarded + // completely in the future. // toggleRadarMode(); teleporter.dragTeleportUpdate(event); teleporter.dragTeleportRelease(event); } -var currentTouchIsValid = false; // Currently used to know if touch hasn't started on a UI overlay +var currentTouchIsValid = false; // Currently used to know if touch hasn't + // started on a UI overlay var DOUBLE_TAP_TIME = 300; var fakeDoubleTapStart = Date.now(); var touchEndCount = 0; -/* Counts touchEnds and if there were 2 in the DOUBLE_TAP_TIME lapse, it triggers a fakeDoubleTap and returns true. - Otherwise, returns false (no double tap yet) */ +/* + * Counts touchEnds and if there were 2 in the DOUBLE_TAP_TIME lapse, it + * triggers a fakeDoubleTap and returns true. Otherwise, returns false (no + * double tap yet) + */ function analyzeDoubleTap(event) { var fakeDoubleTapEnd = Date.now(); var elapsed = fakeDoubleTapEnd - fakeDoubleTapStart; if (elapsed > DOUBLE_TAP_TIME) { touchEndCount = 0; } - + // if this is our first "up" then record time so we can // later determine if second "up" is a double tap if (touchEndCount == 0) { fakeDoubleTapStart = Date.now(); } touchEndCount++; - + if (touchEndCount >= 2) { var fakeDoubleTapEnd = Date.now(); var elapsed = fakeDoubleTapEnd - fakeDoubleTapStart; - printd("-- fakeDoubleTapEnd:" + fakeDoubleTapEnd + "-- elapsed:" + elapsed) + printd("-- fakeDoubleTapEnd:" + fakeDoubleTapEnd + "-- elapsed:" + + elapsed) if (elapsed <= DOUBLE_TAP_TIME) { touchEndCount = 0; fakeDoubleTap(event); @@ -164,13 +205,15 @@ function touchEnd(event) { // Clean up touch variables lastDragAt = null; lastDeltaDrag = null; - touchStartingCoordinates = null; // maybe in special cases it should be setup later? + touchStartingCoordinates = null; // maybe in special cases it should be + // setup later? startedDraggingCamera = false; prevTouchPinchRadius = null; draggingCamera = false; if (movingCamera) { - // if camera was indeed moving, we should not further process, it was just dragging + // if camera was indeed moving, we should not further process, it was + // just dragging movingCamera = false; dragModeFunc = null; return; @@ -185,14 +228,27 @@ function touchEnd(event) { dragModeFunc = null; // if pinching or moving is still detected, cancel - if (event.isPinching) { printd("touchEnd fail because isPinching");return;} - if (event.isPinchOpening) { printd("touchEnd fail because isPinchingOpening");return;} - if (event.isMoved) { printd("touchEnd fail because isMoved");return;} + if (event.isPinching) { + printd("touchEnd fail because isPinching"); + return; + } + if (event.isPinchOpening) { + printd("touchEnd fail because isPinchingOpening"); + return; + } + if (event.isMoved) { + printd("touchEnd fail because isMoved"); + return; + } // if touch is invalid, cancel - if (!currentTouchIsValid) { printd("touchEnd fail because !currentTouchIsValid");return;} + if (!currentTouchIsValid) { + printd("touchEnd fail because !currentTouchIsValid"); + return; + } - if (analyzeDoubleTap(event)) return; // double tap detected, finish + if (analyzeDoubleTap(event)) + return; // double tap detected, finish if (radar) { mousePressOrTouchEnd(event); @@ -200,76 +256,79 @@ function touchEnd(event) { } /** -* Polyfill for sign(x) -*/ + * Polyfill for sign(x) + */ if (!Math.sign) { - Math.sign = function(x) { - // If x is NaN, the result is NaN. - // If x is -0, the result is -0. - // If x is +0, the result is +0. - // If x is negative and not -0, the result is -1. - // If x is positive and not +0, the result is +1. - x = +x; // convert to a number - if (x === 0 || isNaN(x)) { - return Number(x); - } - return x > 0 ? 1 : -1; - }; + Math.sign = function(x) { + // If x is NaN, the result is NaN. + // If x is -0, the result is -0. + // If x is +0, the result is +0. + // If x is negative and not -0, the result is -1. + // If x is positive and not +0, the result is +1. + x = +x; // convert to a number + if (x === 0 || isNaN(x)) { + return Number(x); + } + return x > 0 ? 1 : -1; + }; } -/******************************************************************************************************** +/******************************************************************************* * Line and Plane intersection methods - ********************************************************************************************************/ + ******************************************************************************/ /** -* findLinePlaneIntersection -* Given points p {x: y: z:} and q that define a line, and the plane -* of formula ax+by+cz+d = 0, returns the intersection point or null if none. -*/ + * findLinePlaneIntersection Given points p {x: y: z:} and q that define a line, + * and the plane of formula ax+by+cz+d = 0, returns the intersection point or + * null if none. + */ function findLinePlaneIntersection(p, q, a, b, c, d) { - return findLinePlaneIntersectionCoords(p.x, p.y, p.z, q.x, q.y, q.z, a, b, c, d); + return findLinePlaneIntersectionCoords(p.x, p.y, p.z, q.x, q.y, q.z, a, b, + c, d); } /** -* findLineToHeightIntersection -* Given points p {x: y: z:} and q that define a line, and a planeY -* value that defines a plane paralel to 'the floor' xz plane, -* returns the intersection to that plane or null if none. -*/ + * findLineToHeightIntersection Given points p {x: y: z:} and q that define a + * line, and a planeY value that defines a plane paralel to 'the floor' xz + * plane, returns the intersection to that plane or null if none. + */ function findLineToHeightIntersection(p, q, planeY) { return findLinePlaneIntersection(p, q, 0, 1, 0, -planeY); } /** -* findLinePlaneIntersectionCoords (to avoid requiring unnecessary instantiation) -* Given points p with px py pz and q that define a line, and the plane -* of formula ax+by+cz+d = 0, returns the intersection point or null if none. -*/ + * findLinePlaneIntersectionCoords (to avoid requiring unnecessary + * instantiation) Given points p with px py pz and q that define a line, and the + * plane of formula ax+by+cz+d = 0, returns the intersection point or null if + * none. + */ function findLinePlaneIntersectionCoords(px, py, pz, qx, qy, qz, a, b, c, d) { - var tDenom = a*(qx-px) + b*(qy-py) + c*(qz-pz); - if (tDenom == 0) return null; + var tDenom = a * (qx - px) + b * (qy - py) + c * (qz - pz); + if (tDenom == 0) + return null; - var t = - ( a*px + b*py + c*pz + d ) / tDenom; + var t = -(a * px + b * py + c * pz + d) / tDenom; return { - x: (px+t*(qx-px)), - y: (py+t*(qy-py)), - z: (pz+t*(qz-pz)) + x : (px + t * (qx - px)), + y : (py + t * (qy - py)), + z : (pz + t * (qz - pz)) }; } /** -* findLineToHeightIntersection -* Given points p with px py pz and q that define a line, and a planeY -* value that defines a plane paralel to 'the floor' xz plane, -* returns the intersection to that plane or null if none. -*/ + * findLineToHeightIntersection Given points p with px py pz and q that define a + * line, and a planeY value that defines a plane paralel to 'the floor' xz + * plane, returns the intersection to that plane or null if none. + */ function findLineToHeightIntersectionCoords(px, py, pz, qx, qy, qz, planeY) { - return findLinePlaneIntersectionCoords(px, py, pz, qx, qy, qz, 0, 1, 0, -planeY); + return findLinePlaneIntersectionCoords(px, py, pz, qx, qy, qz, 0, 1, 0, + -planeY); } function findRayIntersection(pickRay) { - // Check 3D overlays and entities. Argument is an object with origin and direction. + // Check 3D overlays and entities. Argument is an object with origin and + // direction. var result = Overlays.findRayIntersection(pickRay); if (!result.intersects) { result = Entities.findRayIntersection(pickRay, true); @@ -278,33 +337,34 @@ function findRayIntersection(pickRay) { } /** - * Given a 2d point (x,y) this function returns the intersection (x, y, z) - * of the computedPickRay for that point with the plane y = py + * Given a 2d point (x,y) this function returns the intersection (x, y, z) of + * the computedPickRay for that point with the plane y = py */ -function computePointAtPlaneY(x,y,py) { +function computePointAtPlaneY(x, y, py) { var ray = Camera.computePickRay(x, y); - var p1=ray.origin; - var p2=Vec3.sum(p1, Vec3.multiply(ray.direction, 1)); - return findLineToHeightIntersectionCoords(p1.x, p1.y, p1.z, - p2.x, p2.y, p2.z, py); + var p1 = ray.origin; + var p2 = Vec3.sum(p1, Vec3.multiply(ray.direction, 1)); + return findLineToHeightIntersectionCoords(p1.x, p1.y, p1.z, p2.x, p2.y, + p2.z, py); } -/******************************************************************************************************** +/******************************************************************************* * - ********************************************************************************************************/ + ******************************************************************************/ function isTouchValid(coords) { // TODO: Extend to the detection of touches on new menu bars var radarModeTouchValid = radarModeInterface.isTouchValid(coords); - // getItemAtPoint does not exist anymore, look for another way to know if we are touching buttons + // getItemAtPoint does not exist anymore, look for another way to know if we + // are touching buttons // is it still needed? - return /*!tablet.getItemAtPoint(coords) && */radarModeTouchValid; + return /* !tablet.getItemAtPoint(coords) && */radarModeTouchValid; } -/******************************************************************************************************** +/******************************************************************************* * - ********************************************************************************************************/ + ******************************************************************************/ var touchStartingCoordinates = null; @@ -312,8 +372,11 @@ var KEEP_PRESSED_FOR_TELEPORT_MODE_TIME = 750; var touchBeginTime; function touchBegin(event) { - var coords = { x: event.x, y: event.y }; - if (!isTouchValid(coords) ) { + var coords = { + x : event.x, + y : event.y + }; + if (!isTouchValid(coords)) { printd("analyze touch - RADAR_TOUCH - INVALID"); currentTouchIsValid = false; touchStartingCoordinates = null; @@ -329,39 +392,49 @@ var startedDraggingCamera = false; // first time var draggingCamera = false; // is trying var movingCamera = false; // definitive -var MIN_DRAG_DISTANCE_TO_CONSIDER = 100; // distance by axis, not real distance +var MIN_DRAG_DISTANCE_TO_CONSIDER = 100; // distance by axis, not real + // distance var prevTouchPinchRadius = null; function pinchUpdate(event) { - if (!event.isMoved) return; - if (event.radius <= 0) return; + if (!event.isMoved) + return; + if (event.radius <= 0) + return; // pinch management var avatarY = MyAvatar.position.y; var pinchIncrement; if (!!prevTouchPinchRadius) { // no prev value - pinchIncrement = PINCH_INCREMENT * Math.abs(event.radius - prevTouchPinchRadius) * 0.1; + pinchIncrement = PINCH_INCREMENT + * Math.abs(event.radius - prevTouchPinchRadius) * 0.1; } else { pinchIncrement = PINCH_INCREMENT_FIRST; } if (event.isPinching) { - if (radarHeight + pinchIncrement > RADAR_HEIGHT_MAX_PLUS_AVATAR + avatarY) { + if (radarHeight + pinchIncrement > RADAR_HEIGHT_MAX_PLUS_AVATAR + + avatarY) { radarHeight = RADAR_HEIGHT_MAX_PLUS_AVATAR + avatarY; } else { radarHeight += pinchIncrement; } } else if (event.isPinchOpening) { - if (radarHeight - pinchIncrement < RADAR_HEIGHT_MIN_PLUS_AVATAR + avatarY) { + if (radarHeight - pinchIncrement < RADAR_HEIGHT_MIN_PLUS_AVATAR + + avatarY) { radarHeight = RADAR_HEIGHT_MIN_PLUS_AVATAR + avatarY; } else { radarHeight -= pinchIncrement; } } var deltaHeight = avatarY + radarHeight - Camera.position.y; - Camera.position = Vec3.sum(Camera.position, {x:0, y: deltaHeight, z: 0}); + Camera.position = Vec3.sum(Camera.position, { + x : 0, + y : deltaHeight, + z : 0 + }); if (!draggingCamera) { startedDraggingCamera = true; draggingCamera = true; @@ -371,22 +444,29 @@ function pinchUpdate(event) { } function isInsideSquare(coords0, coords1, halfside) { - return Math.abs(coords0.x-coords1.x) <= halfside && Math.abs(coords0.y-coords1.y) <= halfside; + return Math.abs(coords0.x - coords1.x) <= halfside + && Math.abs(coords0.y - coords1.y) <= halfside; } function dragScrollUpdate(event) { - if (!event.isMoved) return; + if (!event.isMoved) + return; // drag management var pickRay = Camera.computePickRay(event.x, event.y); - var dragAt = Vec3.sum(pickRay.origin, Vec3.multiply(pickRay.direction, radarHeight)); + var dragAt = Vec3.sum(pickRay.origin, Vec3.multiply(pickRay.direction, + radarHeight)); if (lastDragAt === undefined || lastDragAt === null) { lastDragAt = dragAt; return; } - var deltaDrag = {x: (lastDragAt.x - dragAt.x), y: 0, z: (lastDragAt.z-dragAt.z)}; + var deltaDrag = { + x : (lastDragAt.x - dragAt.x), + y : 0, + z : (lastDragAt.z - dragAt.z) + }; lastDragAt = dragAt; if (lastDeltaDrag === undefined || lastDeltaDrag === null) { @@ -399,77 +479,105 @@ function dragScrollUpdate(event) { draggingCamera = true; } else { if (!movingCamera) { - if (!isInsideSquare(touchStartingCoordinates, event, MIN_DRAG_DISTANCE_TO_CONSIDER)) { + if (!isInsideSquare(touchStartingCoordinates, event, + MIN_DRAG_DISTANCE_TO_CONSIDER)) { movingCamera = true; } } if (movingCamera) { - if (Math.sign(deltaDrag.x) == Math.sign(lastDeltaDrag.x) && Math.sign(deltaDrag.z) == Math.sign(lastDeltaDrag.z)) { - // Process movement if direction of the movement is the same than the previous frame + if (Math.sign(deltaDrag.x) == Math.sign(lastDeltaDrag.x) + && Math.sign(deltaDrag.z) == Math.sign(lastDeltaDrag.z)) { + // Process movement if direction of the movement is the same + // than the previous frame // process delta var moveCameraTo = Vec3.sum(Camera.position, deltaDrag); // move camera Camera.position = moveCameraTo; } else { - // Do not move camera if it's changing direction in this case, wait until the next direction confirmation.. + // Do not move camera if it's changing direction in this case, + // wait until the next direction confirmation.. } lastDeltaDrag = deltaDrag; // save last } } } -/******************************************************************************************************** +/******************************************************************************* * Teleport feature - ********************************************************************************************************/ + ******************************************************************************/ function Teleporter() { - var SURFACE_DETECTION_FOR_TELEPORT = true; // true if uses teleport.js similar logic to detect surfaces. false if uses plain teleport to avatar same height. + var SURFACE_DETECTION_FOR_TELEPORT = true; // true if uses teleport.js + // similar logic to detect + // surfaces. false if uses plain + // teleport to avatar same + // height. - var TELEPORT_TARGET_MODEL_URL = Script.resolvePath("../assets/models/teleport-destination.fbx"); - var TELEPORT_TOO_CLOSE_MODEL_URL = Script.resolvePath("../assets/models/teleport-cancel.fbx"); + var TELEPORT_TARGET_MODEL_URL = Script + .resolvePath("../assets/models/teleport-destination.fbx"); + var TELEPORT_TOO_CLOSE_MODEL_URL = Script + .resolvePath("../assets/models/teleport-cancel.fbx"); var TELEPORT_MODEL_DEFAULT_DIMENSIONS = { - x: 0.10, - y: 0.00001, - z: 0.10 + x : 0.10, + y : 0.00001, + z : 0.10 }; var teleportOverlay = Overlays.addOverlay("model", { - url: TELEPORT_TARGET_MODEL_URL, - dimensions: TELEPORT_MODEL_DEFAULT_DIMENSIONS, - orientation: Quat.fromPitchYawRollDegrees(0,180,0), - visible: false + url : TELEPORT_TARGET_MODEL_URL, + dimensions : TELEPORT_MODEL_DEFAULT_DIMENSIONS, + orientation : Quat.fromPitchYawRollDegrees(0, 180, 0), + visible : false }); var teleportCancelOverlay = Overlays.addOverlay("model", { - url: TELEPORT_TOO_CLOSE_MODEL_URL, - dimensions: TELEPORT_MODEL_DEFAULT_DIMENSIONS, - orientation: Quat.fromPitchYawRollDegrees(0,180,0), - visible: false + url : TELEPORT_TOO_CLOSE_MODEL_URL, + dimensions : TELEPORT_MODEL_DEFAULT_DIMENSIONS, + orientation : Quat.fromPitchYawRollDegrees(0, 180, 0), + visible : false }); - var TELEPORT_COLOR = { red: 0, green: 255, blue: 255}; - var TELEPORT_CANCEL_COLOR = { red: 255, green: 255, blue: 0}; + var TELEPORT_COLOR = { + red : 0, + green : 255, + blue : 255 + }; + var TELEPORT_CANCEL_COLOR = { + red : 255, + green : 255, + blue : 0 + }; var teleportLine = Overlays.addOverlay("line3d", { - start: { x: 0, y: 0, z:0 }, - end: { x: 0, y: 0, z: 0 }, - color: TELEPORT_COLOR, - alpha: 1, - lineWidth: 2, - dashed: false, - visible: false + start : { + x : 0, + y : 0, + z : 0 + }, + end : { + x : 0, + y : 0, + z : 0 + }, + color : TELEPORT_COLOR, + alpha : 1, + lineWidth : 2, + dashed : false, + visible : false }); // code from teleport.js var TELEPORT_TARGET = { - NONE: 'none', // Not currently targetting anything - INVISIBLE: 'invisible', // The current target is an invvsible surface - INVALID: 'invalid', // The current target is invalid (wall, ceiling, etc.) - SURFACE: 'surface', // The current target is a valid surface - SEAT: 'seat', // The current target is a seat + NONE : 'none', // Not currently targetting anything + INVISIBLE : 'invisible', // The current target is an invvsible + // surface + INVALID : 'invalid', // The current target is invalid (wall, ceiling, + // etc.) + SURFACE : 'surface', // The current target is a valid surface + SEAT : 'seat', // The current target is a seat } var TELEPORT_CANCEL_RANGE = 1; @@ -483,42 +591,84 @@ function Teleporter() { } } - /* - * Enhanced with intersection with terrain instead of using current avatar y position if SURFACE_DETECTION_FOR_TELEPORT is true - */ - function computeDestination(touchEventPos, avatarPosition, cameraPosition, radarH) { + /* + * Enhanced with intersection with terrain instead of using current avatar y + * position if SURFACE_DETECTION_FOR_TELEPORT is true + */ + function computeDestination(touchEventPos, avatarPosition, cameraPosition, + radarH) { if (SURFACE_DETECTION_FOR_TELEPORT) { - var pickRay = Camera.computePickRay(touchEventPos.x, touchEventPos.y); + var pickRay = Camera.computePickRay(touchEventPos.x, + touchEventPos.y); printd("newTeleportDetect - pickRay " + JSON.stringify(pickRay)); - var destination = Entities.findRayIntersection(pickRay, true, [], [], false, true); - printd("newTeleportDetect - destination " + JSON.stringify(destination)); + var destination = Entities.findRayIntersection(pickRay, true, [], + [], false, true); + printd("newTeleportDetect - destination " + + JSON.stringify(destination)); return destination; } else { - var pickRay = Camera.computePickRay(touchEventPos.x, touchEventPos.y); - var pointingAt = Vec3.sum(pickRay.origin, Vec3.multiply(pickRay.direction, radarH)); - var destination = { x: pointingAt.x, y: avatarPosition.y, z: pointingAt.z }; + var pickRay = Camera.computePickRay(touchEventPos.x, + touchEventPos.y); + var pointingAt = Vec3.sum(pickRay.origin, Vec3.multiply( + pickRay.direction, radarH)); + var destination = { + x : pointingAt.x, + y : avatarPosition.y, + z : pointingAt.z + }; return destination; } } function renderTeleportOverlays(destination) { - var overlayPosition = findLineToHeightIntersection(destination, Camera.position, Camera.position.y - RADAR_CAMERA_DISTANCE_TO_ICONS); - printd("[newTeleport] TELEPORT ! render overlay at " + JSON.stringify(overlayPosition)); + var overlayPosition = findLineToHeightIntersection(destination, + Camera.position, Camera.position.y + - RADAR_CAMERA_DISTANCE_TO_ICONS); + printd("[newTeleport] TELEPORT ! render overlay at " + + JSON.stringify(overlayPosition)); // CLD note Oct 11, 2017 - // Version of teleport.js 3c109f294f88ba7573bd1221f907f2605893c509 doesn't allow invisible surfaces, let's allow it for now - if (teleportTargetType == TELEPORT_TARGET.SURFACE || teleportTargetType == TELEPORT_TARGET.INVISIBLE) { - Overlays.editOverlay(teleportOverlay, { visible: true, position: overlayPosition }); - Overlays.editOverlay(teleportCancelOverlay, { visible: false }); - Overlays.editOverlay(teleportLine, { start: MyAvatar.position, end: destination, color: TELEPORT_COLOR, visible: true }); + // Version of teleport.js 3c109f294f88ba7573bd1221f907f2605893c509 + // doesn't allow invisible surfaces, let's allow it for now + if (teleportTargetType == TELEPORT_TARGET.SURFACE + || teleportTargetType == TELEPORT_TARGET.INVISIBLE) { + Overlays.editOverlay(teleportOverlay, { + visible : true, + position : overlayPosition + }); + Overlays.editOverlay(teleportCancelOverlay, { + visible : false + }); + Overlays.editOverlay(teleportLine, { + start : MyAvatar.position, + end : destination, + color : TELEPORT_COLOR, + visible : true + }); } else if (teleportTargetType == TELEPORT_TARGET.INVALID) { - Overlays.editOverlay(teleportOverlay, { visible: false}); - Overlays.editOverlay(teleportCancelOverlay, { visible: true, position: overlayPosition }); - Overlays.editOverlay(teleportLine, { start: MyAvatar.position, end: destination, color: TELEPORT_CANCEL_COLOR, visible: true }); + Overlays.editOverlay(teleportOverlay, { + visible : false + }); + Overlays.editOverlay(teleportCancelOverlay, { + visible : true, + position : overlayPosition + }); + Overlays.editOverlay(teleportLine, { + start : MyAvatar.position, + end : destination, + color : TELEPORT_CANCEL_COLOR, + visible : true + }); } else { // TELEPORT_TARGET:NONE? - Overlays.editOverlay(teleportOverlay, { visible: false }); - Overlays.editOverlay(teleportCancelOverlay, { visible: false }); - Overlays.editOverlay(teleportLine, { visible: false }); + Overlays.editOverlay(teleportOverlay, { + visible : false + }); + Overlays.editOverlay(teleportCancelOverlay, { + visible : false + }); + Overlays.editOverlay(teleportLine, { + visible : false + }); } } @@ -531,7 +681,7 @@ function Teleporter() { function moveOnBorders(event) { var xDelta = 0; var zDelta = 0; - + if (event.y <= border_top + BORDER_DISTANCE_PX) { zDelta = -0.1; } else if (event.y >= border_bottom - BORDER_DISTANCE_PX) { @@ -547,13 +697,19 @@ function Teleporter() { return; } - Camera.position = Vec3.sum(Camera.position, {x:xDelta, y: 0, z: zDelta}); + Camera.position = Vec3.sum(Camera.position, { + x : xDelta, + y : 0, + z : zDelta + }); draggingCamera = true; } - // When determininig whether you can teleport to a location, the normal of the + // When determininig whether you can teleport to a location, the normal of + // the // point that is being intersected with is looked at. If this normal is more - // than MAX_ANGLE_FROM_UP_TO_TELEPORT degrees from <0, 1, 0> (straight up), then + // than MAX_ANGLE_FROM_UP_TO_TELEPORT degrees from <0, 1, 0> (straight up), + // then // you can't teleport there. const MAX_ANGLE_FROM_UP_TO_TELEPORT = 70; function getTeleportTargetType(intersection) { @@ -561,7 +717,8 @@ function Teleporter() { if (!intersection.intersects) { return TELEPORT_TARGET.NONE; } - var props = Entities.getEntityProperties(intersection.entityID, ['userData', 'visible']); + var props = Entities.getEntityProperties(intersection.entityID, [ + 'userData', 'visible' ]); var data = parseJSON(props.userData); if (data !== undefined && data.seat !== undefined) { return TELEPORT_TARGET.SEAT; @@ -572,12 +729,14 @@ function Teleporter() { } var surfaceNormal = intersection.surfaceNormal; - var adj = Math.sqrt(surfaceNormal.x * surfaceNormal.x + surfaceNormal.z * surfaceNormal.z); + var adj = Math.sqrt(surfaceNormal.x * surfaceNormal.x + + surfaceNormal.z * surfaceNormal.z); var angleUp = Math.atan2(surfaceNormal.y, adj) * (180 / Math.PI); - if (angleUp < (90 - MAX_ANGLE_FROM_UP_TO_TELEPORT) || - angleUp > (90 + MAX_ANGLE_FROM_UP_TO_TELEPORT) || - Vec3.distance(MyAvatar.position, intersection.intersection) <= TELEPORT_CANCEL_RANGE) { + if (angleUp < (90 - MAX_ANGLE_FROM_UP_TO_TELEPORT) + || angleUp > (90 + MAX_ANGLE_FROM_UP_TO_TELEPORT) + || Vec3.distance(MyAvatar.position, + intersection.intersection) <= TELEPORT_CANCEL_RANGE) { return TELEPORT_TARGET.INVALID; } else { return TELEPORT_TARGET.SURFACE; @@ -586,17 +745,20 @@ function Teleporter() { var destination = intersection; if (Vec3.distance(MyAvatar.position, destination) <= TELEPORT_CANCEL_RANGE) { return TELEPORT_TARGET.INVALID; - } else { + } else { return TELEPORT_TARGET.SURFACE; } } - }; + } + ; function moveToFromEvent(event) { - var destination = computeDestination(event, MyAvatar.position, Camera.position, radarHeight); - moveTo(SURFACE_DETECTION_FOR_TELEPORT? - Vec3.sum(destination.intersection, {y: 1}) - :destination); + var destination = computeDestination(event, MyAvatar.position, + Camera.position, radarHeight); + moveTo(SURFACE_DETECTION_FOR_TELEPORT ? Vec3.sum( + destination.intersection, { + y : 1 + }) : destination); return true; } @@ -604,38 +766,56 @@ function Teleporter() { dragTeleportBegin : function(event) { printd("[newTeleport] TELEPORT began"); var overlayDimensions = entityIconModelDimensions(); - //var destination = computeDestination(event, MyAvatar.position, Camera.position, radarHeight); + // var destination = computeDestination(event, MyAvatar.position, + // Camera.position, radarHeight); // Dimension teleport and cancel overlays (not show them yet) - Overlays.editOverlay(teleportOverlay, { dimensions: overlayDimensions }); - Overlays.editOverlay(teleportCancelOverlay, { dimensions: overlayDimensions }); + Overlays.editOverlay(teleportOverlay, { + dimensions : overlayDimensions + }); + Overlays.editOverlay(teleportCancelOverlay, { + dimensions : overlayDimensions + }); // Position line - Overlays.editOverlay(teleportLine, { visible: true, start: 0, end: 0 }); + Overlays.editOverlay(teleportLine, { + visible : true, + start : 0, + end : 0 + }); }, dragTeleportUpdate : function(event) { // if in border, move camera moveOnBorders(event); - var destination = computeDestination(event, MyAvatar.position, Camera.position, radarHeight); + var destination = computeDestination(event, MyAvatar.position, + Camera.position, radarHeight); teleportTargetType = getTeleportTargetType(destination); - renderTeleportOverlays( SURFACE_DETECTION_FOR_TELEPORT? - destination.intersection: - destination); + renderTeleportOverlays(SURFACE_DETECTION_FOR_TELEPORT ? destination.intersection + : destination); }, - dragTeleportRelease : function (event) { - printd("[newTeleport] TELEPORT released at " + JSON.stringify(event)); + dragTeleportRelease : function(event) { + printd("[newTeleport] TELEPORT released at " + + JSON.stringify(event)); // CLD note Oct 11, 2017 - // Version of teleport.js 3c109f294f88ba7573bd1221f907f2605893c509 doesn't allow invisible surfaces, let's allow it for now - if (teleportTargetType == TELEPORT_TARGET.SURFACE || teleportTargetType == TELEPORT_TARGET.INVISIBLE) { + // Version of teleport.js 3c109f294f88ba7573bd1221f907f2605893c509 + // doesn't allow invisible surfaces, let's allow it for now + if (teleportTargetType == TELEPORT_TARGET.SURFACE + || teleportTargetType == TELEPORT_TARGET.INVISIBLE) { moveToFromEvent(event); } teleportTargetType = TELEPORT_TARGET.NONE; - Overlays.editOverlay(teleportOverlay, { visible: false }); - Overlays.editOverlay(teleportLine, { visible: false }); - Overlays.editOverlay(teleportCancelOverlay, { visible: false }); + Overlays.editOverlay(teleportOverlay, { + visible : false + }); + Overlays.editOverlay(teleportLine, { + visible : false + }); + Overlays.editOverlay(teleportCancelOverlay, { + visible : false + }); } }; @@ -643,9 +823,9 @@ function Teleporter() { var teleporter = Teleporter(); -/******************************************************************************************************** - * - ********************************************************************************************************/ +/******************************************************************************* + * + ******************************************************************************/ var dragModeFunc = null; // by default is nothing @@ -653,7 +833,8 @@ function oneFingerTouchUpdate(event) { if (dragModeFunc) { dragModeFunc(event); } else { - if (!isInsideSquare(touchStartingCoordinates, event, MIN_DRAG_DISTANCE_TO_CONSIDER)) { + if (!isInsideSquare(touchStartingCoordinates, event, + MIN_DRAG_DISTANCE_TO_CONSIDER)) { dragModeFunc = dragScrollUpdate; dragModeFunc(event); } else { @@ -680,25 +861,32 @@ function touchUpdate(event) { } } -/******************************************************************************************************** +/******************************************************************************* * Avatar cache structure for showing avatars markers - ********************************************************************************************************/ + ******************************************************************************/ // by QUuid var avatarsData = {}; -var avatarsIcons = []; // a parallel list of icons (overlays) to easily run through -var avatarsNames = []; // a parallel list of names (overlays) to easily run through +var avatarsIcons = []; // a parallel list of icons (overlays) to easily run + // through +var avatarsNames = []; // a parallel list of names (overlays) to easily run + // through function getAvatarIconForUser(uid) { var color = uniqueColor.getColor(uid); - if (color.charAt(0) == '#' ) { + if (color.charAt(0) == '#') { color = color.substring(1, color.length); } - // FIXME: this is a temporary solution until we can use circle3d with lineWidth - return Script.resolvePath("assets/images/circle-"+color+".svg"); + // FIXME: this is a temporary solution until we can use circle3d with + // lineWidth + return Script.resolvePath("assets/images/circle-" + color + ".svg"); } -var avatarIconDimensionsVal = { x: 0, y: 0, z: 0.00001}; +var avatarIconDimensionsVal = { + x : 0, + y : 0, + z : 0.00001 +}; function avatarIconPlaneDimensions() { // given the current height, give a size var xy = -0.003531 * radarHeight + 0.1; @@ -725,48 +913,74 @@ function currentOverlayNameForAvatar(QUuid) { } function saveAvatarData(QUuid) { - if (QUuid == null) return; + if (QUuid == null) + return; var avat = AvatarList.getAvatar(QUuid); printd("avatar added save avatar " + QUuid); - if (!avat) return; + if (!avat) + return; if (avatarsData[QUuid] != undefined) { avatarsData[QUuid].position = avat.position; } else { var avatarIcon = Overlays.addOverlay("image3d", { - subImage: { x: 0, y: 0, width: 150, height: 142}, - url: getAvatarIconForUser(QUuid), - dimensions: ICON_ENTITY_DEFAULT_DIMENSIONS, - visible: false, - ignoreRayIntersection: false, - orientation: Quat.fromPitchYawRollDegrees(-90,0,0) - }); + subImage : { + x : 0, + y : 0, + width : 150, + height : 142 + }, + url : getAvatarIconForUser(QUuid), + dimensions : ICON_ENTITY_DEFAULT_DIMENSIONS, + visible : false, + ignoreRayIntersection : false, + orientation : Quat.fromPitchYawRollDegrees(-90, 0, 0) + }); var needRefresh = !avat || !avat.displayName; - var displayName = avat && avat.displayName ? avat.displayName : "Unknown"; + var displayName = avat && avat.displayName ? avat.displayName + : "Unknown"; var textWidth = displayName.length * AVATAR_DISPLAY_NAME_CHAR_WIDTH; var avatarName = Overlays.addOverlay("text", { - width: textWidth, - height: AVATAR_DISPLAY_NAME_HEIGHT, - color: { red: 255, green: 255, blue: 255}, - backgroundAlpha: 0.0, - textRaiseColor: { red: 0, green: 0, blue: 0}, - font: {size: 68, bold: true}, - visible: false, - text: displayName, - textAlignCenter: true + width : textWidth, + height : AVATAR_DISPLAY_NAME_HEIGHT, + color : { + red : 255, + green : 255, + blue : 255 + }, + backgroundAlpha : 0.0, + textRaiseColor : { + red : 0, + green : 0, + blue : 0 + }, + font : { + size : 68, + bold : true + }, + visible : false, + text : displayName, + textAlignCenter : true }); avatarsIcons.push(avatarIcon); avatarsNames.push(avatarName); - avatarsData[QUuid] = { position: avat.position, icon: avatarIcon, name: avatarName, textWidth: textWidth, needRefresh: needRefresh }; + avatarsData[QUuid] = { + position : avat.position, + icon : avatarIcon, + name : avatarName, + textWidth : textWidth, + needRefresh : needRefresh + }; } } function removeAvatarData(QUuid) { - if (QUuid == null) return; + if (QUuid == null) + return; - var itsOverlay = currentOverlayIconForAvatar(QUuid); + var itsOverlay = currentOverlayIconForAvatar(QUuid); if (itsOverlay != null) { Overlays.deleteOverlay(itsOverlay); } @@ -793,9 +1007,9 @@ function saveAllOthersAvatarsData() { } } - function avatarAdded(QUuid) { - printd("avatar added " + QUuid);// + " at " + JSON.stringify(AvatarList.getAvatar(QUuid).position)); + printd("avatar added " + QUuid);// + " at " + + // JSON.stringify(AvatarList.getAvatar(QUuid).position)); saveAvatarData(QUuid); } @@ -804,93 +1018,122 @@ function avatarRemoved(QUuid) { removeAvatarData(QUuid); } -/******************************************************************************************************** +/******************************************************************************* * Avatar Icon/Markers rendering - ********************************************************************************************************/ + ******************************************************************************/ var myAvatarIcon; var myAvatarName; function renderMyAvatarIcon() { - var iconPos = findLineToHeightIntersectionCoords( MyAvatar.position.x, - MyAvatar.position.y + RADAR_ICONS_APPARENT_DISTANCE_TO_AVATAR_BASE, - MyAvatar.position.z, - Camera.position.x, Camera.position.y, Camera.position.z, - Camera.position.y - RADAR_CAMERA_DISTANCE_TO_ICONS); - if (!iconPos) { printd("avatarmy icon pos null"); return;} + var iconPos = findLineToHeightIntersectionCoords(MyAvatar.position.x, + MyAvatar.position.y + RADAR_ICONS_APPARENT_DISTANCE_TO_AVATAR_BASE, + MyAvatar.position.z, Camera.position.x, Camera.position.y, + Camera.position.z, Camera.position.y + - RADAR_CAMERA_DISTANCE_TO_ICONS); + if (!iconPos) { + printd("avatarmy icon pos null"); + return; + } var iconDimensions = avatarIconPlaneDimensions(); var avatarPos = MyAvatar.position; var cameraPos = Camera.position; var commonY = Camera.position.y - RADAR_CAMERA_DISTANCE_TO_ICONS; var borderPoints = [ - computePointAtPlaneY(0, 0, commonY), - computePointAtPlaneY(Window.innerWidth, Window.innerHeight, commonY) - ]; + computePointAtPlaneY(0, 0, commonY), + computePointAtPlaneY(Window.innerWidth, Window.innerHeight, commonY) ]; - var p1 = findLineToHeightIntersectionCoords(avatarPos.x, avatarPos.y, avatarPos.z, - cameraPos.x, cameraPos.y, cameraPos.z, - commonY); - var x = (p1.x - borderPoints[0].x) * (Window.innerWidth) / (borderPoints[1].x - borderPoints[0].x); - var y = (p1.z - borderPoints[0].z) * (Window.innerHeight) / (borderPoints[1].z - borderPoints[0].z); + var p1 = findLineToHeightIntersectionCoords(avatarPos.x, avatarPos.y, + avatarPos.z, cameraPos.x, cameraPos.y, cameraPos.z, commonY); + var x = (p1.x - borderPoints[0].x) * (Window.innerWidth) + / (borderPoints[1].x - borderPoints[0].x); + var y = (p1.z - borderPoints[0].z) * (Window.innerHeight) + / (borderPoints[1].z - borderPoints[0].z); if (!myAvatarIcon && MyAvatar.sessionUUID) { myAvatarIcon = Overlays.addOverlay("image3d", { - subImage: { x: 0, y: 0, width: 150, height: 142}, - url: getAvatarIconForUser(MyAvatar.sessionUUID), - dimensions: ICON_ENTITY_DEFAULT_DIMENSIONS, - visible: false, - ignoreRayIntersection: false, - orientation: Quat.fromPitchYawRollDegrees(-90,0,0) - }); + subImage : { + x : 0, + y : 0, + width : 150, + height : 142 + }, + url : getAvatarIconForUser(MyAvatar.sessionUUID), + dimensions : ICON_ENTITY_DEFAULT_DIMENSIONS, + visible : false, + ignoreRayIntersection : false, + orientation : Quat.fromPitchYawRollDegrees(-90, 0, 0) + }); } if (!myAvatarName) { myAvatarName = Overlays.addOverlay("text", { - width: 40, - height: AVATAR_DISPLAY_NAME_HEIGHT, - textAlignCenter: true, - color: { red: 255, green: 255, blue: 255}, - backgroundAlpha: 0.0, - font: {size: 68, bold: true}, - textRaiseColor: { red: 0, green: 0, blue: 0}, - visible: false, - text: "Me" - }); + width : 40, + height : AVATAR_DISPLAY_NAME_HEIGHT, + textAlignCenter : true, + color : { + red : 255, + green : 255, + blue : 255 + }, + backgroundAlpha : 0.0, + font : { + size : 68, + bold : true + }, + textRaiseColor : { + red : 0, + green : 0, + blue : 0 + }, + visible : false, + text : "Me" + }); } if (myAvatarIcon) { Overlays.editOverlay(myAvatarIcon, { - visible: true, - dimensions: iconDimensions, - position: iconPos + visible : true, + dimensions : iconDimensions, + position : iconPos }); } var textSize = (14 + (iconDimensions.y - 0.03) * 15 / 0.06); - - Overlays.editOverlay(myAvatarName, { - visible: true, - x: x - 18 + (iconDimensions.y - 0.03) * 2 / 0.06, - y: y + iconDimensions.y * 550, - font: {size: textSize, bold: true}, - }); + Overlays.editOverlay(myAvatarName, { + visible : true, + x : x - 18 + (iconDimensions.y - 0.03) * 2 / 0.06, + y : y + iconDimensions.y * 550, + font : { + size : textSize, + bold : true + }, + }); } function hideAllAvatarIcons() { var len = avatarsIcons.length; for (var i = 0; i < len; i++) { - Overlays.editOverlay(avatarsIcons[i], {visible: false}); + Overlays.editOverlay(avatarsIcons[i], { + visible : false + }); } len = avatarsNames.length; for (var j = 0; j < len; j++) { - Overlays.editOverlay(avatarsNames[j], {visible: false}); + Overlays.editOverlay(avatarsNames[j], { + visible : false + }); } if (myAvatarIcon) { - Overlays.editOverlay(myAvatarIcon, {visible: false}); + Overlays.editOverlay(myAvatarIcon, { + visible : false + }); } - Overlays.editOverlay(myAvatarName, {visible: false}) + Overlays.editOverlay(myAvatarName, { + visible : false + }) } function renderAllOthersAvatarIcons() { @@ -898,50 +1141,62 @@ function renderAllOthersAvatarIcons() { var iconDimensions = avatarIconPlaneDimensions(); var commonY = Camera.position.y - RADAR_CAMERA_DISTANCE_TO_ICONS; var borderPoints = [ - computePointAtPlaneY(0, 0, commonY), - computePointAtPlaneY(Window.innerWidth, Window.innerHeight, commonY) - ]; + computePointAtPlaneY(0, 0, commonY), + computePointAtPlaneY(Window.innerWidth, Window.innerHeight, commonY) ]; - for (var QUuid in avatarsData) { + for ( var QUuid in avatarsData) { if (avatarsData.hasOwnProperty(QUuid)) { if (AvatarList.getAvatar(QUuid) != null) { avatarPos = AvatarList.getAvatar(QUuid).position; - var cameraPos = Camera.position; - var p1 = findLineToHeightIntersectionCoords(avatarPos.x, avatarPos.y, avatarPos.z, - cameraPos.x, cameraPos.y, cameraPos.z, - commonY); + var cameraPos = Camera.position; + var p1 = findLineToHeightIntersectionCoords(avatarPos.x, + avatarPos.y, avatarPos.z, cameraPos.x, cameraPos.y, + cameraPos.z, commonY); - var x = (p1.x - borderPoints[0].x) * (Window.innerWidth) / (borderPoints[1].x - borderPoints[0].x); - var y = (p1.z - borderPoints[0].z) * (Window.innerHeight) / (borderPoints[1].z - borderPoints[0].z); + var x = (p1.x - borderPoints[0].x) * (Window.innerWidth) + / (borderPoints[1].x - borderPoints[0].x); + var y = (p1.z - borderPoints[0].z) * (Window.innerHeight) + / (borderPoints[1].z - borderPoints[0].z); if (avatarsData[QUuid].icon != undefined) { - var iconPos = findLineToHeightIntersectionCoords( avatarPos.x, avatarPos.y + RADAR_ICONS_APPARENT_DISTANCE_TO_AVATAR_BASE, avatarPos.z, - Camera.position.x, Camera.position.y, Camera.position.z, - Camera.position.y - RADAR_CAMERA_DISTANCE_TO_ICONS); - if (!iconPos) { print ("avatar icon pos bad for " + QUuid); continue; } + var iconPos = findLineToHeightIntersectionCoords( + avatarPos.x, + avatarPos.y + + RADAR_ICONS_APPARENT_DISTANCE_TO_AVATAR_BASE, + avatarPos.z, Camera.position.x, Camera.position.y, + Camera.position.z, Camera.position.y + - RADAR_CAMERA_DISTANCE_TO_ICONS); + if (!iconPos) { + print("avatar icon pos bad for " + QUuid); + continue; + } if (avatarsData[QUuid].needRefresh) { var avat = AvatarList.getAvatar(QUuid); if (avat && avat.displayName) { Overlays.editOverlay(avatarsData[QUuid].name, { - width: avat.displayName.length * AVATAR_DISPLAY_NAME_CHAR_WIDTH, - text: avat.displayName, - textAlignCenter: true + width : avat.displayName.length + * AVATAR_DISPLAY_NAME_CHAR_WIDTH, + text : avat.displayName, + textAlignCenter : true }); avatarsData[QUuid].needRefresh = false; } } var textSize = (14 + (iconDimensions.y - 0.03) * 15 / 0.06); Overlays.editOverlay(avatarsData[QUuid].icon, { - visible: true, - dimensions: iconDimensions, - position: iconPos + visible : true, + dimensions : iconDimensions, + position : iconPos }); Overlays.editOverlay(avatarsData[QUuid].name, { - visible: true, - x: x - avatarsData[QUuid].textWidth * 0.5, - y: y + iconDimensions.y * 550, - font: {size: textSize, bold: true} + visible : true, + x : x - avatarsData[QUuid].textWidth * 0.5, + y : y + iconDimensions.y * 550, + font : { + size : textSize, + bold : true + } }); } } @@ -950,41 +1205,49 @@ function renderAllOthersAvatarIcons() { } function entityAdded(entityID) { - printd ("Entity added " + entityID); - var props = Entities.getEntityProperties(entityID, ["type"]); - printd ("Entity added " + entityID + " PROPS " + JSON.stringify(props)); + printd("Entity added " + entityID); + var props = Entities.getEntityProperties(entityID, [ "type" ]); + printd("Entity added " + entityID + " PROPS " + JSON.stringify(props)); if (props && props.type == "Web") { - printd ("Entity Web added " + entityID); + printd("Entity Web added " + entityID); saveEntityData(entityID, true); } } function entityRemoved(entityID) { - printd ("Entity removed " + entityID); - var props = Entities.getEntityProperties(entityID, ["type"]); + printd("Entity removed " + entityID); + var props = Entities.getEntityProperties(entityID, [ "type" ]); if (props && props.type == "Web") { - print ("Entity Web removed " + entityID); + print("Entity Web removed " + entityID); removeEntityData(entityID); } } -/******************************************************************************************************** +/******************************************************************************* * Entities (to remark) cache structure for showing entities markers - ********************************************************************************************************/ + ******************************************************************************/ var entitiesData = {}; // by entityID var entitiesByOverlayID = {}; // by overlayID -var entitiesIcons = []; // a parallel list of icons (overlays) to easily run through +var entitiesIcons = []; // a parallel list of icons (overlays) to easily run + // through var ICON_ENTITY_WEB_MODEL_URL = Script.resolvePath("../assets/images/web.svg"); -var ICON_ENTITY_IMG_MODEL_URL = Script.resolvePath("../assets/models/teleport-cancel.fbx"); // FIXME - use correct model&texture +var ICON_ENTITY_IMG_MODEL_URL = Script + .resolvePath("../assets/models/teleport-cancel.fbx"); // FIXME - use + // correct + // model&texture var ICON_ENTITY_DEFAULT_DIMENSIONS = { - x: 0.10, - y: 0.00001, - z: 0.10 + x : 0.10, + y : 0.00001, + z : 0.10 }; -var entityIconModelDimensionsVal = { x: 0, y: 0.00001, z: 0}; +var entityIconModelDimensionsVal = { + x : 0, + y : 0.00001, + z : 0 +}; function entityIconModelDimensions() { // given the current height, give a size var xz = -0.002831 * radarHeight + 0.1; @@ -994,7 +1257,8 @@ function entityIconModelDimensions() { return entityIconModelDimensionsVal; } /* - * entityIconPlaneDimensions: similar to entityIconModelDimensions but using xy plane + * entityIconPlaneDimensions: similar to entityIconModelDimensions but using xy + * plane */ function entityIconPlaneDimensions() { var dim = entityIconModelDimensions(); @@ -1013,32 +1277,41 @@ function currentOverlayForEntity(QUuid) { } function saveEntityData(QUuid, planar) { - if (QUuid == null) return; - var entity = Entities.getEntityProperties(QUuid, ["position"]); + if (QUuid == null) + return; + var entity = Entities.getEntityProperties(QUuid, [ "position" ]); printd("entity added save entity " + QUuid); if (entitiesData[QUuid] != undefined) { entitiesData[QUuid].position = entity.position; } else { var entityIcon = Overlays.addOverlay("image3d", { - subImage: { x: 0, y: 0, width: 150, height: 150}, - url: ICON_ENTITY_WEB_MODEL_URL, - dimensions: ICON_ENTITY_DEFAULT_DIMENSIONS, - visible: false, - ignoreRayIntersection: false, - orientation: Quat.fromPitchYawRollDegrees(-90,0,0) - }); - + subImage : { + x : 0, + y : 0, + width : 150, + height : 150 + }, + url : ICON_ENTITY_WEB_MODEL_URL, + dimensions : ICON_ENTITY_DEFAULT_DIMENSIONS, + visible : false, + ignoreRayIntersection : false, + orientation : Quat.fromPitchYawRollDegrees(-90, 0, 0) + }); entitiesIcons.push(entityIcon); - entitiesData[QUuid] = { position: entity.position, icon: entityIcon}; + entitiesData[QUuid] = { + position : entity.position, + icon : entityIcon + }; entitiesByOverlayID[entityIcon] = QUuid; } } function removeEntityData(QUuid) { - if (QUuid == null) return; + if (QUuid == null) + return; - var itsOverlay = currentOverlayForEntity(QUuid); + var itsOverlay = currentOverlayForEntity(QUuid); if (itsOverlay != null) { Overlays.deleteOverlay(itsOverlay); delete entitiesByOverlayID[itsOverlay]; @@ -1049,14 +1322,16 @@ function removeEntityData(QUuid) { delete entitiesData[QUuid]; } -/******************************************************************************************************** +/******************************************************************************* * Entities to remark Icon/Markers rendering - ********************************************************************************************************/ + ******************************************************************************/ function hideAllEntitiesIcons() { var len = entitiesIcons.length; for (var i = 0; i < len; i++) { - Overlays.editOverlay(entitiesIcons[i], {visible: false}); + Overlays.editOverlay(entitiesIcons[i], { + visible : false + }); } } @@ -1064,22 +1339,32 @@ function renderAllEntitiesIcons() { var entityPos; var entityProps; var iconDimensions = entityIconModelDimensions(); - var planeDimensions = entityIconPlaneDimensions(); // plane overlays uses xy instead of xz - for (var QUuid in entitiesData) { + var planeDimensions = entityIconPlaneDimensions(); // plane overlays uses + // xy instead of xz + for ( var QUuid in entitiesData) { if (entitiesData.hasOwnProperty(QUuid)) { - entityProps = Entities.getEntityProperties(QUuid, ["position","visible"]); + entityProps = Entities.getEntityProperties(QUuid, [ "position", + "visible" ]); if (entityProps != null) { entityPos = entityProps.position; if (entitiesData[QUuid].icon != undefined && entityPos) { - var iconPos = findLineToHeightIntersectionCoords( entityPos.x, entityPos.y + RADAR_ICONS_APPARENT_DISTANCE_TO_AVATAR_BASE, entityPos.z, - Camera.position.x, Camera.position.y, Camera.position.z, - Camera.position.y - RADAR_CAMERA_DISTANCE_TO_ICONS); - if (!iconPos) { printd ("entity icon pos bad for " + QUuid); continue; } - var dimensions = entitiesData[QUuid].planar? planeDimensions : iconDimensions; + var iconPos = findLineToHeightIntersectionCoords( + entityPos.x, + entityPos.y + + RADAR_ICONS_APPARENT_DISTANCE_TO_AVATAR_BASE, + entityPos.z, Camera.position.x, Camera.position.y, + Camera.position.z, Camera.position.y + - RADAR_CAMERA_DISTANCE_TO_ICONS); + if (!iconPos) { + printd("entity icon pos bad for " + QUuid); + continue; + } + var dimensions = entitiesData[QUuid].planar ? planeDimensions + : iconDimensions; Overlays.editOverlay(entitiesData[QUuid].icon, { - visible: entityProps.visible, - dimensions: dimensions, - position: iconPos + visible : entityProps.visible, + dimensions : dimensions, + position : iconPos }); } } @@ -1087,17 +1372,21 @@ function renderAllEntitiesIcons() { } } -/******************************************************************************************************** +/******************************************************************************* * - ********************************************************************************************************/ + ******************************************************************************/ function startRadar() { printd("avatar added my avatar is " + MyAvatar.sessionUUID); saveAllOthersAvatarsData(); Camera.mode = "independent"; - Camera.position = Vec3.sum(MyAvatar.position, {x:0, y: radarHeight, z: 0}); - Camera.orientation = Quat.fromPitchYawRollDegrees(-90,0,0); + Camera.position = Vec3.sum(MyAvatar.position, { + x : 0, + y : radarHeight, + z : 0 + }); + Camera.orientation = Quat.fromPitchYawRollDegrees(-90, 0, 0); radar = true; connectRadarModeEvents(); @@ -1121,11 +1410,11 @@ function onMyViewModeClicked() { endRadar(); } -radarModeInterface.startRadarMode = function () { +radarModeInterface.startRadarMode = function() { startRadar(); }; -radarModeInterface.endRadarMode = function () { +radarModeInterface.endRadarMode = function() { endRadar(); }; @@ -1162,17 +1451,17 @@ function entitiesAnalysis() { for (var i = 0; i < ids.length; i++) { var id = ids[i]; var properties = Entities.getEntityProperties(id); - entities.push({ - id: id, - name: properties.name, - type: properties.type, - url: properties.type == "Model" ? properties.modelURL : "", - sourceUrl: properties.sourceUrl, - locked: properties.locked, - visible: properties.visible, - drawCalls: valueIfDefined(properties.renderInfo.drawCalls), - hasScript: properties.script !== "" - }); + entities.push({ + id : id, + name : properties.name, + type : properties.type, + url : properties.type == "Model" ? properties.modelURL : "", + sourceUrl : properties.sourceUrl, + locked : properties.locked, + visible : properties.visible, + drawCalls : valueIfDefined(properties.renderInfo.drawCalls), + hasScript : properties.script !== "" + }); } } @@ -1185,7 +1474,11 @@ function connectRadarModeEvents() { } function positionGoneTo() { - Camera.position = Vec3.sum(MyAvatar.position, {x:0, y: radarHeight, z: 0}); + Camera.position = Vec3.sum(MyAvatar.position, { + x : 0, + y : radarHeight, + z : 0 + }); } function disconnectRadarModeEvents() { @@ -1207,6 +1500,4 @@ function init() { Entities.addingEntity.connect(entityAdded); Entities.deletingEntity.connect(entityRemoved); -} - - +} diff --git a/tools/ktx-tool/src/main.cpp b/tools/ktx-tool/src/main.cpp index 1ef03ba80b..803b08c115 100644 --- a/tools/ktx-tool/src/main.cpp +++ b/tools/ktx-tool/src/main.cpp @@ -94,77 +94,6 @@ void processKtxFile(const QFileInfo& inputFileInfo) { auto outputStorage = outputKtx->getStorage(); storage::FileStorage::create(finalFilename, outputStorage->size(), outputStorage->data()); -#if 0 - const auto& header = inputKtx->getHeader(); - - - detexTexture **input_textures; - int nu_levels; - if (!detexLoadTextureFileWithMipmaps(inputFileName.toStdString().c_str(), 32, &input_textures, &nu_levels)) { - return; - //throw std::runtime_error(detexGetErrorMessage()); - } - - switch (header.glInternalFormat) { - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: - case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: - outputHeader.glFormat = GL_RGBA; - outputHeader.glInternalFormat = GL_RGBA8; - break; - - case GL_COMPRESSED_RED_GREEN_RGTC2_EXT: - outputHeader.glFormat = GL_RG; - outputHeader.glInternalFormat = GL_RG8; - qWarning() << "Unsupported"; - return; - break; - - case GL_COMPRESSED_RED_RGTC1_EXT: - outputHeader.glFormat = GL_RED; - outputHeader.glInternalFormat = GL_R8; - qWarning() << "Unsupported"; - return; - break; - - default: - qWarning() << "Unsupported"; - return; - } - - - auto outputKtx = ktx::KTX::createBare(outputHeader, ktx->_keyValues); - auto outputDescriptor = outputKtx->toDescriptor(); - auto outputStorage = outputKtx->getStorage(); - auto outputPointer = outputStorage->mutableData(); - auto outputSize = outputStorage->size(); - - glm::uvec2 dimensions{ header.pixelWidth, header.pixelHeight }; - for (uint16_t mip = 0; mip < header.numberOfMipmapLevels; ++mip) { - auto mipDimensions = evalMipDimension(mip, dimensions); - - for (uint8_t face = 0; face < header.numberOfFaces; ++face) { - auto faceSize = outputDescriptor.getMipFaceTexelsSize(mip, face); - auto faceOffset = outputDescriptor.getMipFaceTexelsOffset(mip, face); - assert(faceOffset + faceSize <= outputSize); - auto mipFace = ktx->getMipFaceTexelsData(mip, face); - auto outputMipFace = outputKtx->getMipFaceTexelsData(); - if (header.glInternalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT) { - BlockDecompressImageDXT5(mipDimensions.x, mipDimensions.y, mipFace->data(), (unsigned long*)(outputPointer + faceOffset)); - } else if (header.glInternalFormat == GL_COMPRESSED_SRGB_S3TC_DXT1_EXT) { - BlockDecompressImageDXT1(mipDimensions.x, mipDimensions.y, mipFace->data(), (unsigned long*)(outputPointer + faceOffset)); - } else { - qWarning() << "Unsupported"; - return; - } - } - } - - storage::FileStorage::create(outputFileName, outputStorage->size(), outputStorage->data()); -#endif - //if (gliTexture.empty()) { - // throw std::runtime_error("Unable to load texture using GLI"); - //} - //gli::texture2d gliTextureConverted = gli::convert(gliTexture, gli::FORMAT_RGBA8_UNORM_PACK8); } void scanDir(const QDir& dir) {