A Static Mesh Maya Exporter & Irrlicht Mesh Viewer – How to write Maya Plugin with c++

本文介绍了一种使用C++编写的Maya静态网格导出器的实现方法。作者最初计划添加皮肤动画的额外功能,但发现Maya C++ API过于复杂。在收集所有三角形的过程中,解决了顶点共享问题,并使用连续的顶点缓冲区和索引缓冲区以提高GPU性能。此外,还提供了一个简单的Irrlicht引擎1.7.2的网格加载器来查看导出的网格。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

screen_shot-300x248

This sample program shows us how to write a Maya static mesh exporter with c++. At first, I planed to write some additional features on the skin animation, but Maya C++ API seems very complicated for me. I could own a copy of Maya programming white paper, and know all the classes. but I could not figure out what the relationship among them, and can not easily grab a path from class A object to class B object. That is how the graphic goes in the Maya editor. I am not family with such big stuff. Cause I am a programmer, not a artist.


I defined a customized kind of static mesh format, that will be used to hold the exported data. To view the exporting meshes, I implemented a simple mesh loader with Irrlicht engine 1.7.2. The above screen shot was from the demo screen-shot.

 

Some Ideas

During the process of coding, some ideas grow up in my mind:
1) The first questions is how to resolve the vertex shared problem. The way I collect all of the triangles was like this: go though all polygons and find all triangles for each polygon; For each triangle, I collected 3 vertex elements without considering some of them could be shared by other triangles. That means 3 new elements will be added into the vertex buffer for each triangle, and 1 triangle (3 vertex index number) will be added into the index buffer. I tried to save each vertex element and do a quick search before a new vertex element need to add. But here come a very serious problem. The search process it-self take too much time. I tried to use the binary search to address the search performance issue, but the result was far from what I expected. So finally I made some duplicated vertex elements into my vertex buffer.
2) At last a continue vertex buffer and an index buffer were used.  Yes, this solution will increase some memory usage, but maybe we could get some performance improved. Because we make those two memory access continuously, the GPU process units do not need to jump back and forward to fetch the vertex data. Of course there are still some optimization space here: we could reduce some duplicated vertex element and also get some performance better. Remember that the GPU has some cache hardware, that device could cache some vertex data that need to access frequently.
3) You could some some low polygon model instead of high polygon model. Too many geometry will be a big burden for GPU. I tried to use a model with 12M in Maya, and the frame rate drops dramatically.
4) Thanks to http://www.mayawu.com/ that provide me with a free robot Maya model.

 

Run the Demo

The full source code could be downloaded from here. Here are some limitations when you want to compile and run the program:
1) I will not provide maya libraries and dlls. and I used Maya2009 develop kit, so you’d better to do a full Maya2009 installing on your computer. You should  install the Maya software package, develop kit and full documents. I did not try other Maya version, it may work. I am not sure.
2) To make the exporter could be run  more smoothly, you need to set MAYA_LOCATION environment path to figure out where you maya have installed. For example, I set MAYA_LOCATION to “C:\Program Files\Autodesk\Maya2009″ on my computer.
3) I will not provide some library about Irrlicht. This is an open source graphics engine, you could download it from website for free. The Irrlicht engine version that I used here is Irrlicht-1.7.2. After you re-compile the Irrlicht locally, you need to copy Irrlicht.dll file into the MayaPlugin\bin directory.
4) After you download the Irrlicht, you could un-zip it. You should put my source code under the “Irrlicht-1.7.2\tool” directory if you do not want to change the include & lib path.
5) Be care of where you install the Maya, you need to set the Maya include & lib path in your project if possible.
6) Obviously, I used the windows OS. And of course VS2008 used here. You need to do translate works when you want to use other make tools.
7) Another project “objExporter” also provided here. If you want to write a Maya Plug-in, and put all exporting stuff under the Maya “Export All..” menu item, you could deep further.
8) Some other documents that I collected from the web site also provided.

转载于:https://www.cnblogs.com/open-coder/archive/2012/08/24/2653565.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值