Skip to content

Instantly share code, notes, and snippets.

View AndresMWeber's full-sized avatar
💭
Katas for Life!

Andres Weber AndresMWeber

💭
Katas for Life!
View GitHub Profile
@AndresMWeber
AndresMWeber / node_types.py
Last active October 5, 2017 20:50
node registration
import sys
from joint import Joint
from transform import Transform
from unicode_delegate import UnicodeDelegate
from dag_node import DagNode
from curve import Curve
REGISTERED_NODES = {}
@AndresMWeber
AndresMWeber / service.py
Last active August 14, 2017 20:50
Trying to figure out implementing services pattern
import maya.cmds as cmds
platform = cmds
class EventService(object):
def __init__(self):
self.events = []
self.event_log = []
def add_event(self, event):
@AndresMWeber
AndresMWeber / faux_wireframe.py
Created June 2, 2017 00:08
Create curve dense fake wireframe of component edges converted to degree 1 curves
import maya.cmds as cmds
cmds.refresh(suspend=True)
selection_edges = cmds.filterExpand(cmds.polyListComponentConversion(te=1), sm=32, ex=1)
curve_transforms = []
for edge in selection_edges:
vertices = cmds.ls(cmds.polyListComponentConversion(edge, fe=1, tv=1), fl=1)
created_curve = cmds.curve(d=1, p=[cmds.pointPosition(vertex) for vertex in vertices])
@AndresMWeber
AndresMWeber / cache.py
Created May 4, 2017 03:56
Property caching decorator/property subclass
"""
Stolen from:
https://bytes.com/topic/python/answers/751180-how-memoize-cache-property-access
"""
class cached(property):
'Convert a method into a cached attribute'
def __init__(self, method):
private = '_' + method.__name__
def fget(s):
try:
import sys
from PySide2.QtWidgets import *
import maya.standalone as ms
import maya.cmds as mc
class Window(QWidget):
def __init__(self):
super(Window, self).__init__()
self.setupUI()
@AndresMWeber
AndresMWeber / delegate.py
Last active April 6, 2017 22:29
Trying to delegate but inherit.
# Delegator
class Delegate(object):
def __init__(self):
pass
def name(self):
print 'yo'
class HasDelegate(object):
def __init__(self):
class MayaElement(AbstractElement):
def __init__(self,
group_top='',
group_model='',
group_joint='',
group_nodes='',
group_world='',
parent='',
scale=1.0,
**kwargs):
@AndresMWeber
AndresMWeber / file_import.py
Created April 3, 2017 01:47
Return imported top nodes from maya.cmds import
import maya.cmds as mc
file = "D:/dev/procedural_rigging/assets/komodo/model/komodo_model.mb"
new_nodes = mc.file(file, i=True, returnNewNodes=True)
print cmds.ls(new_nodes, assemblies=True)[0]
@AndresMWeber
AndresMWeber / position_on_mesh.py
Created March 15, 2017 04:18
Closest position on mesh to point...
import maya.api.OpenMaya as om
import maya.cmds as mc
mpoint_to_point = lambda mpoint: [float(p) for p in mpoint][:3]
loc_at_mpoint = lambda point: mc.xform(mc.spaceLocator(), t=point, ws=True)
dag_iterator = om.MItDag(om.MItDag.kDepthFirst, om.MFn.kInvalid)
def get_dag_path(xform):
selectionList = om.MSelectionList()
try:
@AndresMWeber
AndresMWeber / influence_from_distance.py
Created March 15, 2017 00:08
Add weights from influence based on distance
import maya.cmds as mc
import math
def mesh_verts_distance_from_point(point, transform_with_shape):
distance_between = lambda p1, p2: math.sqrt(sum([(a - b) ** 2 for a, b in zip(p1, p2)]))
shapes = mc.listRelatives(transform_with_shape, s=True, c=True, type='mesh')
distances = {}
if shapes:
mesh_verts = mc.ls("{MESH}.vtx[*]".format(MESH=shapes[0]), fl=True)