diff --git a/src/main/java/mesh/util/MeshBoundsCalculator.java b/src/main/java/mesh/util/MeshBoundsCalculator.java new file mode 100644 index 00000000..f3d13c31 --- /dev/null +++ b/src/main/java/mesh/util/MeshBoundsCalculator.java @@ -0,0 +1,39 @@ +package mesh.util; + +import java.util.List; + +import math.Bounds; +import math.Vector3f; +import mesh.Mesh3D; + +public class MeshBoundsCalculator { + + /** + * Calculates the axis-aligned bounding box (AABB) for the given 3D mesh. + * + * @param mesh The mesh object whose bounding box needs to be calculated. + * @return A {@link Bounds} object representing the calculated bounding box. + */ + public static Bounds calculateBounds(Mesh3D mesh) { + List vertices = mesh.getVertices(); + if (vertices.isEmpty()) { + return new Bounds(Vector3f.ZERO, Vector3f.ZERO); + } + + Vector3f min = new Vector3f(vertices.get(0)); + Vector3f max = new Vector3f(vertices.get(0)); + + for (Vector3f vertex : vertices) { + min.set( + Math.min(min.getX(), vertex.getX()), + Math.min(min.getY(), vertex.getY()), + Math.min(min.getZ(), vertex.getZ())); + max.set( + Math.max(max.getX(), vertex.getX()), + Math.max(max.getY(), vertex.getY()), + Math.max(max.getZ(), vertex.getZ())); + } + + return new Bounds(min, max); + } +} diff --git a/src/main/java/workspace/Editor.java b/src/main/java/workspace/Editor.java index 0c24edaf..24c13666 100644 --- a/src/main/java/workspace/Editor.java +++ b/src/main/java/workspace/Editor.java @@ -23,153 +23,152 @@ public class Editor implements ModelListener { - protected List sceneObjects; - - protected UiComponent rootUi; - - protected KeyCommandMap commands; - - protected WorkspaceModel model; - - protected ViewportCompass gizmo; - - protected WorkspaceSideBarUi sideBar; - - protected UiEditorMenu menu; - - public Editor() { - setup(); - } - - private void setup() { - setupLookAndFeel(); - initializeModel(); - initializeSceneObjects(); - initializeRootUi(); - createUi(); - initializeCommandMap(); - registerKeyCommands(); - } - - @Override - public void onModelChanged() { - rootUi.setVisible(model.isUiVisible()); - } - - private void initializeSceneObjects() { - sceneObjects = new ArrayList(); - } - - private void createUi() { - rootUi.add(getSideBar()); - rootUi.add(getGizmo()); - rootUi.add(getMenu()); - } - - private WorkspaceSideBarUi getSideBar() { - if (sideBar == null) { - sideBar = new WorkspaceSideBarUi(model); - } - return sideBar; - } - - private ViewportCompass getGizmo() { - if (gizmo == null) { - gizmo = new ViewportCompass(); - } - return gizmo; - } - - private UiEditorMenu getMenu() { - if (menu == null) { - menu = new UiEditorMenu(); - } - return menu; - } - - private void initializeRootUi() { - rootUi = new UiComponent(); - } - - private void setupLookAndFeel() { - LookAndFeel.setup(); - } - - private void initializeCommandMap() { - commands = new KeyCommandMap(); - } - - private void initializeModel() { - model = new WorkspaceModel(); - } - - private void registerKeyCommands() { - commands.register(new ShowHideGridCommand(model)); - commands.register(new ShowHideXAxisCommand(model)); - commands.register(new ShowHideYAxisCommand(model)); - commands.register(new ShowHideZAxisCommand(model)); - commands.register(new ShowHideSideBarCommand(model)); - commands.register(new ShowHideFaceNormalsCommand(model)); - commands.register(new ResetPanningCommand(model)); - commands.register(new ShowHideVertexNormalsCommand(model)); - commands.register(new ShowHideEdgesCommand(model)); - commands.register(new WireframeCommand(model)); - commands.register(new ShadeSmoothFlatCommand(model)); - } - - private void resizeRootUi(int x, int y, int width, int height) { - rootUi.setX(x); - rootUi.setY(y); - rootUi.setWidth(width); - rootUi.setHeight(height); - } - - public void resize(int x, int y, int width, int height) { - resizeRootUi(x, y, width, height); - updateGizmo(width, height); - } - - public void handleMouseClicked(int x, int y) { - rootUi.onMouseClicked(x, y); - } - - public void handleMousePressed(int x, int y) { - rootUi.onMousePressed(x, y); - } - - public void handleMouseDragged(int x, int y) { - rootUi.onMouseDragged(x, y); - } - - public void handleMouseReleased(int x, int y) { - rootUi.onMouseReleased(x, y); - } - - public void handleMouseWheel(float amount) { - float scale = model.getScale(); - scale -= amount * scale * 0.2f; - model.setScale(scale); - } - - private void updateGizmo(int width, int height) { - gizmo.setX(width - 80); - gizmo.setY(130); - } - - public void add(UiComponent component) { - rootUi.add(component); - } - - public void addSceneObject(SceneObject sceneObject) { - sceneObjects.add(sceneObject); - } - - public void addAll(Collection sceneObjects) { - this.sceneObjects.addAll(sceneObjects); - } - - public void clearSceneObjects() { - sceneObjects.clear(); - } - + protected List sceneObjects; + + protected UiComponent rootUi; + + protected KeyCommandMap commands; + + protected WorkspaceModel model; + + protected ViewportCompass gizmo; + + protected WorkspaceSideBarUi sideBar; + + protected UiEditorMenu menu; + + public Editor() { + setup(); + } + + private void setup() { + setupLookAndFeel(); + initializeModel(); + initializeSceneObjects(); + initializeRootUi(); + createUi(); + initializeCommandMap(); + registerKeyCommands(); + } + + @Override + public void onModelChanged() { + rootUi.setVisible(model.isUiVisible()); + } + + private void initializeSceneObjects() { + sceneObjects = new ArrayList(); + } + + private void createUi() { + rootUi.add(getSideBar()); + rootUi.add(getGizmo()); + rootUi.add(getMenu()); + } + + private WorkspaceSideBarUi getSideBar() { + if (sideBar == null) { + sideBar = new WorkspaceSideBarUi(model); + } + return sideBar; + } + + private ViewportCompass getGizmo() { + if (gizmo == null) { + gizmo = new ViewportCompass(); + } + return gizmo; + } + + private UiEditorMenu getMenu() { + if (menu == null) { + menu = new UiEditorMenu(); + } + return menu; + } + + private void initializeRootUi() { + rootUi = new UiComponent(); + } + + private void setupLookAndFeel() { + LookAndFeel.setup(); + } + + private void initializeCommandMap() { + commands = new KeyCommandMap(); + } + + private void initializeModel() { + model = new WorkspaceModel(); + } + + private void registerKeyCommands() { + commands.register(new ShowHideGridCommand(model)); + commands.register(new ShowHideXAxisCommand(model)); + commands.register(new ShowHideYAxisCommand(model)); + commands.register(new ShowHideZAxisCommand(model)); + commands.register(new ShowHideSideBarCommand(model)); + commands.register(new ShowHideFaceNormalsCommand(model)); + commands.register(new ResetPanningCommand(model)); + commands.register(new ShowHideVertexNormalsCommand(model)); + commands.register(new ShowHideEdgesCommand(model)); + commands.register(new WireframeCommand(model)); + commands.register(new ShadeSmoothFlatCommand(model)); + } + + private void resizeRootUi(int x, int y, int width, int height) { + rootUi.setX(x); + rootUi.setY(y); + rootUi.setWidth(width); + rootUi.setHeight(height); + } + + public void resize(int x, int y, int width, int height) { + resizeRootUi(x, y, width, height); + updateGizmo(width, height); + } + + public void handleMouseClicked(int x, int y) { + rootUi.onMouseClicked(x, y); + } + + public void handleMousePressed(int x, int y) { + rootUi.onMousePressed(x, y); + } + + public void handleMouseDragged(int x, int y) { + rootUi.onMouseDragged(x, y); + } + + public void handleMouseReleased(int x, int y) { + rootUi.onMouseReleased(x, y); + } + + public void handleMouseWheel(float amount) { + float scale = model.getScale(); + scale -= amount * scale * 0.2f; + model.setScale(scale); + } + + private void updateGizmo(int width, int height) { + gizmo.setX(width - 80); + gizmo.setY(130); + } + + public void add(UiComponent component) { + rootUi.add(component); + } + + public void addSceneObject(SceneObject sceneObject) { + sceneObjects.add(sceneObject); + } + + public void addAll(Collection sceneObjects) { + this.sceneObjects.addAll(sceneObjects); + } + + public void clearSceneObjects() { + sceneObjects.clear(); + } } diff --git a/src/main/java/workspace/FirstPersonView.java b/src/main/java/workspace/FirstPersonView.java index 9480aad7..3ea8691d 100644 --- a/src/main/java/workspace/FirstPersonView.java +++ b/src/main/java/workspace/FirstPersonView.java @@ -1,6 +1,5 @@ package workspace; -import engine.world.PlayerMock; import math.Mathf; import math.Matrix3f; import math.Matrix4f; @@ -79,8 +78,6 @@ public void pre() { eye.addLocal(velocity.mult(speed)); eye.setY(-300); - - PlayerMock.playerPosition.addLocal(velocity.mult(0.1f)); } public void apply() { diff --git a/src/main/java/workspace/ui/layout/Anchor.java b/src/main/java/workspace/ui/layout/Anchor.java new file mode 100644 index 00000000..f70fd0d2 --- /dev/null +++ b/src/main/java/workspace/ui/layout/Anchor.java @@ -0,0 +1,65 @@ +package workspace.ui.layout; + +/** + * Enum representing different anchor points for UI layout alignment. These anchor points determine + * how a UI element will align within its parent container or layout system. + */ +public enum Anchor { + + /** No specific anchoring; element remains free or defaults to its own positioning logic. */ + NONE, + + /** Anchors element to the top-left corner of the parent container. */ + TOP_LEFT, + + /** Anchors element to the top-right corner of the parent container. */ + TOP_RIGHT, + + /** Anchors element to the bottom-right corner of the parent container. */ + BOTTOM_RIGHT, + + /** Anchors element to the bottom-left corner of the parent container. */ + BOTTOM_LEFT, + + /** Anchors element to the center left of the parent container. */ + CENTER_LEFT, + + /** Anchors element to the center top of the parent container. */ + CENTER_TOP, + + /** Anchors element to the center right of the parent container. */ + CENTER_RIGHT, + + /** Anchors element to the center bottom of the parent container. */ + CENTER_BOTTOM, + + /** Anchors element to the exact center of the parent container. */ + CENTER, + + /** Makes the element extend horizontally across a wide area starting from the left edge. */ + LEFT_WIDE, + + /** Makes the element extend horizontally across a wide area starting from the top edge. */ + TOP_WIDE, + + /** Makes the element extend horizontally across a wide area starting from the right edge. */ + RIGHT_WIDE, + + /** Makes the element extend horizontally across a wide area starting from the bottom edge. */ + BOTTOM_WIDE, + + /** Anchors the element in a vertical-centered wide area relative to its container. */ + VERTICAL_CENTER_WIDE, + + /** Anchors the element in a horizontally-centered wide area relative to its container. */ + HORIZONTAL_CENTER_WIDE, + + /** Extends the element to occupy the full rectangle of its parent container. */ + FULL_RECTANGLE, + + /** Makes the element extend vertically across a wide area starting from the center. */ + VERTICAL_WIDE, + + /** Makes the element extend horizontally across a wide area starting from the center. */ + HORIZONTAL_WIDE; +}