Skip to content

Instantly share code, notes, and snippets.

@patwooky
Last active October 14, 2016 06:59
Show Gist options
  • Save patwooky/49b8d9f8f966eb6722b90fded9e66fa1 to your computer and use it in GitHub Desktop.
Save patwooky/49b8d9f8f966eb6722b90fded9e66fa1 to your computer and use it in GitHub Desktop.
constraint normals of objects to surface vertices
'''
constraints objects to normal of each vertex
constraints to face normals are exactly the same procedure
'''
from pymel.core import *
def normalsTest(inObj):
sel=inObj
grpName = group(empty=True)
ptsList = inObj.getShape().getPoints(space='world')
loc = spaceLocator()
loc.getShape().localScale.set([0.1]*3)
cube = polyCube()[0]
for x in xrange(len(ptsList)):
cubeDup = duplicate(cube)[0]
xform(cubeDup, ws=True, scale=[.1]*3, t=ptsList[x])
parent(cubeDup, grpName)
nConstr = normalConstraint(inObj.getShape().vtx[x], cubeDup,
weight=1, aimVector=[1, 0, 0], upVector=[0, 1, 0], worldUpType='scene')
delete(nConstr)
delete(cube)
return
normalsTest(polySphere()[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment