PDA

View Full Version : OBJ Exporter from API


dbsmith
03-03-2009, 05:03 AM
Hey all,
Just wanting to add some custom options in my OBJ Exporter. My code works all good, except at this piece here:



// Test for equivalent materials
//
bool materialsEqual = false;
if ( (lastMaterials != NULL) &&
(lastMaterials->length() == currentMaterials->length (http://download.autodesk.com/us/maya/2009help/API/class_m_int_array.html#03c4aeca1197c24b051e91bbfa6a778c)())
) {
materialsEqual = true;
length = lastMaterials->length (http://download.autodesk.com/us/maya/2009help/API/class_m_int_array.html#03c4aeca1197c24b051e91bbfa6a778c)();
for ( i=0; i<length; i++ )
{
if ( (*lastMaterials)[i] != (*currentMaterials)[i] ) {
materialsEqual = false;
break;
}
}
}

if ( !materialsEqual ) {
if ( lastMaterials != NULL )
delete lastMaterials;

lastMaterials = currentMaterials;

if (materials) {


int mLength = mArray.length (http://download.autodesk.com/us/maya/2009help/API/class_m_string_array.html#d32d78348bc93275b7daba5accf15e9a)();

if ( mLength > 0 ) {
fprintf(fp,"usemtl");
for ( i=0; i<mLength; i++ ) {
fprintf(fp," %s",mArray[i].asChar());
}
fprintf(fp,"\n");
}
}
}
else
{
delete currentMaterials;
}




Basically its the bit where before the face output, it writes a line saying:
usemtl shaderA_SG

However, and I've found this happens with ALL the custom build-your-own-OBJ-exporter plugins, when I export 2 objects with the same shader, it doesn't add that line for the second object (and I need it to). I.e. the obj would look something like:

g Ground CutoutA
usemtl lambert16SG
f 9/6/1 6/7/2 8/8/3
...
...
g Ground CutoutB
f 44/44/1 45/45/2 47/47/3

The usemtl line is missing from the second object's faces (same shader, diff object...)

I'm sure the answer should be in changing the code above (which is all straight from the Maya example OBJ Exporter API)..... anyone got any ideas about how to put the usemtl line back into the second object?

This happens straight out of the Maya's API OBJ Exporter, so if you just create two objects that share the same shader, export them, you'll see that the usemtl is missing in the obj for the second object

Robert Bateman
03-03-2009, 10:13 AM
It's not missing the second usemtl line, the materials in obj files are assigned on a state basis (i.e. in the same way openGL materials work). Set material. Draw stuff. Draw More Stuff. Set Material etc.

The best way of handling this is to modify your obj loading code rather than the exporter itself (since your app won't actually support valid obj files).

If you really want to do it (and i suspect, that realy you don't want to do this at all), replace the if(!materialsEqual) with if(1)

dbsmith
03-03-2009, 08:25 PM
Thanks heaps Rob, appreciate your time.
I owe u the virtual equivalent of a beer...

CGTalk Moderation
03-03-2009, 08:25 PM
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.