Model With Many Meshs Disregards Bones

Discuss any questions about BEPUphysics or problems encountered.
jstroh
Posts: 37
Joined: Fri May 02, 2008 9:33 am

Model With Many Meshs Disregards Bones

Post by jstroh »

So I have this model.

It has 222 meshes.

Each mesh without it's bone world transfer applied is sideways at 0,0,0

Collision works great buuuut I need to transform things within the physics simulation.

Sooo how do I tell "Space" to transform all the meshes in the model when I create the triangle collision thinga?

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

Re: Model With Many Meshs Disregards Bones

Post by Norbo »

Are you using v0.5.1's initializeData(Model model) method? If so, it should take into account the mesh's parent bones unless I managed to upload the wrong files or something equally strange. If you're using initializeData(ModelMesh collisionModelMesh, bool useBoneTransform), then you can specify whether or not you want the transform to be used for a specific mesh. Calling this many times on the same group, however, would continually overwrite its previous data with the new mesh's information. You can also fiddle with the group's worldMatrix to transform everything in it at once.

If all else fails, you can compile the index and vertex buffers 'manually' and give the StaticTriangleGroup data directly with initializeData(List<StaticTriangleGroupVertex> triangleVertices, List<int> triangleIndices) and such.
jstroh
Posts: 37
Joined: Fri May 02, 2008 9:33 am

Re: Model With Many Meshs Disregards Bones

Post by jstroh »

Yeah I tried just passing in the Model first and when that didn't work I tried passing in each sub mesh and using the bone flag but that did the same thing. If I apply the bone transforms and assign them to the effect for the mesh in the draw loop it all displays fine so I don't think it's my model.

I suppose I could do the whole static compiled route but that means I have to relearn all the underlying directx I've forgotten and that's no fun! lmao

EDIT:

List<StaticTriangleGroupVertex> triangleVertices, List<int> triangleIndices

So to get that from Mesh I just grab the vertex buffer and the index buffer and pretty much copy things over. Well just the verts from the vertex buffer. Right? And then apply the bone transform to all the verts before sending it along to initializeData?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Model With Many Meshs Disregards Bones

Post by Norbo »

Yeah, and you can use the initializeData that takes in just a vertices list if you want to use the index buffer/vertex buffer of the model to create a long triangle list with no associated index buffer. It'll create the indices for you.

Is there any chance I could get a copy of a model/source that causes the issue for reproduction purposes? So far I haven't been able to replicate the issue.
jstroh
Posts: 37
Joined: Fri May 02, 2008 9:33 am

Re: Model With Many Meshs Disregards Bones

Post by jstroh »

It's a commercial model so I can't. But I ripped out the vertices and transformed them and it works great!

<3 this engine, it's so easy to set up.

3.4k triangles isn't speedy though ;o

Thanks for your help!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Model With Many Meshs Disregards Bones

Post by Norbo »

Glad you got it working, thanks for trying it out!

About the performance though, I've tested it with 320,000 triangles without noticable performance loss on my desktop (though I haven't tried that specific test on the Xbox360), and the default model used in the demos with over 5000 triangles works quickly on all platforms I've tested on (including Xbox and a 1.6ghz laptop). Is it possible that the things the group interacts with are large compared to triangles in the group? This would mean that there are many collisions that need to be handled, which overrides the cost of the StaticTriangleGroup by a large margin. The main usage for static triangle mesh is as a sub-graphics detail collision mesh, which usually means one object is rarely hitting more than a few simulated triangles at once.

Technically speaking, the time it takes to find the right triangle grows slowly (logarithmically)- going from 1,000 triangles to 1,000,000 triangles is only about twice as expensive. It's very small compared to the subsequent collision detection and response that must be done.

The only other thing that I could think of would be graphics causing the slowdown; if you're using something similar to the drawing method used in the DisplayModel, it calls draw once for every mesh in the model. I don't think 200 draw calls in a vacuum would be enough to cause significant slowdowns, but it doesn't leave much room for other things.


I also have yet to duplicate the transform bug. It doesn't seem to be stress related, since 383 separate meshes in a model worked. A separate reproduction case, if possible, or additional information about how the group was setup would be helpful for tracking down the problem.
jstroh
Posts: 37
Joined: Fri May 02, 2008 9:33 am

Re: Model With Many Meshs Disregards Bones

Post by jstroh »

What's your e-mail I'll send you the model.
jstroh
Posts: 37
Joined: Fri May 02, 2008 9:33 am

Re: Model With Many Meshs Disregards Bones

Post by jstroh »

Also at times I get a "function does not accept Not-A-Number" for Math.Sin

The slowdown happens when I send in this model and drop say like 5+ blocks from the static triangle demo code. Slowdown of course happens when they hit the ground.

EDIT:

When it's just the ground polys of the model I can do like 100+ without slowdown.
jstroh
Posts: 37
Joined: Fri May 02, 2008 9:33 am

Re: Model With Many Meshs Disregards Bones

Post by jstroh »

How would I go about doing a ray statictrianglegroup intersection so I can lock my player to the ground?

Or is there a better way to go about this?

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

Re: Model With Many Meshs Disregards Bones

