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.

Skin weights lost when opening file

Skin weights lost when opening file

TECH_HARI
Explorer Explorer
3,269 Views
5 Replies
Message 1 of 6

Skin weights lost when opening file

TECH_HARI
Explorer
Explorer

Hello!

 

Here at Hari Studios, we encounter weird issues since Maya 2020.

 

From a newly opened instance of Maya, opening some of our asset rigs loose their skin weights:

TECH_HARI_0-1649926966097.png

 

Reopening the same file from the same instance of Maya, restore the skin weights:

TECH_HARI_1-1649927051791.png

 

Acknowledments:

  • The opened file contains no reference to other files
  • There is only a skin cluster applied to the mesh, no other deformers
  • History of the file has been cleaned
  • The issue is reproductible from any new Maya instance
  • Issue appears also with fresh preferences
  • Evaluation mode is in Parallel
  • The issue seems to appear for other deformers too (ffd as we experienced)
  • The issue appears on both Windows and Linux

I also note that this problem appears when dealing with references.

Let's say, the above rig file "A" is referenced twice in another scene (A1 and A2), the first reference is always broken (as explained above) but the other references to the same files are always fine. I guess loading a reference multiple times has the same effect as reopening a file.

 

 

My analysis:

Because Maya successfully recover the skin weights on reopen, it does not seem like the file content is corrupted or anything. Maya just "fails" at loading it correctly from a fresh state.

 

We thought that might come from a deferred plugin load.

But loading the plugins prior to opening the scene: same problem.

 

We compared all the MEL commands Maya executes while opening the file (Script Editor -> History -> Echo All Commands) to see if there is any difference between opening the file from fresh Maya or from an already loaded file: no difference at all.

 

I then tried to check the weights stored within the skinCluster node using the following python script:

 

from maya import cmds

indices = cmds.getAttr("skinCluster8.weightList", multiIndices=True)

for idx in indices:
    attr = "skinCluster8.weightList[{}].weights".format(idx)
    attr_indices = cmds.getAttr(attr, multiIndices=True)
    
    for attr_idx in attr_indices:
        print cmds.getAttr(attr + '[{}]'.format(attr_idx))

 

 

I only get values of 1.0 everywhere despite the viewport clearly showing values of 0.0 (see the first image above).

 

Furthermore, trying to repaint the weights from that state results in a Maya Fatal Error:

 

Stack trace:
  DeformSlice.dll!TDNskinCluster::getComponentWeights
  DeformSlice.dll!TDNskinCluster::saveCurrentWeights
  JasperSlice.dll!TartAttrSkinPaintCmd::createIterator
  JasperSlice.dll!TartTangentStamp::paint
  JasperSlice.dll!Tart2DStroke::interpolate
  JasperSlice.dll!Tart2DStroke::continuePaintStroke
  JasperSlice.dll!TartBaseContext::batchPaint
  JasperSlice.dll!TartBaseContext::doDrag
  SharedUI.dll!TstandardContext::preDoDrag
  ExtensionLayer.dll!TtoolCallback::doIt
  ExtensionLayer.dll!Tcontrol::doDrag
  3dGraphics.dll!QmayaGLWidget::mouseMoveEvent
  Qt5Widgets.dll!QWidget::event
  Qt5Widgets.dll!QApplicationPrivate::notify_helper
  Qt5Widgets.dll!QApplication::notify
  ExtensionLayer.dll!QmayaApplication::currentMousePos
  Qt5Core.dll!QCoreApplication::notifyInternal2
  Qt5Widgets.dll!QApplicationPrivate::sendMouseEvent
  Qt5Widgets.dll!QSizePolicy::QSizePolicy
  Qt5Widgets.dll!QSizePolicy::QSizePolicy
  Qt5Widgets.dll!QApplicationPrivate::notify_helper
  Qt5Widgets.dll!QApplication::notify
  ExtensionLayer.dll!QmayaApplication::currentMousePos
  Qt5Core.dll!QCoreApplication::notifyInternal2
  Qt5Gui.dll!QGuiApplicationPrivate::processMouseEvent
  Qt5Gui.dll!QWindowSystemInterface::sendWindowSystemEvents
  Qt5Core.dll!QEventDispatcherWin32::processEvents
  USER32.dll!TranslateMessageEx
  USER32.dll!TranslateMessage
  Qt5Core.dll!QEventDispatcherWin32::processEvents
  qwindows.dll!qt_plugin_query_metadata
  Qt5Core.dll!QEventLoop::exec
  Qt5Core.dll!QCoreApplication::exec
  ExtensionLayer.dll!Tapplication::start
  maya.exe!TiteratorWrapperFwd<TscenePartitions::ConstIteratorDescriptor,TiteratorWrapper<TscenePartitions::ConstIteratorDescriptor> >::operator++
  maya.exe!TiteratorWrapperFwd<TscenePartitions::ConstIteratorDescriptor,TiteratorWrapper<TscenePartitions::ConstIteratorDescriptor> >::operator++
  maya.exe!TiteratorWrapperFwd<TscenePartitions::ConstIteratorDescriptor,TiteratorWrapper<TscenePartitions::ConstIteratorDescriptor> >::operator++
  kernel32.dll!BaseThreadInitThunk
  ntdll.dll!RtlUserThreadStart
