Fix newly created entity not being grabbed

This commit is contained in:
David Rowe 2017-08-09 09:26:33 +12:00
parent 046ce353fd
commit 22432671ca
3 changed files with 28 additions and 12 deletions

View file

@ -10,7 +10,7 @@
/* global CreatePalette */
CreatePalette = function (side, leftInputs, rightInputs) {
CreatePalette = function (side, leftInputs, rightInputs, uiCommandCallback) {
// Tool menu displayed on top of forearm.
"use strict";
@ -108,7 +108,8 @@ CreatePalette = function (side, leftInputs, rightInputs) {
}
function update(intersectionOverlayID) {
var CREATE_OFFSET = { x: 0, y: 0.05, z: -0.02 };
var entityID,
CREATE_OFFSET = { x: 0, y: 0.05, z: -0.02 };
// Highlight cube.
if (intersectionOverlayID === cubeOverlay !== isHighlightingCube) {
isHighlightingCube = !isHighlightingCube;
@ -126,7 +127,8 @@ CreatePalette = function (side, leftInputs, rightInputs) {
Vec3.multiplyQbyV(controlHand.orientation(),
Vec3.sum({ x: 0, y: CUBE_ENTITY_PROPERTIES.dimensions.z / 2, z: 0 }, CREATE_OFFSET)));
CUBE_ENTITY_PROPERTIES.rotation = controlHand.orientation();
Entities.addEntity(CUBE_ENTITY_PROPERTIES);
entityID = Entities.addEntity(CUBE_ENTITY_PROPERTIES);
uiCommandCallback("autoGrab");
} else {
Overlays.editOverlay(cubeOverlay, {
localPosition: CUBE_PROPERTIES.localPosition

View file

@ -10,7 +10,7 @@
/* global ToolMenu */
ToolMenu = function (side, leftInputs, rightInputs, doCallback) {
ToolMenu = function (side, leftInputs, rightInputs, uiCommandCallback) {
// Tool menu displayed on top of forearm.
"use strict";
@ -467,7 +467,7 @@ ToolMenu = function (side, leftInputs, rightInputs, doCallback) {
properties.solid = true;
}
if (optionsItems[i].setting.callback) {
doCallback(optionsItems[i].setting.callback.method, value);
uiCommandCallback(optionsItems[i].setting.callback.method, value);
}
}
}
@ -527,7 +527,7 @@ ToolMenu = function (side, leftInputs, rightInputs, doCallback) {
if (optionsSettings.currentColor) {
Settings.setValue(optionsSettings.currentColor.key, value);
}
doCallback("setColor", value);
uiCommandCallback("setColor", value);
} else {
// Swatch has no color; set swatch color to current fill color.
value = Overlays.getProperty(optionsOverlays[optionsOverlaysIDs.indexOf("currentColor")], "color");
@ -671,7 +671,7 @@ ToolMenu = function (side, leftInputs, rightInputs, doCallback) {
if (intersectionItems[intersectedItem].callback.parameter) {
parameterValue = evaluateParameter(intersectionItems[intersectedItem].callback.parameter);
}
doCallback(intersectionItems[intersectedItem].callback.method, parameterValue);
uiCommandCallback(intersectionItems[intersectedItem].callback.method, parameterValue);
}
}
}

View file

@ -179,7 +179,7 @@
};
UI = function (side, leftInputs, rightInputs, setToolCallback) {
UI = function (side, leftInputs, rightInputs, uiCommandCallback) {
// Tool menu and Create palette.
var // Primary objects.
@ -197,8 +197,8 @@
}
toolIcon = new ToolIcon(otherHand(side));
toolMenu = new ToolMenu(side, leftInputs, rightInputs, setToolCallback);
createPalette = new CreatePalette(side, leftInputs, rightInputs);
toolMenu = new ToolMenu(side, leftInputs, rightInputs, uiCommandCallback);
createPalette = new CreatePalette(side, leftInputs, rightInputs, uiCommandCallback);
getIntersection = side === LEFT_HAND ? rightInputs.intersection : leftInputs.intersection;
@ -331,6 +331,7 @@
isGripClicked = false,
wasGripClicked = false,
hoveredOverlayID = null,
isAutoGrab = false,
// Position values.
initialHandOrientationInverse,
@ -382,6 +383,11 @@
handles.hover(overlayID);
}
function enableAutoGrab() {
// Used to grab entity created from Create palette.
isAutoGrab = true;
}
function isHandle(overlayID) {
return handles.isHandle(overlayID);
}
@ -849,10 +855,12 @@
&& otherEditor.isHandle(intersection.overlayID)) {
highlightedEntityID = otherEditor.rootEntityID();
setState(EDITOR_HANDLE_SCALING);
} else if (intersection.entityID && intersection.editableEntity && (wasTriggerClicked || !isTriggerClicked)) {
} else if (intersection.entityID && intersection.editableEntity
&& (wasTriggerClicked || !isTriggerClicked) && !isAutoGrab) {
highlightedEntityID = Entities.rootOf(intersection.entityID);
setState(EDITOR_HIGHLIGHTING);
} else if (intersection.entityID && intersection.editableEntity && !wasTriggerClicked && isTriggerClicked) {
} else if (intersection.entityID && intersection.editableEntity
&& (!wasTriggerClicked || isAutoGrab) && isTriggerClicked) {
highlightedEntityID = Entities.rootOf(intersection.entityID);
if (otherEditor.isEditing(highlightedEntityID)) {
if (toolSelected !== TOOL_SCALE) {
@ -1067,6 +1075,7 @@
wasTriggerClicked = isTriggerClicked;
wasGripClicked = isGripClicked;
isAutoGrab = isAutoGrab && isTriggerClicked;
if (DEBUG && editorState !== previousState) {
debug(side, EDITOR_STATE_STRINGS[editorState]);
@ -1115,6 +1124,7 @@
return {
setReferences: setReferences,
hoverHandle: hoverHandle,
enableAutoGrab: enableAutoGrab,
isHandle: isHandle,
isEditing: isEditing,
isScaling: isScaling,
@ -1318,6 +1328,10 @@
ui.setToolColor(parameter);
colorToolColor = parameter;
break;
case "autoGrab":
editors[LEFT_HAND].enableAutoGrab();
editors[RIGHT_HAND].enableAutoGrab();
break;
default:
debug("ERROR: Unexpected command in onUICommand()!");
}