Maya Viewport Plugin
- nickgravelyn
- Halfling
- Posts: 96
- Joined: Sat Jan 28, 2006 7:41 pm
- Location: Michigan
Maya Viewport Plugin
Does anyone here have experience writing plugins for Maya? I recently saw oFusion and was quite impressed. Problem is that I (and my artists) prefer Maya over 3DSM. Does anyone have any ideas how long writing a viewport plugin for Maya would take? Is anyone working on one, by chance? Where's a good place to start learning how to write one myself (I need to create one for Windows and OSX)?
Nick Gravelyn
-
gramulho
- Halfling
- Posts: 47
- Joined: Mon Jul 10, 2006 4:15 pm
- Location: Brazil
- Contact:
Well, I was about to try this when a project ate my time. But it shouldnt be hard as maya allows you to use any OpenGL command on its viewports, just write a wrapper that intercepts Ogre OpenGL stuff and send it to the maya viewport (best bet is that OFusion does the same). Best place for you to start, is looking at the API and the exemples found in the maya\devkit folder.
-
JeDi
- Gnome
- Posts: 351
- Joined: Thu Oct 21, 2004 1:34 pm
- Location: Diepenbeek, Belgium
- x 3
- Contact:
Actually, the way this is done most of the time (and also in OFusion, as you can choose whether to use OpenGL or DirectX), is creating an ogre window and providing the viewport window as parent. I'm not sure how to do this using the maya api, but I'm sure there's a function to get the viewport handle. Look at the various wxwidgets/.NET/QT examples to see how to create an ogre window as a child of another.
Greetz,
JeDi
Greetz,
JeDi
- nickgravelyn
- Halfling
- Posts: 96
- Joined: Sat Jan 28, 2006 7:41 pm
- Location: Michigan
Alright. I have a project set up with a simple Maya command that gets me the viewport's window handle. Any suggestions on how I should create an Ogre context that actually renders what's in my Maya scene?
Edit: To joshua: I am interested in developing this. If you would like to help, you are more than welcome.
Edit: To joshua: I am interested in developing this. If you would like to help, you are more than welcome.
Nick Gravelyn
-
Lodes
- Google Summer of Code Student

- Posts: 228
- Joined: Mon Mar 17, 2003 12:02 am
- Location: San Jose, CA, USA
Code: Select all
Ogre::NameValuePairList options;
#if TOOL_PLATFORM == WINDOWS_PLATFORM
HWND handle = static_cast<HWND>(vc.GetParentWindowHandle());
options.insert(Ogre::NameValuePairList::value_type("parentWindowHandle",
Ogre::StringConverter::toString(reinterpret_cast<size_t>(handle))));
#else if TOOL_PLATFORM == LINUX_PLATFORM
// TODO: Linux Support
#endif
_window = root.createRenderWindow(name, 640, 480, false, &options);
instead of options.insert(...) you can also do:
options["parentWindowHandle"]=Ogre::StringConverter::toString(...);
Now to render the Maya Scene... well that's a whole other ballpark.
- xavier
- OGRE Retired Moderator

