fix upright tree
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-05-28 13:39:03 -04:00
parent 27f9cc4771
commit c32263675a
6 changed files with 75 additions and 29 deletions

View File

@ -2020,6 +2020,7 @@ Properly show loading state when waiting on character list
Fix standard uniform buffer interaction with actor panel Fix standard uniform buffer interaction with actor panel
Fix foundation generation for structures in chunkgen Fix foundation generation for structures in chunkgen
Body synchronization includes enabled state Body synchronization includes enabled state
Fix upright tree continuously re-enabling bodies

View File

@ -440,31 +440,46 @@ public class CollisionEngine {
try { try {
//null out the contact buffer //null out the contact buffer
contacts.nullify(); contacts.nullify();
SurfaceParams surfaceParams = c1.getSurfaceParams(); SurfaceParams surfaceParams1 = c1.getSurfaceParams();
SurfaceParams surfaceParams2 = c2.getSurfaceParams();
for (int i=0; i<MAX_CONTACTS; i++) { for (int i=0; i<MAX_CONTACTS; i++) {
DContact contact = contacts.get(i); DContact contact = contacts.get(i);
contact.surface.mode = surfaceParams.getMode(); contact.surface.mode = surfaceParams1.getMode();
contact.surface.mu = surfaceParams.getMu(); contact.surface.mu = surfaceParams1.getMu();
if(surfaceParams.getRho() != null){ if(surfaceParams1.getRho() != null){
contact.surface.rho = surfaceParams.getRho(); contact.surface.rho = surfaceParams1.getRho();
} else if(surfaceParams2.getRho() != null){
contact.surface.rho = surfaceParams2.getRho();
} }
if(surfaceParams.getRho2() != null){ if(surfaceParams1.getRho2() != null){
contact.surface.rho2 = surfaceParams.getRho2(); contact.surface.rho2 = surfaceParams1.getRho2();
} else if(surfaceParams2.getRho2() != null){
contact.surface.rho = surfaceParams2.getRho2();
} }
if(surfaceParams.getRhoN() != null){ if(surfaceParams1.getRhoN() != null){
contact.surface.rhoN = surfaceParams.getRhoN(); contact.surface.rhoN = surfaceParams1.getRhoN();
} else if(surfaceParams2.getRhoN() != null){
contact.surface.rho = surfaceParams2.getRhoN();
} }
if(surfaceParams.getBounce() != null){ if(surfaceParams1.getBounce() != null){
contact.surface.bounce = surfaceParams.getBounce(); contact.surface.bounce = surfaceParams1.getBounce();
} else if(surfaceParams2.getBounce() != null){
contact.surface.rho = surfaceParams2.getBounce();
} }
if(surfaceParams.getBounceVel() != null){ if(surfaceParams1.getBounceVel() != null){
contact.surface.bounce_vel = surfaceParams.getBounceVel(); contact.surface.bounce_vel = surfaceParams1.getBounceVel();
} else if(surfaceParams2.getBounceVel() != null){
contact.surface.rho = surfaceParams2.getBounceVel();
} }
if(surfaceParams.getSoftErp() != null){ if(surfaceParams1.getSoftErp() != null){
contact.surface.soft_erp = surfaceParams.getSoftErp(); contact.surface.soft_erp = surfaceParams1.getSoftErp();
} else if(surfaceParams2.getSoftErp() != null){
contact.surface.rho = surfaceParams2.getSoftErp();
} }
if(surfaceParams.getSoftCfm() != null){ if(surfaceParams1.getSoftCfm() != null){
contact.surface.soft_cfm = surfaceParams.getSoftCfm(); contact.surface.soft_cfm = surfaceParams1.getSoftCfm();
} else if(surfaceParams2.getSoftCfm() != null){
contact.surface.rho = surfaceParams2.getSoftCfm();
} }
} }
//calculate collisions //calculate collisions
@ -1276,7 +1291,7 @@ public class CollisionEngine {
protected void setAutoDisableFlags(DBody body, boolean autoDisable, double linearThreshold, double angularThreshold, int steps){ protected void setAutoDisableFlags(DBody body, boolean autoDisable, double linearThreshold, double angularThreshold, int steps){
spaceLock.lock(); spaceLock.lock();
body.setAutoDisableFlag(autoDisable); body.setAutoDisableFlag(autoDisable);
body.setAutoDisableLinearThreshold(0.1); body.setAutoDisableLinearThreshold(linearThreshold);
body.setAutoDisableAngularThreshold(angularThreshold); body.setAutoDisableAngularThreshold(angularThreshold);
body.setAutoDisableSteps(steps); body.setAutoDisableSteps(steps);
spaceLock.unlock(); spaceLock.unlock();
@ -1319,6 +1334,29 @@ public class CollisionEngine {
* @param enabled Whether the body is enabled or not -- true to enable, false to disable * @param enabled Whether the body is enabled or not -- true to enable, false to disable
*/ */
protected void synchronizeData(DBody body, Vector3d position, Quaterniond rotation, Vector3d linearVel, Vector3d angularVel, Vector3d linearForce, Vector3d angularForce, boolean enabled){ protected void synchronizeData(DBody body, Vector3d position, Quaterniond rotation, Vector3d linearVel, Vector3d angularVel, Vector3d linearForce, Vector3d angularForce, boolean enabled){
if(body != null){
spaceLock.lock();
this.synchronizeData(body, position, rotation, linearVel, angularVel, linearForce, angularForce);
if(enabled){
body.enable();
} else {
body.disable();
}
spaceLock.unlock();
}
}
/**
* Synchronizes the data on a body
* @param body The body
* @param position The position
* @param rotation The rotation
* @param linearVel The linear velocity
* @param angularVel The angular velocity
* @param linearForce The linear force
* @param angularForce The angular force
*/
protected void synchronizeData(DBody body, Vector3d position, Quaterniond rotation, Vector3d linearVel, Vector3d angularVel, Vector3d linearForce, Vector3d angularForce){
if(body != null){ if(body != null){
spaceLock.lock(); spaceLock.lock();
body.setPosition(position.x - this.floatingOrigin.x, position.y - this.floatingOrigin.y, position.z - this.floatingOrigin.z); body.setPosition(position.x - this.floatingOrigin.x, position.y - this.floatingOrigin.y, position.z - this.floatingOrigin.z);
@ -1327,11 +1365,6 @@ public class CollisionEngine {
body.setAngularVel(PhysicsUtils.jomlVecToOdeVec(angularVel)); body.setAngularVel(PhysicsUtils.jomlVecToOdeVec(angularVel));
body.setForce(PhysicsUtils.jomlVecToOdeVec(linearForce)); body.setForce(PhysicsUtils.jomlVecToOdeVec(linearForce));
body.setTorque(PhysicsUtils.jomlVecToOdeVec(angularForce)); body.setTorque(PhysicsUtils.jomlVecToOdeVec(angularForce));
if(enabled){
body.enable();
} else {
body.disable();
}
spaceLock.unlock(); spaceLock.unlock();
} }
} }

View File

@ -35,12 +35,12 @@ public class PhysicsEntityUtils {
/** /**
* The linear velocity threshold to disable under * The linear velocity threshold to disable under
*/ */
static final double LINEAR_THRESHOLD = 0.1; static final double LINEAR_THRESHOLD = 3;
/** /**
* The angular velocity threshold to disable under * The angular velocity threshold to disable under
*/ */
static final double ANGULAR_THRESHOLD = 0.1; static final double ANGULAR_THRESHOLD = 3;
/** /**
* The number of steps below threshold to disable after * The number of steps below threshold to disable after

View File

@ -122,6 +122,20 @@ public class PhysicsUtils {
collisionEngine.synchronizeData(body, position, rotation, linearVel, angularVel, linearForce, angularForce, enabled); collisionEngine.synchronizeData(body, position, rotation, linearVel, angularVel, linearForce, angularForce, enabled);
} }
/**
* Synchronizes the data on a body
* @param body The body
* @param position The position
* @param rotation The rotation
* @param linearVel The linear velocity
* @param angularVel The angular velocity
* @param linearForce The linear force
* @param angularForce The angular force
*/
public static void synchronizeData(CollisionEngine collisionEngine, DBody body, Vector3d position, Quaterniond rotation, Vector3d linearVel, Vector3d angularVel, Vector3d linearForce, Vector3d angularForce){
collisionEngine.synchronizeData(body, position, rotation, linearVel, angularVel, linearForce, angularForce);
}
/** /**
* Sets the position + rotation + scale of a body * Sets the position + rotation + scale of a body

View File

@ -37,14 +37,13 @@ public class ClientAlwaysUprightTree implements BehaviorTree {
Vector3d angularVelocity = new Vector3d(); Vector3d angularVelocity = new Vector3d();
Vector3d linearForce = PhysicsUtils.odeVecToJomlVec(body.getForce()); Vector3d linearForce = PhysicsUtils.odeVecToJomlVec(body.getForce());
Vector3d angularForce = new Vector3d(); Vector3d angularForce = new Vector3d();
boolean enabled = body.isEnabled();
//make sure rotation is vertical //make sure rotation is vertical
// sourceRotation = sourceRotation.mul(0.001, 1, 0.001, 1).normalize(); // sourceRotation = sourceRotation.mul(0.001, 1, 0.001, 1).normalize();
EntityUtils.getPosition(parent).set(position); EntityUtils.getPosition(parent).set(position);
EntityUtils.getRotation(parent).set(sourceRotation); EntityUtils.getRotation(parent).set(sourceRotation);
PhysicsUtils.synchronizeData(Globals.clientState.clientSceneWrapper.getCollisionEngine(), body, position, sourceRotation, linearVelocity, angularVelocity, linearForce, angularForce, enabled); PhysicsUtils.synchronizeData(Globals.clientState.clientSceneWrapper.getCollisionEngine(), body, position, sourceRotation, linearVelocity, angularVelocity, linearForce, angularForce);
} }
} }

View File

@ -42,7 +42,6 @@ public class ServerAlwaysUprightTree implements BehaviorTree {
Vector3d angularVelocity = new Vector3d(); Vector3d angularVelocity = new Vector3d();
Vector3d linearForce = PhysicsUtils.odeVecToJomlVec(body.getForce()); Vector3d linearForce = PhysicsUtils.odeVecToJomlVec(body.getForce());
Vector3d angularForce = new Vector3d(); Vector3d angularForce = new Vector3d();
boolean enabled = body.isEnabled();
//make sure rotation is vertical //make sure rotation is vertical
// sourceRotation = sourceRotation.mul(0.001, 0.001, 0.001, 1).normalize(); // sourceRotation = sourceRotation.mul(0.001, 0.001, 0.001, 1).normalize();
@ -54,7 +53,7 @@ public class ServerAlwaysUprightTree implements BehaviorTree {
EntityUtils.getPosition(parent).set(position); EntityUtils.getPosition(parent).set(position);
EntityUtils.getRotation(parent).set(sourceRotation); EntityUtils.getRotation(parent).set(sourceRotation);
PhysicsUtils.synchronizeData(realm.getCollisionEngine(), body, position, sourceRotation, linearVelocity, angularVelocity, linearForce, angularForce, enabled); PhysicsUtils.synchronizeData(realm.getCollisionEngine(), body, position, sourceRotation, linearVelocity, angularVelocity, linearForce, angularForce);
} }
} }