Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- import bpy.app
- from mathutils import Vector
- from mathutils import Quaternion
- def calculateRotation(obj):
- up = Vector((0, 0, 1))
- diameter = obj.dimensions[0]
- previousLocation = Vector(tuple(obj.get("previousLocation", [0, 0, 0])))
- rotation = Quaternion(tuple(obj.get("previousRotation", [1, 0, 0, 0])))
- deltaLocation = obj.location - previousLocation
- distance = deltaLocation.length
- deltaLocation.normalize()
- axis = -deltaLocation.cross(up)
- angle = distance / diameter * 2
- rotation.rotate(Quaternion(axis, angle))
- obj["previousLocation"] = obj.location
- obj["previousRotation"] = rotation
- return rotation
- bpy.app.driver_namespace["calculateRotation"] = calculateRotation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement