CR changes + eslint fixes

This commit is contained in:
David Back 2018-06-21 16:45:09 -07:00
parent ed56f09fcf
commit c019a4816f

View file

@ -13,11 +13,12 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
/* global SPACE_LOCAL, SelectionManager */
/* global SelectionManager, grid, rayPlaneIntersection, rayPlaneIntersection2, pushCommandForSelections,
getMainTabletIDs, getControllerWorldLocation */
SPACE_LOCAL = "local";
SPACE_WORLD = "world";
HIGHLIGHT_LIST_NAME = "editHandleHighlightList";
var SPACE_LOCAL = "local";
var SPACE_WORLD = "world";
var HIGHLIGHT_LIST_NAME = "editHandleHighlightList";
Script.include([
"./controllers.js",
@ -179,7 +180,7 @@ SelectionManager = (function() {
}
});
return duplicatedEntityIDs;
}
};
that._update = function(selectionUpdated) {
var properties = null;
@ -257,11 +258,12 @@ SelectionManager = (function() {
// Normalize degrees to be in the range (-180, 180)
function normalizeDegrees(degrees) {
degrees = ((degrees + 180) % 360) - 180;
if (degrees <= -180) {
degrees += 360;
var maxDegrees = 360;
var halfMaxDegrees = maxDegrees / 2;
degrees = ((degrees + halfMaxDegrees) % maxDegrees) - halfMaxDegrees;
if (degrees <= -halfMaxDegrees) {
degrees += maxDegrees;
}
return degrees;
}
@ -319,14 +321,14 @@ SelectionDisplay = (function() {
X: 0,
Y: 1,
Z: 2
}
};
var STRETCH_DIRECTION = {
X: 0,
Y: 1,
Z: 2,
ALL: 3
}
};
var SCALE_DIRECTION = {
LBN: 0,
@ -337,13 +339,13 @@ SelectionDisplay = (function() {
RTN: 5,
LTF: 6,
RTF: 7
}
};
var ROTATE_DIRECTION = {
PITCH: 0,
YAW: 1,
ROLL: 2
}
};
var spaceMode = SPACE_LOCAL;
var overlayNames = [];
@ -412,17 +414,17 @@ SelectionDisplay = (function() {
var handleRotatePitchRing = Overlays.addOverlay("circle3d", handlePropertiesRotateRings);
Overlays.editOverlay(handleRotatePitchRing, {
color: COLOR_RED,
majorTickMarksColor: COLOR_RED,
majorTickMarksColor: COLOR_RED
});
var handleRotateYawRing = Overlays.addOverlay("circle3d", handlePropertiesRotateRings);
Overlays.editOverlay(handleRotateYawRing, {
color: COLOR_GREEN,
majorTickMarksColor: COLOR_GREEN,
majorTickMarksColor: COLOR_GREEN
});
var handleRotateRollRing = Overlays.addOverlay("circle3d", handlePropertiesRotateRings);
Overlays.editOverlay(handleRotateRollRing, {
color: COLOR_BLUE,
majorTickMarksColor: COLOR_BLUE,
majorTickMarksColor: COLOR_BLUE
});
var handleRotateCurrentRing = Overlays.addOverlay("circle3d", {
@ -474,7 +476,7 @@ SelectionDisplay = (function() {
visible: false,
ignoreRayIntersection: true,
drawInFront: true
}
};
var handleStretchXPanel = Overlays.addOverlay("shape", handlePropertiesStretchPanel);
Overlays.editOverlay(handleStretchXPanel, { color: COLOR_RED });
var handleStretchYPanel = Overlays.addOverlay("shape", handlePropertiesStretchPanel);
@ -506,7 +508,7 @@ SelectionDisplay = (function() {
ignoreRayIntersection: true,
drawInFront: true,
lineWidth: 0.2
}
};
var handleScaleTREdge = Overlays.addOverlay("line3d", handlePropertiesScaleEdge);
var handleScaleTLEdge = Overlays.addOverlay("line3d", handlePropertiesScaleEdge);
var handleScaleTFEdge = Overlays.addOverlay("line3d", handlePropertiesScaleEdge);
@ -646,7 +648,7 @@ SelectionDisplay = (function() {
that.shutdown = function() {
that.restoreAvatarCollisionsFromStretch();
}
};
Script.scriptEnding.connect(that.shutdown);
// We get mouseMoveEvents from the handControllers, via handControllerPointer.
@ -773,11 +775,11 @@ SelectionDisplay = (function() {
};
that.resetPreviousHandleColor = function() {
if (previousHandle != null) {
if (previousHandle !== null) {
Overlays.editOverlay(previousHandle, { color: previousHandleColor });
previousHandle = null;
}
if (previousHandleHelper != null) {
if (previousHandleHelper !== null) {
Overlays.editOverlay(previousHandleHelper, { color: previousHandleColor });
previousHandleHelper = null;
}
@ -874,7 +876,7 @@ SelectionDisplay = (function() {
Overlays.editOverlay(result.overlayID, { color: COLOR_HOVER });
previousHandle = result.overlayID;
previousHandleHelper = that.getHandleHelper(result.overlayID);
if (previousHandleHelper != null) {
if (previousHandleHelper !== null) {
Overlays.editOverlay(previousHandleHelper, { color: COLOR_HOVER });
}
previousHandleColor = pickedColor;
@ -932,7 +934,7 @@ SelectionDisplay = (function() {
ctrlPressed = false;
that.updateActiveRotateRing();
}
}
};
// Triggers notification on specific key driven events
that.keyPressEvent = function(key) {
@ -940,7 +942,7 @@ SelectionDisplay = (function() {
ctrlPressed = true;
that.updateActiveRotateRing();
}
}
};
// NOTE: mousePressEvent and mouseMoveEvent from the main script should call us., so we don't hook these:
// Controller.mousePressEvent.connect(that.mousePressEvent);
@ -1007,8 +1009,6 @@ SelectionDisplay = (function() {
lastCameraOrientation = Camera.getOrientation();
if (event !== false) {
pickRay = generalComputePickRay(event.x, event.y);
var wantDebug = false;
if (wantDebug) {
print("select() with EVENT...... ");
@ -1034,7 +1034,8 @@ SelectionDisplay = (function() {
spaceMode = newSpaceMode;
that.updateHandles();
} else if (wantDebug) {
print("WARNING: entitySelectionTool.setSpaceMode - Can't update SpaceMode. CurrentMode: " + spaceMode + " DesiredMode: " + newSpaceMode);
print("WARNING: entitySelectionTool.setSpaceMode - Can't update SpaceMode. CurrentMode: " +
spaceMode + " DesiredMode: " + newSpaceMode);
}
if (wantDebug) {
print("====== SetSpaceMode called. <========");
@ -1084,7 +1085,8 @@ SelectionDisplay = (function() {
}
if (!handleTools.hasOwnProperty(toolHandle)) {
print("WARNING: entitySelectionTool.isActiveTool - Encountered unknown grabberToolHandle: " + toolHandle + ". Tools should be registered via addHandleTool.");
print("WARNING: entitySelectionTool.isActiveTool - Encountered unknown grabberToolHandle: " +
toolHandle + ". Tools should be registered via addHandleTool.");
// EARLY EXIT
return false;
}
@ -1114,13 +1116,14 @@ SelectionDisplay = (function() {
var rotationInverse = Quat.inverse(rotation);
var toCameraDistance = getDistanceToCamera(position);
var localRotationX = Quat.fromPitchYawRollDegrees(0, 0, -90);
var rotationDegrees = 90;
var localRotationX = Quat.fromPitchYawRollDegrees(0, 0, -rotationDegrees);
var rotationX = Quat.multiply(rotation, localRotationX);
worldRotationX = rotationX;
var localRotationY = Quat.fromPitchYawRollDegrees(0, 90, 0);
var localRotationY = Quat.fromPitchYawRollDegrees(0, rotationDegrees, 0);
var rotationY = Quat.multiply(rotation, localRotationY);
worldRotationY = rotationY;
var localRotationZ = Quat.fromPitchYawRollDegrees(90, 0, 0);
var localRotationZ = Quat.fromPitchYawRollDegrees(rotationDegrees, 0, 0);
var rotationZ = Quat.multiply(rotation, localRotationZ);
worldRotationZ = rotationZ;
@ -1360,7 +1363,7 @@ SelectionDisplay = (function() {
dimensions: stretchPanelYDimensions
});
var stretchPanelZDimensions = Vec3.subtract(scaleLTNCubePositionRotated, scaleRBFCubePositionRotated);
var tempX = Math.abs(stretchPanelZDimensions.x);
tempX = Math.abs(stretchPanelZDimensions.x);
stretchPanelZDimensions.x = Math.abs(stretchPanelZDimensions.y);
stretchPanelZDimensions.y = tempX;
stretchPanelZDimensions.z = STRETCH_PANEL_WIDTH;
@ -1458,7 +1461,7 @@ SelectionDisplay = (function() {
} else if (isActiveTool(handleRotateRollRing)) {
activeRotateRing = handleRotateRollRing;
}
if (activeRotateRing != null) {
if (activeRotateRing !== null) {
var tickMarksAngle = ctrlPressed ? ROTATE_CTRL_SNAP_ANGLE : ROTATE_DEFAULT_TICK_MARKS_ANGLE;
Overlays.editOverlay(activeRotateRing, { majorTickMarksAngle: tickMarksAngle });
}
@ -1640,7 +1643,7 @@ SelectionDisplay = (function() {
},
onMove: function(event) {
var wantDebug = false;
pickRay = generalComputePickRay(event.x, event.y);
var pickRay = generalComputePickRay(event.x, event.y);
var pick = rayPlaneIntersection2(pickRay, translateXZTool.pickPlanePosition, {
x: 0,
@ -1706,7 +1709,8 @@ SelectionDisplay = (function() {
}
constrainMajorOnly = event.isControl;
var cornerPosition = Vec3.sum(startPosition, Vec3.multiply(-0.5, SelectionManager.worldDimensions));
var negateAndHalve = -0.5;
var cornerPosition = Vec3.sum(startPosition, Vec3.multiply(negateAndHalve, SelectionManager.worldDimensions));
vector = Vec3.subtract(
grid.snapToGrid(Vec3.sum(cornerPosition, vector), constrainMajorOnly),
cornerPosition);
@ -1752,6 +1756,7 @@ SelectionDisplay = (function() {
var pickNormal = null;
var lastPick = null;
var projectionVector = null;
var previousPickRay = null;
addHandleTool(overlay, {
mode: mode,
onBegin: function(event, pickRay, pickResult) {
@ -1794,7 +1799,7 @@ SelectionDisplay = (function() {
pushCommandForSelections(duplicatedEntityIDs);
},
onMove: function(event) {
pickRay = generalComputePickRay(event.x, event.y);
var pickRay = generalComputePickRay(event.x, event.y);
// Use previousPickRay if new pickRay will cause resulting rayPlaneIntersection values to wrap around
if (usePreviousPickRay(pickRay.direction, previousPickRay.direction, pickNormal)) {
@ -1865,7 +1870,7 @@ SelectionDisplay = (function() {
Menu.setIsOptionChecked(AVATAR_COLLISIONS_OPTION, true);
handleStretchCollisionOverride = false;
}
}
};
// TOOL DEFINITION: HANDLE STRETCH TOOL
function makeStretchTool(stretchMode, directionEnum, directionVec, pivot, offset, stretchPanel, scaleHandle) {
@ -1892,7 +1897,6 @@ SelectionDisplay = (function() {
var lastPick3D = null;
var initialPosition = null;
var initialDimensions = null;
var initialIntersection = null;
var initialProperties = null;
var registrationPoint = null;
var deltaPivot = null;
@ -1933,7 +1937,7 @@ SelectionDisplay = (function() {
var scaledOffset = Vec3.multiply(0.5, offset);
// Offset from the registration point
offsetRP = Vec3.subtract(scaledOffset, centeredRP);
var offsetRP = Vec3.subtract(scaledOffset, centeredRP);
// Scaled offset in world coordinates
var scaledOffsetWorld = vec3Mult(initialDimensions, offsetRP);
@ -1944,56 +1948,9 @@ SelectionDisplay = (function() {
// pivot, offset and pickPlanePosition for 3D manipulation
var scaledPivot3D = Vec3.multiply(0.5, Vec3.multiply(1.0, directionFor3DStretch));
deltaPivot3D = Vec3.subtract(centeredRP, scaledPivot3D);
var scaledOffsetWorld3D = vec3Mult(initialDimensions,
Vec3.subtract(Vec3.multiply(0.5, Vec3.multiply(-1.0, directionFor3DStretch)), centeredRP));
pickRayPosition3D = Vec3.sum(initialPosition, Vec3.multiplyQbyV(rotation, scaledOffsetWorld));
}
var start = null;
var end = null;
if ((numDimensions === 1) && mask.x) {
start = Vec3.multiplyQbyV(rotation, {
x: -10000,
y: 0,
z: 0
});
start = Vec3.sum(start, properties.position);
end = Vec3.multiplyQbyV(rotation, {
x: 10000,
y: 0,
z: 0
});
end = Vec3.sum(end, properties.position);
}
if ((numDimensions === 1) && mask.y) {
start = Vec3.multiplyQbyV(rotation, {
x: 0,
y: -10000,
z: 0
});
start = Vec3.sum(start, properties.position);
end = Vec3.multiplyQbyV(rotation, {
x: 0,
y: 10000,
z: 0
});
end = Vec3.sum(end, properties.position);
}
if ((numDimensions === 1) && mask.z) {
start = Vec3.multiplyQbyV(rotation, {
x: 0,
y: 0,
z: -10000
});
start = Vec3.sum(start, properties.position);
end = Vec3.multiplyQbyV(rotation, {
x: 0,
y: 0,
z: 10000
});
end = Vec3.sum(end, properties.position);
}
if (numDimensions === 1) {
if (mask.x === 1) {
planeNormal = {
@ -2064,10 +2021,10 @@ SelectionDisplay = (function() {
SelectionManager.saveProperties();
that.resetPreviousHandleColor();
if (stretchPanel != null) {
if (stretchPanel !== null) {
Overlays.editOverlay(stretchPanel, { visible: true });
}
if (scaleHandle != null) {
if (scaleHandle !== null) {
Overlays.editOverlay(scaleHandle, { color: COLOR_SCALE_CUBE_SELECTED });
}
if (Menu.isOptionChecked(AVATAR_COLLISIONS_OPTION)) {
@ -2079,10 +2036,10 @@ SelectionDisplay = (function() {
};
var onEnd = function(event, reason) {
if (stretchPanel != null) {
if (stretchPanel !== null) {
Overlays.editOverlay(stretchPanel, { visible: false });
}
if (scaleHandle != null) {
if (scaleHandle !== null) {
Overlays.editOverlay(scaleHandle, { color: COLOR_SCALE_CUBE });
}
that.restoreAvatarCollisionsFromStretch();
@ -2092,14 +2049,12 @@ SelectionDisplay = (function() {
var onMove = function(event) {
var proportional = (spaceMode === SPACE_WORLD) || directionEnum === STRETCH_DIRECTION.ALL;
var position, dimensions, rotation;
var position, rotation;
if (spaceMode === SPACE_LOCAL) {
position = SelectionManager.localPosition;
dimensions = SelectionManager.localDimensions;
rotation = SelectionManager.localRotation;
} else {
position = SelectionManager.worldPosition;
dimensions = SelectionManager.worldDimensions;
rotation = SelectionManager.worldRotation;
}
@ -2115,6 +2070,7 @@ SelectionDisplay = (function() {
// Are we using handControllers or Mouse - only relevant for 3D tools
var controllerPose = getControllerWorldLocation(activeHand, true);
var vector = null;
var newPick = null;
if (HMD.isHMDAvailable() && HMD.isHandControllerAvailable() &&
controllerPose.valid && that.triggered && directionFor3DStretch) {
localDeltaPivot = deltaPivot3D;
@ -2166,15 +2122,15 @@ SelectionDisplay = (function() {
var minimumDimension = directionEnum === STRETCH_DIRECTION.ALL ? STRETCH_ALL_MINIMUM_DIMENSION :
STRETCH_MINIMUM_DIMENSION;
if (newDimensions.x <= minimumDimension) {
if (newDimensions.x < minimumDimension) {
newDimensions.x = minimumDimension;
changeInDimensions.x = minimumDimension - initialDimensions.x;
}
if (newDimensions.y <= minimumDimension) {
if (newDimensions.y < minimumDimension) {
newDimensions.y = minimumDimension;
changeInDimensions.y = minimumDimension - initialDimensions.y;
}
if (newDimensions.z <= minimumDimension) {
if (newDimensions.z < minimumDimension) {
newDimensions.z = minimumDimension;
changeInDimensions.z = minimumDimension - initialDimensions.z;
}
@ -2224,7 +2180,7 @@ SelectionDisplay = (function() {
stretchPanel = handleStretchYPanel;
directionVector = { x: 0, y: -1, z: 0 };
} else if (directionEnum === STRETCH_DIRECTION.Z) {
stretchPanel = handleStretchZPanel
stretchPanel = handleStretchZPanel;
directionVector = { x: 0, y: 0, z: -1 };
}
offset = Vec3.multiply(directionVector, NEGATE_VECTOR);
@ -2268,7 +2224,6 @@ SelectionDisplay = (function() {
// FUNCTION: UPDATE ROTATION DEGREES OVERLAY
function updateRotationDegreesOverlay(angleFromZero, position) {
var angle = angleFromZero * (Math.PI / 180);
var toCameraDistance = getDistanceToCamera(position);
var overlayProps = {
position: position,
@ -2459,9 +2414,10 @@ SelectionDisplay = (function() {
var startAtCurrent = 0;
var endAtCurrent = angleFromZero;
var maxDegrees = 360;
if (angleFromZero < 0) {
startAtCurrent = 360 + angleFromZero;
endAtCurrent = 360;
startAtCurrent = maxDegrees + angleFromZero;
endAtCurrent = maxDegrees;
}
Overlays.editOverlay(handleRotateCurrentRing, {
startAt: startAtCurrent,
@ -2473,8 +2429,9 @@ SelectionDisplay = (function() {
if (spaceMode === SPACE_LOCAL) {
Overlays.editOverlay(handleRotateCurrentRing, { rotation: worldRotationZ });
} else {
var rotationDegrees = 90;
Overlays.editOverlay(handleRotateCurrentRing, {
rotation: Quat.fromPitchYawRollDegrees(-90, 0, 0)
rotation: Quat.fromPitchYawRollDegrees(-rotationDegrees, 0, 0)
});
}
}