[Bf-extensions-cvs] [db8ee9e3] master: mesh_auto_mirror: initial port to 2.9 T62797
meta-androcto
noreply at git.blender.org
Tue Mar 26 07:37:05 CET 2019
Commit: db8ee9e3679bb7a469dc941b81185f578f3c31a6
Author: meta-androcto
Date: Tue Mar 26 17:36:27 2019 +1100
Branches: master
https://developer.blender.org/rBAdb8ee9e3679bb7a469dc941b81185f578f3c31a6
mesh_auto_mirror: initial port to 2.9 T62797
===================================================================
M mesh_auto_mirror.py
===================================================================
diff --git a/mesh_auto_mirror.py b/mesh_auto_mirror.py
index 68193c1a..022981a3 100644
--- a/mesh_auto_mirror.py
+++ b/mesh_auto_mirror.py
@@ -1,17 +1,18 @@
-# ########################################################### #
-# An simple add-on to auto cut in two and mirror an object #
-# Actually partially uncommented (see further version) #
-# Author: Lapineige #
-# License: GPL v3 #
-# ########################################################### #
+######################################################################################################
+# An simple add-on to auto cut in two and mirror an object #
+# Actualy partialy uncommented (see further version) #
+# Author: Lapineige, Bookyakuno #
+# License: GPL v3 #
+######################################################################################################
+# 2.8 update by Bookyakuno, meta-androcto
bl_info = {
"name": "Auto Mirror",
- "description": "Super fast cutting and mirroring for Mesh objects",
+ "description": "Super fast cutting and mirroring for mesh",
"author": "Lapineige",
- "version": (2, 4, 2),
- "blender": (2, 71, 0),
- "location": "View 3D > Toolbar > Tools tab > AutoMirror (panel)",
+ "version": (2, 5, 2),
+ "blender": (2, 80, 0),
+ "location": "View 3D > Sidebar > Tools Tab > AutoMirror (panel)",
"warning": "",
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/"
"Py/Scripts/Modeling/AutoMirror",
@@ -19,26 +20,38 @@ bl_info = {
import bpy
+from mathutils import Vector
+
+import bmesh
+import bpy
+import collections
+import mathutils
+import math
+from bpy_extras import view3d_utils
+from bpy.types import (
+ Operator,
+ Menu,
+ Panel,
+ AddonPreferences,
+ )
from bpy.props import (
BoolProperty,
EnumProperty,
FloatProperty,
+ IntProperty,
PointerProperty,
+ StringProperty,
)
-from bpy.types import (
- Operator,
- Panel,
- PropertyGroup,
- )
-from mathutils import Vector
-# Operators
-class AlignVertices(Operator):
+# Operator
+
+class AlignVertices(bpy.types.Operator):
+
+ """ Automatically cut an object along an axis """
+
bl_idname = "object.align_vertices"
- bl_label = "Align Vertices on an Axis"
- bl_description = ("Align Vertices on an Axis\n"
- "Needs an Active Mesh Object")
+ bl_label = "Align Vertices on 1 Axis"
@classmethod
def poll(cls, context):
@@ -46,88 +59,95 @@ class AlignVertices(Operator):
return obj and obj.type == "MESH"
def execute(self, context):
- auto_m = context.scene.auto_mirror
- bpy.ops.object.mode_set(mode='OBJECT')
+ bpy.ops.object.mode_set(mode = 'OBJECT')
- x1, y1, z1 = bpy.context.scene.cursor.location
+ x1,y1,z1 = bpy.context.scene.cursor.location
bpy.ops.view3d.snap_cursor_to_selected()
- x2, y2, z2 = bpy.context.scene.cursor.location
+ x2,y2,z2 = bpy.context.scene.cursor.location
bpy.context.scene.cursor.location[0], \
bpy.context.scene.cursor.location[1], \
- bpy.context.scene.cursor.location[2] = 0, 0, 0
+ bpy.context.scene.cursor.location[2] = 0, 0, 0
- # Vertices coordinate to 0 (local coordinate, so on the origin)
+ #Vertices coordinate to 0 (local coordinate, so on the origin)
for vert in bpy.context.object.data.vertices:
if vert.select:
- if auto_m.axis == 'x':
+ if bpy.context.scene.AutoMirror_axis == 'x':
axis = 0
- elif auto_m.axis == 'y':
+ elif bpy.context.scene.AutoMirror_axis == 'y':
axis = 1
- elif auto_m.axis == 'z':
+ elif bpy.context.scene.AutoMirror_axis == 'z':
axis = 2
vert.co[axis] = 0
+ #
+ bpy.context.scene.cursor.location = x2,y2,z2
- bpy.context.scene.cursor.location = x2, y2, z2
bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
- bpy.context.scene.cursor.location = x1, y1, z1
- bpy.ops.object.mode_set(mode='EDIT')
+ bpy.context.scene.cursor.location = x1,y1,z1
+ bpy.ops.object.mode_set(mode = 'EDIT')
return {'FINISHED'}
-class AutoMirror(Operator):
+class AutoMirror(bpy.types.Operator):
+ """ Automatically cut an object along an axis """
bl_idname = "object.automirror"
bl_label = "AutoMirror"
- bl_description = ("Automatically cut an object along an axis\n"
- "Needs an Active Mesh Object")
- bl_options = {'REGISTER'}
+ bl_options = {'REGISTER'} # 'UNDO' ?
@classmethod
def poll(cls, context):
obj = context.active_object
return obj and obj.type == "MESH"
+ def draw(self, context):
+ layout = self.layout
+ if bpy.context.object and bpy.context.object.type == 'MESH':
+ layout.prop(context.scene, "AutoMirror_axis", text="Mirror axis")
+ layout.prop(context.scene, "AutoMirror_orientation", text="Orientation")
+ layout.prop(context.scene, "AutoMirror_threshold", text="Threshold")
+ layout.prop(context.scene, "AutoMirror_toggle_edit", text="Toggle edit")
+ layout.prop(context.scene, "AutoMirror_cut", text="Cut and mirror")
+ if bpy.context.scene.AutoMirror_cut:
+ layout.prop(context.scene, "AutoMirror_clipping", text="Clipping")
+ layout.prop(context.scene, "AutoMirror_apply_mirror", text="Apply mirror")
+
+ else:
+ layout.label(icon="ERROR", text="No mesh selected")
+
def get_local_axis_vector(self, context, X, Y, Z, orientation):
loc = context.object.location
- bpy.ops.object.mode_set(mode="OBJECT") # Needed to avoid to translate vertices
-
- v1 = Vector((loc[0], loc[1], loc[2]))
- bpy.ops.transform.translate(
- value=(X * orientation, Y * orientation, Z * orientation),
- constraint_axis=((X == 1), (Y == 1), (Z == 1)),
- orient_type='LOCAL'
- )
- v2 = Vector((loc[0], loc[1], loc[2]))
- bpy.ops.transform.translate(
- value=(-X * orientation, -Y * orientation, -Z * orientation),
- constraint_axis=((X == 1), (Y == 1), (Z == 1)),
- orient_type='LOCAL'
- )
+ bpy.ops.object.mode_set(mode="OBJECT") # Needed to avoid to translate vertices
+
+ v1 = Vector((loc[0],loc[1],loc[2]))
+ bpy.ops.transform.translate(value=(X*orientation, Y*orientation, Z*orientation),
+ constraint_axis=((X==1), (Y==1), (Z==1)),
+ orient_type='LOCAL')
+ v2 = Vector((loc[0],loc[1],loc[2]))
+ bpy.ops.transform.translate(value=(-X*orientation, -Y*orientation, -Z*orientation),
+ constraint_axis=((X==1), (Y==1), (Z==1)),
+ orient_type='LOCAL')
bpy.ops.object.mode_set(mode="EDIT")
- return v2 - v1
+ return v2-v1
def execute(self, context):
- auto_m = context.scene.auto_mirror
-
- X, Y, Z = 0, 0, 0
- if auto_m.axis == 'x':
+ X,Y,Z = 0,0,0
+ if bpy.context.scene.AutoMirror_axis == 'x':
X = 1
- elif auto_m.axis == 'y':
+ elif bpy.context.scene.AutoMirror_axis == 'y':
Y = 1
- elif auto_m.axis == 'z':
+ elif bpy.context.scene.AutoMirror_axis == 'z':
Z = 1
- current_mode = bpy.context.object.mode # Save the current mode
+ current_mode = bpy.context.object.mode # Save the current mode
if bpy.context.object.mode != "EDIT":
- bpy.ops.object.mode_set(mode="EDIT") # Go to edit mode
-
- bpy.ops.mesh.select_all(action='SELECT') # Select all the vertices
- if auto_m.orientation == 'positive':
+ bpy.ops.object.mode_set(mode="EDIT") # Go to edit mode
+ bpy.ops.mesh.select_all(action='SELECT') # Select all the vertices
+ if bpy.context.scene.AutoMirror_orientation == 'positive':
orientation = 1
else:
orientation = -1
@@ -136,38 +156,32 @@ class AutoMirror(Operator):
# Cut the mesh
bpy.ops.mesh.bisect(
plane_co=(
- bpy.context.object.location[0],
- bpy.context.object.location[1],
- bpy.context.object.location[2]
- ),
+ bpy.context.object.location[0],
+ bpy.context.object.location[1],
+ bpy.context.object.location[2]
+ ),
plane_no=cut_normal,
- use_fill=False,
- clear_inner=auto_m.cut,
- clear_outer=0,
- threshold=auto_m.threshold
- )
-
- # Use to align the vertices on the origin, needed by the "threshold"
- bpy.ops.object.align_vertices()
-
- if not auto_m.toggle_edit:
- bpy.ops.object.mode_set(mode=current_mode) # Reload previous mode
-
- if auto_m.cut:
- bpy.ops.object.modifier_add(type='MIRROR') # Add a mirror modifier
- bpy.context.object.modifiers[-1].use_x = X # Choose the axis to use, based on the cut's axis
- bpy.context.object.modifiers[-1].use_y = Y
- bpy.context.object.modifiers[-1].use_z = Z
- bpy.context.object.modifiers[-1].use_clip = auto_m.use_clip
- bpy.context.object.modifiers[-1].show_on_cage = auto_m.show_on_cage
-
- if auto_m.apply_mirror:
+ use_fill= False,
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list