Newton Plugin for Unity 3D

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

Moderator: Alain

Newton Plugin for Unity 3D

Postby Sweenie » Sat Apr 23, 2016 3:37 am

Ok.

I think I have something that we can start with.

https://github.com/svenberra/NewtonUnityPlugin

I'm a bit new to working with source control since I've been a solo developer for all my life.
So it took a while to setup the repo. :lol:

Try it out. Hopefully it works. :wink:

The vehicle isn't done yet.
Working on it. ;)
Sweenie
 
Posts: 481
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Sat Apr 23, 2016 10:31 am

Ok I cloned the github project now I am getting unity 5.3.4

I guess I nee to spend some time learning Unity a little, I see you have a ready to go demo, can you tell me how do I run it quickly?

do no worry about vehicle of any advanced feature for now, The Unity community is large, I want to this plug in to be as polish as I can be.

we need to investigate the issue of random order creation, Ideally the plugin in has to deal with it graciously. But that come be later. for now let us get the basics.

I want to be so cool and robust that I can switch to make demos and feature using the plugin, first and the port them to. Back in 2001 when newton was no public, I made a GameStudio plugin, and for almost two years I use the Game studio editor as the sandbox for the engine until the Game studio people start to play hard ball think that Newton was a Game studio app, so I decide to make a stand alone SDK.

Lithe did I know that using a Game engine as sand box in in fact far more productive than making you own demos.
Julio Jerez
Moderator
Moderator
 
Posts: 10916
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Kaos » Sat Apr 23, 2016 10:50 am

First let me thank you for efforts sweenie.

But i was wondering why you were not going with the swig thing?

I got the unity dll link and i could include the newton .h dependencies even if i may did something wrong there but i had to do each folder by themselves which kind a * ... since its not a recursive include
and i missclicked and had to do some double ..




I may have found an source error or at least spell error :
DECLARE_CUSTON_JOINT(CustomHinge, CustomJoint)
from customhinge.h
I couldnt find this in the newton project
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Sat Apr 23, 2016 11:06 am

wow, I am loving this Unity editor stuff, I am going over a tutorials making my first scene, and this is awesome :D .
I like a lot that the went for the look and feel of xcode in OSX. it feels just familiar.

on the swig, let us not get ahead of yourself.
Let us have something and resolve all the logistical issue between the Game engine and the physics engine, the swig script is a had core C++ programming stuff, I will do that later, when we have a robust plugin.


DECLARE_CUSTON_JOINT(CustomHinge, CustomJoint)

this is on the newton side what is the error?
Julio Jerez
Moderator
Moderator
 
Posts: 10916
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Kaos » Sat Apr 23, 2016 12:03 pm

i jsut thought that would be double the work but fine by me.

Ok i got the first crash ;D
Since i dont know what to use with what ;D

i created a plane and tried a newton convex collider on that. That crashes unity.
Using a convex collider empty too i think. I got it working with a simple mesh so it justs need some kind of protection.

And i needed a second to get that a newton manager is needed ;D

Ok now i used a tree collider and that worked ;D So tree colliders are for planes and heightfields and the like!?.

BTW. my own compiled plugin works as is the demo you provided so good job on those sweenie works great and the information provided is sufficient if one has some plan how to use VS.
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Plugin for Unity 3D

Postby Sweenie » Sat Apr 23, 2016 12:44 pm

A Convex hull requires the point cloud to form a volume. A perfect flat plane or no vertices has no volume so that is probably why it crashes. But your right, we will need to add some safety nets for these cases.

Regarding swig, I don't want bite off more than i can chew. For now i have only manually wrapped a few basic functions to test the engine. Later on when we need to add all functionality of Newton, swig will be needed, or some other kind of automated wrapping.
Sweenie
 
Posts: 481
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Kaos » Sat Apr 23, 2016 1:02 pm

DECLARE_CUSTON_JOINT(CustomHinge, CustomJoint)

this is on the newton side what is the error?[/quote]

Custon should be CUSTOM ...thats just a grammar nazi error ;D since the source compiles fine.

Since VStudio is compiling fine it doesent look like its an code error its just a typo i think.

