body synchronization includes enabled state
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-05-28 13:22:50 -04:00
parent 091653756a
commit 27f9cc4771
10 changed files with 48 additions and 12 deletions

View File

@ -2019,6 +2019,7 @@ Fix texture map for lod human model
Properly show loading state when waiting on character list
Fix standard uniform buffer interaction with actor panel
Fix foundation generation for structures in chunkgen
Body synchronization includes enabled state

View File

@ -1316,8 +1316,9 @@ public class CollisionEngine {
* @param angularVel The angular velocity
* @param linearForce The linear force
* @param angularForce The angular force
* @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){
protected void synchronizeData(DBody body, Vector3d position, Quaterniond rotation, Vector3d linearVel, Vector3d angularVel, Vector3d linearForce, Vector3d angularForce, boolean enabled){
if(body != null){
spaceLock.lock();
body.setPosition(position.x - this.floatingOrigin.x, position.y - this.floatingOrigin.y, position.z - this.floatingOrigin.z);
@ -1326,6 +1327,11 @@ public class CollisionEngine {
body.setAngularVel(PhysicsUtils.jomlVecToOdeVec(angularVel));
body.setForce(PhysicsUtils.jomlVecToOdeVec(linearForce));
body.setTorque(PhysicsUtils.jomlVecToOdeVec(angularForce));
if(enabled){
body.enable();
} else {
body.disable();
}
spaceLock.unlock();
}
}

View File

@ -116,9 +116,10 @@ public class PhysicsUtils {
* @param angularVel The angular velocity
* @param linearForce The linear force
* @param angularForce The angular force
* @param enabled Whether the body is enabled or not -- true to enable, false to disable
*/
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);
public static void synchronizeData(CollisionEngine collisionEngine, DBody body, Vector3d position, Quaterniond rotation, Vector3d linearVel, Vector3d angularVel, Vector3d linearForce, Vector3d angularForce, boolean enabled){
collisionEngine.synchronizeData(body, position, rotation, linearVel, angularVel, linearForce, angularForce, enabled);
}

View File

@ -57,6 +57,7 @@ public class ClientPhysicsSyncTree implements BehaviorTree {
Vector3d angularVelocity = new Vector3d();
Vector3d linearForce = new Vector3d(latestMessage.getlinForceX(), latestMessage.getlinForceY(), latestMessage.getlinForceZ());
Vector3d angularForce = new Vector3d();
boolean enabled = latestMessage.getbodyEnabled();
DBody body = PhysicsEntityUtils.getDBody(parent);
//
@ -76,7 +77,7 @@ public class ClientPhysicsSyncTree implements BehaviorTree {
//Synchronize data
EntityUtils.getPosition(parent).set(position);
EntityUtils.getRotation(parent).set(rotationFromServer);
PhysicsUtils.synchronizeData(Globals.clientState.clientSceneWrapper.getCollisionEngine(), body, position, rotationFromServer, linearVelocity, angularVelocity, linearForce, angularForce);
PhysicsUtils.synchronizeData(Globals.clientState.clientSceneWrapper.getCollisionEngine(), body, position, rotationFromServer, linearVelocity, angularVelocity, linearForce, angularForce, enabled);
//
//update facing vector if relevant

View File

@ -77,7 +77,8 @@ public class ServerPhysicsSyncTree implements BehaviorTree {
linearForce.z,
angularForce.x,
angularForce.y,
angularForce.z
angularForce.z,
body.isEnabled()
)
);
}

View File

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

View File

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

View File

@ -64,6 +64,7 @@ public class EntityMessage extends NetworkMessage {
int targetID;
int bTreeID;
int propertyValueInt;
boolean bodyEnabled;
String interactionSignal;
/**
@ -562,6 +563,20 @@ public class EntityMessage extends NetworkMessage {
this.propertyValueInt = propertyValueInt;
}
/**
* Gets bodyEnabled
*/
public boolean getbodyEnabled() {
return bodyEnabled;
}
/**
* Sets bodyEnabled
*/
public void setbodyEnabled(boolean bodyEnabled) {
this.bodyEnabled = bodyEnabled;
}
/**
* Gets interactionSignal
*/
@ -876,7 +891,7 @@ public class EntityMessage extends NetworkMessage {
* Parses a message of type syncPhysics
*/
public static EntityMessage parsesyncPhysicsMessage(ByteBuffer byteBuffer, MessagePool pool, Map<Short,BiConsumer<NetworkMessage,ByteBuffer>> customParserMap){
if(byteBuffer.remaining() < 164){
if(byteBuffer.remaining() < 168){
return null;
}
EntityMessage rVal = (EntityMessage)pool.get(MessageType.ENTITY_MESSAGE);
@ -902,13 +917,14 @@ public class EntityMessage extends NetworkMessage {
rVal.setangForceX(byteBuffer.getDouble());
rVal.setangForceY(byteBuffer.getDouble());
rVal.setangForceZ(byteBuffer.getDouble());
rVal.setbodyEnabled(byteBuffer.get() == 1 ? true : false);
return rVal;
}
/**
* Constructs a message of type syncPhysics
*/
public static EntityMessage constructsyncPhysicsMessage(int entityID,long time,double positionX,double positionY,double positionZ,double rotationX,double rotationY,double rotationZ,double rotationW,double linVelX,double linVelY,double linVelZ,double angVelX,double angVelY,double angVelZ,double linForceX,double linForceY,double linForceZ,double angForceX,double angForceY,double angForceZ){
public static EntityMessage constructsyncPhysicsMessage(int entityID,long time,double positionX,double positionY,double positionZ,double rotationX,double rotationY,double rotationZ,double rotationW,double linVelX,double linVelY,double linVelZ,double angVelX,double angVelY,double angVelZ,double linForceX,double linForceY,double linForceZ,double angForceX,double angForceY,double angForceZ,boolean bodyEnabled){
EntityMessage rVal = new EntityMessage(EntityMessageType.SYNCPHYSICS);
rVal.setentityID(entityID);
rVal.settime(time);
@ -931,6 +947,7 @@ public class EntityMessage extends NetworkMessage {
rVal.setangForceX(angForceX);
rVal.setangForceY(angForceY);
rVal.setangForceZ(angForceZ);
rVal.setbodyEnabled(bodyEnabled);
return rVal;
}
@ -1240,7 +1257,7 @@ public class EntityMessage extends NetworkMessage {
}
break;
case SYNCPHYSICS:
rawBytes = new byte[2+4+8+8+8+8+8+8+8+8+8+8+8+8+8+8+8+8+8+8+8+8];
rawBytes = new byte[2+4+8+8+8+8+8+8+8+8+8+8+8+8+8+8+8+8+8+8+8+8+1];
//message header
rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY;
//entity messaage header
@ -1329,6 +1346,7 @@ public class EntityMessage extends NetworkMessage {
for(int i = 0; i < 8; i++){
rawBytes[158+i] = intValues[i];
}
rawBytes[166] = bodyEnabled ? (byte)1 : (byte)0;
break;
case INTERACT:
rawBytes = new byte[2+4+4+interactionSignal.length()];
@ -1533,6 +1551,7 @@ public class EntityMessage extends NetworkMessage {
ByteStreamUtils.writeDouble(stream, angForceX);
ByteStreamUtils.writeDouble(stream, angForceY);
ByteStreamUtils.writeDouble(stream, angForceZ);
stream.write(bodyEnabled ? (byte)1 : (byte)0);
} break;
case INTERACT: {

View File

@ -41,7 +41,7 @@ public class TypeBytes {
public static final byte ENTITY_MESSAGE_TYPE_DESTROY_SIZE = 6;
public static final byte ENTITY_MESSAGE_TYPE_SETPROPERTY_SIZE = 22;
public static final byte ENTITY_MESSAGE_TYPE_UPDATEENTITYVIEWDIR_SIZE = 34;
public static final short ENTITY_MESSAGE_TYPE_SYNCPHYSICS_SIZE = 166;
public static final short ENTITY_MESSAGE_TYPE_SYNCPHYSICS_SIZE = 167;
/*
Lore subcategories

View File

@ -141,6 +141,10 @@
"name" : "propertyValueInt",
"type" : "FIXED_INT"
},
{
"name" : "bodyEnabled",
"type" : "FIXED_BOOL"
},
{
"name" : "interactionSignal",
"type" : "VAR_STRING"
@ -272,7 +276,8 @@
"linForceZ",
"angForceX",
"angForceY",
"angForceZ"
"angForceZ",
"bodyEnabled"
]
},
{