Unity plugin progress?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Unity plugin progress?

Postby Sweenie » Wed Feb 22, 2017 11:27 am

Julio Jerez wrote:nice!!,
since we have that demo now I will quickly add the utility function that calculate, a more realistic Archimedean buoyancy force


I fiddled a bit with that, trying to implement the code in the sandbox archimedes demo into the NewtonWrapper.

My idea was to implement a function called CalculateBuoyancy directly on the dNewtonBody class and then you only need to pass the plane and viscosity value and get the correct force and torque back.

I'm pretty sure I did everything right but the marshalling of the calculated force and torque just returned 0 values. I let you handle that instead because I'm about to toss my computer out of the window.
I need to figure out how to debug the plugin while running Unity because it's difficult to find problems like this without a debugger. I don't know if it was the marshalling or my c++ code that was the problem.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Unity plugin progress?

Postby Julio Jerez » Wed Feb 22, 2017 12:00 pm

ha cool, see if you can figure out hwo to implement that buoyancy funtionality.

Ye believe the body and appropriate place for that function, but would that add more parameter to the body?
maybe is Bette to make a component class that people can add to the body if the want to.
the way the body is no cluster with parameters that may no necessarily be used.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Sweenie » Wed Feb 22, 2017 2:39 pm

I didn't add any parameters to NewtonBody. It's just a helper function to calculate buoyancy forces for the body.

I've checked in what I have so far but the function always returns zero forces.
For now I have hardcoded gravity and volumetoshape density.

Occasionally I can see a positive float appear on the y component but other than that the body is dead in the water... ;)

I'm not sure about the plane parameter. I thought it was a global position and that the calculation check if the body's volume is below that point or not.
I see that in your demo you set the plane value to (0.0f, 1.0f, 0.0f, 1.5f)
I'm don't know what the w component of 1.5 does.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Unity plugin progress?

Postby Julio Jerez » Wed Feb 22, 2017 6:23 pm

The first thing we need to find out is what is does not work, I will check it out tonight.

on this.
Sweenie wrote:I didn't add any parameters to NewtonBody. It's just a helper function to calculate buoyancy forces for the body.

I've checked in what I have so far but the function always returns zero forces.
For now I have hardcoded gravity and volumetoshape density.


Yes I know, we can make add function that we want, and ultimately that how every thing is done.
however adding functionality by adding function call to the base class is not the design philosophy of Unity.
we should have a library with a library of component that that generate specific functionality.
the end user can pick for this as add that to the body to cerate specific behavior.
we can start with Buoyancy, and we can even have Gravity as well, alothght gravity is set by default in the word idea that I really do not like at all.

once we have that library the end user can extended if they like, or just uses as they are.
the second benefic is that we can elaborate the editor and get as fancy as we like and present configurations.
In the case of buoyancy we can display the plane with gizmo, we can know the water density and so on, say we are making space game, we can have a component called General Gravitation,
Imagine we can have trigger that are wind tunnel stuff like that.

then the body will only have minimal interface functions like set velocity, set force, set matrix and so on. I know is more laborious but this is my interpretation of object oriented programing.
what do you think?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Julio Jerez » Wed Feb 22, 2017 7:43 pm

Ok I got it working now. The plane equation is not a vector3 is a vector 4 representing the confection of the equation for a plane in global space.

Later we can formalize this to a class something like NewtonBodyBehavior
which can have a virtual function like Physic Update.

Then when the component is assigned to a body (in the case a trigger) all the user has to do is iterate over the array of NewtonBodyBehavior calling behavior.PhysicaUpdate(...)
to get the ball rolling I will do the first use for the buoyancy, then we can add more.

question I see that you some time use ref and sometime do not, what is the difference?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Sweenie » Thu Feb 23, 2017 2:56 am

aha, of course.

A plane can be defined by a normal and a distance, right?
So the x,y,z defines the normal and w the distance along that normal.
No wonder it wouldn't work... :oops:

I c# ref means you pass a value type by reference instead of by value.
I suppose like & in c++
In this case i pass Vector3 which is a value type(struct)

I should probably replace ref with out instead.
ref expects the variable to be initialized first, while out defines that the function will initialize the value.

Like this...
Code: Select all
Vector3 pos = Vector3.zero;
MyFunction(ref pos);

could be replaced by this...
Code: Select all
Vector3 pos;
MyFunction(out pos);


Classes in c# are always passed by reference though.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Unity plugin progress?

Postby Sweenie » Thu Feb 23, 2017 5:18 am

I think your idea of making Bouyancy a component is a good idea.

I updated the demo to test bodies of different density.
It would probably be better to have the body density defined as a parameter of the body, or rather for the collider i suppose.

By the way, never thought of it but does Newton support density or compound colliders there each collider can have different mass?

I was thinking if I wanted to model a Hammer i can simply adjust the cog to get correct behaviour but if wanted the cog to be calculated automatically the hammer would need a compund collider with different mass/density for the head and shaft.

Regarding compounds and trigger.

You added a flag to the collider that define if it's a trigger or not.
What if i add several colliders to a gameobject and only one collider is flagged as a trigger.
Does the whole compound collider become a trigger or only the subcollider flagged as a trigger?
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Unity plugin progress?

