Remove too many influences on a skinCluster

import pymel.core as pm

ignore_below = 0.0001
meshes = pm.selected()
if len(meshes) > 0:
    for mesh in meshes:
        #use a quickie MEL command to get the skincluster
        skin = pm.mel.eval('findRelatedSkinCluster %s' % mesh)

        #get the max allowed influenced for the current skinCluster
        max_influences = pm.PyNode(skin).getMaximumInfluences()

        #empty list to hold a pair for transform value
        transform_value = []

        #get the total number of vertices in the selected mesh
        total_verts = pm.polyEvaluate(vertex=True)


        for i in xrange(0, total_verts):
            transform_value = []

            vertex = "%s.vtx[%s]" % (mesh, i)
            trans = "%s %s" % (skin, vertex)
            influences = pm.skinPercent(skin, vertex, ignoreBelow = ignore_below, query = True, transform = None)
            values = pm.skinPercent(skin, vertex, ignoreBelow = ignore_below, query = True, value = True)

            # if there are more entries in the transform values list than we have allowed influences
            # we know we're going to have to delete some
            if len(transform_value) > max_influences:
                #sort the transform value list from small to big, based on the second entry of the pair (value)
                transform_value.sort(key = lambda list: list[1])

            #add a transform value pair to our list
            for j in xrange(0, len(influences)):
                tv = [influences[j], values[j]]
                transform_value.append(tv)

                #figure out how many extra influences there are
                extra_influences = len(transform_value) - max_influences
                print "Found %s influences too many on %s" % (extra_influences, vertex)

                #loop through all these extra influences
                for k in xrange(0, extra_influences):
                    joint_name = str(transform_value[k][0])
                    value = transform_value[k][1]

                    #and set their influence to 0
                    print "Removing: %s, value: %s" % (joint_name, value)
                    pm.skinPercent(skin, vertex, transformValue = [joint_name, 0], normalize = True)
    pm.select(None)

I adapted a script that was written in MEL to remove extra influences on particular vertices on a skinned mesh. Mostly because it didn’t always work on my machine and I didn’t want to try and figure out why… I don’t like having to edit MEL code and avoid it where I can 🙂

When you set up your skinCluster and very carefully tell Maya to not go over your maximum allowed influences per vert, Maya doesn’t always listen. Most likely floating point rounding errors creep in when painting skin weights and normalizing the skinCluster. Most times you don’t know really care about these extra influences because their values are usually extremely small ( < 0.001). However, if for whatever reason you need to get rid of these extremely small values and don't want to prune weights, you can use something like this to remove only the smallest influences depending on how many influences are allowed for your skinCluster.

Urchin

This was actually a proof of concept and thought exercise than anything else. I had a discussion with a fellow freelancer who got ripped off after sending Maya files and never receiving any payment. I started brainstorming about a possible solution for this problem and came up with this. The script allows you to secure a Maya file and set permissions on its usage. I don’t think it’s anything that should be used in the real world, but it was fun to make and think about. I actually did some research on how viruses and worms work to keep under the radar and how they deal with deletion attempts 🙂 It’s by no means a fool proof system, but it does kind of work and could be refined in the future.

Sorry about the vacation video-y music. Turn off your volume if you think it sucks 🙂

 

Coconut Curves

I’ve always liked this way of rigging faces. By constraining joints to the curves moving the curves around, you get some nice fall off that makes everything feel squishy and soft. Which works really well on cartoony characters. Not posting the entire code because it’s pretty messy, pretty long and spread across multiple files. Take a look at the YouTube video to see how it works and feel free to comment or ask if you want to.

 

Skin weight copy/export

Using Maya’s own deformerWeights command, I managed to write a neat little tool that works very fast and very reliable.

All skinning information can be saved in offline files or as a custom node in the actual scene itself, so it never gets lost.

The code needs some tinkering before I put it up, but take a look at the video to see how it works.

 

Copying Channel Box information between objects

I’ve spent a lot of time in Unity and as anyone who’s spent a lot of time in Unity, you’re using the Transform component quite a lot. One thing that I’ve always like about Unity’s Inspector is the ability to copy a component and paste it either as a new component on another object, or just copy the component values. I’m in the middle of doing some hard surface modeling and things need to line up pretty accurately. The manual way of getting Channel Box information from one object to another is first selecting the object that needs to be adjust, shift select the other you want to adjust to and then tab-enter your way through the Channel Box. It works and it’s actually quite fast. But it’s not the one click solution I’m usually after.

Continue reading