Wrapping the SDK in .NET

I'd like to start by saying that I understand the benefits of C++ in general, and I know a wrapper isn't a substitute for writing good unmanaged code.  The disclaimer may not be necessary here, everyone on the Daz forums has been super nice, but in a lot of forums, anyone asking about coding C# in a C++ environment tends to draw a pretty negative response.  cheeky

That said, I've been considering wrapping the Daz SDK or using something like SWIG.  The bulk  of my development experience is in C# / .NET.  I'm trying to boost my C++ chops, but the reality is, I work much faster in C#.  I also tend to feel it's ok to want to work where you're most comfortable, so long as the performance trade-offs are negligible.  On that note, it seems like the SDK methods handle a lot of array sizing, garbage collection, etc. anyway, so I don't know that much optimization opportunity would really be lost anyway.  Some pinvoke overhead, I suppose?

Does anyone have any thoughts on this?  Potential pitfalls specific to the Daz SDK?  And I'm really reaching here, but would anyone be interested in helping? laugh  A wrapper could really open up plugin development to a wider audience.  That may not be what anyone wants, but it seems like a good thing (or I'm just rationalizing :-P ).

Comments

  • shoei321shoei321 Posts: 106

    I wouldn't do this, for a variety of reasons.   I have some experience working with wrapper code in other environments, and it will guaranteed add a layer of complexity and complication, and bring little value of it's own.    As a general rule you will always be best off working in the native language of whichever SDK you are interacting with, and in this case it's c++.

    The logistics of this would be very complicated, given the Daz plugin architecture.    The Daz application invokes plugins via it's own interface (c++), so you would be faced with writing some c++ to bridge between Daz Studio and your c# environment (which would have to be invoked and run in a separate process, given the different runtimes), and then you would have to bridge again from c# to the c++ Daz SDK to make use of any of it's functions from your c# code.     In a word, absurd.

    My advice -- just learn c++.  

     

     

  • hphoenixhphoenix Posts: 1,237

    As someone who professionally codes in C# and C++, I can tell you the primary issue.....time.

    Writing a C# wrapper API would require writing a LOT of code.  For every single object exposed by the DAZ C++ API, you would have to write an equivalent C# class, with all the methods, slots, and signals converted over using pInvoke wrapping with proper marshalling of the data passed.  It's NOT a simple task.

    Since the plugin architecture also uses Qt, you'd ALSO have to create an API for those calls.  Even bigger task there.  It would be quite the enormous undertaking.

    Now, it IS possible to write a simple converter that would take the C++ headers and convert those into C# wrappers with pInvoke declarations.  But that's just the start.....

    And, as shoei321 says, the actual connection between DS and the plugin requires some special handling.  And since we only have the C++ headers (and out-of-date ones, at that) creating that linkage would be pretty tricky.

     

    It's honestly easier to just write your plugins in C++.  Learn to manage your own memory and threading.  The majority of the syntax is the same, and once you get head wrapped around referencing and dereferencing pointers properly, you're 99% there.

     

  • mjc1016mjc1016 Posts: 15,001

    And since it hasn't been mentioned yet...cross platform.  C++ can be easily cross platform (remember Studio does support Macs, too).  C#/.NET less easily so.

  • simtenerosimtenero Posts: 369

    Thanks for the feedback all, exactly what I was looking for!  I guess I'll need to fire up some practice applications to get more proficient with C++.  I'm mostly there with core-concepts, it's just about internalizing the syntax and structure (I'm super accustomed to classes and name spaces :-P).

  • I SamuelI Samuel Posts: 226

    Unity and Cry Engine have done it beautifully which has really increased developer productivity. C#/.Net are cross platform and open source as well; all platforms supported e.g.; Mac, iOS, Android, Windows, Linux etc. Even Visual Studio for Mac is available now. They also have lightweight Visual Studio code as well. It will require some work may be an open source C# Wrappers project can be created to help with this effort. It will surely bring many developers onboard. I have not played with DAZ Studio SDK yet but it will be cool if it can be extended with tons of modeling features like Carrara.

     

Sign In or Register to comment.