From 5e7a5ecf03898df04461e537863aa706fbb11bcb Mon Sep 17 00:00:00 2001 From: austin Date: Wed, 14 May 2025 20:05:26 -0400 Subject: [PATCH] grid alignment visualization work --- docs/src/progress/renderertodo.md | 1 + .../ui/menu/ingame/MenuGeneratorsInGame.java | 10 ++++++ .../data/settings/UserSettings.java | 31 ++++++++++++---- .../pipelines/debug/DebugContentPipeline.java | 36 +++++++++++++++++++ 4 files changed, 72 insertions(+), 6 deletions(-) diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 6c5cdf02..b7878811 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1780,6 +1780,7 @@ Sorting imgui debug windows Grid alignment cursor Furniture spawner items triggers grid alignment cursor Grid aligned entity work +Grid alignment visualization work diff --git a/src/main/java/electrosphere/client/ui/menu/ingame/MenuGeneratorsInGame.java b/src/main/java/electrosphere/client/ui/menu/ingame/MenuGeneratorsInGame.java index 1527b2cc..8f7305a9 100644 --- a/src/main/java/electrosphere/client/ui/menu/ingame/MenuGeneratorsInGame.java +++ b/src/main/java/electrosphere/client/ui/menu/ingame/MenuGeneratorsInGame.java @@ -285,6 +285,16 @@ public class MenuGeneratorsInGame { togglePhysicsObjectsButton.setMarginLeft(BUTTON_MARGIN); scrollable.addChild(togglePhysicsObjectsButton); + //toggle draw grid alignment data + Button toggleDrawGridAlignmentDataButton = Button.createButton("Toggle draw grid alignment data", new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){ + // Main.running = false; + Globals.userSettings.setGraphicsDebugDrawGridAlignment(!Globals.userSettings.getGraphicsDebugDrawGridAlignment()); + return false; + }}); + toggleDrawGridAlignmentDataButton.setMarginTop(BUTTON_MARGIN); + toggleDrawGridAlignmentDataButton.setMarginLeft(BUTTON_MARGIN); + scrollable.addChild(toggleDrawGridAlignmentDataButton); + //label (toggle draw movement vectors) Button toggleMovementVectorsButton = Button.createButton("Toggle draw movement vectors", new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){ // Main.running = false; diff --git a/src/main/java/electrosphere/data/settings/UserSettings.java b/src/main/java/electrosphere/data/settings/UserSettings.java index ae8943f9..07bb2512 100644 --- a/src/main/java/electrosphere/data/settings/UserSettings.java +++ b/src/main/java/electrosphere/data/settings/UserSettings.java @@ -52,6 +52,7 @@ public class UserSettings { boolean graphicsDebugDrawPhysicsObjects; boolean graphicsDebugDrawMovementVectors; boolean graphicsDebugDrawNavmesh; + boolean graphicsDebugDrawGridAlignment; //debug network boolean netRunNetMonitor; @@ -187,12 +188,30 @@ public class UserSettings { this.graphicsPerformanceEnableFoliageManager = graphicsPerformanceEnableFoliageManager; } - - - - - - + /** + * Checks if should render the grid alignment data + * @return true if should render grid alignment data, false otherwise + */ + public boolean getGraphicsDebugDrawGridAlignment() { + return graphicsDebugDrawGridAlignment; + } + + /** + * Sets whether to draw the grid alignment data or not + * @param graphicsDebugDrawGridAlignment true to render the data, false otherwise + */ + public void setGraphicsDebugDrawGridAlignment(boolean graphicsDebugDrawGridAlignment) { + this.graphicsDebugDrawGridAlignment = graphicsDebugDrawGridAlignment; + } + + + + + + + + + /** * Generates a default settings file diff --git a/src/main/java/electrosphere/renderer/pipelines/debug/DebugContentPipeline.java b/src/main/java/electrosphere/renderer/pipelines/debug/DebugContentPipeline.java index a54efdba..f1a805d9 100644 --- a/src/main/java/electrosphere/renderer/pipelines/debug/DebugContentPipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/debug/DebugContentPipeline.java @@ -11,12 +11,15 @@ import org.ode4j.ode.DCapsule; import org.ode4j.ode.DGeom; import org.ode4j.ode.DSphere; +import electrosphere.client.block.BlockChunkData; import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.collision.CollisionEngine; import electrosphere.collision.PhysicsUtils; import electrosphere.collision.collidable.Collidable; import electrosphere.data.collidable.CollidableTemplate; import electrosphere.data.collidable.HitboxData; +import electrosphere.data.common.CommonEntityType; +import electrosphere.data.grident.GridAlignedData; import electrosphere.engine.Globals; import electrosphere.engine.assetmanager.AssetDataStrings; import electrosphere.entity.Entity; @@ -24,6 +27,7 @@ import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.hitbox.HitboxCollectionState; import electrosphere.entity.state.hitbox.HitboxCollectionState.HitboxState; +import electrosphere.entity.types.common.CommonEntityUtils; import electrosphere.renderer.OpenGLState; import electrosphere.renderer.RenderPipelineState; import electrosphere.renderer.RenderingEngine; @@ -230,6 +234,38 @@ public class DebugContentPipeline implements RenderPipeline { } } + // + //Draw grid alignment data + if(Globals.userSettings.getGraphicsDebugDrawGridAlignment()){ + Model physicsGraphicsModel = Globals.assetManager.fetchModel(AssetDataStrings.UNITCUBE); + for(Entity entity : Globals.clientSceneWrapper.getScene().getEntityList()){ + CommonEntityType data = CommonEntityUtils.getCommonData(entity); + if(data == null){ + continue; + } + if(data.getGridAlignedData() != null){ + GridAlignedData gridAlignedData = data.getGridAlignedData(); + Texture texture = Globals.assetManager.fetchTexture("Textures/transparent_blue.png"); + if(texture != null){ + texture.bind(openGLState); + } + Vector3d position = EntityUtils.getPosition(entity); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).add(0,gridAlignedData.getLength() * BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0f,0).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + modelTransformMatrix.identity(); + modelTransformMatrix.translate(cameraModifiedPosition); + modelTransformMatrix.rotate(EntityUtils.getRotation(entity)); + modelTransformMatrix.scale( + gridAlignedData.getWidth() * BlockChunkData.BLOCK_SIZE_MULTIPLIER, + gridAlignedData.getHeight() * BlockChunkData.BLOCK_SIZE_MULTIPLIER, + gridAlignedData.getLength() * BlockChunkData.BLOCK_SIZE_MULTIPLIER + ); + physicsGraphicsModel.setModelMatrix(modelTransformMatrix); + physicsGraphicsModel.draw(renderPipelineState,openGLState); + } + } + } + //update pipeline state to use mats again renderPipelineState.setUseMaterial(true);