Get the correct UVs after texture mapping change

Hi all,

I am trying to extract uvs of an object. The way I extract them is this:

ON_TextureMapping texture_map;
ON_Xform localXform;
const ON_MappingRef* pMR = obj->Attributes().m_rendering_attributes.MappingRef(uuidCurrentRenderingPlugIn);
CRhinoTextureMappingTable& table = ::RhinoApp().ActiveDoc()->m_texture_mapping_table;
if (pMR) {
        const int iCount = pMR->m_mapping_channels.Count();
        if (pMR->m_mapping_channels.Count() > 0) {
             const ON_MappingChannel& mc = pMR->m_mapping_channels[0];
             int iIndex = mc.m_mapping_index;
             localXform = mc.m_object_xform;
             texture_map= table[iIndex];
mesh->SetTextureCoordinates(texture_map, &localXform);
for (int p = 0; p < mesh->m_V.Count(); p++) {
       ::RhinoApp().Print("%f , ",meshDup->m_T[p].x);
       ::RhinoApp().Print("%f \n ",meshDup->m_T[p].y);

The problem is that if I change the texture mapping from the GUI (rotation, repetition, offset) the UVs do not change and they are always in a range [0,1]. I might have misunderstood but I expected to find the transformation applied onto the UVs. And however I do not know where to get these change made in the GUI.
Is there any way to get the correct uvs of an object?
Thanks in advance,


Hi Gennaro,

Thanks for the code sample. Problem is that m_mapping_index is set to -1, and I don’t know why it isn’t set to the correct index. But anyways, instead of setting

int iIndex = mc.m_mapping_index;

you need to get the proper index by calling

int iIndex = table.FindTextureMapping(mc.m_mapping_id);