dbsmith
03-03-2009, 04: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
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
