Commit fb0958e7 authored by Ivan Dages's avatar Ivan Dages
Browse files

levels of detail

parent 38eceeb5
......@@ -3,6 +3,7 @@ package fr.ill.ics.n3d.gui;
import java.text.DecimalFormat;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.logging.Logger;
......@@ -69,6 +70,8 @@ public class EditorMenuBar extends MenuBar {
/** View menu. */
private Menu view;
private Menu lodMenu;
/** Show configuration sub-menu. */
private Menu showConfig;
......@@ -94,6 +97,8 @@ public class EditorMenuBar extends MenuBar {
/** Currently displayed configuration. */
private String activeConfiguration;
private int activeLod;
/**
* Constructor.
* @param Nomad3DEditor.getInstance() Editor owning the menu bar
......@@ -104,6 +109,7 @@ public class EditorMenuBar extends MenuBar {
this.showWalls = true;
this.focusSelection = false;
this.activeConfiguration = null;
this.activeLod = 0;
this.file = new Menu("File");
MenuItem openItem = new MenuItem("Open");
......@@ -794,6 +800,10 @@ public class EditorMenuBar extends MenuBar {
Nomad3DEditor.getInstance().getControls().right();
});
cameraMenu.getItems().addAll(topItem, bottomItem, frontItem, backItem, rightItem, leftItem);
this.lodMenu = new Menu("Level of detail");
updateLodMenu();
CheckMenuItem showAxesItem = new CheckMenuItem("Show axes");
showAxesItem.setAccelerator(new KeyCodeCombination(KeyCode.A, KeyCombination.SHIFT_DOWN));
showAxesItem.setSelected(this.showAxes);
......@@ -844,26 +854,17 @@ public class EditorMenuBar extends MenuBar {
}
Component root = Nomad3DEditor.getInstance().getModel().getRoot();
String fancyMeshSize = "";
DecimalFormat df = new DecimalFormat("###,###.###");
long meshSize = root.meshesSize(true);
while (meshSize > 0) {
fancyMeshSize = (meshSize % 1000) + " " + fancyMeshSize;
meshSize /= 1000;
}
Label facesLabel = new Label("Triangle count : ");
facesLabel.setPrefWidth(6*facesLabel.getText().length());
Label facesCountLabel = new Label(fancyMeshSize);
facesCountLabel.setPrefWidth(8*fancyMeshSize.length());
String fancyHierarchySize = "";
Label facesCountLabel = new Label(df.format(meshSize));
facesCountLabel.setPrefWidth(8*facesCountLabel.getText().length());
long hierarchySize = root.hierarchySize();
while (hierarchySize > 0) {
fancyHierarchySize = (hierarchySize % 1000) + " " + fancyHierarchySize;
hierarchySize /= 1000;
}
Label compLabel = new Label("Assembly size : ");
Label compCountLabel = new Label(fancyHierarchySize);
Label compCountLabel = new Label(df.format(hierarchySize));
Label axesLabel = new Label("Axes count : ");
Label axesCountLabel = new Label(""+root.axesCount());
Label axesCountLabel = new Label(df.format(root.axesCount()));
GridPane statsPane = new GridPane();
statsPane.setAlignment(Pos.CENTER);
......@@ -891,6 +892,8 @@ public class EditorMenuBar extends MenuBar {
}
});
this.view.getItems().addAll(cameraMenu,
new SeparatorMenuItem(),
lodMenu,
new SeparatorMenuItem(),
showAxesItem, showSystemItem, showWallsItem,
new SeparatorMenuItem(),
......@@ -1043,7 +1046,7 @@ public class EditorMenuBar extends MenuBar {
this.getMenus().addAll(this.file, this.edit, this.view, this.selection, this.help);
}
/**
* Selects the root component of the selection.
* @param title Title of the warning/error alerts in case of errors
......@@ -1082,6 +1085,7 @@ public class EditorMenuBar extends MenuBar {
* Updates the menu bar and the Nomad3DEditor.getInstance() accordingly.
*/
private void update() {
updateLodMenu();
updateShowConfigMenu();
updateAxes();
updateWalls();
......@@ -1090,6 +1094,36 @@ public class EditorMenuBar extends MenuBar {
updateCamera();
}
private void updateLodMenu() {
Logger.getLogger("nomad-3d").info("Updating LODs...");
if (Nomad3DEditor.getInstance().getModel() == null || Nomad3DEditor.getInstance().getModel().getRoot() == null) {
return;
}
this.lodMenu.getItems().clear();
this.activeLod = 0;
int nbLods = Nomad3DEditor.getInstance().getModel().getGeometriesDirectories().values().size();
Logger.getLogger("nomad-3d").info(nbLods + " LODs to add");
for (int lod = 0 ; lod < nbLods ; lod++) {
CheckMenuItem lodItem = new CheckMenuItem(lod + " - " + Nomad3DEditor.getInstance().getModel().getGeometryDirectory(lod));
lodItem.setSelected(lod == activeLod);
lodItem.setOnAction(lodEvent -> {
int i = 0;
for (MenuItem item : lodMenu.getItems()) {
CheckMenuItem checkItem = (CheckMenuItem)item;
checkItem.setSelected(checkItem == lodItem);
if (checkItem == lodItem) {
activeLod = i;
}
i++;
}
updateScene();
});
lodMenu.getItems().add(lodItem);
Logger.getLogger("nomad-3d").info(lodItem.getText() + " added");
}
Logger.getLogger("nomad-3d").info("LOD menu size : " + lodMenu.getItems().size());
}
/**
* Updates the camera.
*/
......@@ -1186,7 +1220,7 @@ public class EditorMenuBar extends MenuBar {
@SuppressWarnings("unchecked")
private void updateScene() {
Nomad3DEditor.getInstance().getRoot().getChildren().remove(Nomad3DEditor.getInstance().getModel().getRoot().getSceneNode());
Nomad3DEditor.getInstance().getModel().computeSceneHierarchies();
Nomad3DEditor.getInstance().getModel().computeSceneHierarchies(activeLod);
Nomad3DEditor.getInstance().getRoot().getChildren().add(Nomad3DEditor.getInstance().getModel().getRoot().getSceneNode());
((TreeView<Component>)Nomad3DEditor.getInstance().getPane().getLeft()).setRoot(Nomad3DEditor.getInstance().getModel().getRoot().getTreeItem());
......
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