Sun Position: Fix crash when Blender was started in background
[blender-addons.git] / add_mesh_extra_objects / add_mesh_vertex.py
blobf71db26369020570319b3a7cc0ce1b848a3a80c9
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Originals by meta-androcto, Pablo Vazquez, Liero, Richard Wilks
5 import bpy
6 from bpy.types import Operator
9 def object_origin(width, height, depth):
10 """
11 This function takes inputs and returns vertex and face arrays.
12 no actual mesh data creation is done here.
13 """
14 verts = [(+0.0, +0.0, +0.0)]
15 faces = []
17 # apply size
18 for i, v in enumerate(verts):
19 verts[i] = v[0] * width, v[1] * depth, v[2] * height
21 return verts, faces
24 class AddVert(Operator):
25 bl_idname = "mesh.primitive_vert_add"
26 bl_label = "Single Vert"
27 bl_description = "Add a Single Vertice to Edit Mode"
28 bl_options = {'REGISTER', 'UNDO'}
30 def execute(self, context):
31 mesh = bpy.data.meshes.new("Vert")
32 mesh.vertices.add(1)
34 from bpy_extras import object_utils
35 object_utils.object_data_add(context, mesh, operator=None)
36 bpy.ops.object.mode_set(mode='EDIT')
38 return {'FINISHED'}
41 class AddEmptyVert(Operator):
42 bl_idname = "mesh.primitive_emptyvert_add"
43 bl_label = "Empty Object Origin"
44 bl_description = "Add an Object Origin to Edit Mode"
45 bl_options = {'REGISTER', 'UNDO'}
47 def execute(self, context):
48 mesh = bpy.data.meshes.new("Vert")
49 mesh.vertices.add(1)
51 from bpy_extras import object_utils
52 object_utils.object_data_add(context, mesh, operator=None)
53 bpy.ops.object.mode_set(mode='EDIT')
54 bpy.ops.mesh.delete(type='VERT')
56 return {'FINISHED'}
59 def Add_Symmetrical_Empty():
61 bpy.ops.mesh.primitive_plane_add(enter_editmode=True)
63 sempty = bpy.context.object
64 sempty.name = "SymmEmpty"
66 # check if we have a mirror modifier, otherwise add
67 if not any(mod.type == 'MIRROR' for mod in sempty.modifiers):
68 bpy.ops.object.modifier_add(type='MIRROR')
70 # Delete all!
71 bpy.ops.mesh.select_all(action='TOGGLE')
72 bpy.ops.mesh.select_all(action='TOGGLE')
73 bpy.ops.mesh.delete(type='VERT')
76 def Add_Symmetrical_Vert():
78 bpy.ops.mesh.primitive_plane_add(enter_editmode=True)
80 sempty = bpy.context.object
81 sempty.name = "SymmVert"
83 # check if we have a mirror modifier, otherwise add
84 if not any(mod.type == 'MIRROR' for mod in sempty.modifiers):
85 bpy.ops.object.modifier_add(type='MIRROR')
87 # Delete all!
88 bpy.ops.mesh.select_all(action='TOGGLE')
89 bpy.ops.mesh.select_all(action='TOGGLE')
90 bpy.ops.mesh.merge(type='CENTER')
93 class AddSymmetricalEmpty(Operator):
94 bl_idname = "mesh.primitive_symmetrical_empty_add"
95 bl_label = "Add Symmetrical Object Origin"
96 bl_description = "Object Origin with a Mirror Modifier for symmetrical modeling"
97 bl_options = {'REGISTER', 'UNDO'}
99 def draw(self, context):
100 layout = self.layout
101 mirror = next(mod for mod in bpy.context.object.modifiers
102 if mod.type == 'MIRROR')
104 layout.prop(mirror, "use_clip", text="Use Clipping")
106 layout.label(text="Mirror Axis")
107 row = layout.row(align=True)
108 row.prop(mirror, "use_axis")
109 row.prop(mirror, "use_axis")
110 row.prop(mirror, "use_axis")
112 def execute(self, context):
113 Add_Symmetrical_Empty()
115 return {'FINISHED'}
118 class AddSymmetricalVert(Operator):
119 bl_idname = "mesh.primitive_symmetrical_vert_add"
120 bl_label = "Add Symmetrical Origin & Vert"
121 bl_description = "Object Origin with a Mirror Modifier for symmetrical modeling"
122 bl_options = {'REGISTER', 'UNDO'}
124 def draw(self, context):
125 layout = self.layout
126 mirror = next(mod for mod in bpy.context.object.modifiers
127 if mod.type == 'MIRROR')
129 layout.prop(mirror, "use_clip", text="Use Clipping")
131 layout.label(text="Mirror Axis")
132 row = layout.row(align=True)
133 row.prop(mirror, "use_axis")
134 row.prop(mirror, "use_axis")
135 row.prop(mirror, "use_axis")
137 def execute(self, context):
138 Add_Symmetrical_Vert()
140 return {'FINISHED'}