Example #1
0
    def set_axis(self, context, event):

        coord = (event.mouse_region_x, event.mouse_region_y)
        v3d = context.space_data
        rv3d = v3d.region_3d
        view_vector = view3d_utils.region_2d_to_vector_3d(
            context.region, rv3d, coord)
        ray_origin = view3d_utils.region_2d_to_origin_3d(
            context.region, rv3d, coord)
        ray_target = ray_origin + (view_vector * 1000)
        if bversion() < '002.077.000':
            res, obj, loc, no, mx = context.scene.ray_cast(
                ray_origin, ray_target)
        else:
            res, loc, no, ind, obj, mx = context.scene.ray_cast(
                ray_origin, view_vector)

        if res:
            obj.name = str(self.target)
            for ob in bpy.data.objects:
                ob.select = False
            obj.select = True
            obj.show_name = True
            context.scene.objects.active = obj
            bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='BOUNDS')
            return True
        else:
            return False
Example #2
0
    def slice(self):
        self.clear_draw()

        self.get_pt_and_no()

        mx = self.snap_ob.matrix_world
        imx = mx.inverted()
        if bversion() < '002.077.000':
            pt, no, seed, dist = self.bvh.find(imx * self.cut_pt)
        else:
            pt, no, seed, dist = self.bvh.find_nearest(imx * self.cut_pt)

        verts_x, eds = cross_section_seed_ver1(self.bme,
                                               mx,
                                               self.cut_pt,
                                               self.cut_no_x,
                                               seed,
                                               max_tests=100)
        verts_y, eds = cross_section_seed_ver1(self.bme,
                                               mx,
                                               self.cut_pt,
                                               self.cut_no_y,
                                               seed,
                                               max_tests=100)
        #put them in world space

        if verts_x != None:
            self.slice_points_x = [mx * v for v in verts_x]
        else:
            self.slice_points_x = []
        if verts_y != None:
            self.slice_points_y = [mx * v for v in verts_y]
        else:
            self.slice_points_y = []

        bmx = self.bracket_data.bracket_obj.matrix_world
        bracket_x = bmx.to_3x3() * Vector((1, 0, 0))
        bracket_z = bmx.to_3x3() * Vector((0, 0, 1))
        bracket_y = bracket_z.cross(self.cut_no_x)

        v0 = self.cut_pt
        v1 = v0 + self.b_gauge * bracket_y
        v_l = v1 - 4 * bracket_z
        v_m = v1 + 2 * bracket_x
        v_d = v1 - 2 * bracket_x
        self.reference_L = [v0, v1, v_l, v_m, v_d]
Example #3
0
    def set_axis(self, context, event):

        if not self.target:
            return

        empty_name = self.target.name + 'root_empty'
        if empty_name in context.scene.objects:
            ob = context.scene.objects[empty_name]
            ob.empty_draw_type = 'SINGLE_ARROW'
            ob.empty_draw_size = 10
        else:
            ob = bpy.data.objects.new(empty_name, None)
            ob.empty_draw_type = 'SINGLE_ARROW'
            ob.empty_draw_size = 10
            context.scene.objects.link(ob)

        coord = (event.mouse_region_x, event.mouse_region_y)
        v3d = context.space_data
        rv3d = v3d.region_3d
        view_vector = view3d_utils.region_2d_to_vector_3d(
            context.region, rv3d, coord)
        ray_origin = view3d_utils.region_2d_to_origin_3d(
            context.region, rv3d, coord)
        ray_target = ray_origin + (view_vector * 1000)
        if bversion() < '002.077.000':
            res, obj, loc, no, mx = context.scene.ray_cast(
                ray_origin, ray_target)
        else:
            res, loc, no, ind, obj, mx = context.scene.ray_cast(
                ray_origin, view_vector)

        if res:
            if obj != self.target:
                return

            ob.location = loc
        else:
            return

        if ob.rotation_mode != 'QUATERNION':
            ob.rotation_mode = 'QUATERNION'

        vrot = rv3d.view_rotation
        ob.rotation_quaternion = vrot