Post by Norbo »

You can send it to norbo@bepuentertainment.com.

What is the Math.Sin involved in that is causing the NaN exception? Is it one of the calls in the demo you're talking about, or is based on data from the group or something along those lines? I'm beginning to wonder if there's actually something inherent to the model that the engine doesn't like; it would explain why I am unable to replicate it and could explain the slowdowns. It might even explain the NaN error you get, if that was even related. A few thousand triangles with 5+ blocks should be perfectly fine performance wise under normal conditions, unless each block is hitting many dozens of triangles at once. I'll see if I can figure anything out with the model you send.

As for locking to the ground, using a ray would be fine. If you only want to consider the group for 'support,' you can just use the StaticTriangleGroup.rayCast method. There's also a Space.rayCast and other methods. I explained some character-related things in this thread: http://www.bepu-games.com/forums/viewto ... ?f=4&t=317

The simplest way would be just finding the ray intersection and putting your camera/character offset from it a bit. If you want a more proper character, you could tweak it a bit to test just a little below the character to find supports, add gravity and such and so forth. The DynamicCharacterController is a.. fairly complicated demo of where you could go with it (though many games use nondynamic controllers, and I will be adding a demo for that in the next version or two).
jstroh
Posts: 37
Joined: Fri May 02, 2008 9:33 am

Re: Model With Many Meshs Disregards Bones

Post by jstroh »

Yeah I'm guessing the model is screwing up. I'm thinking of modelling a collision mesh of my own and rendering the original.

Yeah I was about to go through and learn your Dynamic stuff but it was involved and I was sick of looking at code all week at the day job lol.

Ahhhh Raycast into the space <3!

I really love the engine and hopefully I'll be licensing it from you in the coming months ;o

Thanks for all your help!

Sending that model along right now.
jstroh
Posts: 37
Joined: Fri May 02, 2008 9:33 am

Re: Model With Many Meshs Disregards Bones

Post by jstroh »

Also is there any way to draw a wireframe or any visualization of a statictrianglegroup?
jstroh
Posts: 37
Joined: Fri May 02, 2008 9:33 am

Re: Model With Many Meshs Disregards Bones

Post by jstroh »

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

Re: Model With Many Meshs Disregards Bones

Post by Norbo »

Alright, I figured out the issue with the model. The transform matrices used by the group are obtained by using mesh.ParentBone.Transform; this model has identity matrices for all meshes. Grabbing all of the transforms from the Model instead references them appropriately. This is because the mesh.ParentBone.Transform is its relative transform, and doesn't represent all the transformations applied to the mesh. The fix for this will either be in a v0.5.2 or v0.6.0, depending on if I find other bugs.

The question is, even after 'fixing' the problem, I still notice some issues. In many parts of the model, there isn't any lag associated with throwing boxes and driving around, while in some areas there seem to be unrendered triangles that overlap with each other severely, to the point where there are 300 collision pairs with a single ball rolling around. In other areas, the graphical representation is correct, but there seems to be no associated collision mesh (such as the grassy areas on the edges). This implies some transforms are still off, so I'll continue to investigate.

Another source of slowdowns you might be experiencing is that associated with the system trying to deal with very large triangles; collision detection between objects of vastly different sizes and of extreme shape (very long and thin, for example) makes things difficult for the detection system. While I can alleviate this to some degree (special case collision detection in v0.6.0 that doesn't use GJK and other miscellaneous optimizations), it's best to keep things on a slightly more regular scale, even if it means triangulating the collision mesh more than would otherwise be necessary. I haven't seen any issues with 10:1 or 20:1 (you could probably get by with higher than that too), so that would be 'safe.'

After profiling some other tests, I have found that in the last version when I implemented collision groups, the order in which collision pairs are validated was improperly fiddled with. This caused bounding box checks to come first, adding a significant chunk to the computational cost of the persistent uniform grid when very large (relative to grid cell size) shapes are present. Luckily, the solution to this is the same as the previous; keeping entities to a more regular size will help prevent extra cells. In the end, despite having quite a few more triangles overall in the mesh, it should run faster. Right now, between this problem and others, it's probable that I'll need to release a v0.5.2. Once the issue is fixed, the extra triangles added will not be a problem (and in fact will still help with collision detection), so you won't need to redo any work.




Doing a little more research, I believe the reason for some difficulties is that it's not quite as simple to extract all the information from a model as previously thought. There's some details on the creator's clubs forums and such, but it basically comes down to it being easier to write a custom content processor to get this sort of data rather than trying to extract it from a Model/ModelMesh at runtime. Chances are you ran into the same problems as I did manually extracting the data, which seems to get it at least partially 'wrong,' I.E. I didn't take everything into account. It could be coincidence that I haven't encountered problems yet, but I have had more luck with importing the .fbx format.
jstroh
Posts: 37
Joined: Fri May 02, 2008 9:33 am

Re: Model With Many Meshs Disregards Bones

Post by jstroh »

Nice analysis!

I have the original of the file if you'd like I can send it to you for export from a different program into fbx.

Would it be possible to detect the overlapping problematic triangles so that they could be edited out in a modelling program?
Post Reply