Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #thingTester
- from pymel.core import *
- import maya.api.OpenMaya as om
- import maya.cmds as mc
- import maya.OpenMaya as omm
- import math
- class thing():
- def __init__(self, thingObject):
- self.thingObj = thingObject[0]
- self.pos = om.MVector(thingObject.getTranslation())
- self.dir = []
- def lookAt(base, target, up=[0,1,0]):
- base = mc.getAttr(base+".worldMatrix")
- target= mc.getAttr(target+".worldMatrix")
- # build transformation matrix
- x = omm.MVector(target[12]-base[12], target[13]-base[13], target[14]-base[14])
- x.normalize()
- z = x ^ omm.MVector(-up[0], -up[1], -up[2])
- z.normalize()
- y = x ^ z
- y.normalize()
- m = omm.MMatrix()
- l = [x.x, x.y, x.z, 0, y.x, y.y, y.z, 0, z.x, z.y, z.z, 0, 0, 0, 0, 1]
- omm.MScriptUtil.createMatrixFromList(l, m)
- # retrieve the desired rotation for "base" to aim at "target", in degrees
- r = omm.MTransformationMatrix(m).eulerRotation() * 57.2958
- return r[0], r[1], r[2]
- sl = selected()
- obj1 = sl[0]#ls("pCone1")[0]
- dObj = sl[1]#ls("pCube102")[0]
- r = lookAt(obj1, dObj)
- rotate(obj1, r)
- """
- thing1 = thing(obj1)
- dirObj = om.MVector(dObj.getTranslation())
- thing1.dir = dirObj
- growDirection = (thing1.dir + thing1.pos)
- growDirection *= -1
- om.MVector.normalize(growDirection)
- l = spaceLocator()
- move(l, growDirection)
- for i in range(1,10):
- newD = thing1.pos + growDirection *i
- l = spaceLocator()
- move(l, newD)
- """
Advertisement
Add Comment
Please, Sign In to add comment