def execute(self,context): settings = get_settings() dbg = settings.debug #TODO: Scene Preservation recording teeth = odcutils.tooth_selection(context) sce = bpy.context.scene layers_copy = [layer for layer in context.scene.layers] context.scene.layers[0] for tooth in teeth: #see if there is a corresponding implant if tooth.name in sce.odc_implants: contour = bpy.data.objects.get(tooth.contour) Z = Vector((0,0,-1)) if contour: if tooth.axis: Axis = bpy.data.objects.get(tooth.axis) if Axis: neg_z = Axis.matrix_world.to_quaternion() * Z rot_diff = odcutils.rot_between_vecs(Vector((0,0,1)), neg_z) else: neg_z = contour.matrix_world.to_quaternion() * Z rot_diff = odcutils.rot_between_vecs(Vector((0,0,1)), neg_z) else: neg_z = contour.matrix_world.to_quaternion() * Z rot_diff = odcutils.rot_between_vecs(Vector((0,0,1)), neg_z) mx = contour.matrix_world x = mx[0][3] y = mx[1][3] z = mx[2][3] #CEJ Location new_loc = odcutils.box_feature_locations(contour, Vector((0,0,-1))) Imp = implant_utils.place_implant(context, sce.odc_implants[tooth.name], new_loc, rot_diff, self.imp, hardware = self.hardware) #reposition platform below CEJ world_mx = Imp.matrix_world delta = Imp.dimensions[2] * world_mx.to_3x3() * Vector((0,0,1)) + self.depth * world_mx.to_3x3() * Vector((0,0,1)) world_mx[0][3] += delta[0] world_mx[1][3] += delta[1] world_mx[2][3] += delta[2] #odcutils.reorient_object(Imp, rot_diff) odcutils.layer_management(sce.odc_implants, debug = False) for i, layer in enumerate(layers_copy): context.scene.layers[i] = layer context.scene.layers[11] = True return {'FINISHED'}
def execute(self, context): settings = get_settings() dbg = settings.debug #TODO: Scene Preservation recording teeth = odcutils.tooth_selection(context) sce = bpy.context.scene layers_copy = [layer for layer in context.scene.layers] context.scene.layers[0] for tooth in teeth: #see if there is a corresponding implant if tooth.name in sce.odc_implants: contour = bpy.data.objects.get(tooth.contour) Z = Vector((0, 0, -1)) if contour: if tooth.axis: Axis = bpy.data.objects.get(tooth.axis) if Axis: neg_z = Axis.matrix_world.to_quaternion() * Z rot_diff = odcutils.rot_between_vecs( Vector((0, 0, 1)), neg_z) else: neg_z = contour.matrix_world.to_quaternion() * Z rot_diff = odcutils.rot_between_vecs( Vector((0, 0, 1)), neg_z) else: neg_z = contour.matrix_world.to_quaternion() * Z rot_diff = odcutils.rot_between_vecs( Vector((0, 0, 1)), neg_z) mx = contour.matrix_world x = mx[0][3] y = mx[1][3] z = mx[2][3] #CEJ Location new_loc = odcutils.box_feature_locations( contour, Vector((0, 0, -1))) Imp = implant_utils.place_implant( context, sce.odc_implants[tooth.name], new_loc, rot_diff, self.imp, hardware=self.hardware) #reposition platform below CEJ world_mx = Imp.matrix_world delta = Imp.dimensions[2] * world_mx.to_3x3() * Vector( (0, 0, 1)) + self.depth * world_mx.to_3x3() * Vector( (0, 0, 1)) world_mx[0][3] += delta[0] world_mx[1][3] += delta[1] world_mx[2][3] += delta[2] #odcutils.reorient_object(Imp, rot_diff) odcutils.layer_management(sce.odc_implants, debug=False) for i, layer in enumerate(layers_copy): context.scene.layers[i] = layer context.scene.layers[11] = True return {'FINISHED'}
def break_contact_deform(context, ob1,ob2, debug = False): ''' separate two objects by deforming a lattice with a plane. Results in a smooth separation. args: ret: ''' if debug: print('ob1 name: %s' % ob1.name) print('ob2 name: %s' % ob2.name) quat_1 = ob1.matrix_world.to_quaternion() quat_2 = ob2.matrix_world.to_quaternion() lat1 = odcutils.bbox_to_lattice(context.scene, ob1) lat2 = odcutils.bbox_to_lattice(context.scene, ob2) print('we made lattices?') loc_1 = odcutils.get_bbox_center(ob1, world = True) loc_2 = odcutils.get_bbox_center(ob2, world = True) diff = loc_2 - loc_1 #the directions to keep things simple. x = Vector((1,0,0)) y = Vector((0,1,0)) z = Vector((0,0,1)) vecs = [x,y,z] #dot each of the x,y,z coords (transformed to workd dir) with the vector between #the two bounding box centers. dirs1 = [(quat_1 * x).dot(diff)**2, (quat_1 * y).dot(diff)**2, (quat_1 * z).dot(diff)**2] dirs2 = [(quat_2 * x).dot(diff)**2, (quat_2 * y).dot(diff)**2, (quat_2 * z).dot(diff)**2] #find the maximium dot product #this is the dirction which is most parallel dir1 = dirs1.index(max(dirs1)) dir2 = dirs2.index(max(dirs2)) #check i we need to negate eithe directions #don't get confused because we will negate again #when we put the shrinwrap mod on. This is determinging #whether +x or -x points at the othe robject neg1 = 1 + -2 * ((quat_1 * vecs[dir1]).dot(diff) < 0) neg2 = 1 + -2 * ((quat_2 * vecs[dir2]).dot(diff) > 0) vec1 = neg1 * vecs[dir1] vec2 = neg2 * vecs[dir2] if debug: print(ob1.name + ' is pointed toward ' + ob2.name + ' in the direction:') print(vec1) print(ob2.name + ' is pointed toward ' + ob1.name + ' in the direction:') print(vec2) pt1 = odcutils.box_feature_locations(ob1, vec1) pt2 = odcutils.box_feature_locations(ob2, vec2) if debug: print(pt1) print(pt2) midpoint = .5 * (pt1 + pt2) pln_verts = [Vector((1,1,0)),Vector((-1,1,0)),Vector((-1,-1,0)),Vector((1,-1,0))] pln_faces = [(0,1,2,3)] pln_mesh = bpy.data.meshes.new('separator') pln_mesh.from_pydata(pln_verts,[],pln_faces) new_plane_ob = bpy.data.objects.new('Separator', pln_mesh) new_plane_ob.rotation_mode = 'QUATERNION' new_plane_ob.rotation_quaternion = odcutils.rot_between_vecs(Vector((0,0,1)), diff) new_plane_ob.location = midpoint new_plane_ob.scale = .5 * (ob1.dimensions + ob2.dimensions) context.scene.objects.link(new_plane_ob) mod1 = lat1.modifiers.new('Contact', 'SHRINKWRAP') mod2 = lat2.modifiers.new('Contact', 'SHRINKWRAP') mod1.wrap_method = 'PROJECT' mod2.wrap_method = 'PROJECT' if neg1 < 0: mod1.use_negative_direction = False mod1.use_positive_direction = True else: mod1.use_negative_direction = True mod1.use_positive_direction = False if neg2 < 0: mod2.use_negative_direction = False mod2.use_positive_direction = True else: mod2.use_negative_direction = True mod2.use_positive_direction = False if dir1 == 0: mod1.use_project_x = True elif dir1 == 1: mod1.use_project_y = True else: mod1.use_project_z = True if dir2 == 0: mod2.use_project_x = True elif dir2 == 1: mod2.use_project_y = True else: mod2.use_project_z = True mod1.target = new_plane_ob mod2.target = new_plane_ob print('broken!')