Hello,
I have a plugin for Maya and think it would make a great plugin for StingRay. It does not rely on any Maya functionality, and operates during runtime. I currently have it running in my own game engine. The plugin is written in C++. Is it possible to use this plugin in StingRay? Is LUA capable of handling native code? Does Stingray have any hooks to accomidate this?
Thanks for any feedback.
H
Looks like there is a solution:
https://www.dropbox.com/s/nq38nfbyadxw6ms/Lua-Extension-Modules.html?dl=0
I think that document is out of date, because Stingray 1.1 has "allow dynamic linking against LuaJIT" in its release notes, and the document describes problems due to static linking. I'm not sure what steps need to be performed for Stingray 1.1, because I don't see any public info on it. My assumption is that you need to build your own .dll that expects to dynamically link with lua51.dll (either x86 or x64 depending on your target) and then get Stingray's Lua VM to load it at runtime by using 'require' with a module name instead of a Lua source file. I don't know if you're supposed to use the headers/interface some specific version or configuration of Lua 5.1 when building your .dll. There's also a lua52.dll in the installation, but it's under a tools directory and I'm assuming this is not the Lua used at runtime by the engine (I guess I could find out by inspecting the process).
There is also this http://help.autodesk.com/view/Stingray/ENU/?guid=__developer_writing_plugins_html but that seems to be an actual plugin API, as opposed to communicating to the engine via the Lua FFI, which is what the old document you described is talking about. The files listed in that plugin API help page don't actually exist in my installation of Stingray. I'm guessing it's actually meant for people with a source code license. I kind of wish the documentation intended for people who have access to the source code wasn't mixed in with the documentation for people who don't have access to it.
There are basically three ways to get your custom C code to run in Stingray using a DLL.
NOTE: As of v.1.1, dynamic linking is only possible on Windows, so these approaches can ONLY be used for games that target only Windows. If you want to target other platforms than Windows, you'll need to either a) get source access, link statically and rebuild the engine binaries with your code in it, or b) stay tuned for a future release where we support dynamic linking on more than just Windows.
Option 1: writing an engine-level plugin using the plug-in API described under http://help.autodesk.com/view/Stingray/ENU/?guid=_
Option 2: using the LuaJIT FFI library. There's a quick summary in the dropbox link given above, and more details in the LuaJIT docs. You make a DLL out of your C code, and place the DLL next to your Stingray engine executable. In a special block within your project's Lua code, you write declarations for the C functions and types that you want to use. Then you load your DLL from Lua using the LuaJIT FFI, and call the C functions you've defined from your Lua code. This way is "easy" because you don't have to write any special binding code in C, and you don't have to worry about compiling your C code against Lua. You can just call your C code as-is from Lua. However, I've personally found it hard to get FFI working with any non-trivial real-world C modules due to complex data type conversions and stuff. YMMV!
Option 3: making a Lua Extension Module by writing your own bindings (in C) that expose your C functions into the Lua environment. Your module needs to have a function called luaopen_<dll_name>, in which you register your C functions. The document on the dropbox link has some information about this, and there's more available on the web. You then compile your C code to a DLL, which you place next to your engine executable. In your project's Lua code (say, in the project.lua file), you put a "require" statement that loads your DLL, and then in your Lua functions you can call whatever functions you've created bindings for on the C side.
For option 3 to work in Stingray v.1.1, I've found that you have to get the version of LuaJIT that matches the one used in Stingray (2.0.0), and link your C code against it dynamically. You have to build the LuaJIT binaries yourself, making sure that you target the right processor (32-bit or 64-bit). Your C code has to include lauxlib.h in order for you to write your bindings, so add the src directory of the LuaJIT distribution to your include directories. Link your code against the lua51.lib that you build from the LuaJIT distribution. The LuaJIT DLL will already be available at runtime, loaded by Stingray (again, as of v.1.1).
It's easy to end up in "DLL hell" doing all this, so start with some simple C code until you get your build and installation working right.
I'm working on making some more official docs for this process, but hopefully this might help get you started.
Extensibility is high on our agenda for both the runtime engine and the editing tools, so keep your eyes on each new upcoming release. If you do give any of these options a shot, let us know what you find.
Thanks for the info. I think our plugin would be considered more middleware and option 1 remains the best bet.
I made a request for the source code a few days ago, but I do not think that it will be approved. At this point, we've hit so many walls that it's probably best to drop it for awhile.
Thanks for your help though.
H
This is a demo of the destruction f/x we've been working on, and would like to run through Stingray.
We use Maya as our world builder and than export the scene to our MOAB game engine.
Ideal scenario for us would be exporting the scene directly to Stingray from Maya. However, because destruction has a lot of moving parts, it requires access to all parts of the creation through rendering process. A generic asset interface won't work.
Thanks Dan for helping out.
Take it easy.
H
@Anonymous wrote:I know nothing about integrating C++ into Stingray, but that video demo is amazing! 🙂
Thanks. I hope I can make this f/x available to all Stingray game developers some day.
Cheers.
H
Can't find what you're looking for? Ask the community or share your knowledge.