diff --git a/add_mesh_extra_objects/Wallfactory.py b/add_mesh_extra_objects/Wallfactory.py index 6d74725e91877a2faf9335f1fa91c5734fd6527e..865f9150432678abf6904f9f842bc732683afdb9 100644 --- a/add_mesh_extra_objects/Wallfactory.py +++ b/add_mesh_extra_objects/Wallfactory.py @@ -55,8 +55,9 @@ from .Blocks import ( stepBack, ) from bpy_extras import object_utils +from . import utils -class add_mesh_wallb(Operator): +class add_mesh_wallb(Operator, object_utils.AddObjectHelper): bl_idname = "mesh.wall_add" bl_label = "Add a Masonry Wall" bl_description = "Create a block (masonry) wall mesh" @@ -639,6 +640,13 @@ class add_mesh_wallb(Operator): row.prop(self, "StepOnly", toggle=True) col.prop(self, "StepBack", toggle=True) + if self.change == False: + # generic transform props + box = layout.box() + box.prop(self, 'align') + box.prop(self, 'location') + box.prop(self, 'rotation') + # Respond to UI - get the properties set by user. # Check and process UI settings to generate masonry @@ -889,6 +897,8 @@ class add_mesh_wallb(Operator): mesh = bpy.data.meshes.new("Wall") mesh.from_pydata(verts_array, [], faces_array) obj = object_utils.object_data_add(context, mesh, operator=None) + + utils.setlocation(self, context) mesh.update() @@ -910,6 +920,8 @@ class add_mesh_wallb(Operator): context.active_object.name = name_active_object bpy.ops.object.mode_set(mode='EDIT') + utils.setlocation(self, context) + return {'FINISHED'} def WallParameters(): diff --git a/add_mesh_extra_objects/__init__.py b/add_mesh_extra_objects/__init__.py index ff1d3037e92912dad65f8f78647b7c69b1c706ca..d009f0a500db48f1ffaa4819f1a77ab8738aa767 100644 --- a/add_mesh_extra_objects/__init__.py +++ b/add_mesh_extra_objects/__init__.py @@ -26,7 +26,7 @@ bl_info = { "name": "Extra Objects", "author": "Multiple Authors", - "version": (0, 3, 5), + "version": (0, 3, 6), "blender": (2, 80, 0), "location": "View3D > Add > Mesh", "description": "Add extra mesh object types", diff --git a/add_mesh_extra_objects/add_mesh_beam_builder.py b/add_mesh_extra_objects/add_mesh_beam_builder.py index 3f62437f1dc138e2e98c72ba012c98970a3594e4..4650e37ab7f3f021d5327c2dd00f762c00ecfb79 100644 --- a/add_mesh_extra_objects/add_mesh_beam_builder.py +++ b/add_mesh_extra_objects/add_mesh_beam_builder.py @@ -13,6 +13,7 @@ from bpy.props import ( StringProperty, ) from bpy_extras import object_utils +from . import utils # ##################### # Create vertices for end of mesh @@ -675,7 +676,7 @@ def addBeamMesh(sRef, context): # # UI functions and object creation. -class addBeam(Operator): +class addBeam(Operator, object_utils.AddObjectHelper): bl_idname = "mesh.add_beam" bl_label = "Beam Builder" bl_description = "Create beam meshes of various profiles" @@ -757,6 +758,13 @@ class addBeam(Operator): if self.Type != '0': box.prop(self, "edgeA") + if self.change == False: + # generic transform props + box = layout.box() + box.prop(self, 'align') + box.prop(self, 'location') + box.prop(self, 'rotation') + def execute(self, context): if bpy.context.mode == "OBJECT": @@ -775,6 +783,8 @@ class addBeam(Operator): mesh = addBeamMesh(self, context) obj = object_utils.object_data_add(context, mesh, operator=None) + utils.setlocation(self, context) + if self.Type == '2': # Rotate C shape bpy.ops.transform.rotate(value=1.570796, constraint_axis=[False, True, False]) bpy.ops.object.transform_apply(location=False, rotation=True, scale=False) @@ -806,10 +816,13 @@ class addBeam(Operator): context.active_object.name = name_active_object bpy.ops.object.mode_set(mode='EDIT') + utils.setlocation(self, context) + return {'FINISHED'} def BeamParameters(): BeamParameters = [ + "Type", "beamZ", "beamX", "beamY", diff --git a/add_mesh_extra_objects/add_mesh_gears.py b/add_mesh_extra_objects/add_mesh_gears.py index 2bfaf8dc28240c20a3550d098c58fdfd276e0ef0..a5fabe4b95b88b2bb688f263be9b0e0dec5a8fca 100644 --- a/add_mesh_extra_objects/add_mesh_gears.py +++ b/add_mesh_extra_objects/add_mesh_gears.py @@ -19,6 +19,7 @@ from mathutils import ( Matrix, ) from bpy_extras import object_utils +from . import utils # A very simple "bridge" tool. # Connects two equally long vertex rows with faces. @@ -562,14 +563,11 @@ def AddGearMesh(self, context): return mesh, verts_tip, verts_valley -class AddGear(Operator): +class AddGear(Operator, object_utils.AddObjectHelper): bl_idname = "mesh.primitive_gear" bl_label = "Add Gear" bl_description = "Construct a gear mesh" bl_options = {'REGISTER', 'UNDO', 'PRESET'} - - # align_matrix for the invoke - align_matrix : Matrix() Gear : BoolProperty(name = "Gear", default = True, @@ -674,6 +672,17 @@ class AddGear(Operator): box.prop(self, 'conangle') box.prop(self, 'crown') + if self.change == False: + # generic transform props + box = layout.box() + box.prop(self, 'align') + box.prop(self, 'location') + box.prop(self, 'rotation') + + @classmethod + def poll(cls, context): + return context.scene is not None + def execute(self, context): if bpy.context.mode == "OBJECT": @@ -697,7 +706,9 @@ class AddGear(Operator): else: mesh, verts_tip, verts_valley = AddGearMesh(self, context) obj = object_utils.object_data_add(context, mesh, operator=None) - + + utils.setlocation(self, context) + # Create vertex groups from stored vertices. tipGroup = obj.vertex_groups.new(name='Tips') tipGroup.add(verts_tip, 1.0, 'ADD') @@ -729,6 +740,14 @@ class AddGear(Operator): bpy.ops.object.join() context.active_object.name = name_active_object bpy.ops.object.mode_set(mode='EDIT') + + utils.setlocation(self, context) + + return {'FINISHED'} + + def invoke(self, context, event): + self.execute(context) + return {'FINISHED'} def GearParameters(): @@ -766,7 +785,7 @@ def AddWormGearMesh(self, context): return mesh, verts_tip, verts_valley -class AddWormGear(Operator): +class AddWormGear(Operator, object_utils.AddObjectHelper): bl_idname = "mesh.primitive_worm_gear" bl_label = "Add Worm Gear" bl_description = "Construct a worm gear mesh" @@ -872,6 +891,13 @@ class AddWormGear(Operator): box.prop(self, "skew") box.prop(self, "crown") + if self.change == False: + # generic transform props + box = layout.box() + box.prop(self, 'align') + box.prop(self, 'location') + box.prop(self, 'rotation') + def execute(self, context): if bpy.context.mode == "OBJECT": @@ -896,7 +922,9 @@ class AddWormGear(Operator): else: mesh, verts_tip, verts_valley = AddWormGearMesh(self, context) obj = object_utils.object_data_add(context, mesh, operator=None) - + + utils.setlocation(self, context) + # Create vertex groups from stored vertices. tipGroup = obj.vertex_groups.new(name = 'Tips') tipGroup.add(verts_tip, 1.0, 'ADD') @@ -929,6 +957,8 @@ class AddWormGear(Operator): context.active_object.name = name_active_object bpy.ops.object.mode_set(mode='EDIT') + utils.setlocation(self, context) + return {'FINISHED'} def WormGearParameters(): diff --git a/add_mesh_extra_objects/add_mesh_gemstones.py b/add_mesh_extra_objects/add_mesh_gemstones.py index 19e517b93385321fac235a803751396cd9e89910..68a7a3f25bbcaf6e596ac6b5131f925d961787da 100644 --- a/add_mesh_extra_objects/add_mesh_gemstones.py +++ b/add_mesh_extra_objects/add_mesh_gemstones.py @@ -13,7 +13,8 @@ from bpy.props import ( BoolProperty, StringProperty, ) - +from bpy_extras import object_utils +from . import utils # Create a new mesh (object) from verts/edges/faces. # verts/edges/faces ... List of vertices/edges/faces for the @@ -207,7 +208,7 @@ def add_diamond(segments, girdle_radius, table_radius, return verts, faces -class AddDiamond(Operator): +class AddDiamond(Operator, object_utils.AddObjectHelper): bl_idname = "mesh.primitive_diamond_add" bl_label = "Add Diamond" bl_description = "Construct a diamond mesh" @@ -270,6 +271,13 @@ class AddDiamond(Operator): box.prop(self, "crown_height") box.prop(self, "pavilion_height") + if self.change == False: + # generic transform props + box = layout.box() + box.prop(self, 'align') + box.prop(self, 'location') + box.prop(self, 'rotation') + def execute(self, context): if bpy.context.mode == "OBJECT": @@ -302,7 +310,9 @@ class AddDiamond(Operator): self.pavilion_height) obj = create_mesh_object(context, verts, [], faces, "Diamond") - + + utils.setlocation(self, context) + obj.data["Diamond"] = True obj.data["change"] = False for prm in DiamondParameters(): @@ -326,6 +336,8 @@ class AddDiamond(Operator): context.active_object.name = name_active_object bpy.ops.object.mode_set(mode='EDIT') + utils.setlocation(self, context) + return {'FINISHED'} def DiamondParameters(): @@ -339,7 +351,7 @@ def DiamondParameters(): return DiamondParameters -class AddGem(Operator): +class AddGem(Operator, object_utils.AddObjectHelper): bl_idname = "mesh.primitive_gem_add" bl_label = "Add Gem" bl_description = "Construct an offset faceted gem mesh" @@ -401,6 +413,13 @@ class AddGem(Operator): box.prop(self, "crown_radius") box.prop(self, "crown_height") box.prop(self, "pavilion_height") + + if self.change == False: + # generic transform props + box = layout.box() + box.prop(self, 'align') + box.prop(self, 'location') + box.prop(self, 'rotation') def execute(self, context): @@ -433,7 +452,9 @@ class AddGem(Operator): self.crown_height) obj = create_mesh_object(context, verts, [], faces, "Gem") - + + utils.setlocation(self, context) + obj.data["Gem"] = True obj.data["change"] = False for prm in GemParameters(): @@ -458,6 +479,8 @@ class AddGem(Operator): context.active_object.name = name_active_object bpy.ops.object.mode_set(mode='EDIT') + utils.setlocation(self, context) + return {'FINISHED'} def GemParameters(): diff --git a/add_mesh_extra_objects/add_mesh_pipe_joint.py b/add_mesh_extra_objects/add_mesh_pipe_joint.py index 99cee55e51c830121e90c94282868c50d00af192..36c3be02639daa549cb7839cf502b5628ce05de7 100644 --- a/add_mesh_extra_objects/add_mesh_pipe_joint.py +++ b/add_mesh_extra_objects/add_mesh_pipe_joint.py @@ -10,6 +10,7 @@ from bpy.props import ( StringProperty, ) from bpy_extras import object_utils +from . import utils # Create a new mesh (object) from verts/edges/faces. # verts/edges/faces ... List of vertices/edges/faces for the @@ -97,7 +98,7 @@ def ElbowJointParameters(): ] return ElbowJointParameters -class AddElbowJoint(Operator): +class AddElbowJoint(Operator, object_utils.AddObjectHelper): bl_idname = "mesh.primitive_elbow_joint_add" bl_label = "Add Pipe Elbow" bl_description = "Construct an elbow pipe mesh" @@ -161,6 +162,13 @@ class AddElbowJoint(Operator): box.prop(self, 'startLength') box.prop(self, 'endLength') + if self.change == False: + # generic transform props + box = layout.box() + box.prop(self, 'align') + box.prop(self, 'location') + box.prop(self, 'rotation') + def execute(self, context): radius = self.radius div = self.div @@ -233,6 +241,8 @@ class AddElbowJoint(Operator): mesh = create_mesh(context, verts, [], faces, "Elbow Joint") obj = object_utils.object_data_add(context, mesh, operator=None) + utils.setlocation(self, context) + mesh.update() obj.data["ElbowJoint"] = True @@ -252,6 +262,8 @@ class AddElbowJoint(Operator): context.active_object.name = name_active_object bpy.ops.object.mode_set(mode='EDIT') + utils.setlocation(self, context) + return {'FINISHED'} @@ -268,7 +280,7 @@ def TeeJointParameters(): ] return TeeJointParameters -class AddTeeJoint(Operator): +class AddTeeJoint(Operator, object_utils.AddObjectHelper): bl_idname = "mesh.primitive_tee_joint_add" bl_label = "Add Pipe Tee-Joint" bl_description = "Construct a tee-joint pipe mesh" @@ -345,6 +357,13 @@ class AddTeeJoint(Operator): box.prop(self, 'endLength') box.prop(self, 'branchLength') + if self.change == False: + # generic transform props + box = layout.box() + box.prop(self, 'align') + box.prop(self, 'location') + box.prop(self, 'rotation') + def execute(self, context): radius = self.radius div = self.div @@ -481,6 +500,8 @@ class AddTeeJoint(Operator): mesh = create_mesh(context, verts, [], faces, "Tee Joint") obj = object_utils.object_data_add(context, mesh, operator=None) + utils.setlocation(self, context) + mesh.update() obj.data["TeeJoint"] = True @@ -500,6 +521,8 @@ class AddTeeJoint(Operator): context.active_object.name = name_active_object bpy.ops.object.mode_set(mode='EDIT') + utils.setlocation(self, context) + return {'FINISHED'} def WyeJointParameters(): @@ -514,7 +537,7 @@ def WyeJointParameters(): ] return WyeJointParameters -class AddWyeJoint(Operator): +class AddWyeJoint(Operator, object_utils.AddObjectHelper): bl_idname = "mesh.primitive_wye_joint_add" bl_label = "Add Pipe Wye-Joint" bl_description = "Construct a wye-joint pipe mesh" @@ -600,6 +623,13 @@ class AddWyeJoint(Operator): box.prop(self, 'branch1Length') box.prop(self, 'branch2Length') + if self.change == False: + # generic transform props + box = layout.box() + box.prop(self, 'align') + box.prop(self, 'location') + box.prop(self, 'rotation') + def execute(self, context): radius = self.radius div = self.div @@ -746,6 +776,8 @@ class AddWyeJoint(Operator): mesh = create_mesh(context, verts, [], faces, "Wye Joint") obj = object_utils.object_data_add(context, mesh, operator=None) + utils.setlocation(self, context) + mesh.update() obj.data["WyeJoint"] = True @@ -765,6 +797,8 @@ class AddWyeJoint(Operator): context.active_object.name = name_active_object bpy.ops.object.mode_set(mode='EDIT') + utils.setlocation(self, context) + return {'FINISHED'} @@ -783,7 +817,7 @@ def CrossJointParameters(): ] return CrossJointParameters -class AddCrossJoint(Operator): +class AddCrossJoint(Operator, object_utils.AddObjectHelper): bl_idname = "mesh.primitive_cross_joint_add" bl_label = "Add Pipe Cross-Joint" bl_description = "Construct a cross-joint pipe mesh" @@ -882,6 +916,13 @@ class AddCrossJoint(Operator): box.prop(self, 'branch2Length') box.prop(self, 'branch3Length') + if self.change == False: + # generic transform props + box = layout.box() + box.prop(self, 'align') + box.prop(self, 'location') + box.prop(self, 'rotation') + def execute(self, context): radius = self.radius div = self.div @@ -1075,6 +1116,8 @@ class AddCrossJoint(Operator): mesh = create_mesh(context, verts, [], faces, "Cross Joint") obj = object_utils.object_data_add(context, mesh, operator=None) + utils.setlocation(self, context) + mesh.update() obj.data["CrossJoint"] = True @@ -1094,6 +1137,8 @@ class AddCrossJoint(Operator): context.active_object.name = name_active_object bpy.ops.object.mode_set(mode='EDIT') + utils.setlocation(self, context) + return {'FINISHED'} @@ -1107,7 +1152,7 @@ def NJointParameters(): ] return NJointParameters -class AddNJoint(Operator): +class AddNJoint(Operator, object_utils.AddObjectHelper): bl_idname = "mesh.primitive_n_joint_add" bl_label = "Add Pipe N-Joint" bl_description = "Construct a n-joint pipe mesh" @@ -1162,6 +1207,13 @@ class AddNJoint(Operator): box.prop(self, 'number') box.prop(self, 'length') + if self.change == False: + # generic transform props + box = layout.box() + box.prop(self, 'align') + box.prop(self, 'location') + box.prop(self, 'rotation') + def execute(self, context): radius = self.radius div = self.div @@ -1301,6 +1353,8 @@ class AddNJoint(Operator): mesh = create_mesh(context, verts, [], faces, "N Joint") obj = object_utils.object_data_add(context, mesh, operator=None) + utils.setlocation(self, context) + obj.data["NJoint"] = True obj.data["change"] = False for prm in NJointParameters(): @@ -1317,6 +1371,7 @@ class AddNJoint(Operator): bpy.ops.object.join() context.active_object.name = name_active_object bpy.ops.object.mode_set(mode='EDIT') - + + utils.setlocation(self, context) return {'FINISHED'} diff --git a/add_mesh_extra_objects/add_mesh_round_brilliant.py b/add_mesh_extra_objects/add_mesh_round_brilliant.py index f68429ee0a3ee05041d18046130f438c74686b19..cb5e5736c2ac1f471c6758ecf211b82f833625db 100644 --- a/add_mesh_extra_objects/add_mesh_round_brilliant.py +++ b/add_mesh_extra_objects/add_mesh_round_brilliant.py @@ -17,6 +17,7 @@ from bpy.props import ( StringProperty, ) from bpy_extras import object_utils +from . import utils # mesh generating function, returns mesh def add_mesh_Brilliant(context, s, table_w, crown_h, girdle_t, pavi_d, bezel_f, @@ -304,7 +305,7 @@ def addBrilliant(context, s, table_w, crown_h, girdle_t, pavi_d, bezel_f, # add new operator for object -class MESH_OT_primitive_brilliant_add(Operator): +class MESH_OT_primitive_brilliant_add(Operator, object_utils.AddObjectHelper): bl_idname = "mesh.primitive_brilliant_add" bl_label = "Custom Brilliant" bl_description = "Construct a custom brilliant mesh" @@ -418,6 +419,13 @@ class MESH_OT_primitive_brilliant_add(Operator): box.prop(self, "culet") box.prop(self, "keep_lga") + if self.change == False: + # generic transform props + box = layout.box() + box.prop(self, 'align') + box.prop(self, 'location') + box.prop(self, 'rotation') + # call mesh/object generator function with user inputs def execute(self, context): @@ -443,6 +451,8 @@ class MESH_OT_primitive_brilliant_add(Operator): self.pavi_f, self.culet, self.girdle_real, self.keep_lga, self.g_real_smooth ) + utils.setlocation(self, context) + obj.data["Brilliant"] = True obj.data["change"] = False for prm in BrilliantParameters(): @@ -463,6 +473,8 @@ class MESH_OT_primitive_brilliant_add(Operator): context.active_object.name = name_active_object bpy.ops.object.mode_set(mode='EDIT') + utils.setlocation(self, context) + return {'FINISHED'} def BrilliantParameters(): diff --git a/add_mesh_extra_objects/utils.py b/add_mesh_extra_objects/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..f9b6675e8ac6e819e8e6b16fd8aa6654e600172f --- /dev/null +++ b/add_mesh_extra_objects/utils.py @@ -0,0 +1,45 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# The Blender Rock Creation tool is for rapid generation of mesh rocks. +# Copyright (C) 2011 Paul Marshall +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# ##### END GPL LICENSE BLOCK ##### + +import bpy + +def setlocation(oper, context): + if oper.align == "WORLD": + location = oper.location - context.active_object.location + bpy.ops.transform.translate(value = location, orient_type='GLOBAL') + bpy.ops.transform.rotate(value = oper.rotation[0], orient_axis = 'X', orient_type='GLOBAL') + bpy.ops.transform.rotate(value = oper.rotation[1], orient_axis = 'Y', orient_type='GLOBAL') + bpy.ops.transform.rotate(value = oper.rotation[2], orient_axis = 'Z', orient_type='GLOBAL') + + elif oper.align == "VIEW": + bpy.ops.transform.translate(value = oper.location) + bpy.ops.transform.rotate(value = oper.rotation[0], orient_axis = 'X') + bpy.ops.transform.rotate(value = oper.rotation[1], orient_axis = 'Y') + bpy.ops.transform.rotate(value = oper.rotation[2], orient_axis = 'Z') + + elif oper.align == "CURSOR": + location = context.active_object.location + oper.location = bpy.context.scene.cursor.location - location + oper.rotation = bpy.context.scene.cursor.rotation_euler + + bpy.ops.transform.translate(value = oper.location) + bpy.ops.transform.rotate(value = oper.rotation[0], orient_axis = 'X') + bpy.ops.transform.rotate(value = oper.rotation[1], orient_axis = 'Y') + bpy.ops.transform.rotate(value = oper.rotation[2], orient_axis = 'Z') \ No newline at end of file