Postby Sweenie » Thu Feb 23, 2017 8:34 am

Added a simple rope demo. Realized though we havent added the classic ballnsocket joint so had to use the hinge joint. :D

[EDIT]
I've implemented the BallAndSocket joint now as well.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Unity plugin progress?

Postby Julio Jerez » Thu Feb 23, 2017 9:43 am

and the rope is procedural, nice!!

I fix a problem with the update.
we had a callback that's update the physics on each body and that's cool,
but we rely on the unity Update function to apply the interpolate transform.

that would be fine as long as there aren't many connected bodies in the scene. in this case if the camera is attached to one body, and the update sequence is something like:

body0, body1, world, body2, bod4, ...

each time an fix world update happens, bodies updated before world update will have a transform slightly different than body updated after the world update.
to fix it we nee another callback that is called ever frame fate the world update the interaction parameter, and that function iterates over every Add to dictionary updating its transform.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Julio Jerez » Thu Feb 23, 2017 10:16 am

Oh no you do no what to make the body to have a density, that a big mistake.
Density is give implicitly aby the ration of the mass and the volume.
we want the water to have a density.

to do the calibration the example we can run is one like this.

made two bodes of equal size say 1 x 1 x 1 and weight an one weighting 1 one weighting 1.1 and the other 0.9
then we set the density of the water trigger to 1.0
the result should be the box waiting 1 should be buoyancy balanced. the one weighting 0.9 should float with about 10% of the volume above the water plane, and the one weighting 1.1 should think slowly.
Now this is only for calibration, tiding the density and the mass to math buoyancy made things very
difficult to calibrate, imaging a vessel the mass is small coampare for the volume of water that
displace.

to fix that what we do is that since the buoyance behavior will be it own component, we add a parameter name density scalar, and this is value that is there to make up of the lack of density that a body may have like you said.
I essence this parameter I part of the body but is no in the body, by it acct as if it was part of the water, but is no in the water either.

It will be more clear when I add the framework fro adding NewtonBodyBehaviors.
I will make tw0: FoxForceAndToque and BouyancyForce.


Do compound have this own mass, no in Newton the mass is a property of the rigid body, what collision shape has is the unitary inertia.
The question has bee ask before, and the answers is not trivial, because what I do is that
say you want t to set the inertia of a body to something different that the inertia of the collision shape. and example of that is a vehicle, say you want to move the vehicle upfront, but you do no want the inertia to change. or the other way around.

what I tell people is that the can create a compound collision shape the model the inertia the want to approximate, and use that to set the mass matrix, while using the collision shape the want for the rigid body. So Far only one person asked me that question long time ago and I do not know if he still uses newton.
If at some point this become an issue we can addressed but for now let us just state with the inertia is the of the shape. Mayeb we can add a function the set the inertia to arbitrate value for people who want to have that control, a typical example is a hallow cylinder rolling down a ramp, should role slower than a solid one.


trigger on compound, that another weak point on the engine, the trigger are contact joint why are per body objects, so a trigger can only be a rigid body.
is you take a compound and you set some shape to trigger the that shape will no collide by it will no say is a trigger one less all are set to trigger.
there is a special case for scene collision (whi are comment put now)
a proxy of a scene collision can act as a trigget is the scene, the advanced player controller use that system. but that's because scene collision make mini contacts joint with can have different settings.

for now triggers granularity is at the rigid body level, not a the collision shape level.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Julio Jerez » Thu Feb 23, 2017 11:00 am

I do not know what I was thinking, we do no really nee a new behavior class the Newton Scripts already does that. we can add the funtionality there.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Julio Jerez » Thu Feb 23, 2017 4:26 pm

Ok I found a real bad bug in the collision system in newton when two non uniform state shapes collide
The image below the wheel is colliding in the wrong place.
I need to find out why is that, those are to very simple shapes.

Untitled.png
Untitled.png (521.37 KiB) Viewed 3060 times


The secund by I think I found is that I believe the scale in Unity is not quite correct. I am guess the apply a local scale to the mesh which make very hard to inherit it.
The think is that I think I had that working before but now is all seems wrong.

we need to get that scale working correctly because is vey tedious to align collision shape each time any small change is applied to a mesh.
I will need to revisit that after I figure out what is wrong with the that collision there
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Julio Jerez » Thu Feb 23, 2017 9:06 pm

Ok I found the problem, but the solution is a little complicated.
it may take me a couple of days to get is fix, but I have to because us a very big bug.
It has to do with non uniform scale, and since we nee to use scale heavily in unity it will show a lot.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Julio Jerez » Thu Feb 23, 2017 10:02 pm

Ok the bug coming form Newton was no that difficult to fix after all,
Now I need to address the issue with scale.
it is unacceptable the way scale works now, my bad for doing that :oops:
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Sweenie » Fri Feb 24, 2017 1:45 am

Julio Jerez wrote:Ok the bug coming form Newton was no that difficult to fix after all,
Now I need to address the issue with scale.
is it unacceptable the way scale works now, my bad for doing that :oops:


Oh no, don't apologize. The fact that you support non uniform scaling at all is amazing. Other engines don't even go near that due to the complexity it brings.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 41 guests