StaticTriangleGroup Question

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Oxgrim
Posts: 3
Joined: Tue Mar 17, 2009 10:50 pm

StaticTriangleGroup Question

Post by Oxgrim »

Hi,

You'll forgive me if I am beating a dead horse, but I've not been able to find an answer to my question on the forums (if it exists, I'd be quite satisfied with a link! :) ).
I'm very new to XNA, as well as Bepu, but I've been programming for sometime (not so long with C#, but it's coming fairly fast). My question is probably very basic, but the answer eludes me.

I'm trying to create an island that floats in the sky, and I'm trying to use the StaticTriangleGroup to create mesh collisions with objects thrown at it. I've taken a look at the available demo source code, but the Fish in a Barrel demo is using an older version of the StaticTriangleGroup class.

My code is as follows:

Code: Select all

StaticTriangleGroup group = new StaticTriangleGroup(1.0f, 1, 0, 0, .4f, 0);
Model skyland = Game.Content.Load<Model>("Models/island");

Box detector = new Box(Vector3.Zero, 1.5f, 1.5f, 1.5f);
detector.isDetector = true;
detector.tag = "noDisplayObject";

group.initializeData(skyland);
space.add(group);

entityRenderer.displayModels.Add(new DisplayModel(skyland, detector));
The arguments for the new StaticTriangleGroup was lifted from another post on the forum, and I'm not 100% on their use. The code compiles, and the island displays fine. However, when testing the collision mesh with a free falling box it doesn't work. The box passes right through the island. I'm obviously not doing something right. I noticed in another post that I would need to match the group's world matrix to that of the display model. If my model is at Vector3.Zero does this still matter?

Are there updated samples, or possibly tutorials online that I can browse? I've skimmed the XML, but it didn't help me much at my current skill level with Bepu. I'd be very appreciative for a quick sample.

Thanks!

**Edit: I've managed to get the box to not pass through the island, but it seems to be colliding with a box instead of the model's mesh. Is this a potential problem with the model itself, or am I still doing something wrong?
doggan
Posts: 20
Joined: Fri Jan 09, 2009 9:26 pm

Re: StaticTriangleGroup Question

Post by doggan »

It looks like you are using an older version of Bepu. In the latest version, 0.9.0, the StaticTriangleGroup constructor has been changed to accept a type of TriangleMesh. The latest demo shows this usage. In older versions of Bepu (0.8.0 and before), StaticTriangleGroup.initializeData was usually not the best way to go. There were a lot of models that caused problems for the initialization. The recommended way was to create a custom processor that stores the models' vertices/indices in the model's tag field, and then you initialize the StaticTriangleGroup with the version that takes an array of vertices/indices.

In 0.9.0, TriangleMesh.getVerticesAndIndicesFromModel has been improved (I have not personally tested it, though). So you could use this to get the verts/indices, create the TriangleMesh, then create the StaticTriangleGroup.

So you should either:
a). Upgrade to 0.9.0 and use a custom content processor (recommended).
b). Upgrade to 0.9.0 and use the improved TriangleMesh functions.
c). Stay at whichever version of Bepu you are using right now, and use a custom content processor.
Oxgrim
Posts: 3
Joined: Tue Mar 17, 2009 10:50 pm

Re: StaticTriangleGroup Question

Post by Oxgrim »

Thanks for the speedy reply!

I'll upgrade to the latest version of Bepu, as you suggest. I'm working on a project for a school program, and the Project Manager has given me several months of work to delve into. I haven't been given a lot of time to research, just code! :D

Thanks again! I'll post any progress I make, or problems I encounter.
Oxgrim
Posts: 3
Joined: Tue Mar 17, 2009 10:50 pm

Re: StaticTriangleGroup Question

Post by Oxgrim »

Thanks doggan!

After upgrading to the latest Bepu engine, I was able to make better use of the samples and got my island's collision mesh working! It didn't take too long to change the rest of the project to work with the latest version (mostly adding additional using statements).

For more information for others, the "Playground" demo was the most helpful for me.

Thanks again!
Genie
Posts: 4
Joined: Sat Apr 04, 2009 2:47 pm

Re: StaticTriangleGroup Question

Post by Genie »

hi! i have also one q regarding STG..

I am using it in the same way as in the last 0.9.0 example...

but my cube is falling through my terrain... (i have tested with plain box in place of terrain and then all works fine...)

