~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/addons/add_mesh_pipe_joint.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#
17
17
# ##### END GPL LICENSE BLOCK #####
18
18
 
19
 
bl_addon_info = {
 
19
bl_info = {
20
20
    "name": "Pipe Joints",
21
21
    "author": "Buerbaum Martin (Pontiac)",
22
 
    "version": (0, 10, 6),
23
 
    "blender": (2, 5, 3),
24
 
    "api": 31965,
25
 
    "location": "View3D > Add > Mesh > Pipe Joint",
26
 
    "description": "Adds 5 pipe Joint types to the Add Mesh menu",
 
22
    "version": (0, 10, 7),
 
23
    "blender": (2, 6, 1),
 
24
    "location": "View3D > Add > Mesh > Pipe Joints",
 
25
    "description": "Add different types of pipe joints",
27
26
    "warning": "",
28
27
    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
29
28
        "Scripts/Add_Mesh/Add_Pipe_Joints",
30
29
    "tracker_url": "https://projects.blender.org/tracker/index.php?"\
31
 
        "func=detail&aid=21443&group_id=153&atid=469",
 
30
        "func=detail&aid=21443",
32
31
    "category": "Add Mesh"}
33
32
 
34
 
"""
35
 
Pipe Joints
36
 
This script lets the user create various types of pipe joints.
37
 
 
38
 
Usage:
39
 
You have to activated the script in the "Add-Ons" tab (user preferences).
40
 
The functionality can then be accessed via the
41
 
"Add Mesh" -> "Pipe Joints" menu.
42
 
Note: Currently only the "Elbow" type supports odd number of vertices.
43
 
 
44
 
Version history:
45
 
v0.10.6 - Removed "recall properties" from all functions.
46
 
    Updated various code for new API.
47
 
    API: mathutils.RotationMatrix -> mathutils.Matrix.Rotation
48
 
    API: xxx.selected -> xxx.select
49
 
    API: "invoke" function for each operator.
50
 
    Updated for new bl_addon_info structure.
51
 
    New code for the "align_matrix".
52
 
    made script PEP8 compatible.
53
 
v0.10.5 - createFaces can now create fan/star like faces.
54
 
v0.10.4 - Updated the function "createFaces" a bit. No functional changes.
55
 
v0.10.3 - Updated store_recall_properties, apply_object_align
56
 
    and create_mesh_object.
57
 
    Changed how recall data is stored.
58
 
    Added 'description'.
59
 
v0.10.2 - API change Mathutils -> mathutils (r557)
60
 
    Fixed wiki url.
61
 
v0.10.1 - Use hidden "edit" property for "recall" operator.
62
 
v0.10 - Store "recall" properties in the created objects.
63
 
    Align the geometry to the view if the user preference says so.
64
 
v0.9.10 - Use bl_addon_info for Add-On information.
65
 
v0.9.9 - Changed the script so it can be managed from the "Add-Ons" tab in
66
 
    the user preferences.
67
 
    Added dummy "PLUGIN" icon.
68
 
v0.9.8 - Fixed some new API stuff.
69
 
    Mainly we now have the register/unregister functions.
70
 
    Also the new() function for objects now accepts a mesh object.
71
 
    Corrected FSF address.
72
 
    Clean up of tooltips.
73
 
v0.9.7 - Use "unit" settings for angles as well.
74
 
    This also lets me use radiant for all internal values..
75
 
v0.9.6 - Use "unit" settings (i.e. none/metric/imperial).
76
 
v0.9.5 - Use mesh.from_pydata() for geometry creation.
77
 
    So we can remove unpack_list and unpack_face_list again.
78
 
v0.9.4 - Creating of the pipe now works in mesh edit mode too.
79
 
    Thanks to ideasman42 (Campbell Barton) for his nice work
80
 
    on the torus script code :-).
81
 
v0.9.3 - Changed to a saner vertex/polygon creation process (previously
82
 
    my usage of mesh.faces.add could only do quads)
83
 
    For this I've copied the functions unpack_list and unpack_face_list
84
 
    from import_scene_obj.py.
85
 
    Elbow joint actually supports 3 vertices per circle.
86
 
    Various comments.
87
 
    Script _should_ now be PEP8 compatible.
88
 
v0.9.2 - Converted from tabs to spaces (4 spaces per tab).
89
 
v0.9.1 - Converted add_mesh and add_object to their new counterparts
90
 
    "bpy.data.meshes.new() and "bpy.data.objects.new()"
91
 
v0.9 - Converted to 2.5. Made mostly pep8 compatible (exept for tabs and
92
 
    stuff the check-script didn't catch).
93
 
v0.8.5 - Fixed bug in Elbow joint. Same problem as in 0.8.1
94
 
v0.8.4 - Fixed bug in Y joint. Same problem as in 0.8.1
95
 
v0.8.3 - Fixed bug in N joint. Same problem as in 0.8.1
96
 
v0.8.2 - Fixed bug in X (cross) joint. Same problem as in 0.8.1
97
 
v0.8.1 - Fixed bug in T joint. Angles greater than 90 deg combined with a
98
 
    radius != 1 resulted in bad geometry (the radius was not taken into
99
 
    account when calculating the joint vertices).
100
 
v0.8 - Added N-Joint.
101
 
    Removed all uses of baseJointLocZ. It just clutters the code.
102
 
v0.7 - Added cross joint
103
 
v0.6 - No visible changes. Lots of internal ones though
104
 
    (complete redesign of face creation process).
105
 
    As a bonus the code is a bit easier to read now.
106
 
    Added a nice&simple little "bridge" function
107
 
    (createFaces) for these changes.
108
 
v0.5.1 - Made it possible to create asymmetric Y joints.
109
 
    Renamed the 2 Wye Joints to something more fitting and unique.
110
 
    One is now the Tee joint, the second one remains the Wye joint.
111
 
v0.5 - Added real Y joint.
112
 
v0.4.3 - Added check for odd vertex numbers. They are not (yet) supported.
113
 
v0.4.2 - Added pipe length to the GUI.
114
 
v0.4.1 - Removed the unfinished menu entries for now.
115
 
v0.4 - Tried to clean up the face creation in addTeeJoint
116
 
v0.3 - Code for wye (Y) shape (straight pipe with "branch" for now)
117
 
v0.2 - Restructured to allow different types of pipe (joints).
118
 
v0.1 - Initial revision.
119
 
 
120
 
More links:
121
 
http://gitorious.org/blender-scripts/blender-pipe-joint-script
122
 
http://blenderartists.org/forum/showthread.php?t=154394
123
 
 
124
 
TODO:
125
 
 
126
 
Use a rotation matrix for rotating the circle vertices:
127
 
rotation_matrix = mathutils.Matrix.Rotation(-math.pi/2, 4, 'x')
128
 
mesh.transform(rotation_matrix)
129
 
"""
130
 
 
131
33
import bpy
132
 
import mathutils
133
34
from math import *
134
35
from bpy.props import *
135
36
 
136
37
 
137
 
# Apply view rotation to objects if "Align To" for
138
 
# new objects was set to "VIEW" in the User Preference.
139
 
# Is now handled in the invoke functions
140
 
# calculates the matrix for the new object
141
 
# depending on user pref
142
 
def align_matrix(context):
143
 
    loc = mathutils.Matrix.Translation(context.scene.cursor_location)
144
 
    obj_align = context.user_preferences.edit.object_align
145
 
    if (context.space_data.type == 'VIEW_3D'
146
 
        and obj_align == 'VIEW'):
147
 
        view_mat = context.space_data.region_3d.view_matrix
148
 
        rot = view_mat.rotation_part().invert().resize4x4()
149
 
    else:
150
 
        rot = mathutils.Matrix()
151
 
    align_matrix = loc * rot
152
 
    return align_matrix
153
 
 
154
 
 
155
38
# Create a new mesh (object) from verts/edges/faces.
156
39
# verts/edges/faces ... List of vertices/edges/faces for the
157
40
#                       new mesh (as used in from_pydata).
158
41
# name ... Name of the new mesh (& object).
159
 
# edit ... Replace existing mesh data.
160
 
# Note: Using "edit" will destroy/delete existing mesh data.
161
 
def create_mesh_object(context, verts, edges, faces, name, edit, align_matrix):
162
 
    scene = context.scene
163
 
    obj_act = scene.objects.active
164
 
 
165
 
    # Can't edit anything, unless we have an active obj.
166
 
    if edit and not obj_act:
167
 
        return None
168
 
 
 
42
def create_mesh_object(context, verts, edges, faces, name):
169
43
    # Create new mesh
170
44
    mesh = bpy.data.meshes.new(name)
171
45
 
175
49
    # Update mesh geometry after adding stuff.
176
50
    mesh.update()
177
51
 
178
 
    # Deselect all objects.
179
 
    bpy.ops.object.select_all(action='DESELECT')
180
 
 
181
 
    if edit:
182
 
        # Replace geometry of existing object
183
 
 
184
 
        # Use the active obj and select it.
185
 
        ob_new = obj_act
186
 
        ob_new.select = True
187
 
 
188
 
        if obj_act.mode == 'OBJECT':
189
 
            # Get existing mesh datablock.
190
 
            old_mesh = ob_new.data
191
 
 
192
 
            # Set object data to nothing
193
 
            ob_new.data = None
194
 
 
195
 
            # Clear users of existing mesh datablock.
196
 
            old_mesh.user_clear()
197
 
 
198
 
            # Remove old mesh datablock if no users are left.
199
 
            if (old_mesh.users == 0):
200
 
                bpy.data.meshes.remove(old_mesh)
201
 
 
202
 
            # Assign new mesh datablock.
203
 
            ob_new.data = mesh
204
 
 
205
 
    else:
206
 
        # Create new object
207
 
        ob_new = bpy.data.objects.new(name, mesh)
208
 
 
209
 
        # Link new object to the given scene and select it.
210
 
        scene.objects.link(ob_new)
211
 
        ob_new.select = True
212
 
 
213
 
        # Place the object at the 3D cursor location.
214
 
        ob_new.matrix_world = align_matrix
215
 
 
216
 
    if obj_act and obj_act.mode == 'EDIT':
217
 
        if not edit:
218
 
            # We are in EditMode, switch to ObjectMode.
219
 
            bpy.ops.object.mode_set(mode='OBJECT')
220
 
 
221
 
            # Select the active object as well.
222
 
            obj_act.select = True
223
 
 
224
 
            # Apply location of new object.
225
 
            scene.update()
226
 
 
227
 
            # Join new object into the active.
228
 
            bpy.ops.object.join()
229
 
 
230
 
            # Switching back to EditMode.
231
 
            bpy.ops.object.mode_set(mode='EDIT')
232
 
 
233
 
            ob_new = obj_act
234
 
 
235
 
    else:
236
 
        # We are in ObjectMode.
237
 
        # Make the new object the active one.
238
 
        scene.objects.active = ob_new
239
 
 
240
 
    return ob_new
241
 
 
 
52
    from bpy_extras import object_utils
 
53
    return object_utils.object_data_add(context, mesh, operator=None)
242
54
 
243
55
# A very simple "bridge" tool.
244
56
# Connects two equally long vertex rows with faces.
314
126
    '''Add an Elbow pipe mesh'''
315
127
    bl_idname = "mesh.primitive_elbow_joint_add"
316
128
    bl_label = "Add Pipe Elbow"
317
 
    bl_options = {'REGISTER', 'UNDO'}
318
 
 
319
 
    # edit - Whether to add or update.
320
 
    edit = BoolProperty(name="",
321
 
        description="",
322
 
        default=False,
323
 
        options={'HIDDEN'})
 
129
    bl_options = {'REGISTER', 'UNDO', 'PRESET'}
324
130
 
325
131
    radius = FloatProperty(name="Radius",
326
 
        description="The radius of the pipe.",
 
132
        description="The radius of the pipe",
327
133
        default=1.0,
328
134
        min=0.01,
329
135
        max=100.0,
330
136
        unit="LENGTH")
331
137
    div = IntProperty(name="Divisions",
332
 
        description="Number of vertices (divisions).",
 
138
        description="Number of vertices (divisions)",
333
139
        default=32, min=3, max=256)
334
140
 
335
141
    angle = FloatProperty(name="Angle",
336
 
        description="The angle of the branching pipe (i.e. the 'arm')." \
337
 
            " Measured from the center line of the main pipe.",
 
142
        description="The angle of the branching pipe (i.e. the 'arm' - " \
 
143
                    "Measured from the center line of the main pipe",
338
144
        default=radians(45.0),
339
145
        min=radians(-179.9),
340
146
        max=radians(179.9),
341
147
        unit="ROTATION")
342
148
 
343
149
    startLength = FloatProperty(name="Length Start",
344
 
        description="Length of the beginning of the pipe.",
 
150
        description="Length of the beginning of the pipe",
345
151
        default=3.0,
346
152
        min=0.01,
347
153
        max=100.0,
348
154
        unit="LENGTH")
349
155
    endLength = FloatProperty(name="End Length",
350
 
        description="Length of the end of the pipe.",
 
156
        description="Length of the end of the pipe",
351
157
        default=3.0,
352
158
        min=0.01,
353
159
        max=100.0,
354
160
        unit="LENGTH")
355
 
    align_matrix = mathutils.Matrix()
356
161
 
357
162
    def execute(self, context):
358
 
        edit = self.edit
359
163
 
360
164
        radius = self.radius
361
165
        div = self.div
412
216
        faces.extend(createFaces(loop1, loop2, closed=True))
413
217
        faces.extend(createFaces(loop2, loop3, closed=True))
414
218
 
415
 
        obj = create_mesh_object(context, verts, [], faces,
416
 
            "Elbow Joint", edit, self.align_matrix)
417
 
 
418
 
        return {'FINISHED'}
419
 
 
420
 
    def invoke(self, context, event):
421
 
        self.align_matrix = align_matrix(context)
422
 
        self.execute(context)
 
219
        base = create_mesh_object(context, verts, [], faces, "Elbow Joint")
 
220
 
423
221
        return {'FINISHED'}
424
222
 
425
223
 
429
227
    '''Add a Tee-Joint mesh'''
430
228
    bl_idname = "mesh.primitive_tee_joint_add"
431
229
    bl_label = "Add Pipe Tee-Joint"
432
 
    bl_options = {'REGISTER', 'UNDO'}
433
 
 
434
 
    # edit - Whether to add or update.
435
 
    edit = BoolProperty(name="",
436
 
        description="",
437
 
        default=False,
438
 
        options={'HIDDEN'})
 
230
    bl_options = {'REGISTER', 'UNDO', 'PRESET'}
439
231
 
440
232
    radius = FloatProperty(name="Radius",
441
 
        description="The radius of the pipe.",
 
233
        description="The radius of the pipe",
442
234
        default=1.0,
443
235
        min=0.01,
444
236
        max=100.0,
445
237
        unit="LENGTH")
446
238
    div = IntProperty(name="Divisions",
447
 
        description="Number of vertices (divisions).",
 
239
        description="Number of vertices (divisions)",
448
240
        default=32,
449
241
        min=4,
450
242
        max=256)
451
243
 
452
244
    angle = FloatProperty(name="Angle",
453
 
        description="The angle of the branching pipe (i.e. the 'arm')." \
454
 
            " Measured from the center line of the main pipe.",
 
245
        description="The angle of the branching pipe (i.e. the 'arm' - " \
 
246
                    "Measured from the center line of the main pipe",
455
247
        default=radians(90.0),
456
248
        min=radians(0.1),
457
249
        max=radians(179.9),
459
251
 
460
252
    startLength = FloatProperty(name="Length Start",
461
253
        description="Length of the beginning of the" \
462
 
            " main pipe (the straight one).",
 
254
                    " main pipe (the straight one)",
463
255
        default=3.0,
464
256
        min=0.01,
465
257
        max=100.0,
466
258
        unit="LENGTH")
467
259
    endLength = FloatProperty(name="End Length",
468
260
        description="Length of the end of the" \
469
 
            " main pipe (the straight one).",
 
261
                    " main pipe (the straight one)",
470
262
        default=3.0,
471
263
        min=0.01,
472
264
        max=100.0,
473
265
        unit="LENGTH")
474
266
    branchLength = FloatProperty(name="Arm Length",
475
 
        description="Length of the arm pipe (the bent one).",
 
267
        description="Length of the arm pipe (the bent one)",
476
268
        default=3.0,
477
269
        min=0.01,
478
270
        max=100.0,
479
271
        unit="LENGTH")
480
 
    align_matrix = mathutils.Matrix()
481
272
 
482
273
    def execute(self, context):
483
 
        edit = self.edit
484
274
 
485
275
        radius = self.radius
486
276
        div = self.div
605
395
        faces.extend(createFaces(loopJoint2, loopArm, closed=True))
606
396
        faces.extend(createFaces(loopJoint3, loopMainEnd, closed=True))
607
397
 
608
 
        obj = create_mesh_object(context, verts, [], faces,
609
 
            "Tee Joint", edit, self.align_matrix)
610
 
 
611
 
        return {'FINISHED'}
612
 
 
613
 
    def invoke(self, context, event):
614
 
        self.align_matrix = align_matrix(context)
615
 
        self.execute(context)
 
398
        base = create_mesh_object(context, verts, [], faces, "Tee Joint")
 
399
 
616
400
        return {'FINISHED'}
617
401
 
618
402
 
620
404
    '''Add a Wye-Joint mesh'''
621
405
    bl_idname = "mesh.primitive_wye_joint_add"
622
406
    bl_label = "Add Pipe Wye-Joint"
623
 
    bl_options = {'REGISTER', 'UNDO'}
624
 
 
625
 
    # edit - Whether to add or update.
626
 
    edit = BoolProperty(name="",
627
 
        description="",
628
 
        default=False,
629
 
        options={'HIDDEN'})
 
407
    bl_options = {'REGISTER', 'UNDO', 'PRESET'}
630
408
 
631
409
    radius = FloatProperty(name="Radius",
632
 
        description="The radius of the pipe.",
 
410
        description="The radius of the pipe",
633
411
        default=1.0,
634
412
        min=0.01,
635
413
        max=100.0,
636
414
        unit="LENGTH")
637
415
    div = IntProperty(name="Divisions",
638
 
        description="Number of vertices (divisions).",
 
416
        description="Number of vertices (divisions)",
639
417
        default=32,
640
418
        min=4,
641
419
        max=256)
642
420
 
643
421
    angle1 = FloatProperty(name="Angle 1",
644
 
        description="The angle of the 1. branching pipe." \
645
 
            " Measured from the center line of the main pipe.",
 
422
        description="The angle of the 1. branching pipe " \
 
423
                    "(measured from the center line of the main pipe)",
646
424
        default=radians(45.0),
647
425
        min=radians(-179.9),
648
426
        max=radians(179.9),
649
427
        unit="ROTATION")
650
428
    angle2 = FloatProperty(name="Angle 2",
651
 
        description="The angle of the 2. branching pipe." \
652
 
            " Measured from the center line of the main pipe.",
 
429
        description="The angle of the 2. branching pipe " \
 
430
                    "(measured from the center line of the main pipe) ",
653
431
        default=radians(45.0),
654
432
        min=radians(-179.9),
655
433
        max=radians(179.9),
657
435
 
658
436
    startLength = FloatProperty(name="Length Start",
659
437
        description="Length of the beginning of the" \
660
 
            " main pipe (the straight one).",
 
438
                    " main pipe (the straight one)",
661
439
        default=3.0,
662
440
        min=0.01,
663
441
        max=100.0,
664
442
        unit="LENGTH")
665
443
    branch1Length = FloatProperty(name="Length Arm 1",
666
 
        description="Length of the 1. arm.",
 
444
        description="Length of the 1. arm",
667
445
        default=3.0,
668
446
        min=0.01,
669
447
        max=100.0,
670
448
        unit="LENGTH")
671
449
    branch2Length = FloatProperty(name="Length Arm 2",
672
 
        description="Length of the 2. arm.",
 
450
        description="Length of the 2. arm",
673
451
        default=3.0,
674
452
        min=0.01,
675
453
        max=100.0,
676
454
        unit="LENGTH")
677
 
    align_matrix = mathutils.Matrix()
678
455
 
679
456
    def execute(self, context):
680
 
        edit = self.edit
681
457
 
682
458
        radius = self.radius
683
459
        div = self.div
813
589
        faces.extend(createFaces(loopJoint2, loopArm1, closed=True))
814
590
        faces.extend(createFaces(loopJoint3, loopArm2, closed=True))
815
591
 
816
 
        obj = create_mesh_object(context, verts, [], faces,
817
 
            "Wye Joint", edit, self.align_matrix)
818
 
 
819
 
        return {'FINISHED'}
820
 
 
821
 
    def invoke(self, context, event):
822
 
        self.align_matrix = align_matrix(context)
823
 
        self.execute(context)
 
592
        base = create_mesh_object(context, verts, [], faces, "Wye Joint")
 
593
 
824
594
        return {'FINISHED'}
825
595
 
826
596
 
829
599
    # Create the vertices and polygons for a coss (+ or X) pipe joint.
830
600
    bl_idname = "mesh.primitive_cross_joint_add"
831
601
    bl_label = "Add Pipe Cross-Joint"
832
 
    bl_options = {'REGISTER', 'UNDO'}
833
 
 
834
 
    # edit - Whether to add or update.
835
 
    edit = BoolProperty(name="",
836
 
        description="",
837
 
        default=False,
838
 
        options={'HIDDEN'})
 
602
    bl_options = {'REGISTER', 'UNDO', 'PRESET'}
839
603
 
840
604
    radius = FloatProperty(name="Radius",
841
 
        description="The radius of the pipe.",
 
605
        description="The radius of the pipe",
842
606
        default=1.0,
843
607
        min=0.01,
844
608
        max=100.0,
845
609
        unit="LENGTH")
846
610
    div = IntProperty(name="Divisions",
847
 
        description="Number of vertices (divisions).",
 
611
        description="Number of vertices (divisions)",
848
612
        default=32,
849
613
        min=4,
850
614
        max=256)
851
615
 
852
616
    angle1 = FloatProperty(name="Angle 1",
853
 
        description="The angle of the 1. arm (from the main axis).",
 
617
        description="The angle of the 1. arm (from the main axis)",
854
618
        default=radians(90.0),
855
619
        min=radians(-179.9),
856
620
        max=radians(179.9),
857
621
        unit="ROTATION")
858
622
    angle2 = FloatProperty(name="Angle 2",
859
 
        description="The angle of the 2. arm (from the main axis).",
 
623
        description="The angle of the 2. arm (from the main axis)",
860
624
        default=radians(90.0),
861
625
        min=radians(-179.9),
862
626
        max=radians(179.9),
863
627
        unit="ROTATION")
864
628
    angle3 = FloatProperty(name="Angle 3 (center)",
865
 
        description="The angle of the center arm (from the main axis).",
 
629
        description="The angle of the center arm (from the main axis)",
866
630
        default=radians(0.0),
867
631
        min=radians(-179.9),
868
632
        max=radians(179.9),
870
634
 
871
635
    startLength = FloatProperty(name="Length Start",
872
636
        description="Length of the beginning of the " \
873
 
                "main pipe (the straight one).",
 
637
                    "main pipe (the straight one)",
874
638
        default=3.0,
875
639
        min=0.01,
876
640
        max=100.0,
877
641
        unit="LENGTH")
878
642
    branch1Length = FloatProperty(name="Length Arm 1",
879
 
        description="Length of the 1. arm.",
 
643
        description="Length of the 1. arm",
880
644
        default=3.0,
881
645
        min=0.01,
882
646
        max=100.0,
883
647
        unit="LENGTH")
884
648
    branch2Length = FloatProperty(name="Length Arm 2",
885
 
        description="Length of the 2. arm.",
 
649
        description="Length of the 2. arm",
886
650
        default=3.0,
887
651
        min=0.01,
888
652
        max=100.0,
889
653
        unit="LENGTH")
890
654
    branch3Length = FloatProperty(name="Length Arm 3 (center)",
891
 
        description="Length of the center arm.",
 
655
        description="Length of the center arm",
892
656
        default=3.0,
893
657
        min=0.01,
894
658
        max=100.0,
895
659
        unit="LENGTH")
896
 
    align_matrix = mathutils.Matrix()
897
660
 
898
661
    def execute(self, context):
899
 
        edit = self.edit
900
662
 
901
663
        radius = self.radius
902
664
        div = self.div
965
727
 
966
728
            verts.append([locX * radius, locY * radius, locZ * radius])
967
729
 
968
 
        loopTemp2 = loopJoint2[:]
 
730
        # loopTemp2 = loopJoint2[:]  # UNUSED
969
731
 
970
732
        # Create 2. deformed joint circle
971
733
        loopTempA = []
1082
844
        faces.extend(createFaces(loopJoint3, loopArm2, closed=True))
1083
845
        faces.extend(createFaces(loopJoint4, loopArm3, closed=True))
1084
846
 
1085
 
        obj = create_mesh_object(context, verts, [], faces,
1086
 
            "Cross Joint", edit, self.align_matrix)
1087
 
 
1088
 
        return {'FINISHED'}
1089
 
 
1090
 
    def invoke(self, context, event):
1091
 
        self.align_matrix = align_matrix(context)
1092
 
        self.execute(context)
 
847
        base = create_mesh_object(context, verts, [], faces, "Cross Joint")
 
848
 
1093
849
        return {'FINISHED'}
1094
850
 
1095
851
 
1098
854
    # Create the vertices and polygons for a regular n-joint.
1099
855
    bl_idname = "mesh.primitive_n_joint_add"
1100
856
    bl_label = "Add Pipe N-Joint"
1101
 
    bl_options = {'REGISTER', 'UNDO'}
1102
 
 
1103
 
    # edit - Whether to add or update.
1104
 
    edit = BoolProperty(name="",
1105
 
        description="",
1106
 
        default=False,
1107
 
        options={'HIDDEN'})
 
857
    bl_options = {'REGISTER', 'UNDO', 'PRESET'}
1108
858
 
1109
859
    radius = FloatProperty(name="Radius",
1110
 
        description="The radius of the pipe.",
 
860
        description="The radius of the pipe",
1111
861
        default=1.0,
1112
862
        min=0.01,
1113
863
        max=100.0,
1114
864
        unit="LENGTH")
1115
865
    div = IntProperty(name="Divisions",
1116
 
        description="Number of vertices (divisions).",
 
866
        description="Number of vertices (divisions)",
1117
867
        default=32,
1118
868
        min=4,
1119
869
        max=256)
1128
878
        min=0.01,
1129
879
        max=100.0,
1130
880
        unit="LENGTH")
1131
 
    align_matrix = mathutils.Matrix()
1132
881
 
1133
882
    def execute(self, context):
1134
 
        edit = self.edit
1135
883
        radius = self.radius
1136
884
        div = self.div
1137
885
        number = self.number
1253
1001
                createFaces(loopsJoints[loopIdx],
1254
1002
                loopsEndCircles[loopIdx], closed=True))
1255
1003
 
1256
 
        obj = create_mesh_object(context, verts, [], faces,
1257
 
            "N Joint", edit, self.align_matrix)
1258
 
 
1259
 
        return {'FINISHED'}
1260
 
 
1261
 
    def invoke(self, context, event):
1262
 
        self.align_matrix = align_matrix(context)
1263
 
        self.execute(context)
 
1004
        base = create_mesh_object(context, verts, [], faces, "N Joint")
 
1005
 
1264
1006
        return {'FINISHED'}
1265
1007
 
1266
1008
 
1285
1027
 
1286
1028
################################
1287
1029
 
1288
 
import space_info
1289
 
 
1290
1030
 
1291
1031
# Define "Pipe Joints" menu
1292
1032
def menu_func(self, context):
1294
1034
 
1295
1035
 
1296
1036
def register():
 
1037
    bpy.utils.register_module(__name__)
 
1038
 
1297
1039
    # Add "Pipe Joints" menu to the "Add Mesh" menu
1298
 
    space_info.INFO_MT_mesh_add.append(menu_func)
 
1040
    bpy.types.INFO_MT_mesh_add.append(menu_func)
1299
1041
 
1300
1042
 
1301
1043
def unregister():
 
1044
    bpy.utils.unregister_module(__name__)
 
1045
 
1302
1046
    # Remove "Pipe Joints" menu from the "Add Mesh" menu.
1303
 
    space_info.INFO_MT_mesh_add.remove(menu_func)
 
1047
    bpy.types.INFO_MT_mesh_add.remove(menu_func)
 
1048
 
1304
1049
 
1305
1050
if __name__ == "__main__":
1306
1051
    register()