2009-11-01 15:21:20 +00:00
|
|
|
# ##### BEGIN GPL LICENSE BLOCK #####
|
|
|
|
#
|
|
|
|
# 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 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2009-11-01 18:07:35 +00:00
|
|
|
#
|
2009-11-01 15:21:20 +00:00
|
|
|
# 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.
|
2009-11-01 18:07:35 +00:00
|
|
|
#
|
2009-11-01 15:21:20 +00:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-11-01 15:21:20 +00:00
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
- add torus back from 2.4x as an operator
bpy.ops.mesh.primitive_torus_add(major_radius=1, minor_radius=0.25, major_segments=48, minor_segments=16)
- experemental dynamic menus, used for INFO_MT_file, INFO_MT_file_import, INFO_MT_file_export and INFO_MT_mesh_add. these can have items added from python.
eg.
- removed OBJECT_OT_mesh_add, use the python add menu instead.
- made mesh primitive ops - MESH_OT_primitive_plane_add, ...cube_add, etc. work in object mode.
- RNA scene.active_object wrapped
- bugfix [#19466] 2.5: Tweak menu only available for mesh objects added within Edit Mode
ED_object_exit_editmode was always doing an undo push, made this optional using the existing flag - EM_DO_UNDO, called everywhere except when adding primitives.
2009-10-10 21:23:20 +00:00
|
|
|
|
2010-01-31 14:46:28 +00:00
|
|
|
# <pep8 compliant>
|
2009-11-01 18:07:35 +00:00
|
|
|
import bpy
|
2010-04-11 14:22:27 +00:00
|
|
|
import mathutils
|
2009-11-01 18:07:35 +00:00
|
|
|
from math import cos, sin, pi
|
|
|
|
|
|
|
|
|
|
|
|
def add_torus(major_rad, minor_rad, major_seg, minor_seg):
|
2010-04-11 14:22:27 +00:00
|
|
|
Vector = mathutils.Vector
|
|
|
|
Quaternion = mathutils.Quaternion
|
2009-11-01 18:07:35 +00:00
|
|
|
|
|
|
|
PI_2 = pi * 2
|
|
|
|
z_axis = (0, 0, 1)
|
|
|
|
|
|
|
|
verts = []
|
|
|
|
faces = []
|
|
|
|
i1 = 0
|
|
|
|
tot_verts = major_seg * minor_seg
|
|
|
|
for major_index in range(major_seg):
|
|
|
|
quat = Quaternion(z_axis, (major_index / major_seg) * PI_2)
|
|
|
|
|
|
|
|
for minor_index in range(minor_seg):
|
|
|
|
angle = 2 * pi * minor_index / minor_seg
|
|
|
|
|
2010-04-25 19:27:59 +00:00
|
|
|
vec = Vector((major_rad + (cos(angle) * minor_rad), 0.0,
|
|
|
|
(sin(angle) * minor_rad))) * quat
|
2009-11-01 18:07:35 +00:00
|
|
|
|
2010-04-26 21:25:14 +00:00
|
|
|
verts.extend(vec[:])
|
2009-11-01 18:07:35 +00:00
|
|
|
|
|
|
|
if minor_index + 1 == minor_seg:
|
|
|
|
i2 = (major_index) * minor_seg
|
|
|
|
i3 = i1 + minor_seg
|
|
|
|
i4 = i2 + minor_seg
|
|
|
|
|
|
|
|
else:
|
|
|
|
i2 = i1 + 1
|
|
|
|
i3 = i1 + minor_seg
|
|
|
|
i4 = i3 + 1
|
|
|
|
|
|
|
|
if i2 >= tot_verts:
|
|
|
|
i2 = i2 - tot_verts
|
|
|
|
if i3 >= tot_verts:
|
|
|
|
i3 = i3 - tot_verts
|
|
|
|
if i4 >= tot_verts:
|
|
|
|
i4 = i4 - tot_verts
|
|
|
|
|
|
|
|
# stupid eekadoodle
|
|
|
|
if i2:
|
|
|
|
faces.extend([i1, i3, i4, i2])
|
|
|
|
else:
|
|
|
|
faces.extend([i2, i1, i3, i4])
|
|
|
|
|
|
|
|
i1 += 1
|
|
|
|
|
|
|
|
return verts, faces
|
- add torus back from 2.4x as an operator
bpy.ops.mesh.primitive_torus_add(major_radius=1, minor_radius=0.25, major_segments=48, minor_segments=16)
- experemental dynamic menus, used for INFO_MT_file, INFO_MT_file_import, INFO_MT_file_export and INFO_MT_mesh_add. these can have items added from python.
eg.
- removed OBJECT_OT_mesh_add, use the python add menu instead.
- made mesh primitive ops - MESH_OT_primitive_plane_add, ...cube_add, etc. work in object mode.
- RNA scene.active_object wrapped
- bugfix [#19466] 2.5: Tweak menu only available for mesh objects added within Edit Mode
ED_object_exit_editmode was always doing an undo push, made this optional using the existing flag - EM_DO_UNDO, called everywhere except when adding primitives.
2009-10-10 21:23:20 +00:00
|
|
|
|
define operator properties in the class, similar to django fields
# Before
[
bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= ""),
bpy.props.BoolProperty(attr="use_modifiers", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True),
bpy.props.BoolProperty(attr="use_normals", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True),
bpy.props.BoolProperty(attr="use_uvs", name="Export UVs", description="Exort the active UV layer", default= True),
bpy.props.BoolProperty(attr="use_colors", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True)
]
# After
path = StringProperty(attr="", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= "")
use_modifiers = BoolProperty(attr="", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True)
use_normals = BoolProperty(attr="", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True)
use_uvs = BoolProperty(attr="", name="Export UVs", description="Exort the active UV layer", default= True)
use_colors = BoolProperty(attr="", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True)
2009-10-31 16:40:14 +00:00
|
|
|
from bpy.props import *
|
- add torus back from 2.4x as an operator
bpy.ops.mesh.primitive_torus_add(major_radius=1, minor_radius=0.25, major_segments=48, minor_segments=16)
- experemental dynamic menus, used for INFO_MT_file, INFO_MT_file_import, INFO_MT_file_export and INFO_MT_mesh_add. these can have items added from python.
eg.
- removed OBJECT_OT_mesh_add, use the python add menu instead.
- made mesh primitive ops - MESH_OT_primitive_plane_add, ...cube_add, etc. work in object mode.
- RNA scene.active_object wrapped
- bugfix [#19466] 2.5: Tweak menu only available for mesh objects added within Edit Mode
ED_object_exit_editmode was always doing an undo push, made this optional using the existing flag - EM_DO_UNDO, called everywhere except when adding primitives.
2009-10-10 21:23:20 +00:00
|
|
|
|
2009-11-01 18:07:35 +00:00
|
|
|
|
2009-11-03 18:56:42 +00:00
|
|
|
class AddTorus(bpy.types.Operator):
|
2010-02-11 23:13:47 +00:00
|
|
|
'''Add a torus mesh'''
|
2009-11-01 18:07:35 +00:00
|
|
|
bl_idname = "mesh.primitive_torus_add"
|
|
|
|
bl_label = "Add Torus"
|
2010-03-01 00:03:51 +00:00
|
|
|
bl_options = {'REGISTER', 'UNDO'}
|
2009-11-01 18:07:35 +00:00
|
|
|
|
|
|
|
major_radius = FloatProperty(name="Major Radius",
|
2010-01-31 14:46:28 +00:00
|
|
|
description="Radius from the origin to the center of the cross sections",
|
2009-11-01 18:07:35 +00:00
|
|
|
default=1.0, min=0.01, max=100.0)
|
|
|
|
minor_radius = FloatProperty(name="Minor Radius",
|
2010-01-15 10:02:02 +00:00
|
|
|
description="Radius of the torus' cross section",
|
2009-11-01 18:07:35 +00:00
|
|
|
default=0.25, min=0.01, max=100.0)
|
|
|
|
major_segments = IntProperty(name="Major Segments",
|
|
|
|
description="Number of segments for the main ring of the torus",
|
|
|
|
default=48, min=3, max=256)
|
|
|
|
minor_segments = IntProperty(name="Minor Segments",
|
|
|
|
description="Number of segments for the minor ring of the torus",
|
2010-02-09 21:05:59 +00:00
|
|
|
default=12, min=3, max=256)
|
2010-01-14 22:45:56 +00:00
|
|
|
use_abso = BoolProperty(name="Use Int+Ext Controls",
|
2010-01-31 14:46:28 +00:00
|
|
|
description="Use the Int / Ext controls for torus dimensions",
|
|
|
|
default=False)
|
2010-01-14 22:45:56 +00:00
|
|
|
abso_major_rad = FloatProperty(name="Exterior Radius",
|
|
|
|
description="Total Exterior Radius of the torus",
|
|
|
|
default=1.0, min=0.01, max=100.0)
|
|
|
|
abso_minor_rad = FloatProperty(name="Inside Radius",
|
|
|
|
description="Total Interior Radius of the torus",
|
|
|
|
default=0.5, min=0.01, max=100.0)
|
2009-11-01 18:07:35 +00:00
|
|
|
|
|
|
|
def execute(self, context):
|
2010-01-31 14:46:28 +00:00
|
|
|
props = self.properties
|
2009-11-01 18:07:35 +00:00
|
|
|
|
2010-01-31 14:46:28 +00:00
|
|
|
if props.use_abso == True:
|
|
|
|
extra_helper = (props.abso_major_rad - props.abso_minor_rad) * 0.5
|
|
|
|
props.major_radius = props.abso_minor_rad + extra_helper
|
|
|
|
props.minor_radius = extra_helper
|
2010-01-14 22:45:56 +00:00
|
|
|
|
2010-01-31 14:46:28 +00:00
|
|
|
verts_loc, faces = add_torus(props.major_radius,
|
|
|
|
props.minor_radius,
|
|
|
|
props.major_segments,
|
|
|
|
props.minor_segments)
|
2009-11-01 18:07:35 +00:00
|
|
|
|
2010-01-09 23:44:01 +00:00
|
|
|
mesh = bpy.data.meshes.new("Torus")
|
2009-11-01 18:07:35 +00:00
|
|
|
|
|
|
|
mesh.add_geometry(int(len(verts_loc) / 3), 0, int(len(faces) / 4))
|
|
|
|
mesh.verts.foreach_set("co", verts_loc)
|
|
|
|
mesh.faces.foreach_set("verts_raw", faces)
|
|
|
|
|
|
|
|
scene = context.scene
|
|
|
|
|
|
|
|
# ugh
|
|
|
|
for ob in scene.objects:
|
|
|
|
ob.selected = False
|
|
|
|
|
|
|
|
mesh.update()
|
2010-02-22 00:07:46 +00:00
|
|
|
ob_new = bpy.data.objects.new("Torus", mesh)
|
2009-11-20 10:00:54 +00:00
|
|
|
scene.objects.link(ob_new)
|
2009-11-01 18:07:35 +00:00
|
|
|
ob_new.selected = True
|
|
|
|
|
2010-01-29 15:19:19 +00:00
|
|
|
ob_new.location = scene.cursor_location
|
2010-01-31 14:46:28 +00:00
|
|
|
|
2010-01-29 15:19:19 +00:00
|
|
|
obj_act = scene.objects.active
|
2010-01-31 14:46:28 +00:00
|
|
|
|
2010-01-29 15:19:19 +00:00
|
|
|
if obj_act and obj_act.mode == 'EDIT':
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2010-01-31 14:46:28 +00:00
|
|
|
|
2010-01-29 15:19:19 +00:00
|
|
|
obj_act.selected = True
|
|
|
|
scene.update() # apply location
|
|
|
|
#scene.objects.active = ob_new
|
|
|
|
|
|
|
|
bpy.ops.object.join() # join into the active.
|
|
|
|
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
|
|
|
else:
|
|
|
|
scene.objects.active = ob_new
|
|
|
|
if context.user_preferences.edit.enter_edit_mode:
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
2009-11-01 18:07:35 +00:00
|
|
|
|
2009-12-24 19:50:43 +00:00
|
|
|
return {'FINISHED'}
|
- add torus back from 2.4x as an operator
bpy.ops.mesh.primitive_torus_add(major_radius=1, minor_radius=0.25, major_segments=48, minor_segments=16)
- experemental dynamic menus, used for INFO_MT_file, INFO_MT_file_import, INFO_MT_file_export and INFO_MT_mesh_add. these can have items added from python.
eg.
- removed OBJECT_OT_mesh_add, use the python add menu instead.
- made mesh primitive ops - MESH_OT_primitive_plane_add, ...cube_add, etc. work in object mode.
- RNA scene.active_object wrapped
- bugfix [#19466] 2.5: Tweak menu only available for mesh objects added within Edit Mode
ED_object_exit_editmode was always doing an undo push, made this optional using the existing flag - EM_DO_UNDO, called everywhere except when adding primitives.
2009-10-10 21:23:20 +00:00
|
|
|
|
2010-01-29 15:19:19 +00:00
|
|
|
|
2010-03-31 20:39:08 +00:00
|
|
|
def menu_func(self, context):
|
|
|
|
self.layout.operator(AddTorus.bl_idname, text="Torus", icon='MESH_DONUT')
|
2009-11-01 18:07:35 +00:00
|
|
|
|
- add torus back from 2.4x as an operator
bpy.ops.mesh.primitive_torus_add(major_radius=1, minor_radius=0.25, major_segments=48, minor_segments=16)
- experemental dynamic menus, used for INFO_MT_file, INFO_MT_file_import, INFO_MT_file_export and INFO_MT_mesh_add. these can have items added from python.
eg.
- removed OBJECT_OT_mesh_add, use the python add menu instead.
- made mesh primitive ops - MESH_OT_primitive_plane_add, ...cube_add, etc. work in object mode.
- RNA scene.active_object wrapped
- bugfix [#19466] 2.5: Tweak menu only available for mesh objects added within Edit Mode
ED_object_exit_editmode was always doing an undo push, made this optional using the existing flag - EM_DO_UNDO, called everywhere except when adding primitives.
2009-10-10 21:23:20 +00:00
|
|
|
|
2010-02-14 11:21:21 +00:00
|
|
|
def register():
|
|
|
|
bpy.types.register(AddTorus)
|
|
|
|
bpy.types.INFO_MT_mesh_add.append(menu_func)
|
|
|
|
|
2010-02-22 23:32:58 +00:00
|
|
|
|
2010-02-14 11:21:21 +00:00
|
|
|
def unregister():
|
|
|
|
bpy.types.unregister(AddTorus)
|
|
|
|
bpy.types.INFO_MT_mesh_add.remove(menu_func)
|
2010-02-16 09:55:07 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
register()
|