Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import bpy
  2. import bpy.app
  3.  
  4. from mathutils import Vector
  5. from mathutils import Quaternion
  6.  
  7. def calculateRotation(obj):
  8. up = Vector((0, 0, 1))
  9. diameter = obj.dimensions[0]
  10. previousLocation = Vector(tuple(obj.get("previousLocation", [0, 0, 0])))
  11. rotation = Quaternion(tuple(obj.get("previousRotation", [1, 0, 0, 0])))
  12.  
  13. deltaLocation = obj.location - previousLocation
  14. distance = deltaLocation.length
  15. deltaLocation.normalize()
  16. axis = -deltaLocation.cross(up)
  17. angle = distance / diameter * 2
  18.  
  19. rotation.rotate(Quaternion(axis, angle))
  20.  
  21. obj["previousLocation"] = obj.location
  22. obj["previousRotation"] = rotation
  23.  
  24. return rotation
  25.  
  26. bpy.app.driver_namespace["calculateRotation"] = calculateRotation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement