Jump to content
  • Advertisement
Sign in to follow this  
IgnisDeus

Maya API Help

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently trying to make a simple file exporter in maya. I've run across the problem of exporting textures that match up with the meshes. Right now I'm ripping vertices/normals/uvs from the mesh via MFnMesh fnMesh(dagPath). Does anybody know how I could find out what texture (only a file name) is mapped to that mesh? I plan to only have 1 texture for a mesh, but possibly 12 meshes with 12 textures. Most of the examples online show how to rip textures and give a list, but that is of no use because I need them linked to a specific mesh. Thanks! [Edited by - IgnisDeus on August 26, 2005 9:31:14 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I haven't done an exporter yet... but to import a texture you have to create several Dependency Graph nodes. Quite different from the nice and easy to use DAG Node Variety

The easiest way I've found to find out how to do all this stuff is to do it the normal way in Maya and then use the Hypergraph to graph the connections. You will see that it works like this:

The outColor attribute plug of a file node is connected to the color attribute of a material node (phong, blinn, etc.). This is basically the image flowing from the texture to the material. You can also have a 2dTexturePlacement node attached to the file node, but this requires several different connections and I have just left it off so far.

Next, the material node is connected to a render set... that is a node created by FnSet with restriction set to kRenderableOnly. This set contains a list of all the shape nodes that are affected by that material =)

Hope that helps... and I hope I got all that right off the top of my head ^_^; You should be able to get most of the correct plug names just by mousing over the connections in the Hypergraph or using the connection editor by double clicking a connection.

Share this post


Link to post
Share on other sites
I'm having difficulty simply going from one dependency node to it's parent/child. This is all that is preventing me from finishing this task! Grr....thank you for replying btw, I figured nobody would :(. Thank you :) Right now I can get the shader name, or the filename path, but not both at the same time. If I do this:
MItDependencyNodes it(MFn::kLambert);
I get all the shader nodes and can get the names. If I do this:
MItDependencyNodes it(MFn::kFileTexture);
I get the child of the shader nodes, the actual file which has the plug for the actual file path, which is what I need.

I want to just go from the shader node, get the name, then go to the child node and pull the filename, but I can't go to the child node that easily. Grr!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
here's the key:

getConnectedShaders

i can't remember what you call that on, i think it might be a MFnMesh.
so that will give you the maya shader, which you can then look at and find the texture filename.
i think getConnectedShaders returns an array of that has one entry for each triangle, and tells you what shader each triangle uses, so you can split your mesh up by texture/shader.

try this google cache of the maya knowledgebase, the link doesn't work anymore.
http://64.233.161.104/search?q=cache:SVhREOxArlsJ:www.alias.com/eng/support/maya/knowledgebase/api/2979.jhtml+MFnMesh::getConnectedShaders&hl=en


http://www.alias.com/eng/support/maya/knowledgebase/api/2979.jhtml

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
here's the key:

getConnectedShaders

i can't remember what you call that on, i think it might be a MFnMesh.
so that will give you the maya shader, which you can then look at and find the texture filename.
i think getConnectedShaders returns an array of that has one entry for each triangle, and tells you what shader each triangle uses, so you can split your mesh up by texture/shader.

try this google cache of the maya knowledgebase, the link doesn't work anymore.
http://64.233.161.104/search?q=cache:SVhREOxArlsJ:www.alias.com/eng/support/maya/knowledgebase/api/2979.jhtml+MFnMesh::getConnectedShaders&hl=en


http://www.alias.com/eng/support/maya/knowledgebase/api/2979.jhtml

Share this post


Link to post
Share on other sites
Yeah I got that far, the problem is the connected shaders is exactly that: a shader. To actually get the filename like "c:/brick.bmp" I need the filetexture node, which I believe is the parent of the shader. I'm having difficulty simply moving up the chain. This is what I got that gives me the full shader name:


unsigned instanceNumber = dagPath.instanceNumber();
MObjectArray Shaders;
// this is used to hold indices to the materials returned in the object array
MIntArray FaceIndices;
// get the shaders used by the instance number
fnMesh.getConnectedShaders(instanceNumber, Shaders, FaceIndices);
char Temp2[200]="";
strcpy(Temp2, "This mesh has material: ");
strcat(Temp2, GetShaderName(Shaders[0]).asChar());
MGlobal::displayInfo( Temp2 );


There is no way to get the parent of the Shaders[0] object, I've tried everything. Everytime I do something that I think will work, it comes up blank on the filename.

Share this post


Link to post
Share on other sites
Check out the API for the MPlug you get from the getPlug function =)

Here's some code from my importer that might help you:

MPlug surfaceShader = setFn.findPlug( MString("surfaceShader") );
MPlugArray arr;
surfaceShader.connectedTo( arr, true, true );

You'd want to do the same thing but use the generic DependencyNodeFn, set it to the shader, get the color Plug, and ask for the connections which will be stored in an array as above.

I had a similar hard time moving from an understanding of the DAG to an understanding of the DG so I feel your pain <G>

Share this post


Link to post
Share on other sites
I finally did it! Took 8 hours of sleep and a shower but I got it! Lol. This function will rip all the full material names, and also their full file names. Then in the actual mesh ripping code I pull the material names, and can match it up with the filename and export. Thank you Shon and everybody else for the help. Finished product:


void StealText()
{

// create an iterator to go through all textures
MItDependencyNodes it(MFn::kFileTexture);
char Temp2[200]="";

while(!it.isDone()) //iterate through all textures
{
MFnDependencyNode fn(it.item()); // attach a dependency node to the file node

MPlugArray PlugArray;

MPlug oc = fn.findPlug("oc"); //Finds the outcolor, where the shader is connected

oc.connectedTo(PlugArray, true, true, NULL);//Get the nodes connected to this file texture node (aka shader!)

MObject OCObject = PlugArray[0].node(); //Make the MObject to attach to the shader node
MFnDependencyNode OCNode(OCObject); //Make a dependency node to attach to the shader node

strcpy(Temp2, "The Material Name: ");
strcat(Temp2, OCNode.name().asChar()); //Pull the name of the shader node
MGlobal::displayInfo( Temp2 );

// get the attribute for the full texture path
MPlug ftn = fn.findPlug("ftn");

// get the filename from the attribute
MString filename;
ftn.getValue(filename);

strcpy(Temp2, "The Material FileName/Location: ");
strcat(Temp2, filename.asChar());
MGlobal::displayInfo( Temp2 );

it.next(); // get next texture

}

}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!