Changeset View
Changeset View
Standalone View
Standalone View
mesh_carver.py
| Show First 20 Lines • Show All 1,612 Lines • ▼ Show 20 Lines | if len(selection) > 0: | ||||
| Already = True | Already = True | ||||
| if Already is False: | if Already is False: | ||||
| bpy.ops.object.modifier_add(type='BEVEL') | bpy.ops.object.modifier_add(type='BEVEL') | ||||
| mod = context.object.modifiers[-1] | mod = context.object.modifiers[-1] | ||||
| mod.limit_method = 'WEIGHT' | mod.limit_method = 'WEIGHT' | ||||
| mod.width = 0.01 | mod.width = 0.01 | ||||
| mod.profile = 0.699099 | mod.profile = 0.699099 | ||||
| mod.use_clamp_overlap = False | mod.use_clight_overlap = False | ||||
| mod.segments = 3 | mod.segments = 3 | ||||
| mod.loop_slide = False | mod.loop_slide = False | ||||
| bpy.ops.object.shade_smooth() | bpy.ops.object.shade_smooth() | ||||
| context.object.data.use_auto_smooth = True | context.object.data.use_auto_smooth = True | ||||
| context.object.data.auto_smooth_angle = 1.0472 | context.object.data.auto_smooth_angle = 1.0472 | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | for m in CurrentObject.modifiers: | ||||
| Already = True | Already = True | ||||
| if Already is False: | if Already is False: | ||||
| bpy.ops.object.modifier_add(type='BEVEL') | bpy.ops.object.modifier_add(type='BEVEL') | ||||
| mod = context.object.modifiers[-1] | mod = context.object.modifiers[-1] | ||||
| mod.limit_method = 'WEIGHT' | mod.limit_method = 'WEIGHT' | ||||
| mod.width = 0.01 | mod.width = 0.01 | ||||
| mod.profile = 0.699099 | mod.profile = 0.699099 | ||||
| mod.use_clamp_overlap = False | mod.use_clight_overlap = False | ||||
| mod.segments = 3 | mod.segments = 3 | ||||
| mod.loop_slide = False | mod.loop_slide = False | ||||
| bpy.ops.object.shade_smooth() | bpy.ops.object.shade_smooth() | ||||
| context.object.data.use_auto_smooth = True | context.object.data.use_auto_smooth = True | ||||
| context.object.data.auto_smooth_angle = 1.0471975 | context.object.data.auto_smooth_angle = 1.0471975 | ||||
| ▲ Show 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | if (self.alt is True) and ((self.nbcol + self.nbrow) < 3): | ||||
| e.z += random.random() | e.z += random.random() | ||||
| qe = e.to_quaternion() | qe = e.to_quaternion() | ||||
| qRot = self.qRot * qe | qRot = self.qRot * qe | ||||
| ob_new.rotation_mode = 'QUATERNION' | ob_new.rotation_mode = 'QUATERNION' | ||||
| ob_new.rotation_quaternion = qRot | ob_new.rotation_quaternion = qRot | ||||
| ob_new.rotation_mode = 'XYZ' | ob_new.rotation_mode = 'XYZ' | ||||
| if (ob_new.draw_type == "WIRE") and (self.BrushSolidify is False): | if (ob_new.display_type == "WIRE") and (self.BrushSolidify is False): | ||||
| ob_new.hide = True | ob_new.hide = True | ||||
| if self.BrushSolidify: | if self.BrushSolidify: | ||||
| ob_new.draw_type = "SOLID" | ob_new.display_type = "SOLID" | ||||
| ob_new.show_x_ray = False | ob_new.show_in_front = False | ||||
| for o in bpy.context.selected_objects: | for o in bpy.context.selected_objects: | ||||
| UndoAdd(self, "DUPLICATE", o) | UndoAdd(self, "DUPLICATE", o) | ||||
| if len(bpy.context.selected_objects) > 0: | if len(bpy.context.selected_objects) > 0: | ||||
| bpy.ops.object.select_all(action='TOGGLE') | bpy.ops.object.select_all(action='TOGGLE') | ||||
| for o in self.SavSel: | for o in self.SavSel: | ||||
| o.select = True | o.select = True | ||||
| ▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | def boolean_operation(bool_type="DIFFERENCE"): | ||||
| bpy.ops.object.modifier_apply(apply_as='DATA', modifier="CT_SOLIDIFY") | bpy.ops.object.modifier_apply(apply_as='DATA', modifier="CT_SOLIDIFY") | ||||
| BoolMod = ActiveObj.modifiers.new( | BoolMod = ActiveObj.modifiers.new( | ||||
| "CT_" + bpy.context.selected_objects[sel_index].name, | "CT_" + bpy.context.selected_objects[sel_index].name, | ||||
| "BOOLEAN" | "BOOLEAN" | ||||
| ) | ) | ||||
| BoolMod.object = bpy.context.selected_objects[sel_index] | BoolMod.object = bpy.context.selected_objects[sel_index] | ||||
| BoolMod.operation = bool_type | BoolMod.operation = bool_type | ||||
| bpy.context.selected_objects[sel_index].draw_type = 'WIRE' | bpy.context.selected_objects[sel_index].display_type = 'WIRE' | ||||
| def Rebool(context, self): | def Rebool(context, self): | ||||
| LastObj = context.active_object | LastObj = context.active_object | ||||
| Brush = context.selected_objects[0] | Brush = context.selected_objects[0] | ||||
| Brush.draw_type = "WIRE" | Brush.display_type = "WIRE" | ||||
| obj = context.selected_objects[1] | obj = context.selected_objects[1] | ||||
| bpy.ops.object.select_all(action='TOGGLE') | bpy.ops.object.select_all(action='TOGGLE') | ||||
| context.scene.objects.active = obj | context.scene.objects.active = obj | ||||
| obj.draw_type = "SOLID" | obj.display_type = "SOLID" | ||||
| obj.select = True | obj.select = True | ||||
| bpy.ops.object.duplicate_move( | bpy.ops.object.duplicate_move( | ||||
| OBJECT_OT_duplicate={ | OBJECT_OT_duplicate={ | ||||
| "linked": False, | "linked": False, | ||||
| "mode": 'TRANSLATION', | "mode": 'TRANSLATION', | ||||
| }, | }, | ||||
| TRANSFORM_OT_translate={ | TRANSFORM_OT_translate={ | ||||
| "value": (0, 0, 0), | "value": (0, 0, 0), | ||||
| Show All 24 Lines | def Rebool(context, self): | ||||
| m.operation = "DIFFERENCE" | m.operation = "DIFFERENCE" | ||||
| m.object = Brush | m.object = Brush | ||||
| for mb in LastObj.modifiers: | for mb in LastObj.modifiers: | ||||
| if mb.type == 'BEVEL': | if mb.type == 'BEVEL': | ||||
| mb.show_viewport = False | mb.show_viewport = False | ||||
| if self.ObjectBrush or self.ProfileBrush: | if self.ObjectBrush or self.ProfileBrush: | ||||
| LastObjectCreated.show_x_ray = False | LastObjectCreated.show_in_front = False | ||||
| try: | try: | ||||
| bpy.ops.object.modifier_apply(apply_as='DATA', modifier="CT_SOLIDIFY") | bpy.ops.object.modifier_apply(apply_as='DATA', modifier="CT_SOLIDIFY") | ||||
| except: | except: | ||||
| exc_type, exc_value, exc_traceback = sys.exc_info() | exc_type, exc_value, exc_traceback = sys.exc_info() | ||||
| self.report({'ERROR'}, str(exc_value)) | self.report({'ERROR'}, str(exc_value)) | ||||
| if self.DontApply is False: | if self.DontApply is False: | ||||
| try: | try: | ||||
| Show All 36 Lines | if "CT_Profil" not in bpy.data.objects: | ||||
| ob.location = Vector((0.0, 0.0, 0.0)) | ob.location = Vector((0.0, 0.0, 0.0)) | ||||
| # Link object to scene and make active | # Link object to scene and make active | ||||
| scn = bpy.context.scene | scn = bpy.context.scene | ||||
| scn.objects.link(ob) | scn.objects.link(ob) | ||||
| scn.objects.active = ob | scn.objects.active = ob | ||||
| ob.select = True | ob.select = True | ||||
| ob.location = Vector((10000.0, 0.0, 0.0)) | ob.location = Vector((10000.0, 0.0, 0.0)) | ||||
| ob.draw_type = "WIRE" | ob.display_type = "WIRE" | ||||
| self.SolidifyPossible = True | self.SolidifyPossible = True | ||||
| else: | else: | ||||
| bpy.data.objects["CT_Profil"].data = bpy.data.meshes[self.Profils[self.nProfil][0]] | bpy.data.objects["CT_Profil"].data = bpy.data.meshes[self.Profils[self.nProfil][0]] | ||||
| def Selection_Save_Restore(self): | def Selection_Save_Restore(self): | ||||
| if "CT_Profil" in bpy.data.objects: | if "CT_Profil" in bpy.data.objects: | ||||
| ▲ Show 20 Lines • Show All 196 Lines • ▼ Show 20 Lines | def modal(self, context, event): | ||||
| self.ProfileBrush = bpy.data.objects["CT_Profil"] | self.ProfileBrush = bpy.data.objects["CT_Profil"] | ||||
| Selection_Save(self) | Selection_Save(self) | ||||
| self.BrushSolidify = True | self.BrushSolidify = True | ||||
| bpy.ops.object.select_all(action='TOGGLE') | bpy.ops.object.select_all(action='TOGGLE') | ||||
| self.ProfileBrush.select = True | self.ProfileBrush.select = True | ||||
| context.scene.objects.active = self.ProfileBrush | context.scene.objects.active = self.ProfileBrush | ||||
| # Set xRay | # Set xRay | ||||
| self.ProfileBrush.show_x_ray = True | self.ProfileBrush.show_in_front = True | ||||
| bpy.ops.object.modifier_add(type='SOLIDIFY') | bpy.ops.object.modifier_add(type='SOLIDIFY') | ||||
| context.object.modifiers["Solidify"].name = "CT_SOLIDIFY" | context.object.modifiers["Solidify"].name = "CT_SOLIDIFY" | ||||
| context.object.modifiers["CT_SOLIDIFY"].thickness = 0.1 | context.object.modifiers["CT_SOLIDIFY"].thickness = 0.1 | ||||
| Selection_Restore(self) | Selection_Restore(self) | ||||
| self.CList = self.CurrentSelection | self.CList = self.CurrentSelection | ||||
| else: | else: | ||||
| if self.ObjectBrush is not None: | if self.ObjectBrush is not None: | ||||
| if self.ObjectMode is False: | if self.ObjectMode is False: | ||||
| if self.ObjectBrush is not None: | if self.ObjectBrush is not None: | ||||
| self.ObjectBrush.location = self.InitBrushPosition | self.ObjectBrush.location = self.InitBrushPosition | ||||
| self.ObjectBrush.scale = self.InitBrushScale | self.ObjectBrush.scale = self.InitBrushScale | ||||
| self.ObjectBrush.rotation_quaternion = self.InitBrushQRotation | self.ObjectBrush.rotation_quaternion = self.InitBrushQRotation | ||||
| self.ObjectBrush.rotation_euler = self.InitBrushERotation | self.ObjectBrush.rotation_euler = self.InitBrushERotation | ||||
| self.ObjectBrush.draw_type = self.ObjectBrush_DT | self.ObjectBrush.display_type = self.ObjectBrush_DT | ||||
| self.ObjectBrush.show_x_ray = self.XRay | self.ObjectBrush.show_in_front = self.XRay | ||||
| # Remove solidify modifier | # Remove solidify modifier | ||||
| Selection_Save(self) | Selection_Save(self) | ||||
| self.BrushSolidify = False | self.BrushSolidify = False | ||||
| bpy.ops.object.select_all(action='TOGGLE') | bpy.ops.object.select_all(action='TOGGLE') | ||||
| self.ObjectBrush.select = True | self.ObjectBrush.select = True | ||||
| context.scene.objects.active = self.ObjectBrush | context.scene.objects.active = self.ObjectBrush | ||||
| bpy.ops.object.modifier_remove(modifier="CT_SOLIDIFY") | bpy.ops.object.modifier_remove(modifier="CT_SOLIDIFY") | ||||
| Selection_Restore(self) | Selection_Restore(self) | ||||
| else: | else: | ||||
| if self.Solidify_Active_Start: | if self.Solidify_Active_Start: | ||||
| Selection_Save(self) | Selection_Save(self) | ||||
| self.BrushSolidify = True | self.BrushSolidify = True | ||||
| self.SolidifyPossible = True | self.SolidifyPossible = True | ||||
| bpy.ops.object.select_all(action='TOGGLE') | bpy.ops.object.select_all(action='TOGGLE') | ||||
| self.ObjectBrush.select = True | self.ObjectBrush.select = True | ||||
| context.scene.objects.active = self.ObjectBrush | context.scene.objects.active = self.ObjectBrush | ||||
| # Set xRay | # Set xRay | ||||
| self.ObjectBrush.show_x_ray = True | self.ObjectBrush.show_in_front = True | ||||
| bpy.ops.object.modifier_add(type='SOLIDIFY') | bpy.ops.object.modifier_add(type='SOLIDIFY') | ||||
| context.object.modifiers["Solidify"].name = "CT_SOLIDIFY" | context.object.modifiers["Solidify"].name = "CT_SOLIDIFY" | ||||
| context.object.modifiers["CT_SOLIDIFY"].thickness = 0.1 | context.object.modifiers["CT_SOLIDIFY"].thickness = 0.1 | ||||
| Selection_Restore(self) | Selection_Restore(self) | ||||
| # Help display | # Help display | ||||
| if event.type == context.scene.Key_Help and event.value == 'PRESS': | if event.type == context.scene.Key_Help and event.value == 'PRESS': | ||||
| self.AskHelp = not self.AskHelp | self.AskHelp = not self.AskHelp | ||||
| ▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | def modal(self, context, event): | ||||
| Selection_Save(self) | Selection_Save(self) | ||||
| self.BrushSolidify = True | self.BrushSolidify = True | ||||
| bpy.ops.object.select_all(action='TOGGLE') | bpy.ops.object.select_all(action='TOGGLE') | ||||
| if self.ObjectMode: | if self.ObjectMode: | ||||
| self.ObjectBrush.select = True | self.ObjectBrush.select = True | ||||
| context.scene.objects.active = self.ObjectBrush | context.scene.objects.active = self.ObjectBrush | ||||
| # Active le xray | # Active le xray | ||||
| self.ObjectBrush.show_x_ray = True | self.ObjectBrush.show_in_front = True | ||||
| else: | else: | ||||
| self.ProfileBrush.select = True | self.ProfileBrush.select = True | ||||
| context.scene.objects.active = self.ProfileBrush | context.scene.objects.active = self.ProfileBrush | ||||
| # Active le xray | # Active le xray | ||||
| self.ProfileBrush.show_x_ray = True | self.ProfileBrush.show_in_front = True | ||||
| bpy.ops.object.modifier_add(type='SOLIDIFY') | bpy.ops.object.modifier_add(type='SOLIDIFY') | ||||
| context.object.modifiers["Solidify"].name = "CT_SOLIDIFY" | context.object.modifiers["Solidify"].name = "CT_SOLIDIFY" | ||||
| context.object.modifiers["CT_SOLIDIFY"].thickness = 0.1 | context.object.modifiers["CT_SOLIDIFY"].thickness = 0.1 | ||||
| Selection_Restore(self) | Selection_Restore(self) | ||||
| ▲ Show 20 Lines • Show All 222 Lines • ▼ Show 20 Lines | def modal(self, context, event): | ||||
| context.scene.mesh_carver.DontApply = self.DontApply | context.scene.mesh_carver.DontApply = self.DontApply | ||||
| # if Object mode, set intiale state | # if Object mode, set intiale state | ||||
| if self.ObjectBrush is not None: | if self.ObjectBrush is not None: | ||||
| self.ObjectBrush.location = self.InitBrushPosition | self.ObjectBrush.location = self.InitBrushPosition | ||||
| self.ObjectBrush.scale = self.InitBrushScale | self.ObjectBrush.scale = self.InitBrushScale | ||||
| self.ObjectBrush.rotation_quaternion = self.InitBrushQRotation | self.ObjectBrush.rotation_quaternion = self.InitBrushQRotation | ||||
| self.ObjectBrush.rotation_euler = self.InitBrushERotation | self.ObjectBrush.rotation_euler = self.InitBrushERotation | ||||
| self.ObjectBrush.draw_type = self.ObjectBrush_DT | self.ObjectBrush.display_type = self.ObjectBrush_DT | ||||
| self.ObjectBrush.show_x_ray = self.XRay | self.ObjectBrush.show_in_front = self.XRay | ||||
| # remove solidify | # remove solidify | ||||
| Selection_Save(self) | Selection_Save(self) | ||||
| self.BrushSolidify = False | self.BrushSolidify = False | ||||
| bpy.ops.object.select_all(action='TOGGLE') | bpy.ops.object.select_all(action='TOGGLE') | ||||
| self.ObjectBrush.select = True | self.ObjectBrush.select = True | ||||
| context.scene.objects.active = self.ObjectBrush | context.scene.objects.active = self.ObjectBrush | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | def modal(self, context, event): | ||||
| context.scene.mesh_carver.DontApply = self.DontApply | context.scene.mesh_carver.DontApply = self.DontApply | ||||
| # Reset Object | # Reset Object | ||||
| if self.ObjectBrush is not None: | if self.ObjectBrush is not None: | ||||
| self.ObjectBrush.location = self.InitBrushPosition | self.ObjectBrush.location = self.InitBrushPosition | ||||
| self.ObjectBrush.scale = self.InitBrushScale | self.ObjectBrush.scale = self.InitBrushScale | ||||
| self.ObjectBrush.rotation_quaternion = self.InitBrushQRotation | self.ObjectBrush.rotation_quaternion = self.InitBrushQRotation | ||||
| self.ObjectBrush.rotation_euler = self.InitBrushERotation | self.ObjectBrush.rotation_euler = self.InitBrushERotation | ||||
| self.ObjectBrush.draw_type = self.ObjectBrush_DT | self.ObjectBrush.display_type = self.ObjectBrush_DT | ||||
| self.ObjectBrush.show_x_ray = self.XRay | self.ObjectBrush.show_in_front = self.XRay | ||||
| # Remove solidify modifier | # Remove solidify modifier | ||||
| Selection_Save(self) | Selection_Save(self) | ||||
| self.BrushSolidify = False | self.BrushSolidify = False | ||||
| bpy.ops.object.select_all(action='TOGGLE') | bpy.ops.object.select_all(action='TOGGLE') | ||||
| self.ObjectBrush.select = True | self.ObjectBrush.select = True | ||||
| context.scene.objects.active = self.ObjectBrush | context.scene.objects.active = self.ObjectBrush | ||||
| ▲ Show 20 Lines • Show All 227 Lines • ▼ Show 20 Lines | def invoke(self, context, event): | ||||
| scene.objects.link(ob) | scene.objects.link(ob) | ||||
| scene.update() | scene.update() | ||||
| # Get default variables | # Get default variables | ||||
| self.InitBrushPosition = self.ObjectBrush.location.copy() | self.InitBrushPosition = self.ObjectBrush.location.copy() | ||||
| self.InitBrushScale = self.ObjectBrush.scale.copy() | self.InitBrushScale = self.ObjectBrush.scale.copy() | ||||
| self.InitBrushQRotation = self.ObjectBrush.rotation_quaternion.copy() | self.InitBrushQRotation = self.ObjectBrush.rotation_quaternion.copy() | ||||
| self.InitBrushERotation = self.ObjectBrush.rotation_euler.copy() | self.InitBrushERotation = self.ObjectBrush.rotation_euler.copy() | ||||
| self.ObjectBrush_DT = self.ObjectBrush.draw_type | self.ObjectBrush_DT = self.ObjectBrush.display_type | ||||
| self.XRay = self.ObjectBrush.show_x_ray | self.XRay = self.ObjectBrush.show_in_front | ||||
| # Test if flat object | # Test if flat object | ||||
| z = self.ObjectBrush.data.vertices[0].co.z | z = self.ObjectBrush.data.vertices[0].co.z | ||||
| ErrorMarge = 0.01 | ErrorMarge = 0.01 | ||||
| self.Solidify_Active_Start = True | self.Solidify_Active_Start = True | ||||
| for v in self.ObjectBrush.data.vertices: | for v in self.ObjectBrush.data.vertices: | ||||
| if abs(v.co.z - z) > ErrorMarge: | if abs(v.co.z - z) > ErrorMarge: | ||||
| self.Solidify_Active_Start = False | self.Solidify_Active_Start = False | ||||
| break | break | ||||
| ▲ Show 20 Lines • Show All 256 Lines • ▼ Show 20 Lines | def Cut(self): | ||||
| # Remove cut object | # Remove cut object | ||||
| if (self.ObjectMode is False) and (self.ProfileMode is False): | if (self.ObjectMode is False) and (self.ProfileMode is False): | ||||
| if len(context.selected_objects) > 0: | if len(context.selected_objects) > 0: | ||||
| bpy.ops.object.select_all(action='TOGGLE') | bpy.ops.object.select_all(action='TOGGLE') | ||||
| bpy.data.objects[self.CurrentObj.name].select = True | bpy.data.objects[self.CurrentObj.name].select = True | ||||
| bpy.ops.object.delete(use_global=False) | bpy.ops.object.delete(use_global=False) | ||||
| else: | else: | ||||
| if self.ObjectMode: | if self.ObjectMode: | ||||
| self.ObjectBrush.draw_type = self.ObjectBrush_DT | self.ObjectBrush.display_type = self.ObjectBrush_DT | ||||
| if len(context.selected_objects) > 0: | if len(context.selected_objects) > 0: | ||||
| bpy.ops.object.select_all(action='TOGGLE') | bpy.ops.object.select_all(action='TOGGLE') | ||||
| # Select cut objects | # Select cut objects | ||||
| for obj in lastSelected: | for obj in lastSelected: | ||||
| bpy.data.objects[obj.name].select = True | bpy.data.objects[obj.name].select = True | ||||
| Show All 12 Lines | def Cut(self): | ||||
| self.ObjectBrush.select = True | self.ObjectBrush.select = True | ||||
| for ActiveObj in ActiveObjList: | for ActiveObj in ActiveObjList: | ||||
| bpy.data.objects[ActiveObj.name].select = True | bpy.data.objects[ActiveObj.name].select = True | ||||
| context.scene.objects.active = ActiveObj | context.scene.objects.active = ActiveObj | ||||
| # If object has children, set "Wire" draw type | # If object has children, set "Wire" draw type | ||||
| if self.ObjectBrush is not None: | if self.ObjectBrush is not None: | ||||
| if len(self.ObjectBrush.children) > 0: | if len(self.ObjectBrush.children) > 0: | ||||
| self.ObjectBrush.draw_type = "WIRE" | self.ObjectBrush.display_type = "WIRE" | ||||
| if self.ProfileMode: | if self.ProfileMode: | ||||
| self.ProfileBrush.draw_type = "WIRE" | self.ProfileBrush.display_type = "WIRE" | ||||
| if bLocalView: | if bLocalView: | ||||
| bpy.ops.view3d.localview() | bpy.ops.view3d.localview() | ||||
| # Reset variables | # Reset variables | ||||
| self.bDone = False | self.bDone = False | ||||
| self.mouse_path.clear() | self.mouse_path.clear() | ||||
| self.mouse_path = [(0, 0), (0, 0)] | self.mouse_path = [(0, 0), (0, 0)] | ||||
| ▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines | |||||