Commit bca6294f authored by yannick legoc's avatar yannick legoc
Browse files

Reset the center of the camera when changing the displayed root

parent 2f335de8
......@@ -417,13 +417,21 @@ public class Nomad3DEditor extends Application {
buildEventHandlers(axesGroup);
// Initialize the camera position
Bounds rootBounds = this.model.getRoot().getSceneNode().localToScene(this.model.getRoot().getSceneNode().getBoundsInLocal());
resetCamera(this.model.getRoot());
return scene;
}
/**
* Sets the camera center and zoom according to the component.
* @param component
*/
private void resetCamera(Component component) {
Bounds rootBounds = component.getSceneNode().localToScene(component.getSceneNode().getBoundsInLocal());
Point3D rootCenter = new Point3D(rootBounds.getMinX(), rootBounds.getMinY(), rootBounds.getMinZ());
rootCenter = rootCenter.add(rootBounds.getWidth() / 2.0, rootBounds.getHeight() / 2.0, rootBounds.getDepth() / 2.0);
this.controls.setCenter(rootCenter);
this.controls.zoom(-1.0 * ((new Point3D(rootBounds.getWidth(), rootBounds.getHeight(), rootBounds.getDepth())).magnitude()), false, false);
return scene;
}
/**
......@@ -695,10 +703,20 @@ public class Nomad3DEditor extends Application {
}
}
public void setComponentAsRoot(Component component) {
/**
* Sets the component as the displayed root.
* The tree view is modified as well as the camera to change the center to the displayed component.
* @param component
*/
public void setDisplayedRootComponent(Component component) {
// Set the components that are not in the hierarchy of the new root component invisible.
Nomad3DEditor.getInstance().getModel().getRoot().resetVisible(component);
menuBar.setDisplayedRoot(component);
// Change the tree view.
menuBar.setDisplayedRootComponent(component);
// Change the center of the camera.
resetCamera(component);
}
}
......@@ -3001,7 +3001,7 @@ public class EditorMenuBar extends MenuBar {
updateScene(Nomad3DEditor.getInstance().getModel().getDisplayedRoot());
}
public void setDisplayedRoot(Component component) {
public void setDisplayedRootComponent(Component component) {
// Save the expanded state of the tree items.
HashMap<String, Boolean> itemStates = Nomad3DEditor.getInstance().getTreeViewExpandedStates(component.getTreeItem());
......
......@@ -63,7 +63,7 @@ public class HierarchyCell extends CheckBoxTreeCell<Component> {
Component component = getItem();
// Set it as the displayed root.
Nomad3DEditor.getInstance().setComponentAsRoot(component);
Nomad3DEditor.getInstance().setDisplayedRootComponent(component);
}
});
......@@ -73,7 +73,7 @@ public class HierarchyCell extends CheckBoxTreeCell<Component> {
displayAllTheComponentsItem.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
// Reset with the root component.
Nomad3DEditor.getInstance().setComponentAsRoot(Nomad3DEditor.getInstance().getModel().getRoot());
Nomad3DEditor.getInstance().setDisplayedRootComponent(Nomad3DEditor.getInstance().getModel().getRoot());
}
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment