plugin for unity 3D

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: plugin for unity 3D

Postby Sweenie » Fri Jun 10, 2016 2:02 am

Haven't tested it but it makes sense.

The checkbox that disables a script stop calls to Update, FixedUpdate and OnGui for example.
If your script doesn't have any of these methods implemented the checkbox wouldn't matter, since the script wouldn't do anything anyway.
Sweenie
 
Posts: 503
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: plugin for unity 3D

Postby Sweenie » Fri Jun 10, 2016 2:09 am

Regarding drawing debug meshes.

You want to implement the method "void OnDrawGizmosSelected()"

This method will be called by the editor when you select the gameobject and every time the editor needs to redraw the debug mesh.

Check my class NewtonCollider under the Colliders folder for some example code.

I'm not too pleased with my debug drawing code, it recreates a new collider every time it needs to draw debug lines. But I couldn't think of a better way since while in the editor, no body is created to fetch the collider from and also the collider needed to be recreated if the user changed the collider parameters, like radius, convex hull tolerance etc.
Sweenie
 
Posts: 503
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: plugin for unity 3D

Postby Julio Jerez » Sat Jun 11, 2016 4:28 pm

how do you set a break point on a .cs functions?
I search and search, but I do no find a clear answer anywhere.

I am experience crash that makes no sense to me, but I can no figure out the reason because until now I has no found a way to debug the csharp plugin.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: plugin for unity 3D

Postby Sweenie » Sun Jun 12, 2016 7:10 am

Usually i simply set the breakpoint in visual studio but by code i think you can use this...

Debugging
Last edited by Sweenie on Mon Jun 13, 2016 1:39 am, edited 1 time in total.
Sweenie
 
Posts: 503
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: plugin for unity 3D

Postby Julio Jerez » Sun Jun 12, 2016 6:50 pm

That's what I thought, but for some reason I can not get any brake point on the c chaps side to hit.
I try on two different machine, and it behaves the same way.
I do get break point on the cpp wrapper.
the only was I can make some sense to the flow if by using print debug.
can you re post the link? some how is does no connect.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: plugin for unity 3D

Postby Sweenie » Mon Jun 13, 2016 1:54 am

Reposted the link above, somehow phpbb didn't like the url with parentheses.

The link points to how to force the debugger to start.

In short, add "using System.Diagnostics" to the top and then call Debugger.Break() or Debugger.Launch()

But when I think about it I recall you have to attach to Unity from within Visual Studio.
To be able to do that you will have to open the script from within Unity so that the special Visual Studio for Unity version is started.

Check this video...
https://unity3d.com/learn/tutorials/top ... ual-studio
Sweenie
 
Posts: 503
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: plugin for unity 3D

Postby Julio Jerez » Mon Jun 13, 2016 1:41 pm

wow, interfacing c# with C++ is very gratuitously tedious for no apparent benefit.

I am using all style print, but that is a bad way.
Code: Select all
  public static void TestCallback()
        {
            UnityEngine.Debug.Log("calling call back");
        }


anyway I am try to call function call back for the C++ class, but I spend three day on and off ready way to do that, people say use C++/cli, other people say use interop, some people talk about Marshel, and swigg has some special keyword. I try all but all I get is complier of link error.

I know this should not be so difficult, there is fundamental misundertanding on my part, but I can not make heard or tail.

can you sync an see why I can pass a function pointer from c# to the C++ class so that the callback is called to displat the gitmos?

of you do plase look at public class NewtonCollider : MonoBehaviour
all I wna to do is call TestCallback from the m_shape class.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: plugin for unity 3D

Postby Julio Jerez » Mon Jun 13, 2016 2:00 pm

Oh I see I have to install a special set of tools for unity, I have VS professional at home and at work I installed VS community, but in neither one I see the option that she is talking about in the tutorial

she keep referring to "Attach to Unity editor" but I do no see that in the debug menu, do you have that command, is so how you find in Visual studio?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: plugin for unity 3D

Postby Julio Jerez » Mon Jun 13, 2016 2:24 pm

Ok I watch the tool videos, and I see that if you has visual studio before unity, it seem you have to find a Unity tamplate and create the project as a unity projects.
That seems moronic, what if you have a project already?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: plugin for unity 3D

Postby Julio Jerez » Mon Jun 13, 2016 2:51 pm

Ok I re install bothe visual studio community and unit again and now I see the "attach to unity command now"
I will do it at home again and se if it works.
Y home I have visual studio professional, so I hope is not a problem.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: plugin for unity 3D

Postby Sweenie » Tue Jun 14, 2016 2:11 am

Found some better documentation how to debug Unity with Visual Studio.
The video I posted assume you create the scripts from within Unity but we are creating a managed plugin.

https://msdn.microsoft.com/en-us/library/dn940020.aspx

Scroll down to the part that says "Debugging a DLL in your Unity project"
Sweenie
 
Posts: 503
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: plugin for unity 3D

Postby Sweenie » Tue Jun 14, 2016 2:55 am

Swig needs to "be aware" that a delegate should be used.

There is some Swig example code in the folder swigwin-3.0.8\Lib\csharp\, check the file csharphead.swg.
Look for SwigStringHelper.

Right now it tries to use the wrapper class SWIGTYPE_p_f___void and that won't work.

Hmm, it seems SWIG has a feature called "Directors" which seems to handle callback stuff...
https://github.com/swig/swig/tree/maste ... p/callback
Sweenie
 
Posts: 503
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: plugin for unity 3D

Postby Julio Jerez » Tue Jun 14, 2016 6:24 pm

I was starting to feel embarrass about this, it is almost like nothing was making sense.
Code: Select all
public delegate void ProgressCallbackGlue();
namespace NewtonPlugin
{
    abstract public class NewtonCollider : MonoBehaviour
    {
        public void TestCallback()
        {
            UnityEngine.Debug.Log("calling call back xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
        }


I now finally figured out what my problem was.
basically I was declaring the delegate inside the namespace, once I did that not matter what I did swig could not figure out how to map the c# function to a cpp function, even if I did it correct following the instructions for delegate declaration the names where different.
Swig map c# type to C types, basically is using this macro
Code: Select all
%define %cs_callback(TYPE, CSTYPE)
    %typemap(ctype) TYPE, TYPE& "void*"
    %typemap(in) TYPE  %{ $1 = ($1_type)$input; %}
    %typemap(in) TYPE& %{ $1 = ($1_type)&$input; %}
    %typemap(imtype, out="IntPtr") TYPE, TYPE& "CSTYPE"
    %typemap(cstype, out="IntPtr") TYPE, TYPE& "CSTYPE"
    %typemap(csin) TYPE, TYPE& "$csinput"
%enddef
%cs_callback(ProgressCallbackGlue, ProgressCallbackGlue)

I found over the swig mailing list, but I could no get it to work because name space, ideally it should be
%cs_callback(ProgressCallbackGlue, NewtonPlugin::ProgressCallbackGlue)

but it does not work, so after three days of trial an errors, but chance I moved the define outside the name space and now is worked.

I check in a test function that only print a massage, now I will see if it can print some data for the class, and of that works we can now make progress.

BTW I do not think that %feature ("director") is for call back stuff. but anyone I hope this is the last for the obstacles.
if you have time, please check it out see if this is correct.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: plugin for unity 3D

Postby Sweenie » Wed Jun 15, 2016 1:49 am

I don't think director is meant for that either, not the way we use callbacks anyway. It seems to be used for calling virtual methods. I guess it could be used for handling callbacks but the method you found seems to be the easier way to go.
I will check the lastest version as soon as I can. A thunderstorm is on it's way though so I probably will be unplugged for some time. Last time it fried my playstation 4 :roll:
Sweenie
 
Posts: 503
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: plugin for unity 3D

Postby Julio Jerez » Wed Jun 15, 2016 2:15 am

I elaborate a lithe more on the call back now the prototype is like this

Code: Select all
// on the c# side
public delegate void DrawFaceDelegateCallback(IntPtr points, int vertexCount);

// on the cpp side
struct dPoints
{
   float m_x;
   float m_y;
   float m_z;
};
typedef void(*DrawFaceCallback)(const dPoints* const points, int vertexCount);


"this is a test xxxxx 1 2 3"
now I will complete the lever call back and so that is can pass all the faces. and do the display
I hope this is a more solid foundation now.

The only part that still seem ugly in on the c# side, the function call back is like this

Code: Select all
    string xxxxxxxxx = "this is a test xxxxx ";
        public void DrawFace(IntPtr points, int vertexCount)
        {
            float[] points___ = new float[vertexCount * 3];

            //Copy(IntPtr source, float[] destination, int startIndex, int length);
            Marshal.Copy(points, points___, 0, vertexCount * 3);
            //UnityEngine.Debug.Log(xxxxxxxxx + vertexCount);
            UnityEngine.Debug.Log(xxxxxxxxx + points___[0] + " " + points___[1] + " " + points___[2]);
        }


to me is silly that swig does not have a way to map array of data other than IntPtr. and we have to use that Marshal.Copy stuff, but that is good enough.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron