Newton Vehicle in Unity 3D

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

Moderator: Alain

Re: Newton Vehicle in Unity 3D

Postby Kaos » Wed Apr 20, 2016 10:39 am

Since i got my first test of ddl loading running with the help of this
http://ericeastwood.com/blog/17/unity-a ... -unmanaged

Then i was just arriving at the same question:
http://stackoverflow.com/questions/4297 ... anaged-dll

with direct use u will hav a lot of these
// Straight From the c++ Dll (unmanaged)
[DllImport("KaosTools", EntryPoint = "TestDivide")]
public static extern float StraightFromDllTestDivide(float a, float b);

since u cant look into a c# dll its actually not very benficial to use one since then u would have to use a c# script to use that one ...

This would have been a nogo with unity 4.
But since unity 5 the free version allows using native plugins!!!

A wrapper in a DLL would be most benificiary if you wanted to obfuscate code and hide functionality from the users. But thats not the goal here.

The goal should be to make this as user friendly as possible also for non programmers. So drag and drop and nice inspectors are important if you want people to use it.
Thats the reason unity is popular in the first place. Just saying.


Another thing i wonder about is if it will be possible to use the unity terrain with newton?
The Terrain has its own pros and contras but it is a quick way to make smaller terrains so its at least useful in somecases and it is somewhat optimized in rendering.

Edit.- i have no what to compile to get a correct newton dll actually i use vs community and they demosandbox project is usable for me but thats not what i want to put in a dll newton alone gives me a compiler error so is dnewton is compileable but that wont give me an dll ???

So i will stop here for now and chill a little an then try to make me a Blender Car.
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Vehicle in Unity 3D

Postby Julio Jerez » Wed Apr 20, 2016 2:46 pm

Another reason I'm using a plugin is because I'm using interops to call into Newton. However, the customjoints doesn't have a C interface so I wrapped the custom joints(including the vehicle) in the plugin dll. I guess I will still need to do that, but I won't need to wrap the standard Newton functions though, and that makes things easier.

How about using swig to make a auto c# wrapper, there is a swig sdk in the newton download along with a sample project.
Using swig will allowed the best of all world, unitary will see only c# interface and we will see c++,
is actually very elegant. anyway I think the most important step if to get started.
on the DLL, I like DLL because is eassy to debug. but we can provide all the source so any one can build it.

I think that the most important is to get started. with what ever you have and have the basics, first the newton C APP and a very basics test. The from there we can expand the custom joint library and the full SDK using Swigg, or maybe the same parcel I used for the old objective C.

by using Swig we eliminate the hassle of keep updating interface east time anything changes in the newton API and we can focus on how to make the plug in itself better with the editor, and that I consider plenty of work.
I can do the swig part.
Julio Jerez
Moderator
Moderator
 
Posts: 10847
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Vehicle in Unity 3D

Postby Kaos » Wed Apr 20, 2016 4:33 pm

I was just looking at swig(because of your post not independent) and thats sounds great and tried it since i also found out how to build the dll for anyone who gets here by search its
newton-dynamics\packages\projects\visualStudio_2013_dll/build

or the higher vs version

the blender swig prject is 2008 compatibel that i couldnt update to vs 2015

The swig part itself do one have to make the custom build path
ii. In Custom Build Tool > General > Command Line enter the command needed for SWiG generation:

swig -csharp -c++ -outdir <MyGenerateFolderLocation> cpp_file.i
and it stated that this had to be done for every file in the dll ..

is that true`??? ok one has to this one time but for every file not just for one time for the whole project???
Thats seems painful but its still better than writing and interface for each function.

i got that from here
http://www.technical-recipes.com/2013/g ... -projects/


OK so besides from that im glad to hear that you will do this part Julio and it looks like you wanna do this so i dont have to blame myself for pushing you into this ;D

I also think it would be good if you add this to the exiting github project And make another Github Project for an Unity Project(NewtonUnityBase). Since its yours anyway and that base could than be used be other and contributed to. So why put this somewhere else.

OK that would leave you to do alle the lifting to start what was not what i intended but it makes sense.

Sweene can then add the first vehicle stuff and i will start learning how to use newton and try to build some demos along the way and can at least give some feedback whats working and whats not from a new users perspective if thats ok and helpful.
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Vehicle in Unity 3D

Postby Sweenie » Thu Apr 21, 2016 5:10 am

Ok, tried my other approach that only uses a managed(C#) plugin. Worked pretty well except for problems with controlling the lifetime of objects in Unity.
The singleton approach causes problems when switching between Play and Edit mode. It seems Unity unloads the AppDomain and therefor the NewtonWorld instance(singleton) is destroyed. This wouldn't normally be a problem but I need the world instance in the Editor as well since I use the colliders to get the debug meshes to visualize the colliders in the editor. Since I need a Native Plugin anyway(to wrap the C++ classes in dJointLibrary) I'm gonna try this approach.

A Native Plugin(C++) that creates the world instance as soon as the plugin is loaded by the Editor.
This plugin also serves as the wrapper for the custom joints.
A Managed Plugin(C#). This creates the Unity Components which internally calls standard Newton Functions(newton.dll) and the native plugin for the custom joints.

Something like this...
http://www.svenberra.net/newtonplugin.png

Not sure if that will work though. Both the Native Plugin and the Managed plugin will call Newton.dll. Maybe that will cause problems...
Haven't tried it yet since I'm still at work.

[EDIT]
Hmm, been thinking about this some more...
The only reason I need a world instance while in edit mode is to be able to get the colliders debug meshes.
Maybe I could make a copy of the DebugCollision methods in each collider, make them static functions and pass the instance members, like height, radius etc as parameters instead.
That way I could get the debug mesh without needing the world instance or an instance of the collider.

I would have to update these if you change the DebugCollision code or add new shapes but that doesn't happen too often I think.

In that case it would work like this...(a bit cleaner)
http://www.svenberra.net/newtonplugin2.png

In fact, it could be even cleaner if the custom joints was exposed as c functions in Newton as well.
Then we would only need the newton.dll and I guess using Swig would be easier as it would only need to run against Newton.h. :)
Sweenie
 
Posts: 478
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Previous

Return to User Gallery

Who is online

Users browsing this forum: No registered users and 1 guest

cron