Use overlays instead of entities

This commit is contained in:
David Rowe 2017-07-27 13:47:35 +12:00
parent 8e4a2ff154
commit 136ea78873
3 changed files with 45 additions and 36 deletions

View file

@ -180,14 +180,10 @@ Laser = function (side) {
} else { } else {
// Special hovering of UI. // Special UI cursor.
intersection = Overlays.findRayIntersection(pickRay, PRECISION_PICKING, NO_INCLUDE_IDS, NO_EXCLUDE_IDS, intersection = Overlays.findRayIntersection(pickRay, PRECISION_PICKING, uiEntityIDs, NO_EXCLUDE_IDS,
VISIBLE_ONLY); // Check for overlay intersections in case they occlude the UI entities. VISIBLE_ONLY);
if (!intersection.intersects) { if (intersection.intersects) {
intersection = Entities.findRayIntersection(pickRay, PRECISION_PICKING, uiEntityIDs, NO_EXCLUDE_IDS,
VISIBLE_ONLY);
}
if (intersection.intersects && intersection.entityID) {
intersection.laserIntersected = true; intersection.laserIntersected = true;
laserLength = (specifiedLaserLength !== null) laserLength = (specifiedLaserLength !== null)
? specifiedLaserLength ? specifiedLaserLength

View file

@ -21,8 +21,9 @@ ToolMenu = function (side, setAppScaleWithHandlesCallback) {
SCALE_MODE_DIRECT_COLOR = { red: 240, green: 240, blue: 0 }, SCALE_MODE_DIRECT_COLOR = { red: 240, green: 240, blue: 0 },
SCALE_MODE_HANDLES_COLOR = { red: 0, green: 240, blue: 240 }, SCALE_MODE_HANDLES_COLOR = { red: 0, green: 240, blue: 240 },
panelEntity, originOverlay,
buttonEntity, panelOverlay,
buttonOverlay,
buttonHighlightOverlay, buttonHighlightOverlay,
LEFT_HAND = 0, LEFT_HAND = 0,
@ -39,35 +40,44 @@ ToolMenu = function (side, setAppScaleWithHandlesCallback) {
ZERO_ROTATION = Quat.fromVec3Radians(Vec3.ZERO), ZERO_ROTATION = Quat.fromVec3Radians(Vec3.ZERO),
PANEL_ENTITY_PROPERTIES = { ORIGIN_PROPERTIES = {
type: "Box", dimensions: { x: 0.005, y: 0.005, z: 0.005 },
dimensions: { x: 0.1, y: 0.2, z: 0.01 }, color: { red: 255, blue: 0, green: 0 },
color: { red: 192, green: 192, blue: 192 }, alpha: 1.0,
parentID: AVATAR_SELF_ID, parentID: AVATAR_SELF_ID,
registrationPoint: { x: 0, y: 0.0, z: 0.0 },
localRotation: ROOT_ROTATION, localRotation: ROOT_ROTATION,
ignoreRayIntersection: true,
visible: false
},
PANEL_PROPERTIES = {
dimensions: { x: 0.1, y: 0.2, z: 0.01 },
localPosition: { x: 0.05, y: 0.1, z: 0.005 },
localRotation: ZERO_ROTATION,
color: { red: 192, green: 192, blue: 192 },
alpha: 1.0,
solid: true,
ignoreRayIntersection: false, ignoreRayIntersection: false,
lifetime: 3600,
visible: true visible: true
}, },
BUTTON_ENTITY_PROPERTIES = { BUTTON_PROPERTIES = {
type: "Box",
dimensions: { x: 0.03, y: 0.03, z: 0.01 }, dimensions: { x: 0.03, y: 0.03, z: 0.01 },
registrationPoint: { x: 0, y: 0.0, z: 0.0 }, localPosition: { x: 0.02, y: 0.02, z: 0.0 },
localPosition: { x: 0.005, y: 0.005, z: -0.005 }, // Relative to the root panel entity. localRotation: ZERO_ROTATION,
color: scaleMode === SCALE_MODE_DIRECT ? SCALE_MODE_DIRECT_COLOR : SCALE_MODE_HANDLES_COLOR, color: scaleMode === SCALE_MODE_DIRECT ? SCALE_MODE_DIRECT_COLOR : SCALE_MODE_HANDLES_COLOR,
alpha: 1.0,
solid: true,
ignoreRayIntersection: false, ignoreRayIntersection: false,
lifetime: 3600,
visible: true visible: true
}, },
BUTTON_HIGHLIGHT_PROPERTIES = { BUTTON_HIGHLIGHT_PROPERTIES = {
dimensions: { x: 0.034, y: 0.034, z: 0.001 }, dimensions: { x: 0.034, y: 0.034, z: 0.001 },
localPosition: { x: 0, y: 0, z: -0.002 },
localRotation: ZERO_ROTATION,
color: { red: 240, green: 240, blue: 0 }, color: { red: 240, green: 240, blue: 0 },
alpha: 0.8, alpha: 0.8,
localPosition: { x: 0.0155, y: 0.0155, z: 0.003 },
localRotation: ZERO_ROTATION,
solid: false, solid: false,
drawInFront: true, drawInFront: true,
ignoreRayIntersection: true, ignoreRayIntersection: true,
@ -99,12 +109,12 @@ ToolMenu = function (side, setAppScaleWithHandlesCallback) {
} }
function getEntityIDs() { function getEntityIDs() {
return [panelEntity, buttonEntity]; return [panelOverlay, buttonOverlay];
} }
function update(intersectionEntityID) { function update(intersectionOverlayID) {
// Highlight button. // Highlight button.
if (intersectionEntityID === buttonEntity !== isHighlightingButton) { if (intersectionOverlayID === buttonOverlay !== isHighlightingButton) {
isHighlightingButton = !isHighlightingButton; isHighlightingButton = !isHighlightingButton;
Overlays.editOverlay(buttonHighlightOverlay, { visible: isHighlightingButton }); Overlays.editOverlay(buttonHighlightOverlay, { visible: isHighlightingButton });
} }
@ -115,7 +125,7 @@ ToolMenu = function (side, setAppScaleWithHandlesCallback) {
if (isButtonPressed) { if (isButtonPressed) {
scaleMode = scaleMode === SCALE_MODE_DIRECT ? SCALE_MODE_HANDLES : SCALE_MODE_DIRECT; scaleMode = scaleMode === SCALE_MODE_DIRECT ? SCALE_MODE_HANDLES : SCALE_MODE_DIRECT;
Entities.editEntity(buttonEntity, { Overlays.editOverlay(buttonOverlay, {
color: scaleMode === SCALE_MODE_DIRECT ? SCALE_MODE_DIRECT_COLOR : SCALE_MODE_HANDLES_COLOR color: scaleMode === SCALE_MODE_DIRECT ? SCALE_MODE_DIRECT_COLOR : SCALE_MODE_HANDLES_COLOR
}); });
setAppScaleWithHandlesCallback(scaleMode === SCALE_MODE_HANDLES); setAppScaleWithHandlesCallback(scaleMode === SCALE_MODE_HANDLES);
@ -147,16 +157,18 @@ ToolMenu = function (side, setAppScaleWithHandlesCallback) {
// Calculate position to put menu. // Calculate position to put menu.
forearmLength = Vec3.distance(MyAvatar.getJointPosition(forearmJointIndex), MyAvatar.getJointPosition(handJointIndex)); forearmLength = Vec3.distance(MyAvatar.getJointPosition(forearmJointIndex), MyAvatar.getJointPosition(handJointIndex));
rootOffset = { x: ROOT_X_OFFSET, y: forearmLength, z: ROOT_Z_OFFSET }; rootOffset = { x: ROOT_X_OFFSET, y: forearmLength, z: ROOT_Z_OFFSET };
PANEL_ENTITY_PROPERTIES.parentJointIndex = forearmJointIndex; ORIGIN_PROPERTIES.parentJointIndex = forearmJointIndex;
PANEL_ENTITY_PROPERTIES.localPosition = rootOffset; ORIGIN_PROPERTIES.localPosition = rootOffset;
originOverlay = Overlays.addOverlay("sphere", ORIGIN_PROPERTIES);
// Create menu items. // Create menu items.
panelEntity = Entities.addEntity(PANEL_ENTITY_PROPERTIES, true); PANEL_PROPERTIES.parentID = originOverlay;
BUTTON_ENTITY_PROPERTIES.parentID = panelEntity; panelOverlay = Overlays.addOverlay("cube", PANEL_PROPERTIES);
buttonEntity = Entities.addEntity(BUTTON_ENTITY_PROPERTIES, true); BUTTON_PROPERTIES.parentID = originOverlay;
buttonOverlay = Overlays.addOverlay("cube", BUTTON_PROPERTIES);
// Prepare highlight overlay. // Prepare highlight overlay.
BUTTON_HIGHLIGHT_PROPERTIES.parentID = buttonEntity; BUTTON_HIGHLIGHT_PROPERTIES.parentID = buttonOverlay;
buttonHighlightOverlay = Overlays.addOverlay("cube", BUTTON_HIGHLIGHT_PROPERTIES); buttonHighlightOverlay = Overlays.addOverlay("cube", BUTTON_HIGHLIGHT_PROPERTIES);
isDisplaying = true; isDisplaying = true;
@ -168,8 +180,9 @@ ToolMenu = function (side, setAppScaleWithHandlesCallback) {
return; return;
} }
Entities.deleteEntity(buttonEntity); Overlays.deleteOverlay(buttonHighlightOverlay);
Entities.deleteEntity(panelEntity); Overlays.deleteOverlay(buttonOverlay);
Overlays.deleteOverlay(panelOverlay);
isDisplaying = false; isDisplaying = false;
} }

View file

@ -201,7 +201,7 @@
function update() { function update() {
if (isDisplaying) { if (isDisplaying) {
intersection = getIntersection(); intersection = getIntersection();
toolMenu.update(intersection.entityID); toolMenu.update(intersection.overlayID);
} }
} }