Loading Static Meshes with there Physics and Textures

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
theneonirvana
Posts: 24
Joined: Wed Aug 17, 2011 9:20 pm

Loading Static Meshes with there Physics and Textures

Post by theneonirvana »

Hi there,

Ive been going through the demo alot and i have isolated alot of things, once thing i want to utalize is loading Static Meshes and having there physics space add and everything...

This is the original Code with just a tad of changes

Code: Select all

    //Load in mesh data for the environment.
                Vector3[] staticTriangleVertices;
                int[] staticTriangleIndices;


                var playgroundModel = Content.Load<Model>("CharacterControllerTestTerrain");
                //This load method wraps the TriangleMesh.GetVerticesAndIndicesFromModel method 
                //to output vertices of type StaticTriangleGroupVertex instead of TriangleMeshVertex or simply Vector3.
                BEPUphysics.DataStructures.TriangleMesh.GetVerticesAndIndicesFromModel(playgroundModel, out staticTriangleVertices, out staticTriangleIndices);
                var staticMesh = new BEPUphysics.Collidables.StaticMesh(staticTriangleVertices, staticTriangleIndices, new AffineTransform(new Vector3(.01f, .01f, .01f), Quaternion.Identity, new Vector3(0, 0, 0)));
                staticMesh.Sidedness = BEPUphysics.CollisionShapes.ConvexShapes.TriangleSidedness.Counterclockwise;

                this.PhysicsSpace.Add(staticMesh);
                this.BuildingDrawer.Add(staticMesh);


Now i have used this code and it is exactly the same except the model i am loading,

in my example the model loads with no errors and i can clearly tell that there is an invisable object in my realm

so i belive the object is loading just fine, however i cant see i add the object to the physics space and a physics drawer however it is still invisable...

I am using XSI mod tool to model and export as a FBX a house basicly... i thought maybe it was because i had no textures on the house so i created constant textures and created uv maps for them and loaded it and the model is still invisable, but clearly stops the character, (walls)

now, if i load the CharacterControllerTestTerrain into my project it all works fine....

So i was wondering what the steps are to create a model that will load properly? or am i missing somthing else?

Thanks again Norbo u have been awsome in the past!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Loading Static Meshes with there Physics and Textures

Post by Norbo »

The BEPUphysicsDrawer doesn't care about texture data or anything other than vertices and indices. As long as that data is valid, it should load fine. In other words, there aren't really any special steps to draw a mesh. If it has correct collision data, the BEPUphysicsDrawer will be able to draw a representation of it to match. So I'm not sure why it wouldn't show up.

Also, you can use any rendering system you'd like to draw. For example, you could use the simple XNA Model.Draw approach.

If you aren't using the BEPUphysicsDrawer, it may be culling related. Try reversing the winding of the mesh to see if that does anything (you'll need to flip the winding of the StaticMesh constructor to maintain the same collision too) or changing the cull mode itself. It could also be related to other renderstates, possibly from SpriteBatch interference. Here's a listing of the things SpriteBatch changes: http://blogs.msdn.com/b/shawnhar/archiv ... o-4-0.aspx


Merry Christmas!
theneonirvana
Posts: 24
Joined: Wed Aug 17, 2011 9:20 pm

Re: Loading Static Meshes with there Physics and Textures

Post by theneonirvana »

Thanks for the Reply Norbo...

So as a Test i have Started a New Scene in XSI and Created a box, Exported as FBX, recompiled and thrown into my application. and again nothing seems to show up.

I want to make a correction, without loading any static mesh i still get some invisible thing that is unrelated. so i do not believe that the static mesh is not drawing at all, and that these are 2 separate problems.

I figure a Cube will be easy for BEPU to do physics around and still i cannot see the item at all, nor am i able to run into it if its invisible some where.

Again if i simply switch the file name back to the CharacterControlledTerrain from the source it comes up fine.

In either example there are no exceptions tripped. Both Models actually load fine. However my simple Cube is not shown.

Im not entirely sure if what you call Collision Data is just the vertices of the model, if it is, this makes complete sense, but just to double check im not interpreting you incorrectly could Collission Data be some setting while modeling?

As a side note as well, Importing the CharacterTerrain from BEPU Source in XSI Crashes my XSI Mod tool :) Never had that happen... lol..

This is very similar problem to when i was doing Billboarding Foilage on a Model, and regardless of what i put the FoilageProcessorClass onto different models, it would only work properly on the one i got from the source example, i finally let it go because i couldn't reproduce the model properly, but i could isolate that the problem was with the .X file and how it was modeled.


Once again Norbo, Massive appreciation to your continuing effort to the Forums and its people :) Its nice to hear it sometimes :)

Merry Xmas!
Zack
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Loading Static Meshes with there Physics and Textures

Post by Norbo »

I want to make a correction, without loading any static mesh i still get some invisible thing that is unrelated.
That makes more sense- could the mesh just be extremely tiny? The mesh is being scaled by 1/100 in the previously posted code.
Im not entirely sure if what you call Collision Data is just the vertices of the model, if it is, this makes complete sense, but just to double check im not interpreting you incorrectly could Collission Data be some setting while modeling?
The collision data is just vertices and indices, so there's nothing special.

Keep in mind you can get the vertex and index data from anywhere. The extraction helper method is not the only way to do it.

Try checking the vertices and indices extracted by the helper method to ensure they match your expectations. If they are correct, then it's most likely the scale issue I mentioned above. If they're wrong, then something is going wrong in the export or import process- though what exactly I don't know.
Once again Norbo, Massive appreciation to your continuing effort to the Forums and its people Its nice to hear it sometimes

Merry Xmas!
Zack
Thanks :)
Post Reply