Example #4
0
    def slice(self):
        self.slice_points = []

        if len(self.crv_dat.b_pts) < 2 or self.crv_dat.selected == -1:
            return

        self.get_pt_and_no()

        mx = self.snap_ob.matrix_world
        imx = mx.inverted()
        if bversion() < '002.077.000':
            pt, no, seed, dist = self.bvh.find(imx * self.cut_pt)
        else:
            pt, no, seed, dist = self.bvh.find_nearest(imx * self.cut_pt)

        verts, eds = cross_section_seed_ver1(self.bme,
                                             mx,
                                             self.cut_pt,
                                             self.cut_no,
                                             seed,
                                             max_tests=40)

        #put them in world space
        self.slice_points = [mx * v for v in verts]
Example #5
0
    def grab_mouse_move(self, context, x, y, normal=False):
        region = context.region
        rv3d = context.region_data
        coord = x, y
        view_vector = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord)
        ray_origin = view3d_utils.region_2d_to_origin_3d(region, rv3d, coord)
        ray_target = ray_origin + (view_vector * 1000)

        hit = False
        if self.snap_type == 'SCENE':

            if bversion() < '002.077.000':
                res, obj, mx, loc, no = context.scene.ray_cast(
                    ray_origin, ray_target)
            else:
                res, loc, no, ind, obj, mx = context.scene.ray_cast(
                    ray_origin, view_vector)
            if res:
                hit = True

        elif self.snap_type == 'OBJECT':
            mx = self.snap_ob.matrix_world
            imx = mx.inverted()

            if bversion() < '002.077.000':
                loc, no, face_ind = self.snap_ob.ray_cast(
                    imx * ray_origin, imx * ray_target)
                if face_ind != -1:
                    hit = True
            else:
                ok, loc, no, face_ind = self.snap_ob.ray_cast(
                    imx * ray_origin, imx * ray_target - imx * ray_origin)
                if ok:
                    hit = True

        if not hit:
            self.grab_cancel()

        else:
            world_location = mx * loc
            imx = mx.inverted()

            #this will be the object Z axis
            world_normal = imx.transposed().to_3x3() * no

            if normal:
                ob_Z = world_normal
                ob_Z.normalize()

                view_Y = rv3d.view_rotation * Vector((0, 1, 0))
                if self.bracket_obj.name.startswith(
                        "U") or self.bracket_obj.name.startswith("u"):
                    view_Y *= -1

                #project view y into the tangetnt plane of teh surface
                ob_Y = view_Y - view_Y.dot(ob_Z) * ob_Z
                ob_Y.normalize()

                ob_X = ob_Y.cross(ob_Z)
                ob_X.normalize()

                #rotation matrix from principal axes
                T = Matrix.Identity(3)  #make the columns of matrix X, Y, Z
                T[0][0], T[0][1], T[0][2] = ob_X[0], ob_Y[0], ob_Z[0]
                T[1][0], T[1][1], T[1][2] = ob_X[1], ob_Y[1], ob_Z[1]
                T[2][0], T[2][1], T[2][2] = ob_X[2], ob_Y[2], ob_Z[2]

                rot = T.to_4x4()

            else:
                rot = self.bracket_obj.matrix_world.to_3x3().to_4x4()

            loc = Matrix.Translation(world_location)
            self.bracket_obj.matrix_world = loc * rot
