Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Error Setting UVs on MFnMesh

Error Setting UVs on MFnMesh

Anonymous
Not applicable
1,631 Views
5 Replies
Message 1 of 6

Error Setting UVs on MFnMesh

Anonymous
Not applicable

I have the code below, where I create a mesh, and try to set UVs

 

MFnMesh fnMeshCreator;
MObject meshMObj = fnMeshCreator.create(uniquePositionsList->Count, mesh->Triangles->Count, mPointArray, polygonCounts, polygonConnects, meshTransformObj); MFnMesh fnMesh(meshMObj); fnMesh.clearUVs(); if (fnMesh.setUVs(uArray, vArray) == MStatus::kFailure) { cerr << "Always comes in here" << endl; }

However, it always returns MStatus::kFailure when attempting to setUVs

 

Anyone know why?

 

Thank you

0 Likes
Accepted solutions (1)
1,632 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

I think you have to create a uv set first.

 

MString uvSetName = MString("UVSet");
mesh.createUVSet(uvSetName);
mesh.clearUVs(&uvSetName);
mesh.setUVs(.., .., &uvSetName);

If this doesn't work you could try assignUVs(...)

0 Likes
Message 3 of 6

Anonymous
Not applicable

Anything I do -- if I pass in MStatus object -- it is always setting it as MStatus Failure

0 Likes
Message 4 of 6

Anonymous
Not applicable

I forgot this already, you must call assignUVs, this will connect the indices to the suitable uv's. When you have a unique uv coordinate for each vertex, then you can simply use the indices. You must also use the UV Linking Editor (select the object, then right mouse click->UV Set->UV Linking..) to choose your uv set (if you have mulitple uv sets)

 

MString uvSetName = MString("UVSet");
fnMeshCreator.createUVSet(uvSetName);
fnMeshCreator.setCurrentUVSetName(uvSetName); // When you call this, then you don't have to assign the name to the following methods

 

fnMeshCreator.clearUVs(&uvSetName);
fnMeshCreator.setUVs(Us, Us, &uvSetName);

 

// Here you use the your polygon Count array and indices (polygonConnects) from the original method, this means for each vertex you create

// a unique uv coordinate. From this follow the Us and Vs array must have the same number like your vertex/point array!

fnMeshCreator.assignUVs(polygonCount, polygonConnects, &uvSetName);

 

 

Which method returns a Failed? In which method you execute your code?

0 Likes
Message 5 of 6

Anonymous
Not applicable

 

MObject meshMObj = fnMeshCreator.create(uniquePositionsList->Count, mesh->Triangles->Count, mPointArray, polygonCounts, polygonConnects, meshTransformObj, &status);

if (status == MStatus::kFailure)
{
  cerr << "Mesh create error" << endl;
}

MFnMesh fnMesh(meshMObj);

MString setName = "UVSet";

fnMesh.createUVSet(setName);
fnMesh.setCurrentUVSetName(setName);

fnMesh.getCurrentUVSetName(setName);

cerr << "Current setName after getCurrentUVSetName: " << setName.asChar() << endl;

if (fnMesh.setUVs(uArray, vArray, &setName) == MStatus::kFailure)
{
  cerr << "setUVs Error" << endl;
}

if (fnMesh.assignUVs(polygonCounts, uvIDs, &setName) == MStatus::kFailure)
{
  cerr << "AssignUVs Error" << endl;
}

 

Output:

 

Current setName after getCurrentUVSetName:  
setUVs Error
AssignUVs Error

------------------------------------------------------------

 

As you can see no errors occured on Creation of the mesh -- and it seems it failed to create the UV set because the currentUVSetName is empty

0 Likes
Message 6 of 6

Anonymous
Not applicable
Accepted solution

Apparently doing this:

 

MObject meshMObj = fnMeshCreator.create(uniquePositionsList->Count, mesh->Triangles->Count, mPointArray, polygonCounts, polygonConnects, meshTransformObj, &status);

if (status == MStatus::kFailure)
{
  cerr << "Mesh create error" << endl;
}

MFnMesh fnMesh(meshMObj);

breaks it.

 

Instead doing:

 

 

MFnMesh fnMesh;
fnMesh.create(uniquePositionsList->Count, mesh->Triangles->Count, mPointArray, polygonCounts, polygonConnects, meshTransformObj, &status);

seems to not have errors in the setting of UVs anymore

 

0 Likes