Skip to content

Commit

Permalink
improved move and rotate tools
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Dec 27, 2023
1 parent cfc40f3 commit 5efb7ff
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public Viewport() {
super();
add(toolBar, BorderLayout.NORTH);
toolBar.setLayout(new FlowLayout(FlowLayout.LEFT,5,1));

addRenderPasses();
addCameraSelector();
addRenderPassSelection();
Expand Down Expand Up @@ -83,7 +84,6 @@ private void addViewportTools() {
}
@Override
public void actionPerformed(ActionEvent e) {
logger.debug("select");
setActiveToolIndex(viewportTools.indexOf(selectionTool));
}
});
Expand All @@ -96,7 +96,6 @@ public void actionPerformed(ActionEvent e) {
}
@Override
public void actionPerformed(ActionEvent e) {
logger.debug("move");
setActiveToolIndex(viewportTools.indexOf(translateToolMulti));
}
});
Expand All @@ -109,7 +108,6 @@ public void actionPerformed(ActionEvent e) {
}
@Override
public void actionPerformed(ActionEvent e) {
logger.debug("rotate");
setActiveToolIndex(viewportTools.indexOf(rotateToolMulti));
}
});
Expand Down Expand Up @@ -169,6 +167,7 @@ private void addRenderPassSelection() {

// Add an ActionListener to the JButton to show the JPopupMenu when clicked
button.addActionListener(e -> renderPassMenu.show(button, button.getWidth()/2, button.getHeight()/2));
button.setToolTipText("Select the render passes to use.");

for(RenderPass renderPass : renderPasses.getList()) {
addRenderPass(renderPass);
Expand Down Expand Up @@ -261,6 +260,7 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
return this;
}
});
cameraSelector.setToolTipText("Select the active camera.");

cameraListModel.addAll(Registry.cameras.getList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public class SelectedItems {
/**
* The list of entities selected in the editorpanel.
*/
private final List<Node> entities = new ArrayList<>();
private final List<Node> nodes = new ArrayList<>();

/**
* The world pose of each node in the selection at the moment it was selected.
*/
private final Map<Node, Matrix4d> entityWorldPoses = new HashMap<>();
private final Map<Node, Matrix4d> worldPoses = new HashMap<>();

public SelectedItems() {
super();
Expand All @@ -35,32 +35,32 @@ public SelectedItems(List<Node> list) {
super();

for(Node e : list) {
addEntity(e);
addNode(e);
}
}

public void addEntity(Node node) {
entities.add(node);
public void addNode(Node node) {
nodes.add(node);
setEntityWorldPose(node);
}

private void setEntityWorldPose(Node node) {
if(node instanceof Pose pose) {
entityWorldPoses.put(node, pose.getWorld());
worldPoses.put(node, pose.getWorld());
}
}

public void removeEntity(Node node) {
entities.remove(node);
entityWorldPoses.remove(node);
nodes.remove(node);
worldPoses.remove(node);
}

public List<Node> getEntities() {
return entities;
public List<Node> getNodes() {
return nodes;
}

public Matrix4d getWorldPoseAtStart(Node node) {
return entityWorldPoses.get(node);
return worldPoses.get(node);
}

public Matrix4d getWorldPoseNow(Node node) {
Expand All @@ -71,16 +71,16 @@ public Matrix4d getWorldPoseNow(Node node) {
}

public boolean isEmpty() {
return entities.isEmpty();
return nodes.isEmpty();
}

public void clear() {
entities.clear();
entityWorldPoses.clear();
nodes.clear();
worldPoses.clear();
}

public void savePose() {
for(Node e : entities) {
for(Node e : nodes) {
setEntityWorldPose(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ public void setFrameOfReference(int index) {}

private void pickItemUnderCursor(boolean isShiftDown) {
Node hit = findNodeUnderCursor();
if(hit!=null) {
// most MeshInstances are children of a Pose, unless they are in the root.
Node parent = hit.getParent();
if(parent instanceof Pose) hit = parent;
}

logger.debug((hit==null)?"hit = nothing":"hit = " + hit.getAbsolutePath());

List<Node> selection = new ArrayList<>(Registry.selection.getList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.marginallyclever.convenience.helpers.IntersectionHelper;
import com.marginallyclever.convenience.helpers.MatrixHelper;
import com.marginallyclever.ro3.Registry;
import com.marginallyclever.ro3.UndoSystem;
import com.marginallyclever.ro3.apps.render.viewporttools.SelectedItems;
import com.marginallyclever.ro3.apps.render.viewporttools.ViewportTool;
import com.marginallyclever.ro3.node.Node;
Expand Down Expand Up @@ -35,7 +34,7 @@ public static Matrix4d getLastItemSelectedMatrix(SelectedItems selectedItems) {
return null;
}

List<Node> list = selectedItems.getEntities();
List<Node> list = selectedItems.getNodes();
Node lastEntity = null;
for(Node e : list) {
if(e instanceof Pose) lastEntity = e;
Expand Down Expand Up @@ -64,7 +63,7 @@ public static Point3d getPointOnPlaneFromCursor(Plane translationPlane, Viewport
}

public static void updateUndoState(SelectedItems selectedItems) {
for (Node node : selectedItems.getEntities()) {
for (Node node : selectedItems.getNodes()) {
if(node instanceof Pose pose) {
Matrix4d before = selectedItems.getWorldPoseAtStart(node);
Matrix4d after = selectedItems.getWorldPoseNow(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void mouseDragged(MouseEvent event) {
pivotInverse.m23=-pivotTranslation.z;


for (Node node : selectedItems.getEntities()) {
for (Node node : selectedItems.getNodes()) {
if(node instanceof Pose pc) {
Matrix4d pose = new Matrix4d(selectedItems.getWorldPoseAtStart(node));
Vector3d translation = MatrixHelper.getPosition(pose);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void mouseDragged(MouseEvent event) {
translation.sub(nearestPoint, startPoint);

// Apply the translation to the selected items
for (Node node : selectedItems.getEntities()) {
for (Node node : selectedItems.getNodes()) {
if(node instanceof Pose pose) {
Matrix4d before = selectedItems.getWorldPoseAtStart(node);
Matrix4d m = new Matrix4d(before);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void mouseDragged(MouseEvent event) {
translation.sub(currentPoint, startPoint);

// Apply the translation to the selected items
for (Node node : selectedItems.getEntities()) {
for (Node node : selectedItems.getNodes()) {
if(node instanceof Pose pose) {
Matrix4d before = selectedItems.getWorldPoseAtStart(node);
Matrix4d m = new Matrix4d(before);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5efb7ff

Please sign in to comment.