Example #6
0
    def execute(self, context):
        layers_copy = [layer for layer in context.scene.layers]
        context.scene.layers[0] = True

        for ob in context.selected_objects:
            mods = [mod.type for mod in ob.modifiers]
            if 'HOOK' in mods:
                self.report({'WARNING'}, 'There are hook modifiers in' +
                            ob.name + '.  Please apply or remove them')
            elif 'LAPLACIANDEFORM' in mods:
                self.report({'WARNING'},
                            'There are laplacial deform modifiers in' +
                            ob.name + '.  Please apply or remove them')
            elif 'SHRINKWRAP' in mods:
                self.report(
                    {'WARNING'},
                    'There are shrinkwrap modifiers in' + ob.name +
                    '.  Use Flexi Tooth BEFORE any margin seating or contact grinding'
                )
                continue

            else:
                if ob.type == 'MESH':
                    mx = ob.matrix_world
                    imx = mx.inverted()

                    if ob.data.name[0:2] not in v_groups: continue

                    ob.lock_location = [True, True, True]
                    #ob.hide_select = True
                    data_name = ob.data.name[0:2]

                    hook_parent = bpy.data.objects.new(data_name + '_hook',
                                                       None)
                    context.scene.objects.link(hook_parent)
                    hook_parent.matrix_world = ob.matrix_world

                    v_islands = v_groups[ob.data.name[0:2]]
                    modnames = [
                        data_name + '_hook.' + str(k).zfill(3)
                        for k in range(len(v_islands))
                    ]

                    bpy.ops.object.select_all(action='DESELECT')
                    context.scene.objects.active = ob
                    ob.select = True
                    N_mods = len(ob.modifiers)
                    for grp, modname in zip(v_islands, modnames):
                        bpy.ops.object.mode_set(mode='EDIT')
                        bpy.ops.mesh.select_all(action='DESELECT')
                        bpy.ops.object.mode_set(mode='OBJECT')
                        center = Vector((0, 0, 0))
                        for ind in grp:
                            ob.data.vertices[ind].select = True
                            center += ob.data.vertices[ind].co
                        center *= 1 / len(grp)

                        hook = bpy.data.objects.new(modname, None)
                        context.scene.objects.link(hook)

                        if bversion() < '002.077.000':
                            new_loc, no, ind = ob.closest_point_on_mesh(center)

                        else:
                            ok, new_loc, no, ind = ob.closest_point_on_mesh(
                                center)
                        world_loc = mx * new_loc

                        hook.parent = hook_parent
                        hook.matrix_world[0][3] = world_loc[0]
                        hook.matrix_world[1][3] = world_loc[1]
                        hook.matrix_world[2][3] = world_loc[2]

                        hook.empty_draw_type = 'SPHERE'
                        hook.empty_draw_size = .5

                        mod = ob.modifiers.new(modname, type='HOOK')
                        mod.object = hook

                        for n in range(0, N_mods):
                            bpy.ops.object.modifier_move_up(modifier=mod.name)
                        bpy.ops.object.mode_set(mode='EDIT')
                        bpy.ops.object.hook_reset(modifier=mod.name)
                        bpy.ops.object.hook_assign(modifier=mod.name)
                        #old_obs = [ob.name for ob in bpy.data.objects]
                        #bpy.ops.object.hook_add_newob()
                        #for obj in bpy.data.objects:
                        #    if obj.name not in old_obs:
                        #        hook = obj
                        #        hook.name = modname
                        #        hook.empty_draw_type = 'SPHERE'
                        #        hook.empty_draw_size = .5
                        #        hook.show_x_ray = True
                        #        loc = hook.location
                        #        bpy.ops.object.mode_set(mode = 'OBJECT')
                        #        new_loc, no, ind = ob.closest_point_on_mesh(imx*loc)
                        #       hook.location = mx * new_loc
                        #TODO, parent in place and keep transform

                    for mod in ob.modifiers:
                        if mod.type == 'HOOK':
                            mod.show_expanded = False
                    if 'Anchor' not in ob.vertex_groups:
                        ob.vertex_groups.new('Anchor')

                    bpy.ops.object.vertex_group_set_active(group='Anchor')
                    bpy.ops.object.mode_set(mode='EDIT')
                    bpy.ops.object.vertex_group_remove_from(use_all_verts=True)
                    bpy.ops.mesh.select_all(action='DESELECT')
                    bpy.ops.object.mode_set(mode='OBJECT')
                    for grp in v_islands:
                        for v in grp:
                            ob.data.vertices[v].select = True

                    bpy.ops.object.mode_set(mode='EDIT')
                    context.scene.tool_settings.vertex_group_weight = 1
                    bpy.ops.object.vertex_group_assign()
                    bpy.ops.object.mode_set(mode='OBJECT')

                    mod = ob.modifiers.new('flexitooth', 'LAPLACIANDEFORM')
                    mod.vertex_group = 'Anchor'
                    mod.iterations = 20

                    for n in range(0, N_mods):
                        bpy.ops.object.modifier_move_up(modifier="flexitooth")
                    bpy.ops.object.mode_set(mode='EDIT')
                    bpy.ops.object.laplaciandeform_bind(modifier="flexitooth")
                    bpy.ops.object.mode_set(mode='OBJECT')

                    for mod in ob.modifiers:
                        if mod.type == 'HOOK':
                            mod.show_expanded = False

                    #ob.modifiers.new

        return {'FINISHED'}