- Posts: 9481
- Joined: Fri Feb 18, 2005 2:03 am
- Location: Dublin, CA, US
- x 22
Yup. You get to create Ogre mesh, materials, bones and animations manually based on what's in the Maya scene...which means you have to duplicate it, translating Maya-isms to Ogre-isms for everything in the scene.Lodes wrote: Now to render the Maya Scene... well that's a whole other ballpark.
It's not trivial, in other words.
- nickgravelyn
- Halfling
- Posts: 96
- Joined: Sat Jan 28, 2006 7:41 pm
- Location: Michigan
Sounds fun. First I have to get Ogre rendering in the viewport. Not quite sure how that one's going to work yet. I thought about testing with the ExampleApplication class but I don't think that's the best approach. Can anyone with any experience with the Maya API and Ogre toss out a few ideas of how to structure this? My main concern is making sure to only have one Root for the whole app and not create a new one for each viewport.
Nick Gravelyn
-
gramulho
- Halfling
- Posts: 47
- Joined: Mon Jul 10, 2006 4:15 pm
- Location: Brazil
- Contact:
Here lies your first clue... this is a quote from maya docs.
I will try to dig in depper and see if I can help in any way...A hardware shading node plug-in is written as a Maya Dependency Graph (DG) node. A basic hardware shading node contains attributes that are treated as inputs and outputs; where each shading node must have an output so that it can be connected in the Dependency Graph. Also, hardware shading node plug-ins implement virtual methods that are called to perform resource creation, deletion and drawing. These virtual methods are called when Maya detects that there is a hardware shader node plug-in attached to a piece of geometry and Hardware Shading is required. You can implement Standard OpenGL rendering, vendor extensions, pixel/vertex shaders and multi-pass shading with the hardware shading node plug-in to provide a fine level of control over Maya's display.
Hardware shading plug-ins are supported in the Maya scene view, the scene view with High Quality Interactive shading mode, the hardware renderer and the UV Texture Editor. The types of geometry supported by these areas of Maya are as follows:
Mesh shapes are supported in all areas
NURBS surfaces are only supported in the scene view with High Quality shading display and the hardware renderer when using the gl interface
Yup. You get to create Ogre mesh, materials, bones and animations manually based on what's in the Maya scene...which means you have to duplicate it, translating Maya-isms to Ogre-isms for everything in the scene.
It's not trivial, in other words.
- nickgravelyn
- Halfling
- Posts: 96
- Joined: Sat Jan 28, 2006 7:41 pm
- Location: Michigan
Thanks for the tip. Here's my code so far. Basically, all I'm trying to do is slowly build up to actually capturing a viewport and rendering to it. I'm not quite there and I do realize that there are some other things to attend to (such as deleting root when Maya closes and probably creating it elsewhere), but this is how to use Maya to create the subwindow (I believe, I haven't tested it yet, but I got the code to get the window from a Maya example plugin). I am getting some Ogre linker errors though. First code, then errors:
Code: Select all
#include <maya/MSimple.h>
#include <maya/MObject.h>
#include <maya/MGlobal.h>
#include <maya/M3dView.h>
#if defined(OSMac_MachO_)
# include <OpenGL/gl.h>
#else
# include <GL/gl.h>
#endif
#include <Ogre.h>
#include <stdlib.h>
#include <maya/MIOStream.h>
DeclareSimpleCommand( viewHijack, "Alias", "7.0" )
Ogre::Root *root = NULL;
Ogre::RenderWindow *window = NULL;
Ogre::SceneManager *sceneMgr = NULL;
Ogre::Camera *camera = NULL;
Ogre::Viewport *viewport = NULL;
MStatus viewHijack::doIt( const MArgList& args )
{
if( root == NULL )
{
root = new Ogre::Root();
Ogre::RenderSystemList *rsList = root->getAvailableRenderers();
int c=0;
bool foundit = false;
Ogre::RenderSystem *selectedRenderSystem = NULL;
while( c < (int)rsList->size() )
{
selectedRenderSystem = rsList->at(c);
Ogre::String rname = selectedRenderSystem->getName();
if( rname.compare( "OpenGL Rendering Subsystem" ) == 0 )
{
foundit = true;
break;
}
c++;
}
if( !foundit )
return MS::kFailure;
root->setRenderSystem(selectedRenderSystem);
selectedRenderSystem->setConfigOption("Full Screen","No");
selectedRenderSystem->setConfigOption("Video Mode","800 x 600 @ 16-bit colour");
M3dWindow viewport = M3dView::active3dView().window();
Ogre::NameValuePairList options;
options.insert( Ogre::NameValuePairList::value_type( "parentWindowHandle",
Ogre::StringConverter::toString( reinterpret_cast<size_t>( viewport ) ) ) );
window = root->createRenderWindow( "Ogre Viewport", 640, 480, false, &options );
}
MStatus status = MS::kSuccess;
return status;
}Code: Select all
1>------ Build started: Project: OgreViewport, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>Linking...
1> Creating library ../build/Debug/OgreViewport.lib and object ../build/Debug/OgreViewport.exp
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) private:
void * __thiscall Ogre::MemoryManager::op_new_sc(unsigned int,unsigned int)"
(__imp_?op_new_sc@MemoryManager@Ogre@@AAEPAXII@Z) referenced in function
"void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) private:
unsigned int __thiscall Ogre::MemoryManager::_getProcessID(void)"
(__imp_?_getProcessID@MemoryManager@Ogre@@AAEIXZ) referenced in function
"void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) private:
void __thiscall Ogre::MemoryManager::op_del_sc(void *,unsigned int)"
(__imp_?op_del_sc@MemoryManager@Ogre@@AAEXPAXI@Z) referenced in function
"void __cdecl operator delete(void *)" (??3@YAXPAX@Z)
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public:
void __thiscall Ogre::MemoryManager::setOwner(char const *,unsigned int,char const *)"
(__imp_?setOwner@MemoryManager@Ogre@@QAEXPBDI0@Z) referenced in function
"public: static void * __cdecl viewHijack::creator(void)" (?creator@viewHijack@@SAPAXXZ)
1>main.obj : error LNK2019: unresolved external symbol
__imp___CrtDbgReportW referenced in function "public: bool __thiscall
std::_Tree<class std::_Tmap_traits<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >,class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >,struct std::less<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > >,class
std::allocator<struct std::pair<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > const ,class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > > >,0> >::const_iterator::operator==(class
std::_Tree<class std::_Tmap_traits<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >,class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >,struct std::less<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > >,class
std::allocator<struct std::pair<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > const ,class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > > >,0> >::const_iterator const &)const "
(??8const_iterator@?$_Tree@V?$_Tmap_traits@V?$basic_string@DU?
$char_traits@D@std@@V?$allocator@D@2@@std@@V12@U?$less@V?
$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@
@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D
@std@@V?$allocator@D@2@@std@@V12@@std@@@2@$0A@@std@@@
std@@QBE_NABV012@@Z)
1>../build/Debug/OgreViewport.mll : fatal error LNK1120: 5 unresolved externals
1>Build log was saved at "file://c:\Documents and Settings\Nick\My Documents\
Visual Studio 2005\Projects\OgreViewport\OgreViewport\Debug\BuildLog.htm"
1>OgreViewport - 6 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Nick Gravelyn
-
gramulho
- Halfling
- Posts: 47
- Joined: Mon Jul 10, 2006 4:15 pm
- Location: Brazil
- Contact:
This is a redirect from a Search i did, so next time try searching your problem before posting. 
I just happened to saw a class on the maya API that you might want to take a very close look at, another quote...Unresolved External Symbols
[edit]
__declspec(dllimport)...Ogre::MemoryManager::op_new_sc()...
LNK2001: unresolved external symbol "__declspec(dllimport) private: void * __thiscall Ogre::MemoryManager::op_new_sc(unsigned int,unsigned int)" (__imp_?op_new_sc@MemoryManager@Ogre@@AAEPAXII@Z)
You tried to link a release mode OgreMain.lib with a debug mode application. So make sure your application's debug configuration links against OgreMain_d.lib. This can be changed in your project properties under Linker->Input in the field Additional Dependencies.
class MPxGlBuffer
Base class for user defined GL buffers (OpenMayaUI)