Make Entity empty constructor public

Post and discuss features you'd like to see in the BEPUphysics library.
Post Reply
philippedasilva
Posts: 7
Joined: Tue May 18, 2010 9:43 pm

Make Entity empty constructor public

Post by philippedasilva » Fri May 21, 2010 3:59 pm

Hi Norbo,

I don't know if it would deeply go against your lib rules but if you could make the empty Entity constructor public instead it would help me (us?) a lot to do some special things such as creating/updating collision ConvexHulls, CompoundBodies and the like in an editor and save/load them using File I/O operations to improve loading performances for instance ;)

It would also allow us to create one Entity using the standard method, store it in a Static field or property and copy its values directly instead of computing them. Today, if I have a ShipEntity class holding a ConvexHull property, and if I want to create a scene with 100 of them, each initialization would take some time.
With such simple feature, I would simply create my first ConvexHull and create a new instance with it.

I don't know what it would take you to add this coding feature but that would be great at least for me :p

Otherwise, you could also provide something like:
public abstract class Entity
{
public ConvexHull(ConvexHull instance)
{
if(instance == null)
throw new ArgumentException("blabla");

// for each property/field that needs to be set, copy from instance :p
}
}

We would then be able to:

ConvexHull firstInstance = new ConvexHull(myVectorList, 10);
ConvexHull anotherInstance = new ConvexHull(firstInstance);

Norbo
Site Admin
Posts: 4558
Joined: Tue Jul 04, 2006 4:45 am

Re: Make Entity empty constructor public

Post by Norbo » Fri May 21, 2010 5:43 pm

I'm working on some plans for v0.13.0 that would introduce the concept of a CollisionShape.

All of the existing Entity types like Box, Sphere, and so on will still exist and will responsible for initializing the appropriate collision shape along with the Entity properties like density, volume, and inertia tensor.

The Entity class itself will gain a constructor that allows the user to specify the entity's collision shape and properties without creating a specific entity type. This can be used to quickly load in many 'heavy' shapes like ConvexHulls while only initializing them once.

The collision shapes used by entities will likely be a sublcass of CollisionShape called EntityCollisionShape. Other direct subclasses of CollisionShape will include triangle meshes/terrain to make them first-class members of the collision system while not letting them be used for Entities.

The CompoundBody will likely lose its Entity hierarchy in favor of a compound collision shape. There are a few questions that remain about dealing with events and providing some of the features that exist in the current CompoundBody that would be lost.

philippedasilva
Posts: 7
Joined: Tue May 18, 2010 9:43 pm

Re: Make Entity empty constructor public

Post by philippedasilva » Fri May 21, 2010 8:42 pm

Great to hear that Norbo :)

Until then, I'll use a static property to hold the BodyPoints generated from the first instance and use them as the constructor argument.
Doing some StopWatch, I noticed that for my case, my spaceship mesh gets its ConvexHull mesh created in 235ms and reusing the BodyPoints in new instances, it drops to 34ms which is better but could be better just copying values only.

Expanding in your direction, could I suggest that you use some Structs instead of classes for such feature as they will be passed by value instead of reference and would therefore be serializable too quite easily ;)

Thanks

Philippe

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest