Addon Mesh Extra Objects: Added Object Helper. Fixed World orientation.

This commit is contained in:
Vladimir Spivak 2020-01-14 00:12:10 +02:00
parent 29bbe142ea
commit 1072d96b7d
Notes: blender-bot 2023-02-14 18:43:27 +01:00
Referenced by issue #84263, Cannot get Round Cube in adding a new Mesh
15 changed files with 706 additions and 271 deletions

View File

@ -55,7 +55,6 @@ from .Blocks import (
stepBack,
)
from bpy_extras import object_utils
from . import utils
class add_mesh_wallb(Operator, object_utils.AddObjectHelper):
bl_idname = "mesh.wall_add"
@ -643,9 +642,9 @@ class add_mesh_wallb(Operator, object_utils.AddObjectHelper):
if self.change == False:
# generic transform props
box = layout.box()
box.prop(self, 'align')
box.prop(self, 'location')
box.prop(self, 'rotation')
box.prop(self, 'align', expand=True)
box.prop(self, 'location', expand=True)
box.prop(self, 'rotation', expand=True)
# Respond to UI - get the properties set by user.
# Check and process UI settings to generate masonry
@ -896,9 +895,7 @@ class add_mesh_wallb(Operator, object_utils.AddObjectHelper):
else:
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)
obj = object_utils.object_data_add(context, mesh, operator=self)
mesh.update()
@ -913,15 +910,13 @@ class add_mesh_wallb(Operator, object_utils.AddObjectHelper):
bpy.ops.object.mode_set(mode='OBJECT')
mesh = bpy.data.meshes.new("TMP")
mesh.from_pydata(verts_array, [], faces_array)
obj = object_utils.object_data_add(context, mesh, operator=None)
obj = object_utils.object_data_add(context, mesh, operator=self)
obj.select_set(True)
active_object.select_set(True)
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 WallParameters():

View File

@ -170,8 +170,11 @@ class VIEW3D_MT_mesh_extras_add(Menu):
oper.change = False
layout.separator()
oper = layout.operator("mesh.primitive_star_add", text="Simple Star")
oper.change = False
oper = layout.operator("mesh.primitive_steppyramid_add", text="Step Pyramid")
oper.change = False
oper = layout.operator("mesh.honeycomb_add", text="Honeycomb")
oper.change = False
oper = layout.operator("mesh.primitive_teapot_add", text="Teapot+")
oper = layout.operator("mesh.menger_sponge_add", text="Menger Sponge")
@ -184,9 +187,12 @@ class VIEW3D_MT_mesh_torus_add(Menu):
def draw(self, context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator("mesh.primitive_twisted_torus_add", text="Twisted Torus")
layout.operator("mesh.primitive_supertoroid_add", text="Supertoroid")
layout.operator("mesh.primitive_torusknot_add", text="Torus Knot")
oper = layout.operator("mesh.primitive_twisted_torus_add", text="Twisted Torus")
oper.change = False
oper = layout.operator("mesh.primitive_supertoroid_add", text="Supertoroid")
oper.change = False
oper = layout.operator("mesh.primitive_torusknot_add", text="Torus Knot")
oper.change = False
class VIEW3D_MT_mesh_pipe_joints_add(Menu):
@ -197,11 +203,16 @@ class VIEW3D_MT_mesh_pipe_joints_add(Menu):
def draw(self, context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator("mesh.primitive_elbow_joint_add", text="Pipe Elbow")
layout.operator("mesh.primitive_tee_joint_add", text="Pipe T-Joint")
layout.operator("mesh.primitive_wye_joint_add", text="Pipe Y-Joint")
layout.operator("mesh.primitive_cross_joint_add", text="Pipe Cross-Joint")
layout.operator("mesh.primitive_n_joint_add", text="Pipe N-Joint")
oper = layout.operator("mesh.primitive_elbow_joint_add", text="Pipe Elbow")
oper.change = False
oper = layout.operator("mesh.primitive_tee_joint_add", text="Pipe T-Joint")
oper.change = False
oper = layout.operator("mesh.primitive_wye_joint_add", text="Pipe Y-Joint")
oper.change = False
oper = layout.operator("mesh.primitive_cross_joint_add", text="Pipe Cross-Joint")
oper.change = False
oper = layout.operator("mesh.primitive_n_joint_add", text="Pipe N-Joint")
oper.change = False
# Register all operators and panels
@ -213,8 +224,9 @@ def menu_func(self, context):
layout.separator()
layout.menu("VIEW3D_MT_mesh_vert_add",
text="Single Vert", icon="DECORATE")
layout.operator("mesh.primitive_round_cube_add",
oper = layout.operator("mesh.primitive_round_cube_add",
text="Round Cube", icon="SPHERE")
oper.change = False
layout.menu("VIEW3D_MT_mesh_torus_add",
text="Torus Objects", icon="MESH_TORUS")
layout.separator()
@ -321,6 +333,55 @@ def Extras_contex_menu(self, context):
for prm in add_mesh_round_brilliant.BrilliantParameters():
setattr(props, prm, obj.data[prm])
layout.separator()
if 'Roundcube' in obj.data.keys():
props = layout.operator("mesh.primitive_round_cube_add", text="Change Roundcube")
props.change = True
for prm in add_mesh_round_cube.RoundCubeParameters():
setattr(props, prm, obj.data[prm])
layout.separator()
if 'TorusKnot' in obj.data.keys():
props = layout.operator("mesh.primitive_torusknot_add", text="Change TorusKnot")
props.change = True
for prm in add_mesh_torusknot.TorusKnotParameters():
setattr(props, prm, obj.data[prm])
layout.separator()
if 'SuperToroid' in obj.data.keys():
props = layout.operator("mesh.primitive_supertoroid_add", text="Change SuperToroid")
props.change = True
for prm in add_mesh_supertoroid.SuperToroidParameters():
setattr(props, prm, obj.data[prm])
layout.separator()
if 'TwistedTorus' in obj.data.keys():
props = layout.operator("mesh.primitive_twisted_torus_add", text="Change TwistedTorus")
props.change = True
for prm in add_mesh_twisted_torus.TwistedTorusParameters():
setattr(props, prm, obj.data[prm])
layout.separator()
if 'Star' in obj.data.keys():
props = layout.operator("mesh.primitive_star_add", text="Change Star")
props.change = True
for prm in add_mesh_star.StarParameters():
setattr(props, prm, obj.data[prm])
layout.separator()
if 'Pyramid' in obj.data.keys():
props = layout.operator("mesh.primitive_steppyramid_add", text="Change Pyramid")
props.change = True
for prm in add_mesh_pyramid.PyramidParameters():
setattr(props, prm, obj.data[prm])
layout.separator()
if 'HoneyComb' in obj.data.keys():
props = layout.operator("mesh.honeycomb_add", text="Change HoneyComb")
props.change = True
for prm in add_mesh_honeycomb.HoneyCombParameters():
setattr(props, prm, obj.data[prm])
layout.separator()
# Register
classes = [

View File

@ -13,7 +13,6 @@ from bpy.props import (
StringProperty,
)
from bpy_extras import object_utils
from . import utils
# #####################
# Create vertices for end of mesh
@ -685,11 +684,6 @@ class addBeam(Operator, object_utils.AddObjectHelper):
Beam : BoolProperty(name = "Beam",
default = True,
description = "Beam")
#### change properties
name : StringProperty(name = "Name",
description = "Name")
change : BoolProperty(name = "Change",
default = False,
description = "change Beam")
@ -761,9 +755,9 @@ class addBeam(Operator, object_utils.AddObjectHelper):
if self.change == False:
# generic transform props
box = layout.box()
box.prop(self, 'align')
box.prop(self, 'location')
box.prop(self, 'rotation')
box.prop(self, 'align', expand=True)
box.prop(self, 'location', expand=True)
box.prop(self, 'rotation', expand=True)
def execute(self, context):
if bpy.context.mode == "OBJECT":
@ -781,9 +775,7 @@ class addBeam(Operator, object_utils.AddObjectHelper):
obj.data.name = oldmeshname
else:
mesh = addBeamMesh(self, context)
obj = object_utils.object_data_add(context, mesh, operator=None)
utils.setlocation(self, context)
obj = object_utils.object_data_add(context, mesh, operator=self)
if self.Type == '2': # Rotate C shape
bpy.ops.transform.rotate(value=1.570796, constraint_axis=[False, True, False])
@ -809,15 +801,13 @@ class addBeam(Operator, object_utils.AddObjectHelper):
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
mesh = addBeamMesh(self, context)
obj = object_utils.object_data_add(context, mesh, operator=None)
obj = object_utils.object_data_add(context, mesh, operator=self)
obj.select_set(True)
active_object.select_set(True)
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 BeamParameters():

View File

@ -19,7 +19,6 @@ 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.
@ -675,9 +674,9 @@ class AddGear(Operator, object_utils.AddObjectHelper):
if self.change == False:
# generic transform props
box = layout.box()
box.prop(self, 'align')
box.prop(self, 'location')
box.prop(self, 'rotation')
box.prop(self, 'align', expand=True)
box.prop(self, 'location', expand=True)
box.prop(self, 'rotation', expand=True)
@classmethod
def poll(cls, context):
@ -705,9 +704,7 @@ class AddGear(Operator, object_utils.AddObjectHelper):
obj.data.name = oldmeshname
else:
mesh, verts_tip, verts_valley = AddGearMesh(self, context)
obj = object_utils.object_data_add(context, mesh, operator=None)
utils.setlocation(self, context)
obj = object_utils.object_data_add(context, mesh, operator=self)
# Create vertex groups from stored vertices.
tipGroup = obj.vertex_groups.new(name='Tips')
@ -726,7 +723,7 @@ class AddGear(Operator, object_utils.AddObjectHelper):
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
mesh, verts_tip, verts_valley = AddGearMesh(self, context)
obj = object_utils.object_data_add(context, mesh, operator=None)
obj = object_utils.object_data_add(context, mesh, operator=self)
# Create vertex groups from stored vertices.
tipGroup = obj.vertex_groups.new(name='Tips')
@ -741,8 +738,6 @@ class AddGear(Operator, object_utils.AddObjectHelper):
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):
@ -894,9 +889,9 @@ class AddWormGear(Operator, object_utils.AddObjectHelper):
if self.change == False:
# generic transform props
box = layout.box()
box.prop(self, 'align')
box.prop(self, 'location')
box.prop(self, 'rotation')
box.prop(self, 'align', expand=True)
box.prop(self, 'location', expand=True)
box.prop(self, 'rotation', expand=True)
def execute(self, context):
@ -921,9 +916,7 @@ class AddWormGear(Operator, object_utils.AddObjectHelper):
obj.data.name = oldmeshname
else:
mesh, verts_tip, verts_valley = AddWormGearMesh(self, context)
obj = object_utils.object_data_add(context, mesh, operator=None)
utils.setlocation(self, context)
obj = object_utils.object_data_add(context, mesh, operator=self)
# Create vertex groups from stored vertices.
tipGroup = obj.vertex_groups.new(name = 'Tips')
@ -942,7 +935,7 @@ class AddWormGear(Operator, object_utils.AddObjectHelper):
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
mesh, verts_tip, verts_valley = AddWormGearMesh(self, context)
obj = object_utils.object_data_add(context, mesh, operator=None)
obj = object_utils.object_data_add(context, mesh, operator=self)
# Create vertex groups from stored vertices.
tipGroup = obj.vertex_groups.new(name = 'Tips')
@ -957,8 +950,6 @@ class AddWormGear(Operator, object_utils.AddObjectHelper):
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
utils.setlocation(self, context)
return {'FINISHED'}
def WormGearParameters():

View File

@ -14,14 +14,13 @@ 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
# new mesh (as used in from_pydata)
# name ... Name of the new mesh (& object)
def create_mesh_object(context, verts, edges, faces, name):
def create_mesh_object(context, self, verts, edges, faces, name):
# Create new mesh
mesh = bpy.data.meshes.new(name)
@ -33,7 +32,7 @@ def create_mesh_object(context, verts, edges, faces, name):
mesh.update()
from bpy_extras import object_utils
return object_utils.object_data_add(context, mesh, operator=None)
return object_utils.object_data_add(context, mesh, operator=self)
# A very simple "bridge" tool.
@ -274,9 +273,9 @@ class AddDiamond(Operator, object_utils.AddObjectHelper):
if self.change == False:
# generic transform props
box = layout.box()
box.prop(self, 'align')
box.prop(self, 'location')
box.prop(self, 'rotation')
box.prop(self, 'align', expand=True)
box.prop(self, 'location', expand=True)
box.prop(self, 'rotation', expand=True)
def execute(self, context):
@ -309,9 +308,7 @@ class AddDiamond(Operator, object_utils.AddObjectHelper):
self.crown_height,
self.pavilion_height)
obj = create_mesh_object(context, verts, [], faces, "Diamond")
utils.setlocation(self, context)
obj = create_mesh_object(context, self, verts, [], faces, "Diamond")
obj.data["Diamond"] = True
obj.data["change"] = False
@ -328,7 +325,7 @@ class AddDiamond(Operator, object_utils.AddObjectHelper):
self.crown_height,
self.pavilion_height)
obj = create_mesh_object(context, verts, [], faces, "TMP")
obj = create_mesh_object(context, self, verts, [], faces, "TMP")
obj.select_set(True)
active_object.select_set(True)
@ -336,8 +333,6 @@ class AddDiamond(Operator, object_utils.AddObjectHelper):
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
utils.setlocation(self, context)
return {'FINISHED'}
def DiamondParameters():
@ -417,9 +412,9 @@ class AddGem(Operator, object_utils.AddObjectHelper):
if self.change == False:
# generic transform props
box = layout.box()
box.prop(self, 'align')
box.prop(self, 'location')
box.prop(self, 'rotation')
box.prop(self, 'align', expand=True)
box.prop(self, 'location', expand=True)
box.prop(self, 'rotation', expand=True)
def execute(self, context):
@ -451,9 +446,7 @@ class AddGem(Operator, object_utils.AddObjectHelper):
self.pavilion_height,
self.crown_height)
obj = create_mesh_object(context, verts, [], faces, "Gem")
utils.setlocation(self, context)
obj = create_mesh_object(context, self, verts, [], faces, "Gem")
obj.data["Gem"] = True
obj.data["change"] = False
@ -471,7 +464,7 @@ class AddGem(Operator, object_utils.AddObjectHelper):
self.pavilion_height,
self.crown_height)
obj = create_mesh_object(context, verts, [], faces, "TMP")
obj = create_mesh_object(context, self, verts, [], faces, "TMP")
obj.select_set(True)
active_object.select_set(True)
@ -479,8 +472,6 @@ class AddGem(Operator, object_utils.AddObjectHelper):
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
utils.setlocation(self, context)
return {'FINISHED'}
def GemParameters():

View File

@ -1,10 +1,7 @@
# GPL # "author": "Kayo Phoenix"
import bpy
from bpy_extras.object_utils import (
AddObjectHelper,
object_data_add,
)
from bpy_extras import object_utils
from math import (
pi, sin,
cos,
@ -15,6 +12,7 @@ from bpy.props import (
BoolVectorProperty,
FloatProperty,
FloatVectorProperty,
StringProperty,
)
@ -210,7 +208,7 @@ def edge_max(diam):
return diam * sin(pi / 3)
class add_mesh_honeycomb(bpy.types.Operator, AddObjectHelper):
class add_mesh_honeycomb(bpy.types.Operator, object_utils.AddObjectHelper):
bl_idname = "mesh.honeycomb_add"
bl_label = "Add HoneyComb"
bl_description = "Simple honeycomb mesh generator"
@ -221,6 +219,13 @@ class add_mesh_honeycomb(bpy.types.Operator, AddObjectHelper):
if self.edge > m:
self.edge = m
HoneyComb : BoolProperty(name = "HoneyComb",
default = True,
description = "HoneyComb")
change : BoolProperty(name = "Change",
default = False,
description = "change HoneyComb")
rows: IntProperty(
name="Num of rows",
default=2,
@ -233,12 +238,6 @@ class add_mesh_honeycomb(bpy.types.Operator, AddObjectHelper):
min=1, max=100,
description='Number of the columns'
)
layers: BoolVectorProperty(
name="Layers",
size=20,
subtype='LAYER',
options={'HIDDEN', 'SKIP_SAVE'},
)
diam: FloatProperty(
name='Cell Diameter',
default=1.0,
@ -252,19 +251,76 @@ class add_mesh_honeycomb(bpy.types.Operator, AddObjectHelper):
description='Width of the edge'
)
def draw(self, context):
layout = self.layout
layout.prop(self, 'rows', expand=True)
layout.prop(self, 'cols', expand=True)
layout.prop(self, 'diam', expand=True)
layout.prop(self, 'edge', expand=True)
if self.change == False:
col = layout.column(align=True)
col.prop(self, 'align', expand=True)
col = layout.column(align=True)
col.prop(self, 'location', expand=True)
col = layout.column(align=True)
col.prop(self, 'rotation', expand=True)
@classmethod
def poll(cls, context):
return context.scene is not None
def execute(self, context):
mesh = bpy.data.meshes.new(name='honeycomb')
if bpy.context.mode == "OBJECT":
if context.selected_objects != [] and context.active_object and \
('HoneyComb' in context.active_object.data.keys()) and (self.change == True):
obj = context.active_object
oldmesh = obj.data
oldmeshname = obj.data.name
comb = honeycomb_geometry(self.rows, self.cols, self.diam, self.edge)
verts, faces = comb.generate()
mesh = bpy.data.meshes.new('HoneyComb')
mesh.from_pydata(verts, [], faces)
obj.data = mesh
for material in oldmesh.materials:
obj.data.materials.append(material)
bpy.data.meshes.remove(oldmesh)
obj.data.name = oldmeshname
else:
comb = honeycomb_geometry(self.rows, self.cols, self.diam, self.edge)
verts, faces = comb.generate()
mesh = bpy.data.meshes.new('HoneyComb')
mesh.from_pydata(verts, [], faces)
obj = object_utils.object_data_add(context, mesh, operator=self)
comb = honeycomb_geometry(self.rows, self.cols, self.diam, self.edge)
verts, faces = comb.generate()
mesh.from_pydata(vertices=verts, edges=[], faces=faces)
mesh.update()
object_data_add(context, mesh, operator=self)
obj.data["HoneyComb"] = True
obj.data["change"] = False
for prm in HoneyCombParameters():
obj.data[prm] = getattr(self, prm)
if bpy.context.mode == "EDIT_MESH":
active_object = context.active_object
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
comb = honeycomb_geometry(self.rows, self.cols, self.diam, self.edge)
verts, faces = comb.generate()
mesh = bpy.data.meshes.new('HoneyComb')
mesh.from_pydata(verts, [], faces)
object_utils.object_data_add(context, mesh, operator=self)
obj.select_set(True)
active_object.select_set(True)
bpy.ops.object.join()
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
return {'FINISHED'}
def HoneyCombParameters():
HoneyCombParameters = [
"rows",
"cols",
"diam",
"edge",
]
return HoneyCombParameters

View File

@ -10,7 +10,6 @@ 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
@ -165,9 +164,9 @@ class AddElbowJoint(Operator, object_utils.AddObjectHelper):
if self.change == False:
# generic transform props
box = layout.box()
box.prop(self, 'align')
box.prop(self, 'location')
box.prop(self, 'rotation')
box.prop(self, 'align', expand=True)
box.prop(self, 'location', expand=True)
box.prop(self, 'rotation', expand=True)
def execute(self, context):
radius = self.radius
@ -239,9 +238,7 @@ class AddElbowJoint(Operator, object_utils.AddObjectHelper):
obj.data.name = oldmeshname
else:
mesh = create_mesh(context, verts, [], faces, "Elbow Joint")
obj = object_utils.object_data_add(context, mesh, operator=None)
utils.setlocation(self, context)
obj = object_utils.object_data_add(context, mesh, operator=self)
mesh.update()
@ -255,15 +252,13 @@ class AddElbowJoint(Operator, object_utils.AddObjectHelper):
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
mesh = create_mesh(context, verts, [], faces, "TMP")
obj = object_utils.object_data_add(context, mesh, operator=None)
obj = object_utils.object_data_add(context, mesh, operator=self)
obj.select_set(True)
active_object.select_set(True)
bpy.ops.object.join()
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
utils.setlocation(self, context)
return {'FINISHED'}
@ -360,9 +355,9 @@ class AddTeeJoint(Operator, object_utils.AddObjectHelper):
if self.change == False:
# generic transform props
box = layout.box()
box.prop(self, 'align')
box.prop(self, 'location')
box.prop(self, 'rotation')
box.prop(self, 'align', expand=True)
box.prop(self, 'location', expand=True)
box.prop(self, 'rotation', expand=True)
def execute(self, context):
radius = self.radius
@ -498,9 +493,7 @@ class AddTeeJoint(Operator, object_utils.AddObjectHelper):
obj.data.name = oldmeshname
else:
mesh = create_mesh(context, verts, [], faces, "Tee Joint")
obj = object_utils.object_data_add(context, mesh, operator=None)
utils.setlocation(self, context)
obj = object_utils.object_data_add(context, mesh, operator=self)
mesh.update()
@ -514,15 +507,13 @@ class AddTeeJoint(Operator, object_utils.AddObjectHelper):
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
mesh = create_mesh(context, verts, [], faces, "TMP")
obj = object_utils.object_data_add(context, mesh, operator=None)
obj = object_utils.object_data_add(context, mesh, operator=self)
obj.select_set(True)
active_object.select_set(True)
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 WyeJointParameters():
@ -626,9 +617,9 @@ class AddWyeJoint(Operator, object_utils.AddObjectHelper):
if self.change == False:
# generic transform props
box = layout.box()
box.prop(self, 'align')
box.prop(self, 'location')
box.prop(self, 'rotation')
box.prop(self, 'align', expand=True)
box.prop(self, 'location', expand=True)
box.prop(self, 'rotation', expand=True)
def execute(self, context):
radius = self.radius
@ -774,9 +765,7 @@ class AddWyeJoint(Operator, object_utils.AddObjectHelper):
obj.data.name = oldmeshname
else:
mesh = create_mesh(context, verts, [], faces, "Wye Joint")
obj = object_utils.object_data_add(context, mesh, operator=None)
utils.setlocation(self, context)
obj = object_utils.object_data_add(context, mesh, operator=self)
mesh.update()
@ -790,15 +779,13 @@ class AddWyeJoint(Operator, object_utils.AddObjectHelper):
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
mesh = create_mesh(context, verts, [], faces, "TMP")
obj = object_utils.object_data_add(context, mesh, operator=None)
obj = object_utils.object_data_add(context, mesh, operator=self)
obj.select_set(True)
active_object.select_set(True)
bpy.ops.object.join()
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
utils.setlocation(self, context)
return {'FINISHED'}
@ -919,9 +906,9 @@ class AddCrossJoint(Operator, object_utils.AddObjectHelper):
if self.change == False:
# generic transform props
box = layout.box()
box.prop(self, 'align')
box.prop(self, 'location')
box.prop(self, 'rotation')
box.prop(self, 'align', expand=True)
box.prop(self, 'location', expand=True)
box.prop(self, 'rotation', expand=True)
def execute(self, context):
radius = self.radius
@ -1114,9 +1101,7 @@ class AddCrossJoint(Operator, object_utils.AddObjectHelper):
obj.data.name = oldmeshname
else:
mesh = create_mesh(context, verts, [], faces, "Cross Joint")
obj = object_utils.object_data_add(context, mesh, operator=None)
utils.setlocation(self, context)
obj = object_utils.object_data_add(context, mesh, operator=self)
mesh.update()
@ -1130,15 +1115,13 @@ class AddCrossJoint(Operator, object_utils.AddObjectHelper):
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
mesh = create_mesh(context, verts, [], faces, "TMP")
obj = object_utils.object_data_add(context, mesh, operator=None)
obj = object_utils.object_data_add(context, mesh, operator=self)
obj.select_set(True)
active_object.select_set(True)
bpy.ops.object.join()
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
utils.setlocation(self, context)
return {'FINISHED'}
@ -1210,9 +1193,9 @@ class AddNJoint(Operator, object_utils.AddObjectHelper):
if self.change == False:
# generic transform props
box = layout.box()
box.prop(self, 'align')
box.prop(self, 'location')
box.prop(self, 'rotation')
box.prop(self, 'align', expand=True)
box.prop(self, 'location', expand=True)
box.prop(self, 'rotation', expand=True)
def execute(self, context):
radius = self.radius
@ -1351,9 +1334,7 @@ class AddNJoint(Operator, object_utils.AddObjectHelper):
obj.data.name = oldmeshname
else:
mesh = create_mesh(context, verts, [], faces, "N Joint")
obj = object_utils.object_data_add(context, mesh, operator=None)
utils.setlocation(self, context)
obj = object_utils.object_data_add(context, mesh, operator=self)
obj.data["NJoint"] = True
obj.data["change"] = False
@ -1365,13 +1346,11 @@ class AddNJoint(Operator, object_utils.AddObjectHelper):
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
mesh = create_mesh(context, verts, [], faces, "TMP")
obj = object_utils.object_data_add(context, mesh, operator=None)
obj = object_utils.object_data_add(context, mesh, operator=self)
obj.select_set(True)
active_object.select_set(True)
bpy.ops.object.join()
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
utils.setlocation(self, context)
return {'FINISHED'}

View File

@ -2,20 +2,18 @@
import bpy
import bmesh
from bpy.types import Operator
from bpy.props import (
FloatProperty,
IntProperty,
StringProperty,
BoolProperty,
)
from math import pi
from mathutils import (
Quaternion,
Vector,
)
from bpy_extras.object_utils import (
AddObjectHelper,
object_data_add,
)
from bpy_extras import object_utils
def create_step(width, base_level, step_height, num_sides):
@ -59,7 +57,7 @@ def get_connector_pairs(lst, n_sides):
return lst
def add_pyramid_object(self, context):
def pyramid_mesh(self, context):
all_verts = []
height_offset = 0
@ -98,15 +96,23 @@ def add_pyramid_object(self, context):
bm.to_mesh(mesh)
mesh.update()
res = object_data_add(context, mesh, operator=self)
return mesh
class AddPyramid(Operator, AddObjectHelper):
class AddPyramid(bpy.types.Operator, object_utils.AddObjectHelper):
bl_idname = "mesh.primitive_steppyramid_add"
bl_label = "Pyramid"
bl_description = "Construct a step pyramid mesh"
bl_options = {'REGISTER', 'UNDO', 'PRESET'}
Pyramid : BoolProperty(name = "Pyramid",
default = True,
description = "Pyramid")
change : BoolProperty(name = "Change",
default = False,
description = "change Pyramid")
num_sides: IntProperty(
name="Number Sides",
description="How many sides each step will have",
@ -138,7 +144,65 @@ class AddPyramid(Operator, AddObjectHelper):
default=.20
)
def draw(self, context):
layout = self.layout
layout.prop(self, 'num_sides', expand=True)
layout.prop(self, 'num_steps', expand=True)
layout.prop(self, 'width', expand=True)
layout.prop(self, 'height', expand=True)
layout.prop(self, 'reduce_by', expand=True)
if self.change == False:
col = layout.column(align=True)
col.prop(self, 'align', expand=True)
col = layout.column(align=True)
col.prop(self, 'location', expand=True)
col = layout.column(align=True)
col.prop(self, 'rotation', expand=True)
def execute(self, context):
add_pyramid_object(self, context)
if bpy.context.mode == "OBJECT":
if context.selected_objects != [] and context.active_object and \
('Pyramid' in context.active_object.data.keys()) and (self.change == True):
obj = context.active_object
oldmesh = obj.data
oldmeshname = obj.data.name
obj.data = pyramid_mesh(self, context)
for material in oldmesh.materials:
obj.data.materials.append(material)
bpy.data.meshes.remove(oldmesh)
obj.data.name = oldmeshname
else:
mesh = pyramid_mesh(self, context)
obj = object_utils.object_data_add(context, mesh, operator=self)
obj.data["Pyramid"] = True
obj.data["change"] = False
for prm in PyramidParameters():
obj.data[prm] = getattr(self, prm)
if bpy.context.mode == "EDIT_MESH":
active_object = context.active_object
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
mesh = pyramid_mesh(self, context)
object_utils.object_data_add(context, mesh, operator=self)
obj.select_set(True)
active_object.select_set(True)
bpy.ops.object.join()
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
return {'FINISHED'}
def PyramidParameters():
PyramidParameters = [
"num_sides",
"num_steps",
"width",
"height",
"reduce_by",
]
return PyramidParameters

View File

@ -17,7 +17,6 @@ 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,
@ -229,7 +228,7 @@ def add_mesh_Brilliant(context, s, table_w, crown_h, girdle_t, pavi_d, bezel_f,
return dmesh
# object generating function, returns final object
def addBrilliant(context, s, table_w, crown_h, girdle_t, pavi_d, bezel_f,
def addBrilliant(context, self, s, table_w, crown_h, girdle_t, pavi_d, bezel_f,
pavi_f, culet, girdle_real, keep_lga, g_real_smooth):
# deactivate possible active Objects
@ -240,7 +239,7 @@ def addBrilliant(context, s, table_w, crown_h, girdle_t, pavi_d, bezel_f,
pavi_f, culet, girdle_real, keep_lga, g_real_smooth)
# Create object and link it into scene.
dobj = object_utils.object_data_add(context, dmesh, operator=None, name="dobj")
dobj = object_utils.object_data_add(context, dmesh, operator=self, name="dobj")
# activate and select object
bpy.context.view_layer.objects.active = dobj
@ -314,11 +313,6 @@ class MESH_OT_primitive_brilliant_add(Operator, object_utils.AddObjectHelper):
Brilliant : BoolProperty(name = "Brilliant",
default = True,
description = "Brilliant")
#### change properties
name : StringProperty(name = "Name",
description = "Name")
change : BoolProperty(name = "Change",
default = False,
description = "change Brilliant")
@ -422,9 +416,9 @@ class MESH_OT_primitive_brilliant_add(Operator, object_utils.AddObjectHelper):
if self.change == False:
# generic transform props
box = layout.box()
box.prop(self, 'align')
box.prop(self, 'location')
box.prop(self, 'rotation')
box.prop(self, 'align', expand=True)
box.prop(self, 'location', expand=True)
box.prop(self, 'rotation', expand=True)
# call mesh/object generator function with user inputs
def execute(self, context):
@ -446,12 +440,11 @@ class MESH_OT_primitive_brilliant_add(Operator, object_utils.AddObjectHelper):
bpy.data.meshes.remove(oldmesh)
obj.data.name = oldmeshname
else:
obj = addBrilliant(context, self.s, self.table_w, self.crown_h,
obj = addBrilliant(context, self, self.s, self.table_w, self.crown_h,
self.girdle_t, self.pavi_d, self.bezel_f,
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
@ -462,7 +455,7 @@ class MESH_OT_primitive_brilliant_add(Operator, object_utils.AddObjectHelper):
active_object = context.active_object
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
obj = addBrilliant(context, self.s, self.table_w, self.crown_h,
obj = addBrilliant(context, self, self.s, self.table_w, self.crown_h,
self.girdle_t, self.pavi_d, self.bezel_f,
self.pavi_f, self.culet, self.girdle_real,
self.keep_lga, self.g_real_smooth
@ -473,8 +466,6 @@ class MESH_OT_primitive_brilliant_add(Operator, object_utils.AddObjectHelper):
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
utils.setlocation(self, context)
return {'FINISHED'}
def BrilliantParameters():

View File

@ -13,7 +13,8 @@ from bpy.props import (
EnumProperty,
FloatProperty,
FloatVectorProperty,
IntProperty
IntProperty,
StringProperty,
)
@ -339,15 +340,23 @@ class AddRoundCube(Operator, object_utils.AddObjectHelper):
sanity_check_verts = 200000
vert_count = 0
Roundcube : BoolProperty(name = "Roundcube",
default = True,
description = "Roundcube")
change : BoolProperty(name = "Change",
default = False,
description = "change Roundcube")
radius: FloatProperty(
name="Radius",
description="Radius of vertices for sphere, capsule or cuboid bevel",
default=1.0, min=0.0, soft_min=0.01, step=10
default=0.2, min=0.0, soft_min=0.01, step=10
)
size: FloatVectorProperty(
name="Size",
description="Size",
subtype='XYZ',
default=(2.0, 2.0, 2.0),
)
arc_div: IntProperty(
name="Arc Divisions",
@ -389,13 +398,48 @@ class AddRoundCube(Operator, object_utils.AddObjectHelper):
self.report({'ERROR'}, 'More than ' + str(self.sanity_check_verts) +
' vertices! Check "No Limit" to proceed')
return {'CANCELLED'}
verts, faces = round_cube(self.radius, self.arc_div, self.lin_div,
if bpy.context.mode == "OBJECT":
if context.selected_objects != [] and context.active_object and \
('Roundcube' in context.active_object.data.keys()) and (self.change == True):
obj = context.active_object
oldmesh = obj.data
oldmeshname = obj.data.name
verts, faces = round_cube(self.radius, self.arc_div, self.lin_div,
self.size, self.div_type, self.odd_axis_align)
mesh = bpy.data.meshes.new('Roundcube')
mesh.from_pydata(verts, [], faces)
obj.data = mesh
for material in oldmesh.materials:
obj.data.materials.append(material)
bpy.data.meshes.remove(oldmesh)
obj.data.name = oldmeshname
else:
verts, faces = round_cube(self.radius, self.arc_div, self.lin_div,
self.size, self.div_type, self.odd_axis_align)
mesh = bpy.data.meshes.new('Roundcube')
mesh.from_pydata(verts, [], faces)
obj = object_utils.object_data_add(context, mesh, operator=self)
mesh = bpy.data.meshes.new('Roundcube')
mesh.from_pydata(verts, [], faces)
object_utils.object_data_add(context, mesh, operator=self)
obj.data["Roundcube"] = True
obj.data["change"] = False
for prm in RoundCubeParameters():
obj.data[prm] = getattr(self, prm)
if bpy.context.mode == "EDIT_MESH":
active_object = context.active_object
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
verts, faces = round_cube(self.radius, self.arc_div, self.lin_div,
self.size, self.div_type, self.odd_axis_align)
mesh = bpy.data.meshes.new('Roundcube')
mesh.from_pydata(verts, [], faces)
object_utils.object_data_add(context, mesh, operator=self)
obj.select_set(True)
active_object.select_set(True)
bpy.ops.object.join()
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
return {'FINISHED'}
@ -412,6 +456,7 @@ class AddRoundCube(Operator, object_utils.AddObjectHelper):
return self.execute(context)
def draw(self, context):
self.check(context)
layout = self.layout
layout.prop(self, 'radius')
@ -442,7 +487,22 @@ class AddRoundCube(Operator, object_utils.AddObjectHelper):
row.alert = self.vert_count > self.sanity_check_verts
row.prop(self, 'no_limit', text='No limit ({})'.format(self.vert_count))
col = layout.column(align=True)
col.prop(self, 'location', expand=True)
col = layout.column(align=True)
col.prop(self, 'rotation', expand=True)
if self.change == False:
col = layout.column(align=True)
col.prop(self, 'align', expand=True)
col = layout.column(align=True)
col.prop(self, 'location', expand=True)
col = layout.column(align=True)
col.prop(self, 'rotation', expand=True)
def RoundCubeParameters():
RoundCubeParameters = [
"radius",
"size",
"arc_div",
"lin_div",
"div_type",
"odd_axis_align",
"no_limit",
]
return RoundCubeParameters

View File

@ -9,8 +9,10 @@ from math import pi
from bpy.props import (
IntProperty,
FloatProperty,
StringProperty,
BoolProperty,
)
from bpy_extras import object_utils
# Create a new mesh (object) from verts/edges/faces.
# verts/edges/faces ... List of vertices/edges/faces for the
@ -142,12 +144,19 @@ def add_star(points, outer_radius, inner_radius, height):
return verts, faces
class AddStar(bpy.types.Operator):
class AddStar(bpy.types.Operator, object_utils.AddObjectHelper):
bl_idname = "mesh.primitive_star_add"
bl_label = "Simple Star"
bl_description = "Construct a star mesh"
bl_options = {'REGISTER', 'UNDO', 'PRESET'}
Star : BoolProperty(name = "Star",
default = True,
description = "Star")
change : BoolProperty(name = "Change",
default = False,
description = "change Star")
points: IntProperty(
name="Points",
description="Number of points for the star",
@ -176,15 +185,84 @@ class AddStar(bpy.types.Operator):
default=0.5
)
def draw(self, context):
layout = self.layout
layout.prop(self, 'points', expand=True)
layout.prop(self, 'outer_radius', expand=True)
layout.prop(self, 'innter_radius', expand=True)
layout.prop(self, 'height', expand=True)
if self.change == False:
col = layout.column(align=True)
col.prop(self, 'align', expand=True)
col = layout.column(align=True)
col.prop(self, 'location', expand=True)
col = layout.column(align=True)
col.prop(self, 'rotation', expand=True)
def execute(self, context):
if bpy.context.mode == "OBJECT":
if context.selected_objects != [] and context.active_object and \
('Star' in context.active_object.data.keys()) and (self.change == True):
obj = context.active_object
oldmesh = obj.data
oldmeshname = obj.data.name
verts, faces = add_star(
self.points,
self.outer_radius,
self.innter_radius,
self.height
)
mesh = bpy.data.meshes.new('Star')
mesh.from_pydata(verts, [], faces)
obj.data = mesh
for material in oldmesh.materials:
obj.data.materials.append(material)
bpy.data.meshes.remove(oldmesh)
obj.data.name = oldmeshname
else:
verts, faces = add_star(
self.points,
self.outer_radius,
self.innter_radius,
self.height
)
mesh = bpy.data.meshes.new('Star')
mesh.from_pydata(verts, [], faces)
obj = object_utils.object_data_add(context, mesh, operator=self)
verts, faces = add_star(
self.points,
self.outer_radius,
self.innter_radius,
self.height
)
obj = create_mesh_object(context, verts, [], faces, "Star")
obj.data["Star"] = True
obj.data["change"] = False
for prm in StarParameters():
obj.data[prm] = getattr(self, prm)
if bpy.context.mode == "EDIT_MESH":
active_object = context.active_object
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
verts, faces = add_star(
self.points,
self.outer_radius,
self.innter_radius,
self.height
)
mesh = bpy.data.meshes.new('Star')
mesh.from_pydata(verts, [], faces)
object_utils.object_data_add(context, mesh, operator=self)
obj.select_set(True)
active_object.select_set(True)
bpy.ops.object.join()
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
return {'FINISHED'}
def StarParameters():
StarParameters = [
"points",
"outer_radius",
"innter_radius",
"height",
]
return StarParameters

View File

@ -5,29 +5,11 @@ from bpy.props import (
FloatProperty,
BoolProperty,
IntProperty,
StringProperty,
)
from math import pi, cos, sin
from mathutils import Vector
# Create a new mesh (object) from verts/edges/faces
# verts/edges/faces ... List of vertices/edges/faces for the
# new mesh (as used in from_pydata)
# name ... Name of the new mesh (& object)
def create_mesh_object(context, verts, edges, faces, name):
# Create new mesh
mesh = bpy.data.meshes.new(name)
# Make a mesh from a list of verts/edges/faces.
mesh.from_pydata(verts, edges, faces)
# Update mesh geometry after adding stuff.
mesh.update()
from bpy_extras import object_utils
return object_utils.object_data_add(context, mesh, operator=None)
from bpy_extras import object_utils
# A very simple "bridge" tool
@ -136,12 +118,19 @@ def supertoroid(R, r, u, v, n1, n2):
return verts, faces
class add_supertoroid(bpy.types.Operator):
class add_supertoroid(bpy.types.Operator, object_utils.AddObjectHelper):
bl_idname = "mesh.primitive_supertoroid_add"
bl_label = "Add SuperToroid"
bl_description = "Construct a supertoroid mesh"
bl_options = {'REGISTER', 'UNDO', 'PRESET'}
SuperToroid : BoolProperty(name = "SuperToroid",
default = True,
description = "SuperToroid")
change : BoolProperty(name = "Change",
default = False,
description = "change SuperToroid")
R: FloatProperty(
name="Big radius",
description="The radius inside the tube",
@ -190,6 +179,25 @@ class add_supertoroid(bpy.types.Operator):
options={'HIDDEN'}
)
def draw(self, context):
layout = self.layout
layout.prop(self, 'R', expand=True)
layout.prop(self, 'r', expand=True)
layout.prop(self, 'u', expand=True)
layout.prop(self, 'v', expand=True)
layout.prop(self, 'n1', expand=True)
layout.prop(self, 'n2', expand=True)
layout.prop(self, 'ie', expand=True)
if self.change == False:
col = layout.column(align=True)
col.prop(self, 'align', expand=True)
col = layout.column(align=True)
col.prop(self, 'location', expand=True)
col = layout.column(align=True)
col.prop(self, 'rotation', expand=True)
def execute(self, context):
props = self.properties
@ -208,16 +216,75 @@ class add_supertoroid(bpy.types.Operator):
# at least as big as the radius of the tube
if rad2 > rad1:
rad1 = rad2
# create mesh
verts, faces = supertoroid(rad1,
if bpy.context.mode == "OBJECT":
if context.selected_objects != [] and context.active_object and \
('SuperToroid' in context.active_object.data.keys()) and (self.change == True):
obj = context.active_object
oldmesh = obj.data
oldmeshname = obj.data.name
verts, faces = supertoroid(rad1,
rad2,
props.u,
props.v,
props.n1,
props.n2
)
# create the object
obj = create_mesh_object(context, verts, [], faces, "SuperToroid")
mesh = bpy.data.meshes.new('SuperToroid')
mesh.from_pydata(verts, [], faces)
obj.data = mesh
for material in oldmesh.materials:
obj.data.materials.append(material)
bpy.data.meshes.remove(oldmesh)
obj.data.name = oldmeshname
else:
verts, faces = supertoroid(rad1,
rad2,
props.u,
props.v,
props.n1,
props.n2
)
mesh = bpy.data.meshes.new('SuperToroid')
mesh.from_pydata(verts, [], faces)
obj = object_utils.object_data_add(context, mesh, operator=self)
obj.data["SuperToroid"] = True
obj.data["change"] = False
for prm in SuperToroidParameters():
obj.data[prm] = getattr(self, prm)
if bpy.context.mode == "EDIT_MESH":
active_object = context.active_object
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
verts, faces = supertoroid(rad1,
rad2,
props.u,
props.v,
props.n1,
props.n2
)
mesh = bpy.data.meshes.new('SuperToroid')
mesh.from_pydata(verts, [], faces)
object_utils.object_data_add(context, mesh, operator=self)
obj.select_set(True)
active_object.select_set(True)
bpy.ops.object.join()
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
return {'FINISHED'}
def SuperToroidParameters():
SuperToroidParameters = [
"R",
"r",
"u",
"v",
"n1",
"n2",
"ie",
"edit",
]
return SuperToroidParameters

View File

@ -3,7 +3,12 @@
import bpy
from mathutils import Vector
from math import sin, cos, pi
from bpy.props import IntProperty
from bpy.props import (
BoolProperty,
IntProperty,
StringProperty,
)
from bpy_extras import object_utils
def create_mesh_object(context, verts, edges, faces, name):
@ -92,12 +97,19 @@ def make_knot(knotidx, ures):
return (verts, faces)
class AddTorusKnot(bpy.types.Operator):
class AddTorusKnot(bpy.types.Operator, object_utils.AddObjectHelper):
bl_idname = "mesh.primitive_torusknot_add"
bl_label = "Add Torus Knot"
bl_description = "Construct a torus knot mesh"
bl_options = {"REGISTER", "UNDO"}
TorusKnot : BoolProperty(name = "TorusKnot",
default = True,
description = "TorusKnot")
change : BoolProperty(name = "Change",
default = False,
description = "change TorusKnot")
resolution: IntProperty(
name="Resolution",
description="Resolution of the Torus Knot",
@ -110,9 +122,66 @@ class AddTorusKnot(bpy.types.Operator):
default=1,
min=1, max=3
)
def draw(self, context):
layout = self.layout
layout.prop(self, 'resolution', expand=True)
layout.prop(self, 'objecttype', expand=True)
if self.change == False:
col = layout.column(align=True)
col.prop(self, 'align', expand=True)
col = layout.column(align=True)
col.prop(self, 'location', expand=True)
col = layout.column(align=True)
col.prop(self, 'rotation', expand=True)
def execute(self, context):
verts, faces = make_knot(self.objecttype, self.resolution)
obj = create_mesh_object(context, verts, [], faces, "Torus Knot")
if bpy.context.mode == "OBJECT":
if context.selected_objects != [] and context.active_object and \
('TorusKnot' in context.active_object.data.keys()) and (self.change == True):
obj = context.active_object
oldmesh = obj.data
oldmeshname = obj.data.name
verts, faces = make_knot(self.objecttype, self.resolution)
mesh = bpy.data.meshes.new('TorusKnot')
mesh.from_pydata(verts, [], faces)
obj.data = mesh
for material in oldmesh.materials:
obj.data.materials.append(material)
bpy.data.meshes.remove(oldmesh)
obj.data.name = oldmeshname
else:
verts, faces = make_knot(self.objecttype, self.resolution)
mesh = bpy.data.meshes.new('TorusKnot')
mesh.from_pydata(verts, [], faces)
obj = object_utils.object_data_add(context, mesh, operator=self)
obj.data["TorusKnot"] = True
obj.data["change"] = False
for prm in TorusKnotParameters():
obj.data[prm] = getattr(self, prm)
if bpy.context.mode == "EDIT_MESH":
active_object = context.active_object
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
verts, faces = make_knot(self.objecttype, self.resolution)
mesh = bpy.data.meshes.new('TorusKnot')
mesh.from_pydata(verts, [], faces)
object_utils.object_data_add(context, mesh, operator=self)
obj.select_set(True)
active_object.select_set(True)
bpy.ops.object.join()
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
return {'FINISHED'}
def TorusKnotParameters():
TorusKnotParameters = [
"resolution",
"objecttype",
]
return TorusKnotParameters

View File

@ -7,7 +7,9 @@ from bpy.props import (
FloatProperty,
IntProperty,
BoolProperty,
StringProperty,
)
from bpy_extras import object_utils
# Create a new mesh (object) from verts/edges/faces
@ -133,12 +135,19 @@ def add_twisted_torus(major_rad, minor_rad, major_seg, minor_seg, twists):
return verts, faces
class AddTwistedTorus(bpy.types.Operator):
class AddTwistedTorus(bpy.types.Operator, object_utils.AddObjectHelper):
bl_idname = "mesh.primitive_twisted_torus_add"
bl_label = "Add Twisted Torus"
bl_description = "Construct a twisted torus mesh"
bl_options = {'REGISTER', 'UNDO', 'PRESET'}
TwistedTorus : BoolProperty(name = "TwistedTorus",
default = True,
description = "TwistedTorus")
change : BoolProperty(name = "Change",
default = False,
description = "change TwistedTorus")
major_radius: FloatProperty(
name="Major Radius",
description="Radius from the origin to the"
@ -195,22 +204,101 @@ class AddTwistedTorus(bpy.types.Operator):
default=0.5
)
def draw(self, context):
layout = self.layout
layout.prop(self, 'major_radius', expand=True)
layout.prop(self, 'minor_radius', expand=True)
layout.prop(self, 'major_segments', expand=True)
layout.prop(self, 'minor_segments', expand=True)
layout.prop(self, 'twists', expand=True)
layout.prop(self, 'use_abso', expand=True)
layout.prop(self, 'abso_major_rad', expand=True)
layout.prop(self, 'abso_minor_rad', expand=True)
if self.change == False:
col = layout.column(align=True)
col.prop(self, 'align', expand=True)
col = layout.column(align=True)
col.prop(self, 'location', expand=True)
col = layout.column(align=True)
col.prop(self, 'rotation', expand=True)
def execute(self, context):
if self.use_abso is True:
extra_helper = (self.abso_major_rad - self.abso_minor_rad) * 0.5
self.major_radius = self.abso_minor_rad + extra_helper
self.minor_radius = extra_helper
if bpy.context.mode == "OBJECT":
if context.selected_objects != [] and context.active_object and \
('TwistedTorus' in context.active_object.data.keys()) and (self.change == True):
obj = context.active_object
oldmesh = obj.data
oldmeshname = obj.data.name
verts, faces = add_twisted_torus(
self.major_radius,
self.minor_radius,
self.major_segments,
self.minor_segments,
self.twists
)
mesh = bpy.data.meshes.new('TwistedTorus')
mesh.from_pydata(verts, [], faces)
obj.data = mesh
for material in oldmesh.materials:
obj.data.materials.append(material)
bpy.data.meshes.remove(oldmesh)
obj.data.name = oldmeshname
else:
verts, faces = add_twisted_torus(
self.major_radius,
self.minor_radius,
self.major_segments,
self.minor_segments,
self.twists
)
mesh = bpy.data.meshes.new('TwistedTorus')
mesh.from_pydata(verts, [], faces)
obj = object_utils.object_data_add(context, mesh, operator=self)
verts, faces = add_twisted_torus(
self.major_radius,
self.minor_radius,
self.major_segments,
self.minor_segments,
self.twists
)
# Create the mesh object from this geometry data.
obj = create_mesh_object(context, verts, [], faces, "TwistedTorus")
obj.data["TwistedTorus"] = True
obj.data["change"] = False
for prm in TwistedTorusParameters():
obj.data[prm] = getattr(self, prm)
if bpy.context.mode == "EDIT_MESH":
active_object = context.active_object
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
verts, faces = add_twisted_torus(
self.major_radius,
self.minor_radius,
self.major_segments,
self.minor_segments,
self.twists
)
mesh = bpy.data.meshes.new('TwistedTorus')
mesh.from_pydata(verts, [], faces)
object_utils.object_data_add(context, mesh, operator=self)
obj.select_set(True)
active_object.select_set(True)
bpy.ops.object.join()
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
return {'FINISHED'}
def TwistedTorusParameters():
TwistedTorusParameters = [
"major_radius",
"minor_radius",
"major_segments",
"minor_segments",
"twists",
"use_abso",
"abso_major_rad",
"abso_minor_rad",
]
return TwistedTorusParameters

View File

@ -1,45 +0,0 @@
# ##### 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')