I am working on a software research project that is entirely in C#, however now we want to have a maya plugin that utilizes some of the functionality from the C# code.
Maya expects an unmanaged dll, which is fine i don't mind writting that.
However, i need to make hooks to the C# code and vice versa, i have no problems accessing my unmanaged dll from C# using InteropServices, but i do not know how to access the managed code from the unmanaged C++, any hints?
I am sure this is possible, but i have never done it.
If anyone has any suggestions for a purely managed solution, i would be thankful
Have you looked into
Managed Extensions for C++ at all? I personally have never used it, but it seems to popular way to tie managed and unmanaged code together. The /clr option still compiles it to MSIL, but I'm not sure exactly what Maya's restrictions are.
found this article that seems to describe the process i need to use, ugh looks like a lot of steps
this article that seems to describe the process i need to use, ugh looks like a lot of steps
I've not read the article, but from the date of it, it's old, pre-2005. They changed the way the C++ managed/unmanaged stuff works with 2005. So unless your using 2003 or 2002, then I probably would take too much notice of that article.
Having said that, I've only done trivial Managed C++ stuff, and did not have to resort to anything spectacular. Though, I did have to create proxies for most things, like data structures, etc.
A few of those proxies were probably unnecessary, as the builtin marshalling stuff is quite extensive. But I found it harder to get up-to-speed with the marshaling stuff than it was to hand-roll my own proxies. You mileage may vary...
After breakfast (and catching up on the new Ch9 videos), I'll see if I have some time, and do a little sleuthing (it's morning over here...)
OK. How performant does this need to be ? How many threads ?
My initial reaction to this is to use COM, mainly because you have the issue of hosting the CLR, and the Managed C++ code (obviously) needs the CLR - I'm presuming that Maya doesn't host the CLR.
So rather than using Managed C++, just bypass C++ altogether, and expose your Manged Code via COM.
Well, you still need to write the Maya DLL, so you probably still need to write that using C++. But these stubs would be interopting via COM.
If you want to write something rapidily (prototype), then depending on the Interfaces Maya expects, you could probably whip up a Native DLL using VB6 - COM is native to VB6, whereas for C++, you probably end up using ATL. Raw COM from C/C++ is ugly...
performance wise i will need it to be able to pass about 100 3d vector structures (x,y,z) floats a second, which is a pretty low requirement. The data will most likely be fed through in a fifo type queue.
The plugin will take in data from the maya ui (in the form of a text string or a wav file--probably still just a text string), and communicate with the C# code, then feed the result back to maya as new vertex points for parts of the model - the plugin has to
interpret this data from a proprietary xml format.
After speaking to the project lead, I think I am first going to ensure i can interact with maya through unmanaged c++, then i will most likely develop a wrapper for managed access.
maya comes with a VS wizard that creates a C++ project for a maya plugin, at this point i am not certain what vector it specifically uses to communicate as that functionality is wrapped in a seperate set of macros.
The other problem is that the project targets .NET 1.1... and i don't have access to 2003 at home, but they might migrate to 2.0... i'll figure it out, but old tutorials are good, for now
COM likes to do things in large chunks because the roundtrip (cross process/ cross machine) is expensive. 100 per second might be OK. I think the last time I benched it, I was able to get up to ~1000 calls per second. But my memory may be wrong in this
case. I certainly wouldn't try going much beyond 100, at least on a single core system.
The other thing to consider is [hosting the 1.1 CLR]. That is, within your Maya Plugin DLL,
you host a CLR domain, and your managed code runs within this isolated environment. Kind of like adding a scripting engine, but the 'scripts' are your managed code.
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.