NewtonCreateConvexHullModifier

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NewtonCreateConvexHullModifier

Postby skarab24 » Sun Jul 28, 2013 8:51 pm

Hello people,

First post here! (couldn't log cause of filled mailbox, now registration works)
I've integrated Newton Dynamics rigid bodies into my upcoming commercial game engine latest year.
Since I strongly require support for matrix skew/bend, that was the reason I chooses NewtonD I need to say,
I use NewtonCreateConvexHullModifier for each body.
With primitive tests, I'm happy with performances, but I wonder if its a bad method or not.
I may detect those cases as well, and use NewtonCreateConvexHullModifier only when required,
but this will imply to destroy/create the bodies which looks overkill.

Question: how much NewtonCreateConvexHullModifier affects performances when no non-uniform scaling is used ?
skarab24
 
Posts: 45
Joined: Sun Jul 28, 2013 8:33 pm

Re: NewtonCreateConvexHullModifier

Postby Julio Jerez » Sun Jul 28, 2013 9:47 pm

the proccees in not really a super overkill, but it is slow enought that if you want to be competitive with comecial engines you can no really suport general scaling using that General 4 x 4 matrices of scaleing.
The code requiries Gausss jordan a full matrix inversion, plus on every step in each operation you need to applity transforntion by three matrices intead of
two scale and one transformation if you settle for only scaling matrieces with no zero on teh diaginal.

The convex hull modifier can be added to core 300 as a new convex shape with has a child shape, and it will not change the engine at all.
This is nice exersize but I will have to have a good reason to spend time on it,
can you tell me what it is that you are doing that require this kind if matrices with skew and shear properties?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCreateConvexHullModifier

Postby skarab24 » Sun Jul 28, 2013 10:13 pm

Ok, looks nice for me then, I'm not looking for "uber perfs" for now, mostly for usability, will test it on bigger scenes later.
I've nearly no use cases for now, but having non-uniform scaling seems a strong requirement to me, since the editor provide it.
For example, in Unity, you easily get non-uniform scaling, then things get creepy...
Looks cool to be able to expand a full room on an axis, or be able to non-uniform scale some platforms...
If it comes a burn-down, I'll add a check-box on rigid-bodies to enable/disable that in editor, but I'll try to avoid it.
Thanks for your help !
skarab24
 
Posts: 45
Joined: Sun Jul 28, 2013 8:33 pm

Re: NewtonCreateConvexHullModifier

Postby Julio Jerez » Mon Jul 29, 2013 12:18 am

The engine does supports non uniform scaling.
when I asked what were you doing that you needed skew and shear matrices,
I was almost sure that what you really meat was non uniform scaling and the engine does fully supports that.

Like is said, try the demos and see if this is what you want, I am amost sure it is.
In almost 10 years I have never seen anyone that required those kind of matrices, for reason other than a cute demo.

are you using Newton with Unity?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCreateConvexHullModifier

Postby skarab24 » Mon Jul 29, 2013 9:08 am

I didn't saw that,
Julio Jerez wrote:The engine does supports non uniform scaling.
when I asked what were you doing that you needed skew and shear matrices,
I was almost sure that what you really meat was non uniform scaling and the engine does fully supports that.


Wow, the wiki is outdated then ?

http://newtondynamics.com/wiki/index.php5?title=NewtonBodySetMatrix : DO NOT use this function to scale objects, the result of scaling this way is undefined and unsupported. If you want to scale objects use NewtonCreateConvexHullModifier and NewtonConvexHullModifierSetMatrix.

http://newtondynamics.com/wiki/index.php5?title=NewtonCreateConvexHullModifier : Typical uses are non-uniform scaling

Note that in a tree hierarchy when a parent use non-uniform, rotated children will may be skewed,
I don't use Unity, I just tested this before choosing Newton.
Even if its not used, it looks like a defect (oh and I used non-uniform in a old demo but its not common lol).
skarab24
 
Posts: 45
Joined: Sun Jul 28, 2013 8:33 pm

Re: NewtonCreateConvexHullModifier

Postby Julio Jerez » Mon Jul 29, 2013 9:15 am

the function for setting the scale Is this

void NewtonCollisionSetScale (const NewtonCollision* const collision, dFloat scaleX, dFloat scaleY, dFloat scaleZ);
void NewtonCollisionGetScale (const NewtonCollision* const collision, dFloat* const scaleX, dFloat* const scaleY, dFloat* const scaleZ);

scaleX, scaleY, scaleZ can be any non zero positive number, and they can be different
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCreateConvexHullModifier

Postby skarab24 » Mon Jul 29, 2013 9:26 am

Awesome. I'll definitively use it!
Thanks!

edit: oh ok, this functions wasn't in 2.36, going to upgrade
skarab24
 
Posts: 45
Joined: Sun Jul 28, 2013 8:33 pm

Re: NewtonCreateConvexHullModifier

Postby JoeJ » Mon Jul 29, 2013 10:56 am

skarab24 wrote:Note that in a tree hierarchy when a parent use non-uniform, rotated children will may be skewed


Personally i think this is very bad practice and you should change something here.
I did the same when i initially made an editor for myself.
But i disliked the behaviour how child shapes change their shape if you rotate a parent in a nununiform scaled hirarchy.
Also this behaviour was not what i knew from professional 3d packages i used for work.
So i took a closer look to those 3d packages to se what they do different.
I found that they do not use a single matrix per node which contains everything: orientation, scale and position.
The apply scale always at local orientation - this changes the position pivot for child note, but it does not affect (skew) child orientaton.
Instead if the parents local x axis is scaled by 2, childs local x axis is also scaled by 2 - no matter what rotation is between them.
I solved that by using two matrices per node to decouple scale from orientation.

I hope you get what i mean. The good things of doing so are:
* Allowing nonuniform scaling does not introduce skewing to your tree (which newton does not support).
* Users will be happy with your editor - i assume nobody will miss 'skewing by accident'.

However - there are 2 example applications wich use both approaches:

After Effects: Single matrix - skewed children - so nonuniform scale is practicaly unusable for hirarchies.
For me that's simply a bug - i needed to implement my own math via scripting to do things right :(

Autodesk Softimage XSI: A good reference, anything perfect here :)
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: NewtonCreateConvexHullModifier

