mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 03:17:06 +02:00
Add entity copying and axis constraining to entity tools
This commit is contained in:
parent
fde7b30501
commit
e556886c72
2 changed files with 50 additions and 14 deletions
|
@ -1132,17 +1132,30 @@ SelectionDisplay = (function () {
|
||||||
UndoStack.pushCommand(applyEntityProperties, undoData, applyEntityProperties, redoData);
|
UndoStack.pushCommand(applyEntityProperties, undoData, applyEntityProperties, redoData);
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastXZPick = null;
|
var initialXZPick = null;
|
||||||
|
var isConstrained = false;
|
||||||
|
var startPosition = null;
|
||||||
var translateXZTool = {
|
var translateXZTool = {
|
||||||
mode: 'TRANSLATE_XZ',
|
mode: 'TRANSLATE_XZ',
|
||||||
onBegin: function(event) {
|
onBegin: function(event) {
|
||||||
SelectionManager.saveProperties();
|
SelectionManager.saveProperties();
|
||||||
var position = SelectionManager.worldPosition;
|
startPosition = SelectionManager.worldPosition;
|
||||||
var dimensions = SelectionManager.worldDimensions;
|
var dimensions = SelectionManager.worldDimensions;
|
||||||
var bottom = position.y - (dimensions.y / 2)
|
|
||||||
|
|
||||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||||
lastXZPick = rayPlaneIntersection(pickRay, position, { x: 0, y: 1, z: 0 });
|
initialXZPick = rayPlaneIntersection(pickRay, startPosition, { x: 0, y: 1, z: 0 });
|
||||||
|
|
||||||
|
// Duplicate entities if alt is pressed. This will make a
|
||||||
|
// copy of the selected entities and move the _original_ entities, not
|
||||||
|
// the new ones.
|
||||||
|
if (event.isAlt) {
|
||||||
|
for (var otherEntityID in SelectionManager.savedProperties) {
|
||||||
|
var properties = SelectionManager.savedProperties[otherEntityID];
|
||||||
|
var entityID = Entities.addEntity(properties);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isConstrained = false;
|
||||||
},
|
},
|
||||||
onEnd: function(event, reason) {
|
onEnd: function(event, reason) {
|
||||||
if (reason == 'cancel') {
|
if (reason == 'cancel') {
|
||||||
|
@ -1154,6 +1167,8 @@ SelectionDisplay = (function () {
|
||||||
} else {
|
} else {
|
||||||
pushCommandForSelections();
|
pushCommandForSelections();
|
||||||
}
|
}
|
||||||
|
Overlays.editOverlay(xRailOverlay, { visible: false });
|
||||||
|
Overlays.editOverlay(zRailOverlay, { visible: false });
|
||||||
},
|
},
|
||||||
onMove: function(event) {
|
onMove: function(event) {
|
||||||
if (!entitySelected || mode !== "TRANSLATE_XZ") {
|
if (!entitySelected || mode !== "TRANSLATE_XZ") {
|
||||||
|
@ -1168,26 +1183,47 @@ SelectionDisplay = (function () {
|
||||||
Quat.getFront(lastCameraOrientation));
|
Quat.getFront(lastCameraOrientation));
|
||||||
|
|
||||||
var vector = Vec3.subtract(newIntersection, lastPlaneIntersection);
|
var vector = Vec3.subtract(newIntersection, lastPlaneIntersection);
|
||||||
|
|
||||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
|
||||||
var pick = rayPlaneIntersection(pickRay, SelectionManager.worldPosition, { x: 0, y: 1, z: 0 });
|
var pick = rayPlaneIntersection(pickRay, SelectionManager.worldPosition, { x: 0, y: 1, z: 0 });
|
||||||
vector = Vec3.subtract(pick, lastXZPick);
|
var vector = Vec3.subtract(pick, initialXZPick);
|
||||||
lastXZPick = pick;
|
// initialXZPick = pick;
|
||||||
|
|
||||||
|
// If shifted, constrain to one axis
|
||||||
|
if (event.isShifted) {
|
||||||
|
if (Math.abs(vector.x) > Math.abs(vector.z)) {
|
||||||
|
vector.z = 0;
|
||||||
|
} else {
|
||||||
|
vector.x = 0;
|
||||||
|
}
|
||||||
|
if (!isConstrained) {
|
||||||
|
Overlays.editOverlay(xRailOverlay, { visible: true });
|
||||||
|
var xStart = Vec3.sum(startPosition, { x: -10000, y: 0, z: 0 });
|
||||||
|
var xEnd = Vec3.sum(startPosition, { x: 10000, y: 0, z: 0 });
|
||||||
|
var zStart = Vec3.sum(startPosition, { x: 0, y: 0, z: -10000 });
|
||||||
|
var zEnd = Vec3.sum(startPosition, { x: 0, y: 0, z: 10000 });
|
||||||
|
Overlays.editOverlay(xRailOverlay, { start: xStart, end: xEnd, visible: true });
|
||||||
|
Overlays.editOverlay(zRailOverlay, { start: zStart, end: zEnd, visible: true });
|
||||||
|
isConstrained = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isConstrained) {
|
||||||
|
Overlays.editOverlay(xRailOverlay, { visible: false });
|
||||||
|
Overlays.editOverlay(zRailOverlay, { visible: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var wantDebug = false;
|
var wantDebug = false;
|
||||||
|
|
||||||
for (var i = 0; i < SelectionManager.selections.length; i++) {
|
for (var i = 0; i < SelectionManager.selections.length; i++) {
|
||||||
var properties = Entities.getEntityProperties(SelectionManager.selections[i]);
|
var properties = SelectionManager.savedProperties[SelectionManager.selections[i].id];
|
||||||
var original = properties.position;
|
Entities.editEntity(SelectionManager.selections[i], {
|
||||||
properties.position = Vec3.sum(properties.position, vector);
|
position: Vec3.sum(properties.position, vector),
|
||||||
Entities.editEntity(SelectionManager.selections[i], properties);
|
});
|
||||||
|
|
||||||
if (wantDebug) {
|
if (wantDebug) {
|
||||||
print("translateXZ... ");
|
print("translateXZ... ");
|
||||||
Vec3.print(" lastPlaneIntersection:", lastPlaneIntersection);
|
Vec3.print(" lastPlaneIntersection:", lastPlaneIntersection);
|
||||||
Vec3.print(" newIntersection:", newIntersection);
|
Vec3.print(" newIntersection:", newIntersection);
|
||||||
Vec3.print(" vector:", vector);
|
Vec3.print(" vector:", vector);
|
||||||
Vec3.print(" originalPosition:", original);
|
|
||||||
Vec3.print(" newPosition:", properties.position);
|
Vec3.print(" newPosition:", properties.position);
|
||||||
Vec3.print(" newPosition:", newPosition);
|
Vec3.print(" newPosition:", newPosition);
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,7 +178,7 @@ var toolBar = (function () {
|
||||||
position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE));
|
position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE));
|
||||||
|
|
||||||
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
||||||
Entities.addEntity({
|
var entityId = Entities.addEntity({
|
||||||
type: "Model",
|
type: "Model",
|
||||||
position: position,
|
position: position,
|
||||||
dimensions: { x: DEFAULT_DIMENSION, y: DEFAULT_DIMENSION, z: DEFAULT_DIMENSION },
|
dimensions: { x: DEFAULT_DIMENSION, y: DEFAULT_DIMENSION, z: DEFAULT_DIMENSION },
|
||||||
|
|
Loading…
Reference in a new issue