simple Mayaexporter

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

Recommended Posts

atm i'm trying to write a simple exporter that creates a binary file and writes vertices+indices to it...it is based on Rob-the-bloke's simple exporterand the code i added is almost copied and pasted from the tuts his site...the only big change i did was switching from textfiles to binary files. these files consists of chunks that i defined in a headerfile. but my problem is that as soon as i export sth in maya creates the file, writes some stuff and crashes...i don't know where the problem could be...my code also contains the loops for getting the Uvs+Normals but the are not exported yet... my code:
std::ofstream ofs(file.fullName().asChar(),ios::out | ios::binary);

// make sure it opened ok
if(!ofs)
{
std::cerr << "[ERROR] Could not open file for writing " << file.fullName().asChar() << std::endl;
}
else
{
// use an iterator to iterate through all Meshnodes in the scene
MItDependencyNodes it(MFn::kMesh);

// loop through all nodes
for( ; !it.isDone(); it.next() )
{

MFnMesh fn(it.item());

if(!fn.isIntermediateObject())
{
//VERTICES:

MPointArray vts;

fn.getPoints(vts);
//ofs << fn.name().asChar() << ":" << std::endl;  //<--Mesh

for(int i=0;i!=vts.length();i++)
{
//it's vertices:
//ofs << "{" << vts.x << ";" << vts.y << ";" << vts.z << "}" <<std::endl;
struct Vert {
float x,y,z;
};
Vert Vertex;
Vertex.x=vts.x;
Vertex.x=vts.y;
Vertex.x=vts.z;
ofs.write(reinterpret_cast<char *>(&Vertex),sizeof(Vertex));
}

//NORMALS:
MFloatVectorArray normals;
fn.getNormals(normals);
for(int i=0;i!=vts.length();i++)   //<--iterate trough all normals
{
//it's Normals:
//ofs << "{" << vts.x << ";" << vts.y << ";" << vts.z << "}" <<std::endl;

}

//UV-Coords:
MStringArray uvsets; //a mesh can have multiple Uvsets!
fn.getUVSetNames(uvsets);
if( !uvsets.length() || !fn.numUVs(uvsets[0]) )
{
cout << "0\n";

}
for(int j=0;j!=uvsets.length();j++)  //for every UVSet
{

cout << uvsets.asChar() <<endl; //print out the name of the uvset

MFloatArray ucoords;
MFloatArray vcoords;

fn.getUVs(ucoords,vcoords,&uvsets);
int NumUvs;
NumUvs=fn.numUVs(uvsets);

for(int i=0;i!=NumUvs;i++)   //for every UVCoord
{

//ucoords= UCoords
//vcoords= VCoords

}

} // for every UVset end

//Indices:

MItMeshPolygon itPoly(it.item());
std::vector<short> VertexIndices;
while(!itPoly.isDone())  //for every Poly
{
int NumVerts=itPoly.polygonVertexCount(); //Vertices per Polygon
if(NumVerts==3)
{
for(int k=0;i<NumVerts;k++) //for every Vertex of the polygon
{

VertexIndices.push_back(short(itPoly.vertexIndex(i)));
//itPoly.vertexIndex(i); outputs Vertexindices
//itPoly.normalIndex(i); outputs Vertexnormalindices

}
}

}
for(int l=0;l<VertexIndices.size();l++) {
std::vector<short>::pointer ptr = &VertexIndices[0];
ofs.write(reinterpret_cast<char *>(ptr),sizeof(short)*VertexIndices.size());

}//UV COORDS MISSING!

ofs.close();
}
}
}
return MS::kSuccess;
}


regards, m4gnus

Share on other sites
run it in debug and step through till it crahses...the let us know where that was and we might be able to help :o)

Share on other sites
i don't know how i can do this because it creates a dll that is loaded by maya as a plugin...
btw i haven't even used a debugger on other projects ...so i don't really know how to use it...especially in .net 2003 (i used VC 6 earlier)

regards,
m4gnus

Share on other sites
If you have a DLL project, when you hit F5 DevStudio should ask you which exe you want to run. Pick the Maya exe. That should work fine.

Using the debugger is pretty simple. If you hit F9 on a line of code it will put a breakpoint there. This will stop the execution on that line. You can then use F10 to proceed line by line and see what happens and F11 will step into a function call on any given line. To get the program to continue running normally, just hit F5 again.

Also, you should be able to start debugging without doing any of this if it's crashing in your DLL. When it crashes, look in the "Call Stack" tab in DevStudio. It should show you which line it stopped on, as well as the previous calls.

Getting familiar with the debugger is a really helpful thing when programming :)

-John

Share on other sites
ok the debugger really helped me...the while loop for getting the indices of every face was an infinite loop because the itPoly.next(); was missing...but the error is also on Rob-the-bloke's homepage so i'll write him a short pm...

Edit: btw i also have a problem with the loading of the data...i think it's just a syntax error so it should be easy to solve...I'll open a new thread

thx

regards,
m4gnus

1. 1
2. 2
3. 3
Rutin
23
4. 4
5. 5

• 13
• 19
• 14
• 9
• 9
• Forum Statistics

• Total Topics
632932
• Total Posts
3009294
• Who's Online (See full list)

There are no registered users currently online

×