so here is my usage of your code :)

Code: Select all

 //Load in mesh data and create the group.
            StaticTriangleGroup.StaticTriangleGroupVertex[] staticTriangleVertices;
            int[] staticTriangleIndices;

            //taking my Model from my pool of models
            Model myTerrain = (GEObjectManager.GetObject("testTerrain") as GEXSIObject).myModel;

            //This load method wraps the TriangleMesh.getVerticesAndIndicesFromModel method to output vertices 
            //of type StaticTriangleGroupVertex instead of TriangleMeshVertex or simply Vector3.
            StaticTriangleGroup.getVerticesAndIndicesFromModel(myTerrain, out staticTriangleVertices, out staticTriangleIndices);
            TriangleMesh mesh = new TriangleMesh(staticTriangleVertices, staticTriangleIndices, 0);
            StaticTriangleGroup group = new StaticTriangleGroup(mesh);
            
            //Modify the group's world matrix to rotate it around (or transform it in general). (also i was playing with this alot but still in vain...)
            group.worldMatrix =  Matrix.CreateTranslation( (GEObjectManager.GetObject("testTerrain") as GEXSIObject).Position);
            space.add(group);           

i debbuged it.. and it got all the vertices and stuff .. but .. not working :/.. my test box falls through ... did i forgot some tinnnny winnnnnie thinnnngie?

(half solved.. not working with XSI models...)
Last edited by Genie on Sat Apr 04, 2009 3:43 pm, edited 1 time in total.
Genie
Posts: 4
Joined: Sat Apr 04, 2009 2:47 pm

Re: StaticTriangleGroup Question

Post by Genie »

dang! it seems that I have a problem with XSI created objects.. when I tried the same with your FBX terrain playground model.. it worked... :oops:

uf... well.. it is not that a big of setback.. but.. maybe any idea why models created with XSI (XSI mod tool..) and saved in .xsi format + loaded in XNA with xsi content processor (but at the end saved as Model XNA object) won't work? Normals?
dweeb
Posts: 14
Joined: Tue Jul 15, 2008 11:17 pm

Re: StaticTriangleGroup Question

Post by dweeb »

When I was working on my own model instead of the one provided in the playground sample I noticed that the triangles in my own model was way to large compared with the rest of the objects. This causes boxes and such to fall through the terrain.

So check that your triangle size (in your terrain) is similar to the rest of your objects.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: StaticTriangleGroup Question

Post by Norbo »

In addition to the possible size/file type issues, it might be something to do with the vertex extraction method. Making a custom content processor and putting the vertex/index data into the model's tag may work better. v0.9.0 should have addressed most of the issues with the extraction method, but it's worth a shot.
Genie
Posts: 4
Joined: Sat Apr 04, 2009 2:47 pm

Re: StaticTriangleGroup Question

Post by Genie »

i managed to find this..

http://forums.xna.com/forums/p/15437/80869.aspx

it seems like a similar problem so ill try to play with it..
Genie
Posts: 4
Joined: Sat Apr 04, 2009 2:47 pm

Re: StaticTriangleGroup Question

Post by Genie »

dang now I am puzzled... I have done few tests...

if I use your playground FBX file as terrain - it works.
if I import your playground FBX file in XSI and save it as XSI asset (not fbx anymore)that I use as terrain - it works.
if I create cube, grid, whatever in XSI and save it as XSI or FBX asset that I use as terrain - it does not work.

So it seems to me that I need to pay attention how I create my terrain in modeling tool... Any suggestions maybe?

Edited....
HA! SOLVED!

Damn scaling in XNA is not applicable! If you (as I did) create not so big terrain and scale it, if your entity is not in contact with original size of you object then it is no go.... Well is that the way it should be?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: StaticTriangleGroup Question

Post by Norbo »

Are the rendered mesh and collision mesh of a different scale when you ran it? If so, are you using the default content processor and then using the getVerticesAndIndicesFromModel function to find collision mesh data? This method probably wouldn't find any somewhat 'nonstandard' data since its just grabbing information that is in the Model that XNA loads in (unless the processor baked in the transformation). If this is the problem, the solution is to either make a custom content processor that loads in the appropriate data or to bake the problematic transformation into the geometry so that the getVerticesAndIndicesFromModel method functions correctly.
Post Reply