Postby skarab24 » Mon Jul 29, 2013 11:24 am

Ok, upgraded to latest version, non-uniform looks ok.

JoeJ: thanks for further explanations, as you said I guess there are two ways of doing it :
- fully implement skew/shear support (so add a gizmos to do it as well)
- only support non-uniform scale, and enforce it into the hierarchy

As you, I think I'm going to go the second way, skewing physics things could be cool but it'll surely become painful in the long run...
And thanks for pointing out the softs :)

edit: or I may simply put a checkbox to enable skewing on a node, in this case all physics children would use the modifier, but that could be added later on...

re-edit: ok, done, it works fine thanks. Going to add a checkbox to tell if skewing is enabled on a node, that cost nothing and may be usefull...
skarab24
 
Posts: 45
Joined: Sun Jul 28, 2013 8:33 pm

Re: NewtonCreateConvexHullModifier

Postby skarab24 » Mon Jul 29, 2013 2:47 pm

The convex hull modifier can be added to core 300 as a new convex shape with has a child shape


deleted: Sorry, I don't see this, I only see the NewtonCreateConvexHull, what is the function to use please ?
The compound ones ?

edit: Oh, I misreaded it, so it's not supported in 3.x. Will live with it then :)
skarab24
 
Posts: 45
Joined: Sun Jul 28, 2013 8:33 pm

Re: NewtonCreateConvexHullModifier

Postby skarab24 » Mon Jul 29, 2013 10:25 pm

I post my PM here since it doesn't work:


Hello Julio,

