Newton Plugin for Unity 3D

Share with us how are you using the powerrrr of the force

Moderator: Alain

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Thu May 12, 2016 6:34 pm

Ok so we remove swig and use CppSharp? that's cool maybe a specialize converter.

Then I applied the reference stuff we discussed and currently I can create the world, bodies, joints and vehicle in any order and destroy them in any order.

this sound like you made a great deal of progress. Is this check in? if not when you have time do it so that we can work together.

yes I did notice that there way I set it up it requires almost a duplication of the engine into CPP classes.
I was having second thoughts, so if you have a wrapping tool that can simplify using C interface that that's much better.
I will wait until you commit what you got.
Julio Jerez
Moderator
Moderator
 
Posts: 10984
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Sweenie » Fri May 13, 2016 6:35 am

yes I did notice that there way I set it up it requires almost a duplication of the engine into CPP classes.


Yes, I also thought that would have been alot of double work.

So the whole chain for creating a NewtonWorld would have been this...

Code: Select all
new Newton (C++ class, NewtonClass.h) --> Newton.lib
NewtonCreate (C-function, Newton.h) --> Newton.lib
new dNewtonWorld (C++ class, WrapperSDK.h) --> NewtonWrapper.dll(C++)
SWIG_dNewtonWorld_Create (C-function SWIG, newton_wrap.cxx) --> NewtonWrapper.dll(C++)
new dNewtonWorld (C# class SWIG, newton_wrap.cs) --> NewtonPlugin.dll(.NET)
NewtonWorld.Awake (C# class, Unity (MonoBehaviour/Component) --> NewtonPlugin.dll(.NET)


This way, the dNewtonWorld(Wrapper SDK C++ class) and NewtonWorld(Unity Component) have to be manually implemented.

If we do it like this instead...
Code: Select all
new Newton (C++ class, NewtonClass.h) --> Newton.lib
NewtonCreate (C-function, Newton.h) --> Newton.lib
WRAPPER_NewtonCreate (C-function CppSharp, newton_wrap.cxx) --> NewtonWrapper.dll(C++)
NewtonWorld.Awake (C# class, Unity (MonoBehaviour/Component) --> NewtonPlugin.dll(.NET)

This way only the Unity Component is manually implemented.

[EDIT]
Actually, it we only had been using the standard Newton functions and was compiling Newton as a Dll instead of a static lib it could have been like this...
Code: Select all
new Newton (C++ class, NewtonClass.h) --> Newton.dll
NewtonCreate (C-function, Newton.h) --> Newton.dll
NewtonWorld.Awake (C# class, Unity (MonoBehaviour/Component) --> NewtonPlugin.dll(.NET)

That way we wouldn't need NewtonWrapper.dll but since there is no C-interface for the CustomJoint library we need the NewtonWrapper.dll to provide a C-interface.
Last edited by Sweenie on Fri May 13, 2016 8:21 am, edited 1 time in total.
Sweenie
 
Posts: 489
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Fri May 13, 2016 7:56 am

we need a least one C++ dll, so that we can debug the wrapper, and further down bugs.
plug we can use unity as the front end to develop new features.

does that CppSharp create a cpp dll? is do we only can link newton core and tools as static library, and copy the PDB, that is sufficient to debug the code.
Julio Jerez
Moderator
Moderator
 
Posts: 10984
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Sweenie » Fri May 13, 2016 8:49 am

CppSharp doesn't generate .cpp files, only C# wrapper bindings.
But I'm not using the bindings generator.

I'm only using the Clang C++ Parser and generate the cpp and c# files myself.

Currently I'm using the "Unsafe" method because it's faster and easier than Marshalling but I will update the Generator to support both. I think the "Unsafe" keyword is a bit misleading because you can mess up equally bad with Marshalling.
Sweenie
 
Posts: 489
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Fri May 13, 2016 1:19 pm

those that mean that will nee to supply dlls,
Netwon.dll, dJoind.dll, dConteainesr.dll, etc?
also has you committed those changes? I do not see them.

For Joint, if you remember I said I has an idea. Maybe I can explain it.
WE will have tow type joints let us call the JointLink and ConstraintLink to borrow a terminology for 3dsmax.,

at the low lever that are identical, but from Unity view point that are very different.
a JointLink, is a class that that will tagged as a unique component of a rigidly.
those joint will connect the body to it immediate parent. So their references are set when the class is initialized. This joint will always match the Skeleton System in newton, and the will be rigid joint always.

ConstraintLink are UnityGameObjects with two reference two bodies. the are set in the editor by the user, and can be anywhere. as a long as they do no conflict with joints.

This arrangement reduce the pollution of GameObjects that do nothing since most object is game are set in hierarchical way. In my experience the user end up using mostly JointLink, which are better joint anyway.
This also simply the creation order for those joints.
Julio Jerez
Moderator
Moderator
 
Posts: 10984
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Sweenie » Fri May 13, 2016 2:19 pm

Ok, I've commited the changes now.

I have some extra "stuff" that I will remove later. I was playing around with interpolation and it currently works but I don't like my implementation. It's too messy.

Also, there isn't a NewtonWorld component yet. Currently a static class(NewtonManager) creates the world using lazy initialization. When the world is created it also injects a gameobject with the component(NewtonWorldController) into the scene that handles the NewtonUpdates. You can add this NewtonWorldController manually as well to control timestep, time scale and debug rendering.
Sweenie
 
Posts: 489
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Fri May 13, 2016 2:47 pm

should we remove the swigg stuff?

I see a file Newton.cxx, was that file crated by CppSharp
that looks very clean. but the look just like c functions to me.

anyway I will open tonight and see how it works.
Julio Jerez
Moderator
Moderator
 
Posts: 10984
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Mon May 16, 2016 2:56 pm

Wow, I though IO was going to have time to put to work on the plugin, but I spend all on the vehicle and the skeleton solver.

On the vehicle I add a more realistic engine, now the engine internal friction loses are modeled with dry function. I also fix a bug in the calculation the lateral friction.
The car will be slightly but this the correct thing to do, because it feel more realistic.

I was able to do tire doughnut and tire burn out.

to do tire Doughnut you move forward and we the RPM the point where is going to change gear, tap the hand break while turning.
at this print you can try to correct by turning there tire the other way ( this is still too lose, but start to show sigh of proper simulation)
If you turn the tires to the same direction of the spin, the car do a perfect Doughnut at about 30 kmh.

The cool thing, is that the Doughnut is maintain even if you straight the tire, :mrgreen:
I see if I can make a video.
here you can observe how important the differential is, the pivot tire is impost to spinning at all, while all other tires spins a different rate. :D

if you turn the tire to the opposite direction the you get out of the Doughnut.
I was also able to drift, but I could no control it yet.

at these point the there are two more features, left before plugging the traction control.

the tire integration required a sun sampling, specially when the are near the goring of the tire friction model. Basically the stiffness f the friction model is too strong and a very small change in slip ratios causes huge forces longitudinal and laterals forces and the tire RMP tend to overshot.

once we have that the we add the traction control so that Tire so not spin more that 2 maybe tree time the velocity of the tire center.
and finally lateral dynamic for controlled drifting, and high speed cruising.

we are getting very close to the final here.
Julio Jerez
Moderator
Moderator
 
Posts: 10984
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Sweenie » Tue May 17, 2016 3:55 am

Wow, the handling feels awesome now. :D

Wish we had a San Francisco like city scene because I really want to do some cool handbrake turns and jumps with the Viper. :lol:
Sweenie
 
Posts: 489
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Tue May 17, 2016 1:01 pm

did you try the doughnut? it takes some practice but after you get it is easy and very cool.
Remember drifting is hard because you are essentially controlling the car in the unstable equilibrium state. however even this instruction has a hard time teaching a trained driver to drift.
https://www.youtube.com/watch?v=5Yl_mO7OexM

the thing is that to do the doughnut you do it following the same instruction that the instructor gives in the video. :mrgreen:

I also managed to drift straight wit the car sideway. for the go fast and the give a slide turn to the steering to produce the weigh transfer(late I see if it can be done by using the clutch instead),
the when the car in going to lose control, turn the wheels the opposite direction and press the hand brake. It will drive sideway for a few second until straighten out or completely lose control.
(here is were the lateral control will help)

I drift more or less like the student in the video, but my goal is that after I add the lateral dynamics control, it will drift like the instructor.

Sweenie wrote:Wish we had a San Francisco like city scene because I really want to do some cool handbrake turns and jumps with the Viper. :lol:

Ha but that's where the Unity plugin will play a role. :shock:
Julio Jerez
Moderator
Moderator
 
Posts: 10984
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Fri May 20, 2016 10:20 am

before getting lost Lightning McQueen used to drive like this
https://www.youtube.com/watch?v=_KwPjQu4m7k

but them after some driving lessons from Doc Hudson Hornet
This aint asphalt son...this is dirt..................you dont have 3 wheel brakes so you gotta pitch it hard...break it loose and...and just drive it with the throttle"


now He drives like this. he finally learned how to float like a Cadillac and sting like a Bee.
https://www.youtube.com/watch?v=zJVQxvJF_n8

Guys see how this feel now wit the traction control. See tire and burn out :shock: :D

to make tire doughnut wit the monster truck, move forward an turn, the when the car go in circle, hit the L key to lock the differential, the car go in\to burn out, then release the Lock and it will continues doing the doughnut, this is so refreshing, and it all come for the simulation. :D
Julio Jerez
Moderator
Moderator
 
Posts: 10984
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Shaderman » Fri May 20, 2016 2:41 pm

That's just awesome Julio!

That's why I hope I can manage the Newton integration I'm working on :)
Shaderman
 
Posts: 66
Joined: Tue Mar 08, 2016 2:51 am

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Fri May 20, 2016 2:44 pm

how far are you?
Julio Jerez
Moderator
Moderator
 
Posts: 10984
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Shaderman » Fri May 20, 2016 3:45 pm

Well, I think I have most major Newton pieces working in a Windows Plugin for the ShiVa engine now. Multithreading, all kinds of collision shapes, most joints, materials and so on.

The last missing piece at the moment seems to be the vehicle integration before I'd start trying to build this plugin for other OS'es (OSX, Linux, iOS, Android and WP8 are on my wish list).

So to answer your question, I didn't make any progress yet after my last post in this thread. I still don't understand why there's no parent body found and have no idea which body the parent is searched for.
I only see this problem is coming up once I called manager->CreateVehicle(). Of course it's not related to the userData which I first thought was required somewhere in the vehicle controller. This function call also works in the sdk demo when NULL is passed as userData parameter, so I don't have to care about it.

By the way, this is a spare time hobby for me, so please forgive me if my posts sound strange and noobish. That's mainly because I'm trying to make things work with my intermediate C++ skills when I'm tired from my day job :oops:
If Newton wasn't so awesome, I had already dropped everything and moved on to something else ;)
Shaderman
 
Posts: 66
Joined: Tue Mar 08, 2016 2:51 am

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Sat May 28, 2016 2:55 pm

It is a long weekend, I see if I can do some work on the pluging.

I try to build it and I go many errors,
I see what you did, the cpp sharp[ give you a clean lint of function that you can call form CS, that seem like a clear wing at first but I do no thing is as good as swig.

The problem we have with swig is that is does no work nice with C style functions, but of we wrap all our c function in a CPP class, that there is no problem.

I even have a \script that can ado that automatically that I used to make the objective C wrapper, but is old and I do no wan go back to it, instead I made a CNewton class we can just add all the function there. we for not have to add all of them we can do as we need then.

This is what I will do.

I will make a copy in my system, and I will try to advance the wrapper using wig, if I can make significant headway, I will comment it. if no I will not.

To get back to where we were three weeks ago, I could not figure out how using GitHub, so I did reverse, to get the old code, and the reverse again to restore back to where you are.


To summaze, the reason I think using cppShap, is not better that using swig, is that we will have to do a lot of manual conversion of many C++ code.
Swig does do a nice job with CPP classes already, we only nee to add the conversing for C to Cpp an that's less code, I think.

all the CS code remain unchanged.
Julio Jerez
Moderator
Moderator
 
Posts: 10984
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

PreviousNext

Return to User Gallery

Who is online

Users browsing this forum: No registered users and 1 guest