Reputation: 3285
I want to animate the creation of a cylinder. That means I want to set the scale for the first keyframe to 0 and for the last keyframe to the actual cylinder size. First I create a cylinder between two points like this:
# p1 is point 1 and p2 is point 2
dx, dy, dz = p2.x - p1.x, p2.y - p1.y, p2.z - p1.z
v_axis = mathutils.Vector((dx, dy, dz)).normalized()
v_obj = mathutils.Vector((0,0,1))
v_rot = v_obj.cross(v_axis)
angle = math.acos(v_obj.dot(v_axis))
bpy.ops.mesh.primitive_cylinder_add()
bpy.ops.transform.rotate(value=angle, axis=v_rot)
After this rotation I would like to set the pivot point at the location of p1 in order to be able to manipulate the location and scaling in respect to p1. I know how to set the pivot point to the 3D cursor from within the blender UI but how can I set the pivot point to a specific location (p1) from within my python script?
Upvotes: 0
Views: 3197
Reputation: 3549
Another technique to try is to experiment with the use of parent objects. I created a cylinder at the origin. I created an Empty object and moved it to <0,-4,0>. I then set the Empty as the parent of the cylinder using the Parent field of the Relations subtab of the Object tab in the Properties window. The cylinder's position of <0,0,0> was then interpreted relative to the empty. I moved the cylinder so it was back at the world origin, but now it's Location (which is relative to its parent) was <0,4,0>. I then animated the Scale of the Empty object to go from 1 to 2. The cylinder, being a child, was affected by this scaling, and the Empty provided the origin of the scaling, so the cylinder slid along the y axis as it scaled.
Upvotes: 0
Reputation: 2814
I think the approach people use is first translating the volume so that the desired pivot point is at (0,0), and then rotating, and translating it back to the proper position.
You can also see 6.1 of the following webpage: http://inside.mines.edu/~gmurray/ArbitraryAxisRotation/
Upvotes: 1
Reputation: 3285
What I ended up doing was scaling from 0 to 100% and at the same time changing the location of the cylinder so that the bottom of the cylinder is always at p1.
But I am still looking for a better solution.
Upvotes: 0