- Set the spring's skrew distance to the appropriate value for the desired resting position.
- Run the script below after setting the sides variable to the number of sides of the spring.
import bpy
obj = bpy.context.active_object
sides = 8
steps = obj.modifiers["Screw"].steps
iterations = obj.modifiers["Screw"].iterations
bpy.ops.object.modifier_apply(modifier = "Screw")
bpy.ops.object.vertex_group_add()
group = obj.vertex_groups['Group']
loops = steps * iterations + 1
weight = 0.0
for loop in range(loops):
weight = loop / (loops - 1)
group.add( range(sides*loop, sides*(loop + 1)), weight, 'REPLACE' )
- After running the script, the skrew modifier will have been applied and a vertex group added with the correct weights.
At this point, you can either use an armature or a control object (with a hook modifier) to deform the spring along the Z axis. In the example below, I have used an empty and a hook modifier to rig the spring:
I wasn't able to get the deformation to work with the armature modifier, but the hook modifier can use bones as well, which worked fine.