As for more interesting things. I put some 4x4 rows of your cube stacks besides each other and of the physx and then let stacks of thoses 4x4 fall on these and in another test just stapled those 4x4 3-4 times on another to see how the performance is and how they behave.

As expected the fps is not so great for the newtons compared to physx i would say its cut in half at the moment in this situation.
But the visuals man o man. Physx all fall the same stupid unbelivable way and newtons way more realistic unpredictable and more uniformly if that is putting it right.

And im suprised as i somewhat expected that this would be not working (what was stupid i have to admit) one can mix physx and newton objects and they collide and behave quite nicely together. You just have to give one side the collider of the other. So you double the collider components but that isnt a big problem.. that leaves one with interesting mixing possibilties even if that wasent the point of this project ;D
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Plugin for Unity 3D

Postby Kaos » Sat Apr 23, 2016 1:08 pm

Sweenie wrote:A Convex hull requires the point cloud to form a volume. A perfect flat plane or no vertices has no volume so that is probably why it crashes. But your right, we will need to add some safety nets for these cases.

Regarding swig, I don't want bite off more than i can chew. For now i have only manually wrapped a few basic functions to test the engine. Later on when we need to add all functionality of Newton, swig will be needed, or some other kind of automated wrapping.


Yeah the convex thing i thought that that was why it wasent or shouldnt workign but crashing is still not a good behaviour. ;D But thats something for later.

As far as testing goes im having fun.
I compared this also to the bulelt thingy and its wayyyy better. you cant scale the colliders in the bullet pliugin so you just take a cube and resize it and it works as a ground level. so Newton an physx are more similar the way you set things up in bullet you would need code to these things.
If thats a bullet thing or comes with the plugin i dont know. But if newton works like that out of the box one point for newton .. but whos countin ;D
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Sat Apr 23, 2016 1:20 pm

ah I see, fixed the misspelled error,

As for more interesting things. I put some 4x4 rows of your cube stacks besides each other and of the physx and then let stacks of thoses 4x4 fall on these and in another test just stapled those 4x4 3-4 times on another to see how the performance is and how they behave.

guys guys you are way way ahead of me, your are killing me here :mrgreen:
I am drooling to get to the point were I can run the plug in I am still learning the Unity basis,
I do no know to load a thro party plugin in yet.
Julio Jerez
Moderator
Moderator
 
Posts: 10916
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Kaos » Sat Apr 23, 2016 1:22 pm

Julio Jerez wrote:wow, I am loving this Unity editor stuff, I am going over a tutorials making my first scene, and this is awesome :D .
I like a lot that the went for the look and feel of xcode in OSX. it feels just familiar.



ok im a windows guy but i like unity for its usabilty.
At first i didnt like how one drags and drops object references in other components that was just something i never did as a programmer. But you can call and referencing from script also so there is nothing forcing you. But stuff like that makes things faster to reuse and setup for non programmers.

One only has to be careful to have all this in mind since you code and therefore your error can be all over the place since you can put as component to anything. ;D


Later on when we need to add all functionality of Newton

A song from queen comes to mind .. i want it all .. and i want it now ;D LOL
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Plugin for Unity 3D

Postby Kaos » Sat Apr 23, 2016 1:25 pm

Julio Jerez wrote:ah I see, fixed the misspelled error,

As for more interesting things. I put some 4x4 rows of your cube stacks besides each other and of the physx and then let stacks of thoses 4x4 fall on these and in another test just stapled those 4x4 3-4 times on another to see how the performance is and how they behave.

guys guys you are way way ahead of me, your are killing me here :mrgreen:
I am drooling to get to the point were I can run the plug in I am still learning the Unity basis,
I do no know to load a thro party plugin in yet.



just use his demo and have a look
link is on the end of the github page
http://www.svenberra.net/NewtonDemo.zip

i wish i had seen this before making my own:D Like in school test jsut read the whole page before starting.... i learned nothing it seems..
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Plugin for Unity 3D

Postby Kaos » Sat Apr 23, 2016 1:38 pm

Crazy YOU can actually put physx and newton on the same body and it works without problems.. a stack of cubes is behaving as it should.
I had expected it would do crazy things and totally misbehave.. but it doesent.

That also means you should be able to join physx bodys with jointed newtons.

But one bad thing: The Terrain isnt working .. my physxnewtons are falling through with the normal mesh collider and when adding a newton tree collider unity crashes. :(

EDIT: I think i know why.. first of all it crashes becaue i dint give the tree colidera mesh .. so that has to be intercepted.
And the issue then is that the terrain is an asset and therefore theres is no mesh to reference to in the editor itself.

Workaround would be a script that get the actual meshdata from the terrain class so it can copy that and then the newton tree collider should work for that also.


That would be great if it can be fixed or made work.

And sometimes unity wont exit the application with the plugin. I didnt saved the scene and closed app then it hang forever. Cant say i had this without the plug but im not sure it is related yet.

Yeah so im off to a walk around the block .. but all in all great stuff thank you guys so much.

ONe things i have to add.. as i said you can mix physx and newtons on the same body .. and actually it looks like newton wins then when i look at the behaviour.. and i wondered why.. but this may come from the script execution time. since newton will be called later than physx i bet. So its a good question if that overides it completly or still both compute .. this will be better seen when used with joints and when used diffrent forces i guess.

And performance might come back quite a bit when changing to swig and pure native implementation.
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Plugin for Unity 3D

Postby Sweenie » Sat Apr 23, 2016 2:32 pm

I compared this also to the bulelt thingy and its wayyyy better. you cant scale the colliders in the bullet pliugin so you just take a cube and resize it and it works as a ground level. so Newton an physx are more similar the way you set things up in bullet you would need code to these things.
If thats a bullet thing or comes with the plugin i dont know. But if newton works like that out of the box one point for newton .. but whos countin ;D


Ha, now make two spheres.

One with Physx body and sphere collider and one with Newton Body and sphere collider.
Next scale the spheres on the Y-axis so they look like Mentos.
Do the same for the colliders. Oh, wait!, PhysX can't... :twisted:

I actually have code for displaying the collider shapes with Newton colliders, but I need to do this a different way since it messes with the NewtonManager.

Was working on the terrain collider. Got caught with something else though so it's not finished.
The thing is, Unity doesn't have a method to return the terrain mesh-data. But we won't need it either. Newton already has a heightmap-collider so we only need to feed Newton the heightmap.

Regarding the Unity Editor hanging on closing it. I've got that a few times as well. Not sure if the plugin is causing it or not. Not sure but seems to happen when I've been running a scene with many bodies for a longer time.
Sweenie
 
Posts: 481
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Sweenie » Sat Apr 23, 2016 2:42 pm

And performance might come back quite a bit when changing to swig and pure native implementation.


Hm, what do you mean with a pure native implementation?

Are you talking about using a Native Unity Plugin?
If that is the case that won't make any difference regarding speed.

You still have to use pinvokes, like we do now.

The only difference is that with the native plugin you can get a callback when the plugin loads and unloads. You also can get a callback to do some low level rendering. But you still have to import c functions like I've done and import them using DllImport
Sweenie
 
Posts: 481
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Sat Apr 23, 2016 3:26 pm

Ok I now when over basic tutorial and I I can navigate the editor and do few basic stuff

Sweenie I now open the demo project and running. very nice.
I nice one thing for when we decide to make improvements.

I see that you set joint the same way we set bodies, this is find but we can do much better that if we set some rules.

In the newton body we place a private Reference to a Joint, this is a private and a public Joint Type
is the joint Type is zero the joint is no link to the paren't, when set to a type it will the Body on initialization will create the joint and connect to the Parent game objects.
This will allowed of to automatically create skeleton joint arrangement.
Bascially this implicitly set of the skeletons is way that are alwyas legal.

We also make the general joint that can link any other two game object the way you do it now. we give those joint a different name make Kinematic Loop or something, but the only difference is that the will no be part of skeletons.

this actually simplify the hierarchy a lot, because the skeleton joints do not need to be GameObjects
the are a unique component of a Newton Body that connect the body to it parent.
the General Joints we make the GameObject with two reference to tow NetwonGameObjects. and the can be anywhere in eh hiearchy

no sure if I explained well, but it will be more clean as I lean more.
basically we make two GameObjects that is call a skeleton articulation and a General Constrain.
Julio Jerez
Moderator
Moderator
 
Posts: 10916
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to User Gallery

Who is online

Users browsing this forum: No registered users and 1 guest