def execute(self, context): #picks tooth based on selected/active object...will refactor soon tooth = odcutils.tooth_selection(context)[0] sce=bpy.context.scene a = tooth.name mesial = tooth.mesial distal = tooth.distal margin = tooth.margin axis = tooth.axis layers_copy = [layer for layer in context.scene.layers] context.scene.layers[0] = True if margin not in bpy.data.objects: self.report({'ERROR'},'No Margin to accept!') return {'CANCELLED'} if axis not in bpy.data.objects: self.report({'ERROR'}, 'No insertion axis for ' + a + ', please define insertion axis') print(tooth.margin) print(tooth.axis) print(tooth.name) print([ob.name for ob in bpy.data.objects]) return {'CANCELLED'} Margin=bpy.data.objects[margin] Axis = bpy.data.objects[axis] if Margin.type != 'MESH': me_data = odcutils.bezier_to_mesh(Margin, tooth.margin, n_points = 200) mx = Margin.matrix_world context.scene.objects.unlink(Margin) bpy.data.objects.remove(Margin) new_obj = bpy.data.objects.new(tooth.margin, me_data) new_obj.matrix_world = mx context.scene.objects.link(new_obj) tooth.margin = new_obj.name #just in case of name collisions Margin = new_obj master=sce.odc_props.master Margin.dupli_type = 'NONE' if mesial: bpy.data.objects[mesial].hide = False if distal: bpy.data.objects[distal].hide = False if bpy.context.mode != 'OBJECT': bpy.ops.object.mode_set(mode='OBJECT') psuedo_margin= str(a + "_Psuedo Margin") tooth.pmargin = psuedo_margin p_margin_me = Margin.to_mesh(context.scene, True, 'PREVIEW') p_margin_bme = bmesh.new() p_margin_bme.from_mesh(p_margin_me) Z = Axis.matrix_world.to_3x3() * Vector((0,0,1)) odcutils.extrude_bmesh_loop(p_margin_bme, p_margin_bme.edges, Margin.matrix_world, Z, .2, move_only = True) odcutils.extrude_bmesh_loop(p_margin_bme, p_margin_bme.edges, Margin.matrix_world, Z, -.4, move_only = False) p_margin_bme.to_mesh(p_margin_me) PMargin = bpy.data.objects.new(psuedo_margin,p_margin_me) PMargin.matrix_world = Margin.matrix_world context.scene.objects.link(PMargin) bpy.data.objects[psuedo_margin].hide=True bpy.context.tool_settings.use_snap = False bpy.context.tool_settings.proportional_edit = 'DISABLED' #Now we want to overpack the verts so that when the edge of the #restoration is snapped to it, it won't displace them too much # I have estimated ~25 microns as a fine linear packin #density....another option is to leave the curve as an #implicit function.... hmmmmm for i, layer in enumerate(layers_copy): context.scene.layers[i] = layer context.scene.layers[4] = True return {'FINISHED'}
def execute(self, context): #picks tooth based on selected/active object...will refactor soon tooth = odcutils.tooth_selection(context)[0] sce = bpy.context.scene a = tooth.name mesial = tooth.mesial distal = tooth.distal margin = tooth.margin axis = tooth.axis layers_copy = [layer for layer in context.scene.layers] context.scene.layers[0] = True if margin not in bpy.data.objects: self.report({'ERROR'}, 'No Margin to accept!') return {'CANCELLED'} if axis not in bpy.data.objects: self.report({'ERROR'}, 'No insertion axis for ' + a + ', please define insertion axis') print(tooth.margin) print(tooth.axis) print(tooth.name) print([ob.name for ob in bpy.data.objects]) return {'CANCELLED'} Margin = bpy.data.objects[margin] Axis = bpy.data.objects[axis] if Margin.type != 'MESH': me_data = odcutils.bezier_to_mesh(Margin, tooth.margin, n_points=200) mx = Margin.matrix_world context.scene.objects.unlink(Margin) bpy.data.objects.remove(Margin) new_obj = bpy.data.objects.new(tooth.margin, me_data) new_obj.matrix_world = mx context.scene.objects.link(new_obj) tooth.margin = new_obj.name #just in case of name collisions Margin = new_obj master = sce.odc_props.master Margin.dupli_type = 'NONE' if mesial: bpy.data.objects[mesial].hide = False if distal: bpy.data.objects[distal].hide = False if bpy.context.mode != 'OBJECT': bpy.ops.object.mode_set(mode='OBJECT') psuedo_margin = str(a + "_Psuedo Margin") tooth.pmargin = psuedo_margin p_margin_me = Margin.to_mesh(context.scene, True, 'PREVIEW') p_margin_bme = bmesh.new() p_margin_bme.from_mesh(p_margin_me) Z = Axis.matrix_world.to_3x3() * Vector((0, 0, 1)) odcutils.extrude_bmesh_loop(p_margin_bme, p_margin_bme.edges, Margin.matrix_world, Z, .2, move_only=True) odcutils.extrude_bmesh_loop(p_margin_bme, p_margin_bme.edges, Margin.matrix_world, Z, -.4, move_only=False) p_margin_bme.to_mesh(p_margin_me) PMargin = bpy.data.objects.new(psuedo_margin, p_margin_me) PMargin.matrix_world = Margin.matrix_world context.scene.objects.link(PMargin) bpy.data.objects[psuedo_margin].hide = True bpy.context.tool_settings.use_snap = False bpy.context.tool_settings.proportional_edit = 'DISABLED' #Now we want to overpack the verts so that when the edge of the #restoration is snapped to it, it won't displace them too much # I have estimated ~25 microns as a fine linear packin #density....another option is to leave the curve as an #implicit function.... hmmmmm for i, layer in enumerate(layers_copy): context.scene.layers[i] = layer context.scene.layers[4] = True return {'FINISHED'}
def cloth_fill_main2(context, loop_obj, oct, smooth, debug = False): ''' notes: make sure the user view is such that you can see the entire ring with out any corosses (knots) if calling from script not in 3dview, you can override the view args: context - blender context loop_obj: blender curve object or mesh object representing just a loop oct - octree depth for the grid to fill. smooth - iteartions to smooth the surface (soap bubble effect) return: CurveMesh : The filled looop object type Blender Object (Mesh) ''' #selection mode = verts sce = context.scene if context.area.type != 'VIEW_3D': # Py cant access notifers for area in context.window.screen.areas: if area.type == 'VIEW_3D': # for reg in area.regions: # if reg.type == 'WINDOW': # region = reg for spc in area.spaces: if spc.type == 'VIEW_3D': v3d = spc region = spc.region_3d else: #get the space data v3d = bpy.context.space_data #v3d.transform_orientation = 'GLOBAL' #v3d.pivot_point = 'MEDIAN_POINT' region = v3d.region_3d vrot = region.view_rotation #this is a quat Z = vrot * Vector((0,0,1)) #change the mesh orientation to align with view..for blockout odcutils.reorient_object(loop_obj, vrot) #TODO test this sce.update() if loop_obj.parent: reparent = True else: reparent = False if loop_obj.type not in {'CURVE', 'MESH'}: return me = loop_obj.to_mesh(context.scene, True, 'PREVIEW') tray_bme = bmesh.new() tray_bme.from_mesh(me) tray_me = bpy.data.meshes.new('cloth tray') TrayOb = bpy.data.objects.new('Cloth Tray', tray_me) TrayOb.matrix_world = loop_obj.matrix_world #do some size estimation min_size = min(loop_obj.dimensions) size = max(list(loop_obj.dimensions)) grid_predict = size * 0.9 / pow(oct,2) print("grid prediction is: " + str(grid_predict)) #make a 2nd object to project down on... tmp_bme = bmesh.new() tmp_bme.from_mesh(me) temp_me = bpy.data.meshes.new('cloth temp') TempOb = bpy.data.objects.new('Cloth Temp', temp_me) TempOb.matrix_world = loop_obj.matrix_world context.scene.objects.link(TempOb) #fill the the surface of the temp geom = bmesh.ops.triangle_fill(tmp_bme, use_beauty = True, edges = tmp_bme.edges) tmp_bme.edges.ensure_lookup_table() tmp_bme.verts.ensure_lookup_table() #move edges outward a little perim_eds = [ed for ed in tmp_bme.edges if not ed.is_manifold] odcutils.extrude_bmesh_loop(tmp_bme, perim_eds, loop_obj.matrix_world, Z, -.001 * min_size, move_only = True) #This time add an extrusion odcutils.extrude_bmesh_loop(tmp_bme, perim_eds, loop_obj.matrix_world, Z, -.05 * min_size, move_only = False) #put the data in tmp_bme.to_mesh(TempOb.data) tmp_bme.free() #Now deal with the tray which is to be remeshed. #first, solidify all of their #flatten. Since oriented into view, this flattens it for v in tray_bme.verts: v.co[2] = 0.00 #triangle fill geom = bmesh.ops.triangle_fill(tray_bme, use_beauty = True, edges = tray_bme.edges) solid_geom = [f for f in tray_bme.faces] + [v for v in tray_bme.verts] + [ed for ed in tray_bme.edges] new_geom = bmesh.ops.solidify(tray_bme, geom = solid_geom, thickness = grid_predict * 0.75) tray_bme.to_mesh(tray_me) tray_bme.free() context.scene.objects.link(TrayOb) mod = TrayOb.modifiers.new('Remesh', type = 'REMESH') mod.octree_depth = oct mod.scale = .9 tray_bme = bmesh.new() final_me = TrayOb.to_mesh(context.scene, apply_modifiers = True, settings = 'PREVIEW') tray_bme.from_mesh(final_me) tray_bme.verts.ensure_lookup_table() to_delete = [] for v in tray_bme.verts: if v.co[2] > .0001 or v.co[2] < -.0001: to_delete.append(v) bmesh.ops.delete(tray_bme, geom = to_delete, context = 1) TrayOb.modifiers.remove(modifier = mod) tray_bme.to_mesh(TrayOb.data) tray_bme.free() #TODOD, manually with ray cast swrap = TrayOb.modifiers.new('Shrinkwrap', type = 'SHRINKWRAP') swrap.wrap_method = 'PROJECT' swrap.use_project_z = True swrap.use_negative_direction = True swrap.use_positive_direction = True swrap.target = TempOb #tray_me = TrayOb.to_mesh(context.scene, apply_modifiers = True, settings = 'PREVIEW') #TrayOb.data = tray_me #TrayOb.modifiers.remove(modifier = swrap) if reparent: TrayOb.update_tag() sce.update() odcutils.parent_in_place(TrayOb, loop_obj.parent) return TrayOb
def cloth_fill_main2(context, loop_obj, oct, smooth, debug=False): ''' notes: make sure the user view is such that you can see the entire ring with out any corosses (knots) if calling from script not in 3dview, you can override the view args: context - blender context loop_obj: blender curve object or mesh object representing just a loop oct - octree depth for the grid to fill. smooth - iteartions to smooth the surface (soap bubble effect) return: CurveMesh : The filled looop object type Blender Object (Mesh) ''' #selection mode = verts sce = context.scene if context.area.type != 'VIEW_3D': # Py cant access notifers for area in context.window.screen.areas: if area.type == 'VIEW_3D': # for reg in area.regions: # if reg.type == 'WINDOW': # region = reg for spc in area.spaces: if spc.type == 'VIEW_3D': v3d = spc region = spc.region_3d else: #get the space data v3d = bpy.context.space_data #v3d.transform_orientation = 'GLOBAL' #v3d.pivot_point = 'MEDIAN_POINT' region = v3d.region_3d vrot = region.view_rotation #this is a quat Z = vrot * Vector((0, 0, 1)) #change the mesh orientation to align with view..for blockout odcutils.reorient_object(loop_obj, vrot) #TODO test this sce.update() if loop_obj.parent: reparent = True else: reparent = False if loop_obj.type not in {'CURVE', 'MESH'}: return me = loop_obj.to_mesh(context.scene, True, 'PREVIEW') tray_bme = bmesh.new() tray_bme.from_mesh(me) tray_me = bpy.data.meshes.new('cloth tray') TrayOb = bpy.data.objects.new('Cloth Tray', tray_me) TrayOb.matrix_world = loop_obj.matrix_world #do some size estimation min_size = min(loop_obj.dimensions) size = max(list(loop_obj.dimensions)) grid_predict = size * 0.9 / pow(oct, 2) print("grid prediction is: " + str(grid_predict)) #make a 2nd object to project down on... tmp_bme = bmesh.new() tmp_bme.from_mesh(me) temp_me = bpy.data.meshes.new('cloth temp') TempOb = bpy.data.objects.new('Cloth Temp', temp_me) TempOb.matrix_world = loop_obj.matrix_world context.scene.objects.link(TempOb) #fill the the surface of the temp geom = bmesh.ops.triangle_fill(tmp_bme, use_beauty=True, edges=tmp_bme.edges) tmp_bme.edges.ensure_lookup_table() tmp_bme.verts.ensure_lookup_table() #move edges outward a little perim_eds = [ed for ed in tmp_bme.edges if not ed.is_manifold] odcutils.extrude_bmesh_loop(tmp_bme, perim_eds, loop_obj.matrix_world, Z, -.001 * min_size, move_only=True) #This time add an extrusion odcutils.extrude_bmesh_loop(tmp_bme, perim_eds, loop_obj.matrix_world, Z, -.05 * min_size, move_only=False) #put the data in tmp_bme.to_mesh(TempOb.data) tmp_bme.free() #Now deal with the tray which is to be remeshed. #first, solidify all of their #flatten. Since oriented into view, this flattens it for v in tray_bme.verts: v.co[2] = 0.00 #triangle fill geom = bmesh.ops.triangle_fill(tray_bme, use_beauty=True, edges=tray_bme.edges) solid_geom = [f for f in tray_bme.faces] + [v for v in tray_bme.verts] + [ ed for ed in tray_bme.edges ] new_geom = bmesh.ops.solidify(tray_bme, geom=solid_geom, thickness=grid_predict * 0.75) tray_bme.to_mesh(tray_me) tray_bme.free() context.scene.objects.link(TrayOb) mod = TrayOb.modifiers.new('Remesh', type='REMESH') mod.octree_depth = oct mod.scale = .9 tray_bme = bmesh.new() final_me = TrayOb.to_mesh(context.scene, apply_modifiers=True, settings='PREVIEW') tray_bme.from_mesh(final_me) tray_bme.verts.ensure_lookup_table() to_delete = [] for v in tray_bme.verts: if v.co[2] > .0001 or v.co[2] < -.0001: to_delete.append(v) bmesh.ops.delete(tray_bme, geom=to_delete, context=1) TrayOb.modifiers.remove(modifier=mod) tray_bme.to_mesh(TrayOb.data) tray_bme.free() #TODOD, manually with ray cast swrap = TrayOb.modifiers.new('Shrinkwrap', type='SHRINKWRAP') swrap.wrap_method = 'PROJECT' swrap.use_project_z = True swrap.use_negative_direction = True swrap.use_positive_direction = True swrap.target = TempOb #tray_me = TrayOb.to_mesh(context.scene, apply_modifiers = True, settings = 'PREVIEW') #TrayOb.data = tray_me #TrayOb.modifiers.remove(modifier = swrap) if reparent: TrayOb.update_tag() sce.update() odcutils.parent_in_place(TrayOb, loop_obj.parent) return TrayOb