000007FEB617F600

 

 

There is clearly something wrong about the way this skinCluster has restored its values when opening the file the first time.

The issue seems to happen at a depper level within Maya and we have no way to debug it further.

 

Any ideas?

We understand it is not possible to fix that for Maya 2020 but if you have a workaround (do not ask to just reopen files twice please, this is not the answer we are looking for) it would be awesome!

 

We cannot share the source files here for confidentiality reasons but do not hesitate to contact us if you need them.

 

Thank you very much for your consideration.

 

The Hari Technology Team

 

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

zewt
Collaborator
Collaborator

That's a strange one and not like any issue I've seen.  My next steps would be:

 

- Look at the scene file (save as .MA), and see if there's anything odd in the setAttr command setting weights, like NaNs.  I often do a text search in .MA files for "NAN" and "INF" to see if NaN or infinities are making it into data, since it can cause really bizarre behavior and is almost always a bug.

 

- If I can't get any clues by looking at the .MA directly and I'm running out of clues, I usually try to to reduce an asset file that has a problem as much as possible to isolate what's causing it.  Change the mesh to a simple 4-vertex plane, so it has minimal bulky mesh data, remove unrelated data like UV sets, materials and third-party plugin dependancies, reduce it to one or two joints, then save as .MA and incrementally remove other unneeded data from the scene file, like setAttr commands on the deformers.  It can be tedious and time-consuming, especially in cases like this where you have to restart Maya over and over to test whether an edit has broken the repro, but it usually does narrow in on the source of the problem.  (It also takes a decent understanding of Maya scene files, but it doesn't sound like that's a problem.)

 

I know you might not be able to upgrade Maya for various reasons, but just to check, does this problem still happen in Maya 2022 or 2023?  It sounds like you tried newer versions, but I'm not 100% sure.

 

0 Likes
Message 3 of 6

TECH_HARI
Explorer
Explorer
Accepted solution

Hello again!

 

I finally found what causes the issue.

 

Here are the steps to reproduce the issue:

 

1) Open a clean instance of Maya

2) Create a polyPlane with 1 subdivision on both axis:

TECH_HARI_0-1650907105757.png

 

3) Go in the UV Editor and pin one of the uv points (I chose the top left corner):

TECH_HARI_1-1650907152348.png

 

4) Create a joint at the world origin and bind skin it with the plane

5) Clean all the non-deformer history

6) Save the file as .ma

 

Now if you simply double-click the saved file to open it with a clean Maya instance, the skin does not work properly.

