Improve compound serialization (#183)

- no more pointer fixups
- reduced storage 20% by removing leaf proxies
This commit is contained in:
Erin Catto 2026-10-07 14:48:58 -07:00 • committed by GitHub
commit 5d83df83ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 845 additions and 376 deletions

View file

@ -1001,6 +1001,9 @@ B3_API b3Mesh b3Shape_GetMesh( b3ShapeId shapeId );
/// Get the shape's height field. Asserts the type is correct.
B3_API const b3HeightFieldData* b3Shape_GetHeightField( b3ShapeId shapeId );
/// Get the shape's compound. Asserts the type is correct.
B3_API const b3CompoundData* b3Shape_GetCompound( b3ShapeId shapeId );
/// Allows you to change a shape to be a sphere or update the current sphere.
/// This does not modify the mass properties.
/// @see b3Body_ApplyMassFromShapes

View file

@ -468,13 +468,8 @@ B3_API b3CompoundData* b3CreateCompound( const b3CompoundDef* def );
/// Destroy a compound shape.
B3_API void b3DestroyCompound( b3CompoundData* compound );
/// Cast the provided compound data to bytes, setting the internal pointers to null.
/// Use this before serializing the compound bytes.
B3_API uint8_t* b3ConvertCompoundToBytes( b3CompoundData* compound );
/// Cast the provided bytes to compound data, setting up internal pointers.
/// Use this after de-serializing the compound bytes.
B3_API b3CompoundData* b3ConvertBytesToCompound( uint8_t* bytes, int byteCount );
// Cast serialized bytes into a compound and validate. Returns null if invalid.
B3_API const b3CompoundData* b3ValidateCompound( const uint8_t* bytes, int byteCount );
/**@}*/ // compound

View file

@ -2487,8 +2487,8 @@ typedef struct b3CompoundDef
int sphereCount;
} b3CompoundDef;
/// The baked compound version depends on the tree, mesh, and hull versions.
#define B3_COMPOUND_VERSION ( 0x7A2F41C9E6D0B358ull ^ B3_DYNAMIC_TREE_VERSION ^ B3_MESH_VERSION ^ B3_HULL_VERSION )
/// The baked compound version depends on the mesh and hull versions.
#define B3_COMPOUND_VERSION ( 0x9E4B17D3A25C68F1ull ^ B3_MESH_VERSION ^ B3_HULL_VERSION )
/// The data for a baked compound shape. This is a potentially large yet highly optimized
/// data structure. It can contain thousands of child shapes, yet at runtime it populates
@ -2505,15 +2505,17 @@ typedef struct b3CompoundData
/// The total number of bytes for this compound.
int byteCount;
// Bounds of the tree.
b3AABB bounds;
// Tree height for diagnostics.
int treeHeight;
/// Offset of the tree node array in bytes from the struct address.
int nodeOffset;
/// Offset of the tree proxy array in bytes from the struct address.
int proxyOffset;
/// Immutable dynamic tree. The node and proxy pointers must be fixed up using the offsets
/// above. A baked tree is never inserted into, so the parent array stays null.
b3DynamicTree tree;
// The number of tree nodes.
int nodeCount;
/// Offset of the material array in bytes from the struct address.
int materialOffset;