mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 13:09:52 +02:00
Add color swatch buttons and "current color" circle
This commit is contained in:
parent
ed497afdc3
commit
d0143c2c19
2 changed files with 152 additions and 11 deletions
|
@ -22,9 +22,15 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
|
|
||||||
menuOverlays = [],
|
menuOverlays = [],
|
||||||
menuCallbacks = [],
|
menuCallbacks = [],
|
||||||
|
|
||||||
optionsOverlays = [],
|
optionsOverlays = [],
|
||||||
|
optionsOverlaysIDs = [],
|
||||||
|
optionsCommands = [],
|
||||||
|
optionsCommandsParameters = [],
|
||||||
optionsCallbacks = [],
|
optionsCallbacks = [],
|
||||||
|
optionsCallbacksParameters = [],
|
||||||
optionsEnabled = [],
|
optionsEnabled = [],
|
||||||
|
|
||||||
highlightOverlay,
|
highlightOverlay,
|
||||||
|
|
||||||
LEFT_HAND = 0,
|
LEFT_HAND = 0,
|
||||||
|
@ -97,6 +103,19 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
drawInFront: true,
|
drawInFront: true,
|
||||||
visible: true
|
visible: true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"circle": {
|
||||||
|
overlay: "circle3d",
|
||||||
|
properties: {
|
||||||
|
size: 0.015,
|
||||||
|
localPosition: { x: 0.0, y: 0.0, z: -0.01 },
|
||||||
|
localRotation: Quat.fromVec3Degrees({ x: 0, y: 180, z: 180 }),
|
||||||
|
color: { red: 128, green: 128, blue: 128 },
|
||||||
|
alpha: 1.0,
|
||||||
|
solid: true,
|
||||||
|
ignoreRayIntersection: true,
|
||||||
|
visible: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -141,6 +160,66 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
properties: {
|
properties: {
|
||||||
localPosition: { x: 0.055, y: 0.0, z: -0.005 }
|
localPosition: { x: 0.055, y: 0.0, z: -0.005 }
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "colorSwatch1",
|
||||||
|
type: "button",
|
||||||
|
properties: {
|
||||||
|
dimensions: { x: 0.02, y: 0.02, z: 0.01 },
|
||||||
|
localPosition: { x: -0.035, y: 0.02, z: -0.005 },
|
||||||
|
color: { red: 255, green: 0, blue: 0 }
|
||||||
|
},
|
||||||
|
command: "setCurrentColor",
|
||||||
|
commandParameter: "colorSwatch1.color",
|
||||||
|
callback: "setColor",
|
||||||
|
callbackParameter: "colorSwatch1.color"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "colorSwatch2",
|
||||||
|
type: "button",
|
||||||
|
properties: {
|
||||||
|
dimensions: { x: 0.02, y: 0.02, z: 0.01 },
|
||||||
|
localPosition: { x: -0.01, y: 0.02, z: -0.005 },
|
||||||
|
color: { red: 0, green: 255, blue: 0 }
|
||||||
|
},
|
||||||
|
command: "setCurrentColor",
|
||||||
|
commandParameter: "colorSwatch2.color",
|
||||||
|
callback: "setColor",
|
||||||
|
callbackParameter: "colorSwatch2.color"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "colorSwatch3",
|
||||||
|
type: "button",
|
||||||
|
properties: {
|
||||||
|
dimensions: { x: 0.02, y: 0.02, z: 0.01 },
|
||||||
|
localPosition: { x: -0.035, y: 0.045, z: -0.005 },
|
||||||
|
color: { red: 0, green: 0, blue: 255 }
|
||||||
|
},
|
||||||
|
command: "setCurrentColor",
|
||||||
|
commandParameter: "colorSwatch3.color",
|
||||||
|
callback: "setColor",
|
||||||
|
callbackParameter: "colorSwatch3.color"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "colorSwatch4",
|
||||||
|
type: "button",
|
||||||
|
properties: {
|
||||||
|
dimensions: { x: 0.02, y: 0.02, z: 0.01 },
|
||||||
|
localPosition: { x: -0.01, y: 0.045, z: -0.005 },
|
||||||
|
color: { red: 255, green: 255, blue: 255 }
|
||||||
|
},
|
||||||
|
command: "setCurrentColor",
|
||||||
|
commandParameter: "colorSwatch4.color",
|
||||||
|
callback: "setColor",
|
||||||
|
callbackParameter: "colorSwatch4.color"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "currentColor",
|
||||||
|
type: "circle",
|
||||||
|
properties: {
|
||||||
|
localPosition: { x: 0.025, y: 0.0325, z: -0.007 },
|
||||||
|
color: { red: 128, green: 128, blue: 128 }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -231,8 +310,12 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
|
|
||||||
optionsItems,
|
optionsItems,
|
||||||
intersectionOverlays,
|
intersectionOverlays,
|
||||||
|
intersectionOverlaysIDs,
|
||||||
|
intersectionCommands,
|
||||||
|
intersectionCommandsParameters,
|
||||||
intersectionCallbacks,
|
intersectionCallbacks,
|
||||||
intersectionCallbacksEnabled,
|
intersectionCallbacksParameters,
|
||||||
|
intersectionEnabled,
|
||||||
intersectionProperties,
|
intersectionProperties,
|
||||||
highlightedItem,
|
highlightedItem,
|
||||||
highlightedSource,
|
highlightedSource,
|
||||||
|
@ -278,11 +361,15 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
// Close current panel, if any.
|
// Close current panel, if any.
|
||||||
for (i = 0, length = optionsOverlays.length; i < length; i += 1) {
|
for (i = 0, length = optionsOverlays.length; i < length; i += 1) {
|
||||||
Overlays.deleteOverlay(optionsOverlays[i]);
|
Overlays.deleteOverlay(optionsOverlays[i]);
|
||||||
optionsOverlays = [];
|
|
||||||
optionsCallbacks = [];
|
|
||||||
optionsEnabled = [];
|
|
||||||
optionsItems = null;
|
|
||||||
}
|
}
|
||||||
|
optionsOverlays = [];
|
||||||
|
optionsOverlaysIDs = [];
|
||||||
|
optionsCommands = [];
|
||||||
|
optionsCommandsParameters = [];
|
||||||
|
optionsCallbacks = [];
|
||||||
|
optionsCallbacksParameters = [];
|
||||||
|
optionsEnabled = [];
|
||||||
|
optionsItems = null;
|
||||||
|
|
||||||
// Open specified panel, if any.
|
// Open specified panel, if any.
|
||||||
if (toolOptions) {
|
if (toolOptions) {
|
||||||
|
@ -293,6 +380,7 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
properties = Object.merge(properties, optionsItems[i].properties);
|
properties = Object.merge(properties, optionsItems[i].properties);
|
||||||
properties.parentID = parentID;
|
properties.parentID = parentID;
|
||||||
optionsOverlays.push(Overlays.addOverlay(UI_ELEMENTS[optionsItems[i].type].overlay, properties));
|
optionsOverlays.push(Overlays.addOverlay(UI_ELEMENTS[optionsItems[i].type].overlay, properties));
|
||||||
|
optionsOverlaysIDs.push(optionsItems[i].id);
|
||||||
if (optionsItems[i].label) {
|
if (optionsItems[i].label) {
|
||||||
properties = Object.clone(UI_ELEMENTS.label.properties);
|
properties = Object.clone(UI_ELEMENTS.label.properties);
|
||||||
properties.text = optionsItems[i].label;
|
properties.text = optionsItems[i].label;
|
||||||
|
@ -300,7 +388,10 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
Overlays.addOverlay(UI_ELEMENTS.label.overlay, properties);
|
Overlays.addOverlay(UI_ELEMENTS.label.overlay, properties);
|
||||||
}
|
}
|
||||||
parentID = optionsOverlays[0]; // Menu buttons parent to menu panel.
|
parentID = optionsOverlays[0]; // Menu buttons parent to menu panel.
|
||||||
|
optionsCommands.push(optionsItems[i].command);
|
||||||
|
optionsCommandsParameters.push(optionsItems[i].commandParameter);
|
||||||
optionsCallbacks.push(optionsItems[i].callback);
|
optionsCallbacks.push(optionsItems[i].callback);
|
||||||
|
optionsCallbacksParameters.push(optionsItems[i].callbackParameter);
|
||||||
optionsEnabled.push(true);
|
optionsEnabled.push(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -316,10 +407,37 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
openOptions();
|
openOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function evaluateParameter(parameter) {
|
||||||
|
var parameters,
|
||||||
|
overlayID,
|
||||||
|
overlayProperty;
|
||||||
|
|
||||||
|
parameters = parameter.split(".");
|
||||||
|
overlayID = parameters[0];
|
||||||
|
overlayProperty = parameters[1];
|
||||||
|
|
||||||
|
return Overlays.getProperty(optionsOverlays[optionsOverlaysIDs.indexOf(overlayID)], overlayProperty);
|
||||||
|
}
|
||||||
|
|
||||||
|
function peformCommand(command, parameter) {
|
||||||
|
switch (command) {
|
||||||
|
case "setCurrentColor":
|
||||||
|
Overlays.editOverlay(optionsOverlays[optionsOverlaysIDs.indexOf("currentColor")], {
|
||||||
|
color: parameter
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// TODO: Log error.
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function update(intersectionOverlayID, groupsCount, entitiesCount) {
|
function update(intersectionOverlayID, groupsCount, entitiesCount) {
|
||||||
var intersectedItem,
|
var intersectedItem,
|
||||||
parentProperties,
|
parentProperties,
|
||||||
BUTTON_PRESS_DELTA = 0.004,
|
BUTTON_PRESS_DELTA = 0.004,
|
||||||
|
commandParameter,
|
||||||
|
callbackParameter,
|
||||||
enableGroupButton,
|
enableGroupButton,
|
||||||
enableUngroupButton;
|
enableUngroupButton;
|
||||||
|
|
||||||
|
@ -328,15 +446,23 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
intersectedItem = menuOverlays.indexOf(intersectionOverlayID);
|
intersectedItem = menuOverlays.indexOf(intersectionOverlayID);
|
||||||
if (intersectedItem !== -1) {
|
if (intersectedItem !== -1) {
|
||||||
intersectionOverlays = menuOverlays;
|
intersectionOverlays = menuOverlays;
|
||||||
|
intersectionOverlaysIDs = null;
|
||||||
|
intersectionCommands = null;
|
||||||
|
intersectionCommandsParameters = null;
|
||||||
intersectionCallbacks = menuCallbacks;
|
intersectionCallbacks = menuCallbacks;
|
||||||
intersectionCallbacksEnabled = null;
|
intersectionCallbacksParameters = null;
|
||||||
|
intersectionEnabled = null;
|
||||||
intersectionProperties = MENU_ITEMS;
|
intersectionProperties = MENU_ITEMS;
|
||||||
} else {
|
} else {
|
||||||
intersectedItem = optionsOverlays.indexOf(intersectionOverlayID);
|
intersectedItem = optionsOverlays.indexOf(intersectionOverlayID);
|
||||||
if (intersectedItem !== -1) {
|
if (intersectedItem !== -1) {
|
||||||
intersectionOverlays = optionsOverlays;
|
intersectionOverlays = optionsOverlays;
|
||||||
|
intersectionOverlaysIDs = optionsOverlaysIDs;
|
||||||
|
intersectionCommands = optionsCommands;
|
||||||
|
intersectionCommandsParameters = optionsCommandsParameters;
|
||||||
intersectionCallbacks = optionsCallbacks;
|
intersectionCallbacks = optionsCallbacks;
|
||||||
intersectionCallbacksEnabled = optionsEnabled;
|
intersectionCallbacksParameters = optionsCallbacksParameters;
|
||||||
|
intersectionEnabled = optionsEnabled;
|
||||||
intersectionProperties = optionsItems;
|
intersectionProperties = optionsItems;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -387,7 +513,7 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
pressedItem = NONE;
|
pressedItem = NONE;
|
||||||
}
|
}
|
||||||
isButtonPressed = isHighlightingButton && controlHand.triggerClicked();
|
isButtonPressed = isHighlightingButton && controlHand.triggerClicked();
|
||||||
if (isButtonPressed && (intersectionCallbacksEnabled === null || intersectionCallbacksEnabled[intersectedItem])) {
|
if (isButtonPressed && (intersectionEnabled === null || intersectionEnabled[intersectedItem])) {
|
||||||
// Press new button.
|
// Press new button.
|
||||||
Overlays.editOverlay(intersectionOverlays[intersectedItem], {
|
Overlays.editOverlay(intersectionOverlays[intersectedItem], {
|
||||||
localPosition: Vec3.sum(intersectionProperties[intersectedItem].properties.localPosition,
|
localPosition: Vec3.sum(intersectionProperties[intersectedItem].properties.localPosition,
|
||||||
|
@ -400,7 +526,18 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
if (intersectionOverlays === menuOverlays) {
|
if (intersectionOverlays === menuOverlays) {
|
||||||
openOptions(intersectionProperties[intersectedItem].toolOptions);
|
openOptions(intersectionProperties[intersectedItem].toolOptions);
|
||||||
}
|
}
|
||||||
commandCallback(intersectionCallbacks[intersectedItem]);
|
if (intersectionCommands && intersectionCommands[intersectedItem]) {
|
||||||
|
if (intersectionCommandsParameters && intersectionCommandsParameters[intersectedItem]) {
|
||||||
|
commandParameter = evaluateParameter(intersectionCommandsParameters[intersectedItem]);
|
||||||
|
}
|
||||||
|
peformCommand(intersectionCommands[intersectedItem], commandParameter);
|
||||||
|
}
|
||||||
|
if (intersectionCallbacks[intersectedItem]) {
|
||||||
|
if (intersectionCallbacksParameters && intersectionCallbacksParameters[intersectedItem]) {
|
||||||
|
callbackParameter = evaluateParameter(intersectionCallbacksParameters[intersectedItem]);
|
||||||
|
}
|
||||||
|
commandCallback(intersectionCallbacks[intersectedItem], callbackParameter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,8 +624,12 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) {
|
||||||
// Initial values.
|
// Initial values.
|
||||||
optionsItems = null;
|
optionsItems = null;
|
||||||
intersectionOverlays = null;
|
intersectionOverlays = null;
|
||||||
|
intersectionOverlaysIDs = null;
|
||||||
|
intersectionCommands = null;
|
||||||
|
intersectionCommandsParameters = null;
|
||||||
intersectionCallbacks = null;
|
intersectionCallbacks = null;
|
||||||
intersectionCallbacksEnabled = null;
|
intersectionCallbacksParameters = null;
|
||||||
|
intersectionEnabled = null;
|
||||||
intersectionProperties = null;
|
intersectionProperties = null;
|
||||||
highlightedItem = NONE;
|
highlightedItem = NONE;
|
||||||
highlightedSource = null;
|
highlightedSource = null;
|
||||||
|
|
|
@ -1235,7 +1235,7 @@
|
||||||
Settings.setValue(VR_EDIT_SETTING, isAppActive);
|
Settings.setValue(VR_EDIT_SETTING, isAppActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onUICommand(command) {
|
function onUICommand(command, parameter) {
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "scaleTool":
|
case "scaleTool":
|
||||||
grouping.clear();
|
grouping.clear();
|
||||||
|
|
Loading…
Reference in a new issue