cwisbg

#thingTester

Aug 17th, 2018
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. #thingTester
  2. from pymel.core import *
  3. import maya.api.OpenMaya as om
  4.  
  5. import maya.cmds as mc
  6. import maya.OpenMaya as omm
  7.  
  8. import math
  9. class thing():
  10.     def __init__(self, thingObject):
  11.         self.thingObj = thingObject[0]
  12.         self.pos = om.MVector(thingObject.getTranslation())
  13.         self.dir = []
  14. def lookAt(base, target, up=[0,1,0]):
  15.     base = mc.getAttr(base+".worldMatrix")
  16.     target= mc.getAttr(target+".worldMatrix")
  17.     # build transformation matrix
  18.     x = omm.MVector(target[12]-base[12], target[13]-base[13], target[14]-base[14])
  19.     x.normalize()
  20.     z = x ^ omm.MVector(-up[0], -up[1], -up[2])
  21.     z.normalize()
  22.     y = x ^ z
  23.     y.normalize()
  24.     m = omm.MMatrix()
  25.     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]
  26.     omm.MScriptUtil.createMatrixFromList(l, m)
  27.     # retrieve the desired rotation for "base" to aim at "target", in degrees
  28.     r = omm.MTransformationMatrix(m).eulerRotation() * 57.2958
  29.     return r[0], r[1], r[2]
  30.  
  31.  
  32.  
  33. sl = selected()
  34. obj1 = sl[0]#ls("pCone1")[0]
  35. dObj = sl[1]#ls("pCube102")[0]
  36.  
  37. r = lookAt(obj1, dObj)
  38. rotate(obj1, r)
  39. """
  40. thing1 = thing(obj1)
  41. dirObj = om.MVector(dObj.getTranslation())
  42. thing1.dir = dirObj
  43.  
  44. growDirection = (thing1.dir + thing1.pos)
  45.  
  46. growDirection *= -1
  47. om.MVector.normalize(growDirection)
  48. l = spaceLocator()  
  49. move(l, growDirection)
  50.  
  51. for i in range(1,10):
  52.    newD = thing1.pos + growDirection *i
  53.    l = spaceLocator()  
  54.    move(l, newD)
  55.  
  56. """
Advertisement
Add Comment
Please, Sign In to add comment