PDA

View Full Version : api draw polygong


fbitonti
01-27-2007, 03:44 PM
I have a txt file filled with a bunch of coordiants. I am tying to import them with c++ then I want to be able to draw a polygon mesh with the api.

Untill this point I have only used the api to query meshes. can some one point me in the direction of what types of commands I need to look at to draw a mesh. Thanks for the help.

fbitonti
01-27-2007, 03:54 PM
I also have one more side question. If I compile a pluging with the 6.5 api will it run in the new maya 8.5.

GennadiyKorol
01-27-2007, 05:33 PM
Go with OpenGL library for drawing polygon meshes inside Maya. Though just vertex coordinates are not enough, you also need triangulation and normals information to properly draw the faces. That's in case if you just want to draw it. You could also create a polygon shape out of your file, and let the maya do the rest of the job (drawing, etc).

And no, you have to compile your plug-in with API of version X to make it work for Maya X :)

Hope it helps :)

fbitonti
01-28-2007, 12:26 AM
I don't understand what it is to "create a polygon shape" out of my file. Can you point me towards some information that might clear that up for me.

also if I have a plugin that i wrote with the 6.5 api can I compile it with the 8.5 api or do i need to re-wright things about it.

I realy appreciate the help.

fbitonti
01-28-2007, 12:40 AM
I found the code online. it seems to be what I am looking for will this work with the maya api. And how can I draw polygons with an unknown number of sides.

view.beginGL(); // Start openGL

// Push the color settings
glPushAttrib( GL_CURRENT_BIT );
glBegin( GL_TRIANGLES );
view.setDrawColor( MColor(0.1, 0.2, 0.7) ); // Set color as desired

// First set normal for the tri we are about to draw, otherwise lighting won't work!
glNormal3f( 0.0, 1.0, 0.0 );
// Now draw the triangle, defined by 3 points
glVertex3f( 0.0, 0.0, 0.0) ; // these are x,y,z positions of point 1
glVertex3f( 1.0, 0.0, 0.0) ; // these are x,y,z positions of point 2
glVertex3f( 0.0, 0.0, 1.0) ; // these are x,y,z positions of point 3
// etc...


glEnd(); // end of LINES
glPopAttrib();


view.endGL(); // End openGL

GennadiyKorol
01-28-2007, 09:45 AM
MFnMesh function set has methods to build new shape objects out of arrays of vertices, normals, connections etc. You could read your file, build the according arrays, and make maya create the shape.

To compile the plug-in for new version just link it with libraries of the new Api. Then fix any compilation errors/warnings you come across :)


As for polygons you need to draw polygon triangles, for that you need to know polygon triangulation. You should know the number of sides in a polygon after reading the file.

Hope it helps :)

Henry

fbitonti
01-28-2007, 03:39 PM
Ok I did some looking on the internet and I understand how the MfnMesh function works. however, I can not find any sample code of how to actualy use it online. I am still fairly new to c++ and the maya api and I realy need to see a sample of how this is done if i am going to undertand it. Can anyone recomend a website where some one may have a tutorial for createing a simple cube mesh with the api online or I am even willing to purchase a book or somthing like that if i can see a real example of how this is used. Thanks for all the help.

GennadiyKorol
01-28-2007, 03:53 PM
I'd really suggest these two books:

Complete Maya Programming An Extensive Guide to MEL and C++ API (http://www.amazon.com/Complete-Maya-Programming-Extensive-Kaufmann/dp/1558608354/sr=8-1/qid=1170002951/ref=pd_bbs_sr_1/102-3487741-3281717?ie=UTF8&s=books)

Complete Maya Programming Vol II. (http://www.amazon.com/Complete-Maya-Programming-Vol-Depth/dp/0120884828/sr=8-2/qid=1170002951/ref=pd_bbs_sr_2/102-3487741-3281717?ie=UTF8&s=books)

Especially the first one.
I find the second book a bit less useful, it doesn't seem to provide many more info than you could get by reading the API guide in maya help + some good 3d math book. But it does contain the concrete examples of building polygon meshes from scratch in maya with API as you need.

Cheers :)

fbitonti
01-28-2007, 04:56 PM
Oddly enough I have the Complete Maya Programming Vol II. (http://www.amazon.com/Complete-Maya-Programming-Vol-Depth/dp/0120884828/sr=8-2/qid=1170002951/ref=pd_bbs_sr_2/102-3487741-3281717?ie=UTF8&s=books) book you described. However, I can only find where they talk about querying meshes and not on building them. Where in the book can I find this information. That would be awsome and solve all my problems.

GennadiyKorol
01-29-2007, 09:31 AM
From page 207, there starts the chapter about Creating Meshes that has the examples of creating custom polygon primitives with a plug-in.

CGTalk Moderation
01-29-2007, 09:31 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.