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 draw_mesh_grid(mesh, gp_frame, mesh_dim): max_node_count = lib.mesh_node_count(mesh) for y_idx in reversed(range(mesh_dim[1])): for x_idx in reversed(range(mesh_dim[0])): if x_idx != 0 and y_idx !=0: if x_idx+(y_idx)*mesh_dim[0] > max_node_count: raise InvalidMeshDimensions br_node = lib.mesh_node_position(mesh, x_idx+(y_idx)*mesh_dim[0]) #mesh_nodes[x_idx+(y_idx)*mesh_dim[0]] br_node_co = [br_node.x, 0, br_node.y] tr_node = lib.mesh_node_position(mesh, x_idx+(y_idx-1)*mesh_dim[0]) #mesh_nodes[x_idx+(y_idx-1)*mesh_dim[0]] tr_node_co = [tr_node.x, 0, tr_node.y] tl_node = lib.mesh_node_position(mesh, x_idx-1+(y_idx-1)*mesh_dim[0]) #mesh_nodes[x_idx-1+(y_idx-1)*mesh_dim[0]] tl_node_co = [tl_node.x, 0, tl_node.y] bl_node = lib.mesh_node_position(mesh, x_idx-1+(y_idx)*mesh_dim[0]) #mesh_nodes[x_idx-1+(y_idx)*mesh_dim[0]] bl_node_co = [bl_node.x, 0, bl_node.y] draw_stroke(gp_frame, [tl_node_co, br_node_co, bl_node_co, tr_node_co], cyclic = True, material_index = 2)
def execute(self, context): bpy.ops.object.mode_set(mode='OBJECT') mesh1 = lib.empty_cloth() print("Clothifying lowerleft") nodes1 = clothify_stroke(mesh1, 'lowerleft') print("Clothifying lowerright") mesh2 = lib.empty_cloth() nodes2 = clothify_stroke(mesh2, 'lowerright') print("Clothifying upperleft") mesh3 = lib.empty_cloth() nodes3 = clothify_stroke(mesh3, 'upperleft') print("Clothifying upperright") mesh4 = lib.empty_cloth() nodes4 = clothify_stroke(mesh4, 'upperright') print("creating frames...") node_count = lib.mesh_node_count(mesh1) min_height_min_width_node = lib.mesh_node_position(mesh1, node_count-1) node_count = lib.mesh_node_count(mesh2) max_height_node = lib.mesh_node_position(mesh2, node_count-1) node_count = lib.mesh_node_count(mesh3) max_width_node = lib.mesh_node_position(mesh3, node_count-1) #node_count = lib.mesh_node_count(mesh4) #max_width_node = lib.mesh_node_position(mesh4, node_count-1) mesh5 = lib.empty_cloth() x_positions, y_positions = generate_grid_coords(16, 9, min_height_min_width_node, max_height_node, max_width_node) mesh5_nodes_ordered, (bl_corner, tr_corner, tl_corner, br_corner, middle), edges_dict = generate_mesh_grid(mesh5, x_positions, y_positions, 0.06 ) #bl_corner, tr_corner, tl_corner, br_corner = generate_mesh_grid(mesh5, range(10), range(10), 0.1) #lib.add_connector(mesh1, nodes1[-1], bl_corner, 0.5) #lib.add_connector(mesh2, nodes2[-1], br_corner, 0.5) #lib.add_connector(mesh3, nodes3[-1], tl_corner, 0.5) #lib.add_connector(mesh4, nodes4[-1], tr_corner, 0.5) lib.add_connector(mesh5, bl_corner, nodes1[-1], 0.01, 0.5) lib.add_connector(mesh5, br_corner, nodes2[-1], 0.01, 0.5) lib.add_connector(mesh5, tl_corner, nodes3[-1], 0.01, 0.5) lib.add_connector(mesh5, tr_corner, nodes4[-1], 0.01, 0.5) lib.add_connector(mesh5, bl_corner, tl_corner, 1.25, 0.5) lib.add_connector(mesh5, tr_corner, br_corner, 0.5, 0.5) lib.add_connector(mesh5, tl_corner, br_corner, 0.75, 0.5) lib.add_connector(mesh5, tr_corner, bl_corner, 2, 0.5) #lib.add_connector(mesh5, bl_corner, middle, 2, 0.5) #lib.add_connector(mesh5, br_corner, middle, 2, 0.5) #lib.add_connector(mesh5, tl_corner, middle, 2, 0.5) #lib.add_connector(mesh5, tr_corner, middle, 2, 0.5) bpy.ops.object.mode_set(mode='OBJECT') gp_layer = init_grease_pencil() #create_frames(mesh1, gp_layer) #create_frames(mesh2, gp_layer) #create_frames(mesh3, gp_layer) #create_frames(mesh4, gp_layer) #create_frames(mesh5, gp_layer) fold_in_frames([mesh1, mesh2, mesh3, mesh4, mesh5], gp_layer, [lambda gp_frame: draw_mesh_grid(mesh5, gp_frame, (16,9))]) return {'FINISHED'}
return gp_stroke NUM_FRAMES = 600 FRAMES_SPACING = 1 # distance between frames bpy.context.scene.frame_start = 0 bpy.context.scene.frame_end = NUM_FRAMES * FRAMES_SPACING #cloth_ptr = lib.get_cloth_mesh(5,10,10) #cloth_ptr = lib.get_woven_cloth_mesh(5,15,5, 120, 0.5) cloth_ptr = lib.get_cloth_mesh_field(5, 10, 5, 120, +3.0, 0.5) gp_layer = init_grease_pencil() for frame in range(NUM_FRAMES): gp_frame = gp_layer.frames.new(frame * FRAMES_SPACING) node_count = lib.mesh_node_count(cloth_ptr) node_pos_d = None node_positions = [ lib.mesh_node_position(cloth_ptr, i) for i in range(node_count) ] #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)