Following the forum posts, today I've upgraded to 3.x, and experienced what JoeJ told me, since it sounded good at first.
But at the end, it looked plainly wrong :
- you have a parent node, scale it on the X axis, if you have a child node rotated by 90°/Y axis, it will scale on Z axis : I'm not an artist but that looks really creepy.
Imaging if a user try to scale a full room on X axis, not only for visuals, but for gameplay : skewing it's not a bug, it's what should happen, and physics should handle it. I've never seen this professionally as well, but one cause could be other physics engines -> game engines don't handle it. (...and cool gameplay, but that's another story)
- handling the "unsheared behavior" internally in the game engine requires to add a "unsheared" matrix to those nodes, with having each controllers (physics, gizmos, user components, ...) be aware of this, which add some big complexity. For physics, when querying the new matrices (translation/rotation), it requires to transform it into the sheared space (since it's now working in unsheared space), which sounds nearly as heavy as what you told NewtonCreateConvexHullModifier introduced.

I'm sure this complexity giving a doubtful user gain, isn't a win-win about killing the Convex hull modifiers, it adds complexity which even touch the final users, which is bad. The user haven't to think about if its sheared or not when he is querying and playing with matrices.

Thats why for now, I'll stick with the 2.36, I'll maybe upgrade later on, keeping skewing for nodes, but "normalizing with non-uniform scale" matrices for physics, it'll create some bugs but better than nothing...
I'm really not a "physics guy", I think if all other physics engines don't handle it there are good reasons to.

Thats why, anyway, I'm glad that you keep supporting the non-uniform scale, which is really a step forward compared to others physics engines (as I told, even Unity doesn't support it, based on PhysX) :)
skarab24
 
Posts: 45
Joined: Sun Jul 28, 2013 8:33 pm

Re: NewtonCreateConvexHullModifier

Postby Julio Jerez » Tue Jul 30, 2013 8:57 am

you are correct skarab24, the scaled applied local does no yield the general result, but cover about 90% or more of all cases when a shape need to be scales.
However you are correct when you have a hierarchy of shapes this simplicity goes away, and the problem because extremely hard to maintain.

for example in another thread, a Newton use bu the name a Bird is scaling compound collisions and as you expect the problem is a real mess, so I put together a hack to see if the problem can be solved, but is does no really work

I end up conversion the mesh to convex hull so that I can bake the transform into the collision shape, to me this is an Asshat solution which is unacceptable.
This is what I going to do.

the scale function will be change to for scaleX, scaleY, scaleZ, to passing a General 4 x 4 transformation matrix
with this everything will be the same as long as the matrix is a diagonal matrix. so I have to make very mono changes to the code.
Mainly on all place the I real the scale as a vector, change the to check if the scale is a matrix and read the matrix instead
then in a second pass I will add the case when the matrix is a general matrix, and tread as the Transform modifier did before, and this will auto autocally support General and local scaling for all shape with having to change meshes.

If you give until next week so that I can complete what I am working now, the you will have that scaling functionality with version 3.12

I suggest you state with core 3.11 because the functionality you seek will be supported, soon.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCreateConvexHullModifier

Postby JoeJ » Tue Jul 30, 2013 11:16 am

Imaging if a user try to scale a full room on X axis...


hmm... you're right - if the room parents some rotated pillars - they will go 'wrong'.
On the other hand - imagine you scale your forearm to be longer, than your hand changes its length depending on it's orientation?... even worse.

However - that changes my mind. I think i'll change my editor and let the user choose between local scale, sheering, and non-scaled children per node.
There seem to be different requirements for things like level editing, character animation, static or animated...
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: NewtonCreateConvexHullModifier

Postby skarab24 » Tue Jul 30, 2013 12:47 pm

Julio: awesome news! I guess its a complicated problem.

JoeJ: You are right, both "modes" are useful depending of contexts. I've reverted all the things I did yesterday because handling this "checkboxes" become awful lol, thinking about if some parent has skewed matrices but some child not and trying to know if some thing is in un-sheared space or not, and if it's make sense to know it, gived me strong headaches ;) I'll give it another fresh try later on.

Thanks!
skarab24
 
Posts: 45
Joined: Sun Jul 28, 2013 8:33 pm

Re: NewtonCreateConvexHullModifier

Postby Julio Jerez » Tue Jul 30, 2013 2:28 pm

No it i sno complicated, is is just a matter of convension and sometime for practicality yo unee to set soem limits.
I decided that scale was goin to be local and alone the x , y, z axis.

if this is a rule then scale can be represenet by a sigle vector, and that save memory and lot of calculations.
however it is clear that it comes short to sove all the problems.

so teh next step is no to sam eteh memory by using a fuel matrix for scaling, and that still provide the perfermence is I add a bit to indicat the
the scale matrix is a diginal matrix, whic is how a local scale really is.

It is not big deal, I will have it over the weekend.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest