Skip to content

Instantly share code, notes, and snippets.

@troughton
Created March 9, 2017 06:40
Show Gist options
  • Save troughton/5780cdd37b1419baf505b8e5699c8344 to your computer and use it in GitHub Desktop.
Save troughton/5780cdd37b1419baf505b8e5699c8344 to your computer and use it in GitHub Desktop.
Maya script to extrude along a curve.
import maya.cmds as cmds
import math
import numpy
def basisToEuler(tangent, bitangent, normal):
#Adapted from http://www.staff.city.ac.uk/~sbbh653/publications/euler.pdf
m = [tangent, bitangent, normal]
if abs(m[2][0]) != 1:
theta = -math.asin(m[2][0])
invCosTheta = 1.0 / math.cos(theta)
psi = math.atan2(m[2][1] * invCosTheta, m[2][2] * invCosTheta)
phi = math.atan2(m[1][0] * invCosTheta, m[0][0] * invCosTheta)
else:
phi = 0
if m[2][0] == -1:
theta = math.pi * 0.5
psi = theta + math.atan2(m[0][1], m[0][2])
else:
theta = -math.pi * 0.5
psi = math.atan2(-m[0][1], -m[0][2])
return (psi, theta, phi)
def degrees(radians):
return radians * 180.0 / math.pi
curve = cmds.ls(selection=True)[0]
startPoint = cmds.pointOnCurve(curve, parameter=0.0)
tangent = cmds.pointOnCurve(curve, normalizedTangent=True)
normal = cmds.pointOnCurve(curve, normalizedNormal=True)
bitangent = numpy.cross(normal, tangent)
rotation = basisToEuler(tangent, bitangent, normal)
(cubeTransform, polyCubeNode) = cmds.polyCube()
cmds.setAttr(cubeTransform + '.translate', startPoint[0], startPoint[1], startPoint[2])
cmds.setAttr(cubeTransform + '.rotate', degrees(rotation[0]), degrees(rotation[1]), degrees(rotation[2]) )
cubeShape = cmds.listRelatives(cubeTransform, children=True)[0]
cmds.polyExtrudeFacet(cubeShape + '.f[4]', inputCurve=curve, divisions=20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment