handling ND in unity

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

handling ND in unity

Postby blackbird_dream » Fri Sep 01, 2017 8:51 am

I'm beginning with unity. I am surprised how simple it is to construct articulated bodies in a few clicks.
If I need to control one body with procedural input forces, how can I do that ?
Is it in the 'Newton body script' panel ?
Do I have to write a script in C# ?
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: handling ND in unity

Postby Julio Jerez » Fri Sep 01, 2017 2:10 pm

yes you have to write a unite script that manipulate the variable exposed to the editor.

It may be the case that you need a expose some functionality, so you may be see to edit the plugin it to add that function to the wrapper class so that you can have asset from c# script

I am no an expert most for the unity user interface was written by Sweenie, and I learn a lot for those examples.

you may take a look at the simple Robot that control the stationary robot form the user input.
It use unity C# script to set actuator variables.
Newton has some special joint that emulate how DC actuator works,

Later I will add a new feature to newton (already in but no expoesedyet) that is call immediate inverse dynamic)
the wile allow the use to set a target position and the whole articulation will move to that target.
(not cheats, and not IK, it will actually calculate joint torques and accelerations)

but if you look at the Sweeney robot demo, the script has a UI, with an slider fro each actuator.
the mean each join require one actuator.

Wit the inverse dynamic this demo will change so that the will be and UI the will specify a target location and orientation and the whole thing will try to match that position.

UI may try to do that test this weekend sine you are experimenting with the script, that way you can see the process as it develops.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: handling ND in unity

Postby blackbird_dream » Mon Sep 04, 2017 4:05 am

Is there a way to protect a model ?
I mean maybe is it better to add a new class in Newton that controls all joints and Physic laws like dCustomBallandSocket.cpp for instance so that we just need the .lib file to build the unity plugin (the .lib file is not human-readable) ?
For instance create a class composed of the newtonbody tree (=chassis+ axle+ wheels+lift components...) all the callback-events for the tire/ground relation and the propulsion power. The problem is how to make the connexion with the game objects of each part of the model.

On the other hand if I build the model via unity scripts like the demo_07_Robot it is human-readable through the C# script.

Hope it's clear.

Maybe the question is how to make my multibody model a Newton physics component of unity. Is it possible ? I guess Rigid body vehicle associated with rigid body wheels is very similar in the philosophy. I don't understand clearly yet how they are organized together.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: handling ND in unity

Postby Julio Jerez » Tue Sep 05, 2017 6:57 pm

could you rephrase the question?
I do not know what you mean by "Is there a way to protect a model ?"
Is that some C# terminology?
what I understand about protect is in the sense of C++

also by this
Maybe the question is how to make my multibody model a Newton physics component of unity. Is it possible ? I guess Rigid body vehicle associated with rigid body wheels is very similar in the philosophy. I don't understand clearly yet how they are organized together.


do you mean making an a model object, that is made of a collection of rigid bodies, joints and collision shape. ex a car, a human, or any other articulation?

if this is what you mean, yes newton supports that in many ways, but is not and Low lever engine functionality, rather a high level that is based on listeners.

this has not been exposed to unity yet, but we can work on it if you like.
an example that we can shout to expose to unity can be the dCustomArticulaledTransformManager

this is a class that can be use to put together object like contraction of objects.
exposing that to Unity, is relatively easy, basically we add a new component an we call it Model.
there we add all the parts, and then you get the callback the you would use to control the model.
this require some C# tricks, but maybe Sweenie can help

but first I need to know, is I am understanding the problem correctly.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: handling ND in unity

Postby blackbird_dream » Wed Sep 06, 2017 2:11 am

'protect', in my mind not a computer terminology but in the legal/commercial sense :
I'd like the formulation of the model not be visible and modifiable from the user. If I write it with scripts the formulation is visible in the c# scripts. If the formulation is part of a compiled file it is not visible.

My model already exists, at least compatible with v1.5.3 and I'd like to transpose it in unity, as a newton component or equivalent but not modifiable. This model is a collection of Newton bodies and procedural interaction forces/torques (like pacejka magic formula).

this is a class that can be use to put together object like contraction of objects.
exposing that to Unity, is relatively easy, basically we add a new component an we call it Model.
there we add all the parts, and then you get the callback the you would use to control the model.

sounds close to what I'd expect
Last edited by blackbird_dream on Wed Sep 06, 2017 2:51 am, edited 1 time in total.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: handling ND in unity

Postby Sweenie » Wed Sep 06, 2017 2:45 am

I'm pretty sure the C# scripts in Unity are compiled into an assembly(.NET DLL) but if you are worried that some user may decompile it to access your code and instead want to do the implementation on the c++ side I guess you could create your vehicle as a custom object in the NewtonWrapper and expose it to Unity the same way we do. But you would have to create functions to handle creation and destruction and functions to get the position and orientation of individual parts yourself i suppose.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: handling ND in unity

Postby blackbird_dream » Wed Sep 06, 2017 2:52 am

Do you mean we do'nt need the C# sources to deploy the model ?
I'm not afraid of decompiling (let's remain humble)
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: handling ND in unity

Postby blackbird_dream » Wed Sep 06, 2017 8:11 am

Hi Sweenie
thanks so much for all your work.
Your plugin is really great.
what do you mean exactly with 'create your vehicle as a custom object in the NewtonWrapper and expose it to Unity ' ?
Do you have a basic example I could go through and understand how to build my model ?
Very best regards.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: handling ND in unity

Postby Sweenie » Wed Sep 06, 2017 9:44 am

I can't really take credit for all code in the plugin. Julio has done a massive amount of work in the plugin.

Now, back to your question.
I don't have a specific example but I guess checking out the class dNewtonDynamicBody(dNewtonBody.h) could be a good start.

dNewtonDynamicBody(inside NewtonWrapper/wrappersdk) is a wrapper class for NewtonDynamicBody. dNewtonDynamicBody will be "picked up" by Swig and exposed to the C# part of the plugin through interop functions in the file newton_wrap.cs(inside the newtonplugin folder)
Next we create a class in the NewtonPlugin(c#) project called NewtonBody that create an instance of this dNewtonDynamicBody class.(This part requires manual work and isn't handled by swig)

I thought maybe you could do something like that.
Like creating a class called for example dCustomVehicle, which creates and handles all the Newtonbodies and joints you need and then you create a C# wrapper called CustomVehicle in the C# plugin which you then use in Unity. I'm just thinking out loud though. Maybe this would be too complicated.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: handling ND in unity

Postby blackbird_dream » Wed Sep 06, 2017 10:05 am

oh my god ! I must digest all this information now.
Thk you
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: handling ND in unity

Postby Julio Jerez » Wed Sep 06, 2017 2:21 pm

you are probably taking too much at once.
If I were you, I start simpler.

I'd try to make my objects C# components, maybe something simple. This will give you some knowledge how the plug in interact with unity.

then you can try rewriting it as a c++ and wrapped in a swig script, this could be optional because Unity is a professional Game Engine, many studios who do protect Intellectual property, write many stuff in Unity also many third party developers write add on that do not provide source code.
so there must be a way to achieve what you want using C# in unity.

So if I where you, I investigate how third parties protect Intellectual property first, I am sure there most be docs on that then if that's true, I focus in getting your code converted to C# script.
and limited all C++ to functionality that is no yet expose in newton to via the plug in.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: handling ND in unity

Postby blackbird_dream » Thu Sep 07, 2017 4:05 am

thks for the advice.
when you write "make my objects C# components" it is building the model using the Newton Physics components of Unity for the multi-body structure and add the functionalities such as tire force formulation in C# scripts. That's right ?
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: handling ND in unity

Postby blackbird_dream » Thu Sep 07, 2017 11:17 am

Sweenie, the class CustomVehicle transposed by swig (as much as I understand the flow) in c# is written in an Ascii file for input to unity isn't it?
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: handling ND in unity

Postby Julio Jerez » Thu Sep 07, 2017 3:43 pm

blackbird_dream wrote:when you write "make my objects C# components" it is building the model using the Newton Physics components of Unity for the multi-body structure and add the functionalities such as tire force formulation in C# scripts. That's right ?


yes,
that is the idea of using a game engine like unity, I gives the use an interface that the can use to set parameters.
the Newton Physics components are just layers on top of the C++ class, you will expose only what you want to expose on those components.

I do no know how you are making your tires, but whether is a joint of a body, it will have a C# component that will represent it.

in eh case that is a joint, you will problem make you own and since will already have the boiler plat method to expose functionality in to unity, you just add the C++_ header to the swig script, and it will give you the interface that you can call from you component.

I sound difficult and tedious, but want you understand it you will see how simple it is.

you can look at any of the joints class like the Hinge, and see how is converted from a dCustomHinge to as C# class that can be insatiate from Unity.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: handling ND in unity

Postby blackbird_dream » Fri Sep 08, 2017 3:27 am

I do no know how you are making your tires, but whether is a joint of a body, it will have a C# component that will represent it.


It's nothing more than forces and torques Fx,Fy,Fz,Mx,My,Mz depending on the camber angle (theta_x), slip ratio(ratio of vehicle longitudinal speed and wheel longitudinal slip speed), slip angle (angle between the instant slip speed and the wheel plane) and vertical deflection (calculated with ray cast) through equations.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 14 guests