Skip to content

Instantly share code, notes, and snippets.

@earthnuker
Created June 9, 2020 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save earthnuker/e3c112966f415adcf3b556ed43883813 to your computer and use it in GitHub Desktop.
Save earthnuker/e3c112966f415adcf3b556ed43883813 to your computer and use it in GitHub Desktop.
import bpy
import random
import mathutils
from math import radians,degrees
bpy.ops.object.select_pattern(pattern="IVY_Curve*",extend=False)
for obj in bpy.context.selected_objects:
obj.select_set(state=True)
bpy.ops.object.delete()
bpy.context.scene.frame_current=1
object = bpy.data.objects["Source"]
object.select_set(state=True)
bpy.context.view_layer.objects.active=object
psys = bpy.context.object.particle_systems["Ivy"]
pset = bpy.data.particles["Ivy"]
psys.seed = random.randint(0,2**31)
bpy.context.scene.frame_current=1
def get_part(obj):
degp = bpy.context.evaluated_depsgraph_get()
return obj.evaluated_get(degp).particle_systems.active.particles
num_particles = len(get_part(object))
o_rot=mathutils.Euler(object.rotation_euler)
for i in range(num_particles):
new_rot=(random.random()*360,random.random()*360,random.random()*360)
object.rotation_euler=tuple(map(radians,new_rot))
erot=mathutils.Euler(object.rotation_euler)
bpy.context.scene.cursor.location=get_part(object)[i].location
bpy.ops.curve.ivy_gen(updateIvy=True, defaultIvy=False)
ivy=[obj for obj in bpy.context.scene.objects if obj.name.startswith("IVY_Curve")][-1]
ivy.parent=object
ivy.matrix_parent_inverse = object.matrix_world.inverted()
object.rotation_euler=o_rot
bpy.context.scene.cursor.location=(0,0,0)
object.rotation_euler=o_rot
bpy.ops.object.select_pattern(pattern="IVY_Curve*",extend=False)
first_frame=bpy.context.scene.frame_start
last_frame=bpy.context.scene.frame_end
min_step=bpy.data.scenes["Scene"].render.fps*3
for i,obj in enumerate(bpy.context.selected_objects):
start=random.random()*max(0,(last_frame-first_frame)-min_step)
end=start+min_step+random.random()*max(0,(last_frame-start)-min_step)
print(obj,start,end)
obj.animation_data_clear()
obj.user_clear()
obj.data.animation_data_clear()
obj.data.user_clear()
obj.data.bevel_factor_end=0.0
obj.data.keyframe_insert(data_path="bevel_factor_end",frame=start)
obj.data.bevel_factor_end=1.0
obj.data.keyframe_insert(data_path="bevel_factor_end",frame=end)
bpy.context.scene.frame_current=last_frame
bpy.ops.object.select_pattern(pattern="",extend=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment