예제 #1
0
    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'}
예제 #2
0
파일: margin.py 프로젝트: digdendes/mnbvcxz
    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'}
예제 #3
0
    def execute(self, context):
        
        tooth = odcutils.tooth_selection(context)[0]
        sce=bpy.context.scene
        
        layers_copy = [layer for layer in context.scene.layers]
        context.scene.layers[0] = True
        
        prep = tooth.prep_model
        Prep = bpy.data.objects.get(prep)
        
        margin = tooth.margin
        if margin not in bpy.data.objects:
            self.report({'ERROR'},'No Margin to Refine!  Please mark margin first')
        if not Prep:
            self.report({'WARNING'},'No Prep to snap margin to!')
            
        Margin = bpy.data.objects[margin]
        Margin.dupli_type = 'NONE'
        
        if bpy.context.mode != 'OBJECT':
            bpy.ops.object.mode_set(mode='OBJECT')
            
        bpy.ops.object.select_all(action='DESELECT')
        
        bpy.context.tool_settings.use_snap = True
        bpy.context.tool_settings.snap_target= 'ACTIVE'
        bpy.context.tool_settings.snap_element = 'FACE'
        
        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
        
        Margin.select = True
        sce.objects.active = Margin
        bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')
        
        if Prep and 'SHRINKWRAP' not in Margin.modifiers:
            i = len(Margin.modifiers)
            bpy.ops.object.modifier_add(type='SHRINKWRAP')
            mod = Margin.modifiers[i]
            mod.target=Prep
            mod.show_on_cage = True

        bpy.context.tool_settings.use_snap = True
        bpy.context.tool_settings.snap_target= 'ACTIVE'
        bpy.context.tool_settings.snap_element = 'FACE'
        bpy.context.tool_settings.proportional_edit = 'ENABLED'
        bpy.context.tool_settings.proportional_size=1
        
        bpy.ops.object.editmode_toggle()
        
        
        for i, layer in enumerate(layers_copy):
            context.scene.layers[i] = layer
        context.scene.layers[4] = True
        
        return {'FINISHED'}
예제 #4
0
파일: margin.py 프로젝트: digdendes/mnbvcxz
    def execute(self, context):

        tooth = odcutils.tooth_selection(context)[0]
        sce = bpy.context.scene

        layers_copy = [layer for layer in context.scene.layers]
        context.scene.layers[0] = True

        prep = tooth.prep_model
        Prep = bpy.data.objects.get(prep)

        margin = tooth.margin
        if margin not in bpy.data.objects:
            self.report({'ERROR'},
                        'No Margin to Refine!  Please mark margin first')
        if not Prep:
            self.report({'WARNING'}, 'No Prep to snap margin to!')

        Margin = bpy.data.objects[margin]
        Margin.dupli_type = 'NONE'

        if bpy.context.mode != 'OBJECT':
            bpy.ops.object.mode_set(mode='OBJECT')

        bpy.ops.object.select_all(action='DESELECT')

        bpy.context.tool_settings.use_snap = True
        bpy.context.tool_settings.snap_target = 'ACTIVE'
        bpy.context.tool_settings.snap_element = 'FACE'

        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

        Margin.select = True
        sce.objects.active = Margin
        bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')

        if Prep and 'SHRINKWRAP' not in Margin.modifiers:
            i = len(Margin.modifiers)
            bpy.ops.object.modifier_add(type='SHRINKWRAP')
            mod = Margin.modifiers[i]
            mod.target = Prep
            mod.show_on_cage = True

        bpy.context.tool_settings.use_snap = True
        bpy.context.tool_settings.snap_target = 'ACTIVE'
        bpy.context.tool_settings.snap_element = 'FACE'
        bpy.context.tool_settings.proportional_edit = 'ENABLED'
        bpy.context.tool_settings.proportional_size = 1

        bpy.ops.object.editmode_toggle()

        for i, layer in enumerate(layers_copy):
            context.scene.layers[i] = layer
        context.scene.layers[4] = True

        return {'FINISHED'}