Saving and loading collisionshapes in BulletSharp

michaelryangreer
Posts: 1
Joined: Wed Aug 10, 2022 4:14 pm

Saving and loading collisionshapes in BulletSharp

Post by michaelryangreer »

Hey all, I know BulletSharp isn't officially supported by this forum but I figured I would post here to try and get some help. I'm trying to figure out the simplest way to save and load a ConvexHullShape in BulletSharp. Here's my current code for saving:

Code: Select all

	    DefaultSerializer serializer = new DefaultSerializer();
            serializer.StartSerialization();

            convexShape.SerializeSingleShape(serializer);

            serializer.FinishSerialization();

            byte[] data = new byte[serializer.CurrentBufferSize];

            System.Runtime.InteropServices.Marshal.Copy(serializer.BufferPointer, data, 0, data.Length);

            using (var file = new System.IO.FileStream(path, System.IO.FileMode.Create))
            {
                file.Write(data, 0, data.Length);
            }
And for loading:

Code: Select all

	    BulletWorldImporter loader = new BulletWorldImporter();

            if (loader.LoadFile(path))
            {
                int numShape = loader.NumCollisionShapes;
                Console.WriteLine(numShape);
                if (numShape > 0)
                {
                    return new (ConvexHullShape)loader.GetCollisionShapeByIndex(0);
                }
            }
When this runs, it is able to save but when I try to load it prints out an error: Failed to find DNA1+SDNA pair.

Any tips on what the error means or how I could resolve it would be really appreciated!