Skip to content

Instantly share code, notes, and snippets.

View OmniZ3D's full-sized avatar

Jason Barnidge OmniZ3D

View GitHub Profile
"""
Functions for generating spline weights.
Usage:
This modules functions each take curve parameters and output control point weights. The weights are generated using
a modified version of de Boor's algorithm. These weights can be used to create a weighted sum to find a point or
tangent on a spline.
While these functions are written for usage in Autodesk Maya, they don't actually have any Maya-specific libraries.
Additionally none of these functions actually care about the data type of provided control points. This way these
@chris-lesage
chris-lesage / example_usage.py
Last active April 14, 2024 20:43
A script to pin an object to a NurbsSurface in Autodesk Maya
import pymel.core as pm
'''
Here are some examples of how to use the pin_to_surface.py script.
'''
# make a nurbsPlane
oNurbs = pm.nurbsPlane(n='nurbsPlane1')
# You can specify the nurbsSurface by string, PyNode transform or PyNode shape.
@BigRoy
BigRoy / maya_list_all_children_with_instances.py
Last active October 5, 2023 18:29
Autodesk Maya Python list or query all children including each instance
"""When using maya.cmds.listRelatives with allDescendents=True it will only return the first instanced child.
Below are some example functions that correctly return all instanced children where they are "somewhat" optimized to rapidly return a result as opposed to slow recursive queries.
"""
import maya.api.OpenMaya as om
from maya import cmds
import time
import re
@BigRoy
BigRoy / maya_snap_objects_to_target_vertex.py
Created March 20, 2020 09:41
Snap multiple objects by vertex index to target vertex.
"""Snap multiple objects by vertex index to target vertex.
1. Select all objects you want to snap
2. Add the target vertex to your selection.
3. Run script
Make sure each object has the same topological order because
this just simply snaps the same vertex number of each object
to the selected target vertex.
@Liametc
Liametc / check_poly_normals.py
Last active August 12, 2024 01:47
Check polygon normals in maya using python api 2.0
import maya.api.OpenMaya as om
import maya.cmds
import time
def is_normal_reversed(poly, mesh):
"""
Check the normal faces in or out of the model by doing a simple ray cast and
count results. Evens face out, odds face in.
@chris-lesage
chris-lesage / check_max_influences.py
Created January 29, 2020 23:31
Check skinClusters for too many influences per vertex in Autodesk Maya.
import maya.OpenMaya as OpenMaya
import pymel.core as pm
import maya.OpenMayaAnim as OpenMayaAnim
import maya.cmds as cmds
import maya.mel as mel
class checkMaxSkinInfluences(object):
''' This script takes a mesh with a skinCluster and checks it for N skin weights.
If it has more than N, it selects the verts, so you can edit them.
def fit(self):
self.centroids, self.std_list = kmeans(self.X, self.k, max_iters=1000)
if not self.std_from_clusters:
dMax = np.max([get_distance(c1, c2) for c1 in self.centroids for c2 in self.centroids])
self.std_list = np.repeat(dMax / np.sqrt(2 * self.k), self.k)
RBF_X = self.rbf_list(self.X, self.centroids, self.std_list)
class RBF:
def __init__(self, X, y, tX, ty, num_of_classes,
k, std_from_clusters=True):
self.X = X
self.y = y
self.tX = tX
self.ty = ty
import numpy as np
def get_distance(x1, x2):
sum = 0
for i in range(len(x1)):
sum += (x1[i] - x2[i]) ** 2
return np.sqrt(sum)
@Muream
Muream / bake_to_opm.py
Last active November 11, 2024 11:58
This script bakes the transformation of a node to its offset parent matrix which then acts as its rest matrix. Only works with maya 2020 and up.
import maya.api.OpenMaya as om
import maya.cmds as cmds
TRANSFORM_NODETYPES = ["transform", "joint"]
def has_non_default_locked_attributes(node):
locked_attributes = []
for attribute in ["translate", "rotate", "scale", "jointOrient"]:
default_value = 1 if attribute == "scale" else 0
for axis in "XYZ":