PDA

View Full Version : Exported UVs vs Viewing UVS in Maya


brekehan
08-30-2008, 03:03 AM
My exported UVs seem to have some approximation problems. Inside maya, they all appear as combinations of

Us of 0.0, 0.333, 0.667, or 1.0
Vs of 0.0, 0.25, 0.5, 0.75, or 1.0

However, when I look at my exporter results I get numbers close to zero, like 2.8929E-9, or worse a negative number, which throws my transformations into another coordinate system for a loop.

I understand that floating point numbers have to be approximated as a #^2, and that the computer cannot necessarily memorize an exact number if it is floating point, but I think it is more than that as the results for zero appear as 2 or 3 different numbers! If that was the only problem, than they should always be the same....


So, is there anything I can do to make the exported UV values match what I see in Maya more precisely?

Maya only shows me 3 decimal places in the application, is there a way to see 7 or 8?

Is there a way to make sure I will never get anything outside 0 to 1?

My exported results:

uv[0] 0.999997, 0.75
uv[1] 0.333333, 1
uv[2] 0.666667, 0.750001
uv[3] 0.333333, 0.75
uv[4] 0.666667, 0.500001
uv[5] 0.333334, 0.5
uv[6] 0.666667, 0.25
uv[7] 0.333334, 0.25
uv[8] 0.666668, 0
uv[9] 0.333334, 0
uv[10] 2.29239e-006, 0.5
uv[11] 1.71131e-008, 0.75
uv[12] 1, 0.499999
uv[13] 0.666667, 1

What I expect to see:
uv[0] 1.0, 0.75
uv[1] 0.333333, 1.0
uv[2] 0.666667, 0.75
uv[3] 0.333333, 0.75
uv[4] 0.666667, 0.5
uv[5] 0.333333, 0.5
uv[6] 0.666667, 0.25
uv[7] 0.333333, 0.25
uv[8] 0.666667, 0
uv[9] 0.333333, 0
uv[10] 0, 0.5
uv[11] 0, 0.75
uv[12] 1, 0.5
uv[13] 0.666667, 1

My code (cut and paste can't seem to keep my indentions correct!):


//-------------------------------------------------------------------------------

void MayaMeshTranslator::ParseUVSets()

{

// Get UV set names

MStringArray uvSetNames;

if( MStatus::kFailure == m_mesh->getUVSetNames(uvSetNames) )

{

throw BaseException("Failed to get UV set names",

"MayaMeshTranslator::MayaMeshTranslator(const MDagPath & path)",

"MayaMeshTranslator.cpp");

}

// Get the UV coordinates for each set

for(unsigned i = 0; i < uvSetNames.length(); ++i)

{

MFloatArray uArray;

MFloatArray vArray;

if( MStatus::kFailure == m_mesh->getUVs(uArray, vArray, &uvSetNames[i]) )

{

throw BaseException("Failed to get UV set data",

"MayaMeshTranslator::MayaMeshTranslator(const MDagPath & path)",

"MayaMeshTranslator.cpp");

}

UVSet uvSet;

uvSet.m_name = uvSetNames[i].asChar();



for( unsigned i = 0; i < uArray.length(); ++i)

{

UVSet::UV uv;

uv.m_u = uArray[i];

uv.m_v = vArray[i];

uvSet.m_uvs.push_back(uv);

}

m_uvSets.push_back(uvSet);

}

}


//-------------------------------------------------------------------------------

void MayaMeshTranslator::WriteASCII(std::ostream & out)

{

//Snip

//-----
// Write out all UV Sets



for(UVSets::iterator uvSet = m_uvSets.begin(); uvSet != m_uvSets.end(); ++uvSet)

{

out << std::endl

<< "// UV Set\n"

<< "// \n"

<< "// Format:\n"

<< "// Set Name\n"

<< "// uv[index] u v\n";

out << uvSet->m_name << std::endl;



for(unsigned i = 0; i < uvSet->m_uvs.size(); ++i)

{

UVSet::UV uv = uvSet->m_uvs[i];

out << "uv[" << i << "] " << uv.m_u << ", " << uv.m_v << std::endl;

}

out << std::endl;

}

out << std::endl;

// Snip

}

NaughtyNathan
09-01-2008, 09:11 AM
Those values you get are all correct and match the reported values fine (based on the way floats are stored and calculated as you surmise). Although the differences are indeed annoying they are all still legit.

If you really want to manually crowbar your returned values into the same thing Maya prints you'll just have to add an auto rounding to them.

:nathaN

CGTalk Moderation
09-01-2008, 09:11 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.