Copy / Clone an entity

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
ThatsAMorais
Posts: 18
Joined: Mon Oct 05, 2009 5:24 am

Copy / Clone an entity

Post by ThatsAMorais »

I'm having a problem with loading time on a couple of my models. Not all of them take this long; just the d6 models that I've noticed are quite high in their number of points. As a result, I was trying to find ways to copy my convexhull sub-classed objects once I had created them one time. I tried ICloneable but it behaved quite strangely. Though I'm pretty comfortable learning new languages, I'm kinda new to C# and there are some aspects I haven't quite traversed yet. Do you know how best this can be accomplished for your classes?

I did some research last night and found that I can make my own clone functions where I'd copy entity members to a new instance and return the new one, but this is problematic when there isn't an empty ConvexHull constructor with empty members. Honestly, that doesn't really bother me because I'd rather have a memcpy-type solution.


I also tried Serializing/Deserializing my entity but visual studio informed me that some of the members could not be serialized.
An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll
Additional information: Type 'DiceRoller.Dice.DieBase' in Assembly 'DiceRoller, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
...for the following code...

Code: Select all

        public object Clone()
        {
            
            System.IO.MemoryStream m = new System.IO.MemoryStream();
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter b =
                new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            b.Serialize(m, this);
            m.Position = 0;
            return b.Deserialize(m);
            //return (object)MemberwiseClone();
        }
Any help would be money. thanks

--Alex
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Copy / Clone an entity

Post by Norbo »

One of the easier approaches would be to save the already convex-hulled list (using getConvexHull) and use it to create new convex hulls. If there's still loading problems with that number of points, then it's likely that the complexity of the convex hull will cause run-time inefficiencies too. It's generally a good idea to minimize the number of points being used to represent the shape, since the core of the collision detection system (the getExtremePoint function) scales linearly with the number of vertices for convex hulls.
ThatsAMorais
Posts: 18
Joined: Mon Oct 05, 2009 5:24 am

Re: Copy / Clone an entity

Post by ThatsAMorais »

Ok, that sounds like a decent option. I thought you might have something in there to export the base class. Thanks!

--Alex
Post Reply