StaticTriangleGroup without model and device

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
J2T
Posts: 48
Joined: Sat Sep 20, 2008 6:20 pm
Contact:

StaticTriangleGroup without model and device

Post by J2T »

Hi Norbo,

is there any way to load a StaticTriangleGroup without a xna model?

The situation is that i'm actually writing a deticated server for our game. In this case we have some items the player have to collect. These items falls from sky to the playground (StaticTriangleGroup). At the moment they fall through the ground (client view). Just normal because i cant load the StaticTriangleGroup because i need a graphics device for loading the model. On the server isn't as normal a graphics device. Do you know a way how i can make this possible?May a method i don't find where i can give BEPU the vertices and indices for my self?Maybe the method used until v0.8 of BEPU with the VerticesExtractionPipeline (with the TagData). But i can't compile the old code because StaticTriangleGroupVertex doesn't exist anymore. Furthermore i can't believe that this can work because it was just a custom content processor. So the code behind should also need a graphics device.

So finally, do you have a idea?

thanks and regards,
j2t
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: StaticTriangleGroup without model and device

Post by Norbo »

Yes; the StaticTriangleGroup constructor takes a TriangleMesh whose vertices are of type StaticTriangleGroupVertex (it still exists; BEPUphysics.StaticTriangleGroup.StaticTriangleGroupVertex). If you have a vertex list and index list, you can use these to create a TriangleMesh with or without an XNA model or the getVerticesAndIndicesFromModel method.

The TriangleMesh class also supports static save/load methods. If you can save the mesh once, you can load it in later without going through the content pipeline. Alternatively, you could just manually save out the vertex/index data, load it in later, and then create the TriangleMesh.
J2T
Posts: 48
Joined: Sat Sep 20, 2008 6:20 pm
Contact:

Re: StaticTriangleGroup without model and device

Post by J2T »

Sry yes for sure StaticTriangleGroupVertex still exists. I just uncommented my old code snipplet without doing research in object browser :roll:

Furthermore i noticed the save/load funtions in the changesnotes from v0.9.0 then. Now i ask my self why i dont remember yesterday :( btw a cool feature at all :D

But anyway no need in my case anymore because its possible to load content with a NULL device (DeviceType.NullReference) as i found out today.

Thanks,
J2T
J2T
Posts: 48
Joined: Sat Sep 20, 2008 6:20 pm
Contact:

Re: StaticTriangleGroup without model and device

Post by J2T »

Hi again,

after all i decide to take the save/load methods. In this way i don't need the model (with the textures) so the deticated becomes more lightweight.

The save method with a string works well. The problem is that loading result in ArgumentNullException (see screenshot). Happens when loading with string and with stream. Using this for stream loading but do not know if this is even correct:

Code: Select all

using (StreamReader sr = new StreamReader("lumberjacks_hood_physics"))
 {
         group = new StaticTriangleGroup(TriangleMesh.load((sr.BaseStream)));
  }
btw saving with the streamwriter also succeed like with string:

Code: Select all

 using (StreamWriter sr = new StreamWriter("lumberjacks_hood_physics"))
 {
        TriangleMesh.save(mesh, sr.BaseStream);
 }
Norbo, what i'm doing wrong? :)

edit: also tried with a FileStream which returns the same result...

bests,
j2t
Attachments
exception.JPG
exception.JPG (109.82 KiB) Viewed 4246 times
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: StaticTriangleGroup without model and device

Post by Norbo »

It looks like there is a bug with the load where a locker object (added in v0.10.0) isn't set before the hierarchy is reconstructed. It has been fixed for the next version. In the mean time, serializing out a array of StaticTriangleGroupVertex and indices and loading those in should work.
Post Reply