floating world origin work
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-05-22 17:25:54 -04:00
parent 47e0ee824c
commit 90031765a9
9 changed files with 63 additions and 37 deletions

View File

@ -1934,6 +1934,8 @@ Geom-only collidables on server
Block colliders leveraging spaces Block colliders leveraging spaces
Scene view debug window Scene view debug window
Debug view of entity colliders Debug view of entity colliders
Fix lookup bug in debug physics ui
Floating point starting to play nice with engine

View File

@ -122,6 +122,10 @@ public class ClientSimulation {
Globals.clientState.clientSceneWrapper.getChemistryEngine().clearCollidableImpulseLists(); Globals.clientState.clientSceneWrapper.getChemistryEngine().clearCollidableImpulseLists();
Globals.profiler.endCpuSample(); Globals.profiler.endCpuSample();
//
//Rebase world origin
Globals.clientState.clientSceneWrapper.getCollisionEngine().rebaseWorldOrigin();
// //
//wrap up functions //wrap up functions
this.runClientFunctions(); this.runClientFunctions();

View File

@ -64,6 +64,7 @@ public class ImGuiEntityMacros {
private static boolean filterToCreatures = false; //filters the entity list to just creatures private static boolean filterToCreatures = false; //filters the entity list to just creatures
private static boolean filterToFoliage = false; //filters the entity list to just foliage private static boolean filterToFoliage = false; //filters the entity list to just foliage
private static boolean filterToTerrain = false; //filters the entity list to just terrain private static boolean filterToTerrain = false; //filters the entity list to just terrain
private static boolean filterHasCollidable = false; //filters the entity list to just entities that have collidables
//window for viewing details about an entity //window for viewing details about an entity
protected static ImGuiWindow clientEntityDetailWindow; protected static ImGuiWindow clientEntityDetailWindow;
@ -118,6 +119,9 @@ public class ImGuiEntityMacros {
if(ImGui.checkbox("Filter to Terrain", filterToTerrain)){ if(ImGui.checkbox("Filter to Terrain", filterToTerrain)){
filterToTerrain = !filterToTerrain; filterToTerrain = !filterToTerrain;
} }
if(ImGui.checkbox("Filter has Collidable", filterHasCollidable)){
filterHasCollidable = !filterHasCollidable;
}
for(Entity entity : Globals.clientState.clientSceneWrapper.getScene().getEntityList()){ for(Entity entity : Globals.clientState.clientSceneWrapper.getScene().getEntityList()){
//filters //filters
if(filterToCreatures && !CreatureUtils.isCreature(entity)){ if(filterToCreatures && !CreatureUtils.isCreature(entity)){
@ -129,6 +133,9 @@ public class ImGuiEntityMacros {
if(filterToTerrain && !TerrainChunk.isTerrainEntity(entity)){ if(filterToTerrain && !TerrainChunk.isTerrainEntity(entity)){
continue; continue;
} }
if(filterHasCollidable && PhysicsEntityUtils.getCollidable(entity) == null){
continue;
}
if(filterBasic && if(filterBasic &&
( (
AmbientFoliage.getAmbientFoliageTree(entity) != null || AmbientFoliage.getAmbientFoliageTree(entity) != null ||

View File

@ -10,7 +10,6 @@ import electrosphere.data.entity.collidable.CollidableTemplate;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.server.datacell.utils.EntityLookupUtils; import electrosphere.server.datacell.utils.EntityLookupUtils;
import imgui.ImGui; import imgui.ImGui;
@ -29,8 +28,8 @@ public class ImGuiEntityPhysicsTab {
if(PhysicsEntityUtils.getDBody(detailViewEntity) != null){ if(PhysicsEntityUtils.getDBody(detailViewEntity) != null){
DBody physicsBody = PhysicsEntityUtils.getDBody(detailViewEntity); DBody physicsBody = PhysicsEntityUtils.getDBody(detailViewEntity);
if(physicsBody != null){ if(physicsBody != null){
ImGui.text("Position: " + EntityUtils.getPosition(detailViewEntity)); ImGui.text("Position: " + physicsBody.getPosition());
ImGui.text("Rotation: " + EntityUtils.getRotation(detailViewEntity)); ImGui.text("Rotation: " + physicsBody.getQuaternion());
ImGui.text("Velocity: " + physicsBody.getLinearVel()); ImGui.text("Velocity: " + physicsBody.getLinearVel());
ImGui.text("Force: " + physicsBody.getForce()); ImGui.text("Force: " + physicsBody.getForce());
ImGui.text("Angular Velocity: " + physicsBody.getAngularVel()); ImGui.text("Angular Velocity: " + physicsBody.getAngularVel());
@ -53,8 +52,8 @@ public class ImGuiEntityPhysicsTab {
if(serverPhysicsBody != null){ if(serverPhysicsBody != null){
ImGui.newLine(); ImGui.newLine();
ImGui.text("Linked server entity:"); ImGui.text("Linked server entity:");
ImGui.text("Position (Server): " + EntityUtils.getPosition(serverEntity)); ImGui.text("Position (Server): " + physicsBody.getPosition());
ImGui.text("Rotation (Server): " + EntityUtils.getRotation(serverEntity)); ImGui.text("Rotation (Server): " + physicsBody.getQuaternion());
ImGui.text("Velocity (Server): " + serverPhysicsBody.getLinearVel()); ImGui.text("Velocity (Server): " + serverPhysicsBody.getLinearVel());
ImGui.text("Force (Server): " + serverPhysicsBody.getForce()); ImGui.text("Force (Server): " + serverPhysicsBody.getForce());
ImGui.text("Angular Velocity: " + serverPhysicsBody.getAngularVel()); ImGui.text("Angular Velocity: " + serverPhysicsBody.getAngularVel());
@ -73,8 +72,8 @@ public class ImGuiEntityPhysicsTab {
if(clientPhysicsBody != null){ if(clientPhysicsBody != null){
ImGui.newLine(); ImGui.newLine();
ImGui.text("Linked client entity:"); ImGui.text("Linked client entity:");
ImGui.text("Position (Client): " + EntityUtils.getPosition(clientEntity)); ImGui.text("Position (Client): " + physicsBody.getPosition());
ImGui.text("Rotation (Client): " + EntityUtils.getRotation(clientEntity)); ImGui.text("Rotation (Client): " + physicsBody.getQuaternion());
ImGui.text("Velocity (Client): " + clientPhysicsBody.getLinearVel()); ImGui.text("Velocity (Client): " + clientPhysicsBody.getLinearVel());
ImGui.text("Force (Client): " + clientPhysicsBody.getForce()); ImGui.text("Force (Client): " + clientPhysicsBody.getForce());
ImGui.text("Angular Velocity: " + clientPhysicsBody.getAngularVel()); ImGui.text("Angular Velocity: " + clientPhysicsBody.getAngularVel());

View File

@ -94,6 +94,11 @@ public class CollisionEngine {
* Default distance to interact with collidables at (ie picking where to place things) * Default distance to interact with collidables at (ie picking where to place things)
*/ */
public static final double DEFAULT_INTERACT_DISTANCE = 5.0; public static final double DEFAULT_INTERACT_DISTANCE = 5.0;
/**
* Distance from current floating point origin to trigger a rebase
*/
private static final double REBASE_TRIGGER_DISTANCE = 500;
/** /**
* world data that the collision engine leverages for position correction and the like * world data that the collision engine leverages for position correction and the like
@ -698,7 +703,7 @@ public class CollisionEngine {
if(geom != null){ if(geom != null){
if(geom instanceof DSpace space){ if(geom instanceof DSpace space){
for(DGeom child : space.getGeoms()){ for(DGeom child : space.getGeoms()){
Vector3d currentBodyOffset = PhysicsUtils.odeVecToJomlVec(child.getPosition()); Vector3d currentBodyOffset = PhysicsUtils.odeVecToJomlVec(child.getPosition()).add(this.floatingOrigin);
if(collected == 0){ if(collected == 0){
newOrigin.set(currentBodyOffset); newOrigin.set(currentBodyOffset);
} else { } else {
@ -709,7 +714,7 @@ public class CollisionEngine {
collected++; collected++;
} }
} else { } else {
Vector3d currentBodyOffset = PhysicsUtils.odeVecToJomlVec(geom.getPosition()); Vector3d currentBodyOffset = PhysicsUtils.odeVecToJomlVec(geom.getPosition()).add(this.floatingOrigin);
if(collected == 0){ if(collected == 0){
newOrigin.set(currentBodyOffset); newOrigin.set(currentBodyOffset);
} else { } else {
@ -721,27 +726,32 @@ public class CollisionEngine {
} }
} }
} }
Vector3d delta = new Vector3d(this.floatingOrigin).sub(newOrigin); Vector3d delta = new Vector3d(this.floatingOrigin);
this.floatingOrigin = this.floatingOrigin.set(newOrigin); delta = delta.sub(newOrigin);
//apply new origin to all geoms
//calculate new origin //only perform rebase if sufficiently far away
for(Collidable collidable : collidableList){ if(delta.length() > REBASE_TRIGGER_DISTANCE){
Entity physicsEntity = collidable.getParent(); this.floatingOrigin = newOrigin;
DBody rigidBody = PhysicsEntityUtils.getDBody(physicsEntity); //apply new origin to all geoms
if(rigidBody != null){ //calculate new origin
Vector3d existingPosition = PhysicsUtils.odeVecToJomlVec(rigidBody.getPosition()); for(Collidable collidable : collidableList){
rigidBody.setPosition(PhysicsUtils.jomlVecToOdeVec(existingPosition.add(delta))); Entity physicsEntity = collidable.getParent();
} DBody rigidBody = PhysicsEntityUtils.getDBody(physicsEntity);
DGeom geom = PhysicsEntityUtils.getDGeom(physicsEntity); if(rigidBody != null){
if(geom != null){ Vector3d existingPosition = PhysicsUtils.odeVecToJomlVec(rigidBody.getPosition());
if(geom instanceof DSpace space){ rigidBody.setPosition(PhysicsUtils.jomlVecToOdeVec(existingPosition.add(delta)));
for(DGeom child : space.getGeoms()){ }
Vector3d existingPosition = PhysicsUtils.odeVecToJomlVec(child.getPosition()); DGeom geom = PhysicsEntityUtils.getDGeom(physicsEntity);
child.setPosition(PhysicsUtils.jomlVecToOdeVec(existingPosition.add(delta))); if(geom != null){
if(geom instanceof DSpace space){
for(DGeom child : space.getGeoms()){
Vector3d existingPosition = PhysicsUtils.odeVecToJomlVec(child.getPosition());
child.setPosition(PhysicsUtils.jomlVecToOdeVec(existingPosition.add(delta)));
}
} else {
Vector3d existingPosition = PhysicsUtils.odeVecToJomlVec(geom.getPosition());
geom.setPosition(PhysicsUtils.jomlVecToOdeVec(existingPosition.add(delta)));
} }
} else {
Vector3d existingPosition = PhysicsUtils.odeVecToJomlVec(geom.getPosition());
geom.setPosition(PhysicsUtils.jomlVecToOdeVec(existingPosition.add(delta)));
} }
} }
} }
@ -1483,6 +1493,7 @@ public class CollisionEngine {
"Geom Ptrs: " + this.geomPointerMap.size() + "\n" + "Geom Ptrs: " + this.geomPointerMap.size() + "\n" +
"Collidables: " + this.collidableList.size() + "\n" + "Collidables: " + this.collidableList.size() + "\n" +
"Space geom count: " + this.space.getNumGeoms() + "\n" + "Space geom count: " + this.space.getNumGeoms() + "\n" +
"Floating origin: " + this.floatingOrigin.x + "," + this.floatingOrigin.y + "," + this.floatingOrigin.z + "\n" +
"" ""
; ;
return message; return message;

View File

@ -63,8 +63,12 @@ public class ClientPhysicsSyncTree implements BehaviorTree {
//bust distance caches if this is the player's entity and we've traveled a long distance suddenly //bust distance caches if this is the player's entity and we've traveled a long distance suddenly
if(parent == Globals.clientState.playerEntity){ if(parent == Globals.clientState.playerEntity){
if(position.distance(EntityUtils.getPosition(parent)) > FoliageCellManager.TELEPORT_DISTANCE){ if(position.distance(EntityUtils.getPosition(parent)) > FoliageCellManager.TELEPORT_DISTANCE){
Globals.clientState.clientDrawCellManager.bustDistanceCache(); if(Globals.clientState.clientDrawCellManager != null){
Globals.clientState.foliageCellManager.bustDistanceCache(); Globals.clientState.clientDrawCellManager.bustDistanceCache();
}
if(Globals.clientState.foliageCellManager != null){
Globals.clientState.foliageCellManager.bustDistanceCache();
}
} }
} }

View File

@ -90,9 +90,7 @@ public class TerrainChunk {
} }
LoggerInterface.loggerEngine.DEBUG("Finished generating terrain polygons; however, entity has already been deleted."); LoggerInterface.loggerEngine.DEBUG("Finished generating terrain polygons; however, entity has already been deleted.");
} }
} catch (Error e){ } catch (Throwable e){
LoggerInterface.loggerEngine.ERROR(e);
} catch(Exception e){
LoggerInterface.loggerEngine.ERROR(e); LoggerInterface.loggerEngine.ERROR(e);
} }
}); });

View File

@ -843,9 +843,7 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
//set ready //set ready
dataCell.setReady(true); dataCell.setReady(true);
} catch(Exception ex){ } catch(Throwable ex){
LoggerInterface.loggerEngine.ERROR(ex);
} catch (Error ex){
LoggerInterface.loggerEngine.ERROR(ex); LoggerInterface.loggerEngine.ERROR(ex);
} }
}); });

View File

@ -3,6 +3,7 @@ package electrosphere.server.macro.character;
import org.joml.Vector3d; import org.joml.Vector3d;
import org.joml.Vector3i; import org.joml.Vector3i;
import electrosphere.collision.PhysicsEntityUtils;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.state.server.ServerCharacterData; import electrosphere.entity.state.server.ServerCharacterData;
@ -59,6 +60,8 @@ public class PlayerCharacterCreation {
//must come after the player is assigned, otherwise the player will not get the item attachment messages //must come after the player is assigned, otherwise the player will not get the item attachment messages
CreatureUtils.serverApplyTemplate(realm, newPlayerEntity, template); CreatureUtils.serverApplyTemplate(realm, newPlayerEntity, template);
PhysicsEntityUtils.disableBody(realm.getCollisionEngine(), newPlayerEntity);
//if macro data hasn't been generated in this area, generate it //if macro data hasn't been generated in this area, generate it
//but only if it's a player's entity //but only if it's a player's entity
realm.updateMacroData(spawnPoint); realm.updateMacroData(spawnPoint);