If you reopen the file from that same instance of Maya, everything should work fine.

 

I investigate into the saved .ma file and discover that some pinData are stored for the mesh deformed origin:

 

createNode mesh -n "pPlaneShape1Orig" -p "pPlane1";
	...
	setAttr ".pd[0]" -type "dataPolyComponent" Index_Data UV 1 
		2 1 ;
	...

 

 

The cleanest solution I found was to do the following in the rig Maya scene:

1) Select the shapes

2) Go in the UV Editor and unpin everything (this should create a polyUvPin node for every shape)

3) Clean all the non-deformer history

 

I provided a sample minimal scene in case anyone at Autodesk wants to investigate further.

 

Hope this may help someone in the future.

 

PS: I still have to check if the issue is still present in the latests release of Maya (2022, 2023). I will let you know as soon as I get my hands on them.

Message 4 of 6

zewt
Collaborator
Collaborator

I see it in 2022, but not 2023.  I don't see anything that looks related in the release notes, though, so I don't know if it's something that was fixed or if it's just not reproing for some reason.

 

0 Likes
Message 5 of 6

TECH_HARI
Explorer
Explorer

I found it in the release notes of 2023:

Skincluster is not applied until scene is reloaded or re-evaluated MAYA-114083

 

I found these related issues over the web:

https://forums.autodesk.com/t5/maya-forum/maya-2016-problem-skin-not-binded-on-first-load-after-open...

https://twitter.com/ChristophSchadl/status/1499295069962186753

 

We cannot switch to 2023 yet but at least I have a decent workaround until then.

 

Thank you very much again for your help!

Message 6 of 6

TECH_HARI
Explorer
Explorer

Hello again!

Here's a script I made to deal with the UV pins for people still using Maya prior to 2023.

Hope you find it useful.

 

"""
Module containing functions to deal with uv pins on meshes.

On old Maya versions (prior to Maya 2023), the presence UV pins corrupt
the internal data of meshes when first reading references.
More information on this forum thread:
https://forums.autodesk.com/t5/maya-forum/skin-weights-lost-when-opening-file/td-p/11105605

To overcome this, you can use the get_meshes_with_uv_pins function 
to get the meshes with uv pins.

The remove_uv_pins function removes the UV Pins from the mesh.
Please note that we do not remove the history when deleting uv pins because Maya
will also break some of the deformer history.
"""

from maya import cmds
from maya import OpenMaya as om


def get_meshes_with_uv_pins(parent=None):
    """Returns all the meshes that have uv pins.

    Args:
        parent(str): maya node parent in which to get the meshes.
            If None, check all the meshes in the Maya scene.

    Returns:
        list[str]: maya meshes that contain uv pins.
    """
    if parent:
        meshes = cmds.listRelatives(
            parent, children=True, allDescendents=True, type='mesh',
            fullPath=True)
    else:
        meshes = cmds.ls(type='mesh', long=True)

    mesh_with_uv_pin = []

    for mesh in meshes:
        slls = om.MSelectionList()
        slls.add(mesh)
        ground_path = om.MDagPath()
        slls.getDagPath(0, ground_path)
        ground_path.extendToShapeDirectlyBelow(0)
        mfn_mesh = om.MFnMesh(ground_path)
        idx_array = om.MUintArray()
        data_array = om.MDoubleArray()

        try:
            mfn_mesh.getPinUVs(idx_array, data_array)
        except RuntimeError:
            continue
        else:
            mesh_with_uv_pin.append(mesh)

    return mesh_with_uv_pin


def remove_uv_pins(meshes):
    """Removes the UV pins in the given maya meshes.

    Args:
        meshes (list[str]): remove uv pins on these meshes
    """

    # We do not delete non deformer history because Maya deletes the
    # skin clusters
    for mesh in meshes:
        cmds.polyPinUV(mesh, operation=2, createHistory=False)

 

Cheers!