From e11030bbc3ebb7229933bbdbf861652a79fbc6cd Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Wed, 1 Aug 2018 09:46:17 -0700 Subject: [PATCH 1/3] mukul's changes, enable parabolic teleport --- .../controllers/controllerModules/teleport.js | 78 ++++++------------- 1 file changed, 25 insertions(+), 53 deletions(-) diff --git a/scripts/system/controllers/controllerModules/teleport.js b/scripts/system/controllers/controllerModules/teleport.js index 4255eeb400..21acb9346b 100644 --- a/scripts/system/controllers/controllerModules/teleport.js +++ b/scripts/system/controllers/controllerModules/teleport.js @@ -22,7 +22,6 @@ Script.include("/~/system/libraries/controllers.js"); (function() { // BEGIN LOCAL_SCOPE var TARGET_MODEL_URL = Script.resolvePath("../../assets/models/teleport-destination.fbx"); - var TOO_CLOSE_MODEL_URL = Script.resolvePath("../../assets/models/teleport-cancel.fbx"); var SEAT_MODEL_URL = Script.resolvePath("../../assets/models/teleport-seat.fbx"); var TARGET_MODEL_DIMENSIONS = { @@ -49,8 +48,6 @@ Script.include("/~/system/libraries/controllers.js"); blue: 73 }; - var COOL_IN_DURATION = 300; - var handInfo = { right: { controllerInput: Controller.Standard.RightHand @@ -61,37 +58,19 @@ Script.include("/~/system/libraries/controllers.js"); }; var cancelPath = { - type: "line3d", color: COLORS_TELEPORT_CANCEL, - ignorePickIntersection: true, alpha: 1, - solid: true, - drawInFront: true, - glow: 1.0 + width: 0.025 }; var teleportPath = { - type: "line3d", color: COLORS_TELEPORT_CAN_TELEPORT, - ignorePickIntersection: true, alpha: 1, - solid: true, - drawInFront: true, - glow: 1.0 + width: 0.025 }; var seatPath = { - type: "line3d", color: COLORS_TELEPORT_SEAT, - ignorePickIntersection: true, alpha: 1, - solid: true, - drawInFront: true, - glow: 1.0 - }; - var cancelEnd = { - type: "model", - url: TOO_CLOSE_MODEL_URL, - dimensions: TARGET_MODEL_DIMENSIONS, - ignorePickIntersection: true + width: 0.025 }; var teleportEnd = { type: "model", @@ -107,20 +86,18 @@ Script.include("/~/system/libraries/controllers.js"); }; - var teleportRenderStates = [{name: "cancel", path: cancelPath, end: cancelEnd}, + var teleportRenderStates = [{name: "cancel", path: cancelPath}, {name: "teleport", path: teleportPath, end: teleportEnd}, {name: "seat", path: seatPath, end: seatEnd}]; - var DEFAULT_DISTANCE = 50; + var DEFAULT_DISTANCE = 8.0; var teleportDefaultRenderStates = [{name: "cancel", distance: DEFAULT_DISTANCE, path: cancelPath}]; - var coolInTimeout = null; var ignoredEntities = []; var TELEPORTER_STATES = { IDLE: 'idle', - COOL_IN: 'cool_in', TARGETTING: 'targetting', TARGETTING_INVALID: 'targetting_invalid' }; @@ -133,7 +110,7 @@ Script.include("/~/system/libraries/controllers.js"); SEAT: 'seat' // The current target is a seat }; - var speed = 7.0; + var speed = 12.0; var accelerationAxis = {x: 0.0, y: -5.0, z: 0.0}; function Teleporter(hand) { @@ -151,8 +128,10 @@ Script.include("/~/system/libraries/controllers.js"); return otherModule; }; - this.teleportParabolaHandVisible = Pointers.createPointer(PickType.Ray, { + this.teleportParabolaHandVisible = Pointers.createPointer(PickType.Parabola, { joint: (_this.hand === RIGHT_HAND) ? "_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND" : "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND", + dirOffset: { x: 0, y: 1, z: 0.1 }, + posOffset: { x: (_this.hand === RIGHT_HAND) ? 0.03 : -0.03, y: 0.2, z: 0.02 }, filter: Picks.PICK_ENTITIES, faceAvatar: true, scaleWithAvatar: true, @@ -161,10 +140,13 @@ Script.include("/~/system/libraries/controllers.js"); accelerationAxis: accelerationAxis, rotateAccelerationWithAvatar: true, renderStates: teleportRenderStates, - defaultRenderStates: teleportDefaultRenderStates + defaultRenderStates: teleportDefaultRenderStates, + maxDistance: 8.0 }); - this.teleportParabolaHandInvisible = Pointers.createPointer(PickType.Ray, { + this.teleportParabolaHandInvisible = Pointers.createPointer(PickType.Parabola, { joint: (_this.hand === RIGHT_HAND) ? "_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND" : "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND", + dirOffset: { x: 0, y: 1, z: 0.1 }, + posOffset: { x: (_this.hand === RIGHT_HAND) ? 0.03 : -0.03, y: 0.2, z: 0.02 }, filter: Picks.PICK_ENTITIES | Picks.PICK_INCLUDE_INVISIBLE, faceAvatar: true, scaleWithAvatar: true, @@ -172,9 +154,10 @@ Script.include("/~/system/libraries/controllers.js"); speed: speed, accelerationAxis: accelerationAxis, rotateAccelerationWithAvatar: true, - renderStates: teleportRenderStates + renderStates: teleportRenderStates, + maxDistance: 8.0 }); - this.teleportParabolaHeadVisible = Pointers.createPointer(PickType.Ray, { + this.teleportParabolaHeadVisible = Pointers.createPointer(PickType.Parabola, { joint: "Avatar", filter: Picks.PICK_ENTITIES, faceAvatar: true, @@ -184,9 +167,10 @@ Script.include("/~/system/libraries/controllers.js"); accelerationAxis: accelerationAxis, rotateAccelerationWithAvatar: true, renderStates: teleportRenderStates, - defaultRenderStates: teleportDefaultRenderStates + defaultRenderStates: teleportDefaultRenderStates, + maxDistance: 8.0 }); - this.teleportParabolaHeadInvisible = Pointers.createPointer(PickType.Ray, { + this.teleportParabolaHeadInvisible = Pointers.createPointer(PickType.Parabola, { joint: "Avatar", filter: Picks.PICK_ENTITIES | Picks.PICK_INCLUDE_INVISIBLE, faceAvatar: true, @@ -195,7 +179,8 @@ Script.include("/~/system/libraries/controllers.js"); speed: speed, accelerationAxis: accelerationAxis, rotateAccelerationWithAvatar: true, - renderStates: teleportRenderStates + renderStates: teleportRenderStates, + maxDistance: 8.0 }); this.cleanup = function() { @@ -216,16 +201,7 @@ Script.include("/~/system/libraries/controllers.js"); 100); this.enterTeleport = function() { - if (coolInTimeout !== null) { - Script.clearTimeout(coolInTimeout); - } - - this.state = TELEPORTER_STATES.COOL_IN; - coolInTimeout = Script.setTimeout(function() { - if (_this.state === TELEPORTER_STATES.COOL_IN) { - _this.state = TELEPORTER_STATES.TARGETTING; - } - }, COOL_IN_DURATION); + this.state = TELEPORTER_STATES.TARGETTING; }; this.isReady = function(controllerData, deltaTime) { @@ -287,11 +263,7 @@ Script.include("/~/system/libraries/controllers.js"); } else if (teleportLocationType === TARGET.INVALID || teleportLocationType === TARGET.INVISIBLE) { this.setTeleportState(mode, "", "cancel"); } else if (teleportLocationType === TARGET.SURFACE) { - if (this.state === TELEPORTER_STATES.COOL_IN) { - this.setTeleportState(mode, "cancel", ""); - } else { - this.setTeleportState(mode, "teleport", ""); - } + this.setTeleportState(mode, "teleport", ""); } else if (teleportLocationType === TARGET.SEAT) { this.setTeleportState(mode, "", "seat"); } @@ -304,7 +276,7 @@ Script.include("/~/system/libraries/controllers.js"); return makeRunningValues(true, [], []); } - if (target === TARGET.NONE || target === TARGET.INVALID || this.state === TELEPORTER_STATES.COOL_IN) { + if (target === TARGET.NONE || target === TARGET.INVALID) { // Do nothing } else if (target === TARGET.SEAT) { Entities.callEntityMethod(result.objectID, 'sit'); From a8c408abe82621431ba3af10f4b252fde39d283f Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Wed, 1 Aug 2018 10:59:21 -0700 Subject: [PATCH 2/3] correct render bounds for parabolas --- interface/src/raypick/ParabolaPointer.cpp | 38 +++++++++++++++++++---- interface/src/raypick/ParabolaPointer.h | 1 + 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/interface/src/raypick/ParabolaPointer.cpp b/interface/src/raypick/ParabolaPointer.cpp index 9371995a2a..fd6bdc7dbb 100644 --- a/interface/src/raypick/ParabolaPointer.cpp +++ b/interface/src/raypick/ParabolaPointer.cpp @@ -117,8 +117,6 @@ ParabolaPointer::RenderState::RenderState(const OverlayID& startID, const Overla _pathWidth = pathWidth; if (render::Item::isValidID(_pathID)) { auto renderItem = std::make_shared(pathColor, pathAlpha, pathWidth, isVisibleInSecondaryCamera, pathEnabled); - // TODO: update bounds properly - renderItem->editBound().setBox(glm::vec3(-16000.0f), 32000.0f); transaction.resetItem(_pathID, std::make_shared(renderItem)); scene->enqueueTransaction(transaction); } @@ -182,6 +180,7 @@ void ParabolaPointer::RenderState::update(const glm::vec3& origin, const glm::ve item.setAcceleration(acceleration); item.setParabolicDistance(parabolicDistance); item.setWidth(width); + item.updateBounds(); }); scene->enqueueTransaction(transaction); } @@ -304,10 +303,10 @@ void ParabolaPointer::RenderState::ParabolaRenderItem::setVisible(bool visible) } void ParabolaPointer::RenderState::ParabolaRenderItem::updateKey() { - // FIXME: There's no way to designate a render item as non-shadow-reciever, and since a parabola's bounding box covers the entire domain, - // it seems to block all shadows. I think this is a bug with shadows. - //auto builder = _parabolaData.color.a < 1.0f ? render::ItemKey::Builder::transparentShape() : render::ItemKey::Builder::opaqueShape(); - auto builder = render::ItemKey::Builder::transparentShape(); + auto builder = _parabolaData.color.a < 1.0f ? render::ItemKey::Builder::transparentShape() : render::ItemKey::Builder::opaqueShape(); + + // TODO: parabolas should cast shadows, but they're so thin that the cascaded shadow maps make them look pretty bad + //builder.withShadowCaster(); if (_enabled && _visible) { builder.withVisible(); @@ -324,6 +323,33 @@ void ParabolaPointer::RenderState::ParabolaRenderItem::updateKey() { _key = builder.build(); } +void ParabolaPointer::RenderState::ParabolaRenderItem::updateBounds() { + glm::vec3 max = _origin; + glm::vec3 min = _origin; + + glm::vec3 end = _origin + _parabolaData.velocity * _parabolaData.parabolicDistance + + 0.5f * _parabolaData.acceleration * _parabolaData.parabolicDistance * _parabolaData.parabolicDistance; + max = glm::max(max, end); + min = glm::min(min, end); + + for (int i = 0; i < 3; i++) { + if (fabsf(_parabolaData.velocity[i]) > EPSILON && fabsf(_parabolaData.acceleration[i]) > EPSILON) { + float maxT = -_parabolaData.velocity[i] / _parabolaData.acceleration[i]; + if (maxT > 0.0f && maxT < _parabolaData.parabolicDistance) { + glm::vec3 maxPoint = _origin + _parabolaData.velocity * maxT + 0.5f * _parabolaData.acceleration * maxT * maxT; + max = glm::max(max, maxPoint); + min = glm::min(min, maxPoint); + } + } + } + + glm::vec3 halfWidth = glm::vec3(0.5f * _parabolaData.width); + max += halfWidth; + min -= halfWidth; + + _bound = AABox(min, max - min); +} + const gpu::PipelinePointer ParabolaPointer::RenderState::ParabolaRenderItem::getParabolaPipeline() { if (!_parabolaPipeline || !_transparentParabolaPipeline) { auto vs = parabola_vert::getShader(); diff --git a/interface/src/raypick/ParabolaPointer.h b/interface/src/raypick/ParabolaPointer.h index ee4977e1e4..93f9a7b055 100644 --- a/interface/src/raypick/ParabolaPointer.h +++ b/interface/src/raypick/ParabolaPointer.h @@ -36,6 +36,7 @@ public: void setVisible(bool visible); void updateKey(); void updateUniformBuffer() { _uniformBuffer->setSubData(0, _parabolaData); } + void updateBounds(); void setColor(const glm::vec3& color) { _parabolaData.color = glm::vec4(color, _parabolaData.color.a); } void setAlpha(const float& alpha) { _parabolaData.color.a = alpha; } From e9d1423c615614c6659372543a1dae3d30b79f06 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Thu, 2 Aug 2018 09:58:29 -0700 Subject: [PATCH 3/3] jsdoc fixes --- interface/src/raypick/PointerScriptingInterface.cpp | 13 +++++++------ libraries/pointers/src/Pick.h | 2 ++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/interface/src/raypick/PointerScriptingInterface.cpp b/interface/src/raypick/PointerScriptingInterface.cpp index 5bb4293ef3..a9b9b6e9ea 100644 --- a/interface/src/raypick/PointerScriptingInterface.cpp +++ b/interface/src/raypick/PointerScriptingInterface.cpp @@ -92,7 +92,7 @@ unsigned int PointerScriptingInterface::createStylus(const QVariant& properties) * @typedef {object} Pointers.LaserPointerProperties * @property {boolean} [faceAvatar=false] If true, the end of the Pointer will always rotate to face the avatar. * @property {boolean} [centerEndY=true] If false, the end of the Pointer will be moved up by half of its height. - * @property {boolean} [lockEnd=false] If true, the end of the Pointer will lock on to the center of the object at which the laser is pointing. + * @property {boolean} [lockEnd=false] If true, the end of the Pointer will lock on to the center of the object at which the pointer is pointing. * @property {boolean} [distanceScaleEnd=false] If true, the dimensions of the end of the Pointer will scale linearly with distance. * @property {boolean} [scaleWithAvatar=false] If true, the width of the Pointer's path will scale linearly with your avatar's scale. * @property {boolean} [followNormal=false] If true, the end of the Pointer will rotate to follow the normal of the intersected surface. @@ -207,9 +207,10 @@ unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& prope * The rendering properties of the parabolic path * * @typedef {object} Pointers.ParabolaProperties -* @property {Color} color The color of the parabola. -* @property {number} alpha The alpha of the parabola. -* @property {number} width The width of the parabola, in meters. +* @property {Color} color=255,255,255 The color of the parabola. +* @property {number} alpha=1.0 The alpha of the parabola. +* @property {number} width=0.01 The width of the parabola, in meters. +* @property {boolean} isVisibleInSecondaryCamera=false The width of the parabola, in meters. */ /**jsdoc * A set of properties used to define the visual aspect of a Parabola Pointer in the case that the Pointer is not intersecting something. Same as a {@link Pointers.ParabolaPointerRenderState}, @@ -232,10 +233,10 @@ unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& prope */ /**jsdoc * A set of properties that can be passed to {@link Pointers.createPointer} to create a new Pointer. Contains the relevant {@link Picks.PickProperties} to define the underlying Pick. -* @typedef {object} Pointers.LaserPointerProperties +* @typedef {object} Pointers.ParabolaPointerProperties * @property {boolean} [faceAvatar=false] If true, the end of the Pointer will always rotate to face the avatar. * @property {boolean} [centerEndY=true] If false, the end of the Pointer will be moved up by half of its height. -* @property {boolean} [lockEnd=false] If true, the end of the Pointer will lock on to the center of the object at which the laser is pointing. +* @property {boolean} [lockEnd=false] If true, the end of the Pointer will lock on to the center of the object at which the pointer is pointing. * @property {boolean} [distanceScaleEnd=false] If true, the dimensions of the end of the Pointer will scale linearly with distance. * @property {boolean} [scaleWithAvatar=false] If true, the width of the Pointer's path will scale linearly with your avatar's scale. * @property {boolean} [followNormal=false] If true, the end of the Pointer will rotate to follow the normal of the intersected surface. diff --git a/libraries/pointers/src/Pick.h b/libraries/pointers/src/Pick.h index dd59b50cc4..790c5dfd27 100644 --- a/libraries/pointers/src/Pick.h +++ b/libraries/pointers/src/Pick.h @@ -145,6 +145,7 @@ public: * * @property {number} Ray Ray Picks intersect a ray with the nearest object in front of them, along a given direction. * @property {number} Stylus Stylus Picks provide "tapping" functionality on/into flat surfaces. + * @property {number} Parabola Parabola Picks intersect a parabola with the nearest object in front of them, with a given initial velocity and acceleration. */ /**jsdoc * @@ -154,6 +155,7 @@ public: * * * + * * *
{@link PickType(0)|PickType.Ray}
{@link PickType(0)|PickType.Stylus}
{@link PickType(0)|PickType.Parabola}
* @typedef {number} PickType