def fold_in_frames(meshes, gp_layer, callbacks = []): NUM_FRAMES = 600 FRAMES_SPACING=1 for frame in range(NUM_FRAMES): for mesh in meshes: if len(list(gp_layer.frames)) <= frame*FRAMES_SPACING: gp_frame = gp_layer.frames.new(frame*FRAMES_SPACING) else: gp_frame = gp_layer.frames[frame*FRAMES_SPACING] inter_con_count = lib.get_cloth_interconnector_count(mesh) constraint_counts = [lib.get_interconnector_constraint_count(mesh, index) for index in range(inter_con_count)] connector_positions = [] for inter_index in range(inter_con_count): connector_positions += [lib.get_interconnector_constraint(mesh, inter_index, index) for index in range(constraint_counts[inter_index])] #nodes = [(node.dx, 0, node.dy) for node in connector_positions] #draw_stroke(gp_frame, nodes) for node in connector_positions: draw_line(gp_frame, (node.x, 0, node.y), (node.dx, 0, node.dy)) for callback in callbacks: callback(gp_frame) lib.update_cloth_mesh(mesh, 0.005, 3)
def execute(self, context): NUM_FRAMES = 400 FRAMES_SPACING=1 gp_layer = init_grease_pencil() cloth_ptr = lib.get_cloth_mesh_field(5,10,5,98,-0.5,0.5) cloth_sims = bpy.data.meshes.new("cloth") cloth_sims.pointer = cloth_ptr for frame in range(NUM_FRAMES): gp_frame = gp_layer.frames.new(frame*FRAMES_SPACING) node_count = lib.mesh_node_count(cloth_ptr) node_positions = [lib.mesh_node_position(cloth_ptr, i) for i in range(node_count)] inter_con_count = lib.get_cloth_interconnector_count(cloth_ptr) constraint_counts = [lib.get_interconnector_constraint_count(cloth_ptr, index) for index in range(inter_con_count)] if frame == 100: name = ffi.new('char[]', bytes("wind", 'utf-8')) lib.remove_constraint_by_id(cloth_ptr, name) connector_positions = [] for inter_index in range(inter_con_count): connector_positions += [lib.get_interconnector_constraint(cloth_ptr, inter_index, index) for index in range(constraint_counts[inter_index])] #for node in connector_positions: # draw_line(gp_frame, (node.x, 0, node.y), (node.dx, 0, node.dy)) node = [(node.x, 0, node.y) for node in connector_positions] draw_stroke(gp_frame, nodes) lib.update_cloth_mesh(cloth_ptr, 0.005, 5) #lib.mesh_free(cloth_ptr) return {'FINISHED'}
def test(): cloth_ptr = lib.get_cloth_mesh(5, 10, 5) print(lib.mesh_node_count(cloth_ptr)) lib.mesh_free(cloth_ptr) lib.update_cloth_mesh(cloth_ptr, 0.0016, 3) import time while True: positions = lib.get_cloth_mesh_positions(cloth_ptr) print(positions) time.sleep(0.2)
def create_frames(mesh, gp_layer, callbacks = []): NUM_FRAMES = 600 FRAMES_SPACING=1 for frame in range(NUM_FRAMES): if len(list(gp_layer.frames)) <= frame*FRAMES_SPACING: gp_frame = gp_layer.frames.new(frame*FRAMES_SPACING) else: gp_frame = gp_layer.frames[frame*FRAMES_SPACING] #node_count = lib.mesh_node_count(mesh) #node_positions = [lib.mesh_node_position(mesh, i) for i in range(node_count)] #print(node_positions) inter_con_count = lib.get_cloth_interconnector_count(mesh) constraint_counts = [lib.get_interconnector_constraint_count(mesh, index) for index in range(inter_con_count)] #if frame == 100: # name = ffi.new('char[]', bytes("wind", 'utf-8')) # lib.remove_constraint_by_id(mesh, name) #if frame == 6: # name = ffi.new('char[]', bytes('gravity', 'utf-8')) # lib.remove_constraint_by_id(mesh, name) connector_positions = [] for inter_index in range(inter_con_count): connector_positions += [lib.get_interconnector_constraint(mesh, inter_index, index) for index in range(constraint_counts[inter_index])] #for node in connector_positions: # draw_line(gp_frame, (node.x, 0, node.y), (node.dx, 0, node.dy)) nodes = [(node.x, 0, node.y) for node in connector_positions] draw_stroke(gp_frame, nodes) for callback in callbacks: callback(gp_frame) lib.update_cloth_mesh(mesh, 0.005, 4)
] #node_pos_d = None #for node_pos in node_positions: # if node_pos_d: # draw_line(gp_frame, (0, node_pos.x, node_pos.y), (0, node_pos_d.x, node_pos_d.y)) # node_pos_d = node_pos inter_con_count = lib.get_cloth_interconnector_count(cloth_ptr) constraint_counts = [ lib.get_interconnector_constraint_count(cloth_ptr, index) for index in range(inter_con_count) ] if frame == 100: name = ffi.new('char[]', bytes("wind", 'utf-8')) lib.remove_constraint_by_id(cloth_ptr, name) connector_positions = [] for inter_index in range(inter_con_count): connector_positions += [ lib.get_interconnector_constraint(cloth_ptr, inter_index, index) for index in range(constraint_counts[inter_index]) ] for node in connector_positions: draw_line(gp_frame, (0, node.x, node.y), (0, node.dx, node.dy)) lib.update_cloth_mesh(cloth_ptr, 0.016, 3) lib.mesh_free(cloth_ptr)