~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/addons_contrib/add_mesh_beam_builder.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-05-12 20:02:22 UTC
  • mfrom: (14.2.16 sid)
  • Revision ID: package-import@ubuntu.com-20120512200222-lznjs2cxzaq96wua
Tags: 2.63a-1
* New upstream bugfix release
  + debian/patches/: re-worked since source code changed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# ##### BEGIN GPL LICENSE BLOCK #####
2
 
#
3
 
#  This program is free software; you can redistribute it and/or
4
 
#  modify it under the terms of the GNU General Public License
5
 
#  as published by the Free Software Foundation; either version 2
6
 
#  of the License, or (at your option) any later version.
7
 
#
8
 
#  This program is distributed in the hope that it will be useful,
9
 
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
#  GNU General Public License for more details.
12
 
#
13
 
#  You should have received a copy of the GNU General Public License
14
 
#  along with this program; if not, write to the Free Software Foundation,
15
 
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
 
#
17
 
# ##### END GPL LICENSE BLOCK #####
18
 
 
19
 
bl_info = {
20
 
    "name": "Beam Builder",
21
 
    "description": "Creates various types of beams.",
22
 
    "author": "revolt_randy",
23
 
    "version": (0, 1, 3),
24
 
    "blender": (2, 6, 0),
25
 
    "location": "View3D > Add > Mesh",
26
 
    "warning": "Currently under development.", 
27
 
    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Add_Mesh/BeamBuilder",
28
 
    "tracker_url": "https://projects.blender.org/tracker/index.php?func=detail&aid=26911",
29
 
    "category": "Add Mesh"}
30
 
 
31
 
#
32
 
# Creates a rectangluar, 'C', 'L', 'T', or 'I' - type beam.
33
 
#
34
 
       
35
 
# Version History
36
 
#
37
 
# v0.1 - Script only generates a multi-sided mesh object,
38
 
#           initial release for testing. 3/12/11
39
 
#
40
 
# v0.1.1 - Added 'C'-type beam, updated to work with 
41
 
#           api r35499. 3/13/11
42
 
#
43
 
# v0.1.2 - Totally changed the way beams are created, size
44
 
#           is now calculated based off width, length, & height
45
 
#           (x,y,z). Added ability to taper beams as well.
46
 
#           Add 'L' - type beam
47
 
#           Add 'T' - type beam
48
 
#           Add 'I' - type beam 
49
 
#
50
 
# v0.1.3 - Updated to work with api r41226, including using object_utils.py -
51
 
#           part of blender's bpy_extras scripts. This is what handles
52
 
#           the 'align to view', 'location', & 'rotation' options in the
53
 
#           toolshelf when creating mesh. Added wiki & tracker url. Fixed
54
 
#           a few bugs & fixed some debug prints that were still printing
55
 
#           to console.  
56
 
#     
57
 
 
58
 
import bpy
59
 
 
60
 
from bpy_extras import object_utils
61
 
 
62
 
 
63
 
def create_mesh (self, context, name, verts, faces, debug):
64
 
    # Creates mesh and object
65
 
    # name - name of object to create
66
 
    # verts - a list of vertex tuples
67
 
    # faces - a list of face tuples
68
 
    # debug - debug flag - if true prints data to console
69
 
           
70
 
    # Actually create mesh and object
71
 
    mesh = bpy.data.meshes.new(name)
72
 
 
73
 
    # add verts & faces to object
74
 
    mesh.from_pydata(verts, [], faces)
75
 
    mesh.update(calc_edges=True)
76
 
    
77
 
    if debug:
78
 
        print("create_mesh function called and finished")    
79
 
      
80
 
    return object_utils.object_data_add(context, mesh, operator=self)
81
 
 
82
 
 
83
 
def recalc_normals(debug):
84
 
    # Recalculate normals
85
 
    # parts of this script creates faces that are backwards or
86
 
    # have thier normals facing the wrong way, so recalculate them
87
 
    # debug - debug flag - if true prints data to console
88
 
    
89
 
    
90
 
    if bpy.context.mode != 'EDIT_MESH':
91
 
        bpy.ops.object.editmode_toggle()
92
 
        # Recalcuate normals
93
 
        bpy.ops.mesh.normals_make_consistent()
94
 
        bpy.ops.object.editmode_toggle()
95
 
        if debug:
96
 
            print("\nObjectMode")
97
 
    else:
98
 
        bpy.ops.mesh.normals_make_consistent()
99
 
        if debug:
100
 
            print("\nEditMode")
101
 
            
102
 
    return
103
 
 
104
 
 
105
 
def create_end_faces(verts_list, thick, debug):
106
 
    # Create End Faces
107
 
    # verts_list - list of vertices
108
 
    # thick - if true object is hollow, so construct loop of end faces
109
 
    #           instead of a solid end face
110
 
    # debug - if true prints values from this function to console
111
 
    
112
 
    # returns:
113
 
    # faces - a list of tuples defining the end faces
114
 
    
115
 
    faces = []
116
 
    
117
 
    num_of_verts = len(verts_list)
118
 
    faces_temp = []
119
 
 
120
 
    sides = 4 # sides - number of sides to mesh *added because of code re-write
121
 
    
122
 
    if thick:
123
 
        # has thickness, so build end faces            
124
 
        num_of_verts = int(num_of_verts / 2)
125
 
        
126
 
        # Create a list of the front faces
127
 
        for index in range(num_of_verts):
128
 
            if index == (num_of_verts - 1):
129
 
                faces_temp.append(verts_list[index])
130
 
                faces_temp.append(verts_list[index-index])
131
 
                faces_temp.append(verts_list[index+1])
132
 
                faces_temp.append(verts_list[index*2+1])
133
 
            else:
134
 
                faces_temp.append(verts_list[index])
135
 
                faces_temp.append(verts_list[index+1])
136
 
                faces_temp.append(verts_list[index+num_of_verts+1])
137
 
                faces_temp.append(verts_list[index+num_of_verts])
138
 
                        
139
 
            faces.append(tuple(faces_temp))
140
 
            faces_temp = []                
141
 
    else:
142
 
        #this code may not be needed, depends upon rewrite...
143
 
        if sides > 4:
144
 
            # more than 4 sides, so replace last list item (center vert) with first list item 
145
 
            # for looping and building faces
146
 
            center_vert = verts_list[num_of_verts - 1]
147
 
            verts_list[num_of_verts - 1] = verts_list[0]
148
 
 
149
 
            for index in range(int(num_of_verts - 1)):
150
 
                faces_temp.append(verts_list[index])
151
 
                faces_temp.append(verts_list[index + 1])
152
 
                faces_temp.append(center_vert)
153
 
                faces.append(tuple(faces_temp))
154
 
                faces_temp = []
155
 
        
156
 
        else:
157
 
            # create 1 end face
158
 
            for index in range(num_of_verts):
159
 
                faces_temp.append(verts_list[index])
160
 
            faces.append(tuple(faces_temp))               
161
 
    
162
 
    # print debug info to console
163
 
    if debug:
164
 
        print("\ncreate_end_faces Function Starts")
165
 
        print("\n End Face Verts list :", verts_list)
166
 
        print("\n End Faces: ", faces)
167
 
        print("\ncreate_end_faces Function Ends\n\n")
168
 
            
169
 
    return faces
170
 
 
171
 
 
172
 
def create_side_faces(front_verts, back_verts, debug):
173
 
    # Create side faces - simple bridging of front_verts & back_verts vertices,
174
 
    #                     both front_verts & back_verts must be ordered in same direction
175
 
    #                     with respect to y-axis
176
 
    # front_verts - a list of front face vertices
177
 
    # back_verts - a list of back face vertices
178
 
    # debug - if true prints values from this function to console
179
 
    
180
 
    # returns:
181
 
    # new_faces - a list of tuples defining the faces bridged between front_verts & back_verts
182
 
    
183
 
    # Number of faces to create
184
 
    num_of_faces = (len(front_verts))
185
 
    new_faces = []
186
 
    
187
 
    # add first value to end of lists for looping
188
 
    front_verts.append(front_verts[0])
189
 
    back_verts.append(back_verts[0])
190
 
    
191
 
    # Build the new_faces list with tuples defining each face    
192
 
    for index in range(num_of_faces):
193
 
        facestemp = (front_verts[index], front_verts[index+1], back_verts[index+1], back_verts[index])
194
 
        new_faces.append(facestemp)
195
 
    
196
 
    # print debug info to console
197
 
    if debug:
198
 
        print("\ncreate_side_faces Function Starts") 
199
 
        print("\n Number of faces to create: ", num_of_faces)
200
 
        print("\n New faces :", new_faces)
201
 
        print("\ncreate_side_faces Function Ends\n\n")
202
 
 
203
 
    return new_faces
204
 
 
205
 
 
206
 
def calc_end_verts(size, y_off, thick, debug):
207
 
    # Calculates vertex location for end of mesh
208
 
    
209
 
    # size - tuple of x,y,z dimensions of mesh to create
210
 
    # y_off - y offset, lets function know where to create verts on y-axis
211
 
    # thick - thickness, if not zero this is the thickness of a hollow mesh
212
 
    #         with the inner faces inset from size dimensions
213
 
    # debug - if true prints values from this function to console
214
 
    
215
 
    # returns:
216
 
    # verts - a list of tuples of the x,y,z location of each vertex
217
 
    
218
 
    verts = []
219
 
    
220
 
    if debug:
221
 
        print ("\ncalc_end_verts Function Starts\n")
222
 
        print("\nsize = ",size)
223
 
        print("y_off = ",y_off)
224
 
        
225
 
    # Create vertices by calculation 
226
 
    x_pos = 0 + size[0]/2
227
 
    z_pos = 0 + size[2]/2
228
 
    verts.append((x_pos, y_off, z_pos))
229
 
 
230
 
    x_pos = 0 - size[0]/2
231
 
    z_pos = 0 + size[2]/2
232
 
    verts.append((x_pos, y_off, z_pos))
233
 
    
234
 
    x_pos = 0 - size[0]/2
235
 
    z_pos = 0 - size[2]/2
236
 
    verts.append((x_pos, y_off, z_pos)) 
237
 
    
238
 
    x_pos = 0 + size[0]/2
239
 
    z_pos = 0 - size[2]/2
240
 
    verts.append((x_pos, y_off, z_pos))   
241
 
         
242
 
    if thick:
243
 
        # has thickness, so calculate inside vertices
244
 
        #### not too sure about this, but it does work the way the 
245
 
        #### solidify modifier works, so leaving as is for now
246
 
        x_pos = size[0] - (thick * 2)
247
 
        z_pos = size[2] - (thick * 2)
248
 
        size = (x_pos, y_off, z_pos)
249
 
        
250
 
        # Create vertices by calculation 
251
 
        x_pos = 0 + size[0]/2
252
 
        z_pos = 0 + size[2]/2
253
 
        verts.append((x_pos, y_off, z_pos))
254
 
 
255
 
        x_pos = 0 - size[0]/2
256
 
        z_pos = 0 + size[2]/2
257
 
        verts.append((x_pos, y_off, z_pos))
258
 
    
259
 
        x_pos = 0 - size[0]/2
260
 
        z_pos = 0 - size[2]/2
261
 
        verts.append((x_pos, y_off, z_pos)) 
262
 
    
263
 
        x_pos = 0 + size[0]/2
264
 
        z_pos = 0 - size[2]/2
265
 
        verts.append((x_pos, y_off, z_pos))          
266
 
            
267
 
    if debug:
268
 
        print ("verts :", verts)
269
 
        print ("\ncalc_end_verts Function Ends.\n\n")
270
 
    
271
 
    return verts
272
 
 
273
 
 
274
 
def adjust_c_beam_verts(verts, taper, debug):
275
 
    # Adjusts verts produced to correct c beam shape
276
 
    # verts - a list of tuples of vertex locations for one end of beam
277
 
    # taper - % to taper outside verts by
278
 
    # debug - if true values are printed to console for debugging
279
 
    
280
 
    # returns:
281
 
    # verts - the corrected list of tuples of the adjustec vertex locations
282
 
    
283
 
    # This function corrects vertex locations to properly shape the
284
 
    # beam, because creating a c beam uses the same code as the 
285
 
    # create_rectangular_beam function does. Therefore the 5th & 6th
286
 
    # vertice's z location needs to be changed to match the 1st & 2nd
287
 
    # vertice's z location.
288
 
 
289
 
    vert_orig = verts[0]
290
 
    
291
 
    # get 3rd value, the z location
292
 
    vert_z = vert_orig[2] 
293
 
    # get 1st value, the x location, for vert taper calcs    
294
 
    vert_x = vert_orig[0]
295
 
  
296
 
    # vert_z has the z value to be used in the 5th & 6th verts
297
 
    # get value of 5th vert 
298
 
    vert_temp = verts[4]
299
 
    
300
 
 
301
 
    
302
 
    # calculate the amount of taper, updating vert_x
303
 
    # with the new value calculated.
304
 
    vert_x = calc_taper(vert_orig[0], vert_temp[0], taper)
305
 
    
306
 
    vert_new = (vert_x,vert_temp[1],vert_z)
307
 
    
308
 
    if debug:
309
 
        print ("\nadjust_c_beam_verts function starting")
310
 
        print ("vert_orig = ",vert_orig[0])
311
 
        print ("vert_x = ",vert_x)
312
 
        print("vert_temp =",vert_temp)
313
 
        print("vert_new =",vert_new)
314
 
 
315
 
    # update 5th vert with new value
316
 
    verts[4] = vert_new
317
 
    
318
 
    vert_orig = verts[1]
319
 
    
320
 
    # get 3rd value, the z location
321
 
    vert_z = vert_orig[2] 
322
 
    # get 1st value, the x location, for vert taper calcs    
323
 
    vert_x = vert_orig[0]
324
 
    # vert_z has the z value to be used in the 5th & 6th verts
325
 
    # get value of 5th vert 
326
 
    vert_temp = verts[5]
327
 
    
328
 
 
329
 
    
330
 
    # calculate the amount of taper, updating vert_x
331
 
    # with the new value calculated.
332
 
    vert_x = calc_taper(vert_orig[0], vert_temp[0], taper)
333
 
    
334
 
    vert_new = (vert_x,vert_temp[1],vert_z)
335
 
    
336
 
    if debug:
337
 
        print ("vert_orig = ",vert_orig[0])
338
 
        print ("vert_x = ",vert_x)
339
 
        print("vert_temp =",vert_temp)
340
 
        print("vert_new =",vert_new)
341
 
    
342
 
    # update 6th vert with new value
343
 
    verts[5] = vert_new    
344
 
    
345
 
    if debug:
346
 
        print("\n adjust_c_beam_verts function ending")
347
 
        print("verts =", verts)
348
 
        
349
 
    return verts        
350
 
 
351
 
 
352
 
def calc_taper(outer_vert, inner_vert, taper):
353
 
    # Calculate tapered edges of beam - inner vert is moved towards
354
 
    #    outer vert based upon percentage value in taper
355
 
    # outer_vert - the outside vertex
356
 
    # inner_vert - the inside vertex to be moved
357
 
    # taper - percentage to move vert
358
 
    
359
 
    # returns:
360
 
    # adjusted_vert - the calculated vertex
361
 
 
362
 
    #print("outer_vert =",outer_vert,"inner_vert",inner_vert)
363
 
    
364
 
    # taper values range from 0 to 100 for UI, but for calculations
365
 
    # this value needs to be flipped, ranging from 100 to 0
366
 
    taper = 100 - taper
367
 
    
368
 
    # calcuate taper & adjust vertex
369
 
    vert_delta = inner_vert - outer_vert
370
 
    adjusted_vert = outer_vert + ((vert_delta/100) * taper)    
371
 
    
372
 
    #print("adjusted_vert =", adjusted_vert)    
373
 
    return adjusted_vert
374
 
 
375
 
    
376
 
def create_rectangular_beam(size, thick, debug):
377
 
    # Creates a rectangular beam mesh object
378
 
    # size - tuple of x,y,z dimensions of box
379
 
    # thick - thickness, if not zero this is the thickness of a hollow 
380
 
    #         box with inner faces inset from size dimensions
381
 
    # debug - if true prints values from this function to console
382
 
    
383
 
    # returns: 
384
 
    # verts_final - a list of tuples of the x, y, z, location of each vertice
385
 
    # faces_final - a list of tuples of the vertices that make up each face  
386
 
    
387
 
    # Create temporarylists to hold vertices locations
388
 
    verts_front_temp=[]
389
 
    verts_back_temp=[]
390
 
    
391
 
    #calculate y offset from center for front vertices
392
 
    y_off = size[1]/2 
393
 
      
394
 
        
395
 
    # Create front vertices by calculation
396
 
    verts_front_temp = calc_end_verts(size, y_off, thick, debug)
397
 
    
398
 
    # re-calculate y offset from center for back vertices
399
 
    y_off = 0 - y_off
400
 
    
401
 
    # Create back vertices by calculation
402
 
    verts_back_temp = calc_end_verts(size, y_off, thick, debug)
403
 
    
404
 
    # Combine all vertices into a final list of tuples
405
 
    verts_final = verts_front_temp + verts_back_temp   
406
 
           
407
 
    # Print debug info to console
408
 
    if debug:
409
 
        print("\ncreate_multi_side_box Function Start")
410
 
        print("\n Front vertices :", verts_front_temp)
411
 
        print("\n Back vertices:", verts_back_temp)
412
 
        print("\n All vertices:", verts_final)
413
 
                      
414
 
    # Create front face
415
 
    faces_front_temp = []
416
 
    verts_front_list = []
417
 
    numofverts = len(verts_front_temp)
418
 
    
419
 
    # Build vertex list
420
 
    for index in range(numofverts):
421
 
        verts_front_list.append(index)
422
 
       
423
 
    faces_front_temp = create_end_faces(verts_front_list, thick, debug) 
424
 
    
425
 
    # Create back face
426
 
    faces_back_temp = []
427
 
    verts_back_list = []
428
 
    numofverts = len(verts_back_temp)
429
 
    
430
 
    # Build vertex list
431
 
    for index in range(numofverts):
432
 
        verts_back_list.append(index + len(verts_back_temp))
433
 
        
434
 
    faces_back_temp = create_end_faces(verts_back_list, thick, debug)
435
 
 
436
 
    # Create side faces
437
 
    faces_side_temp = []
438
 
    
439
 
    # better code needed here???
440
 
    if thick:
441
 
        # Object has thickness, create list of outside vertices
442
 
        numofverts = len(verts_front_list)
443
 
        verts_front_temp = verts_front_list[0:int(numofverts/2)]
444
 
        verts_back_temp = verts_back_list[0:int(numofverts/2)]
445
 
        
446
 
        faces_side_temp = create_side_faces(verts_front_temp, verts_back_temp, debug)
447
 
        
448
 
        # Create list of inside vertices
449
 
        verts_front_temp = verts_front_list[int(numofverts/2):numofverts]
450
 
        verts_back_temp = verts_back_list[int(numofverts/2):numofverts]
451
 
        
452
 
        faces_side_temp += create_side_faces(verts_front_temp, verts_back_temp, debug)            
453
 
    else:
454
 
        # Create list of only outside faces
455
 
        faces_side_temp = create_side_faces(verts_front_list, verts_back_list, debug)
456
 
    
457
 
    # Combine all faces 
458
 
    faces_final = faces_front_temp + faces_back_temp + faces_side_temp
459
 
    
460
 
    # print debug info to console   
461
 
    if debug:
462
 
        print("\ncreate_multi_side_box Function")
463
 
        print("\nAll faces :",faces_final)
464
 
        print("\ncreate_multi_side_box Function Ends\n\n")
465
 
    
466
 
    return verts_final, faces_final
467
 
 
468
 
 
469
 
def create_C_beam(size, thick, taper, debug):
470
 
    # Creates a C or U shaped mesh beam object 
471
 
    # size - tuple of x,y,z dimensions of beam
472
 
    # thick - thickness, the amount the inner faces will be
473
 
    #           inset from size dimensions
474
 
    # taper - % to taper outside edges by
475
 
    # debug - if true prints values from this function to console
476
 
    
477
 
    # returns: 
478
 
    # verts_final - a list of tuples of the x, y, z, location of each vertice
479
 
    # faces_final - a list of tuples of the vertices that make up each face
480
 
    
481
 
    # print debug info to console
482
 
    if debug:
483
 
        print ("\ncreate_C_beam - function called")
484
 
 
485
 
    # Get y offset of vertices from center
486
 
    y_off = size[1] / 2
487
 
    
488
 
    # Create temporarylists to hold vertices locations
489
 
    verts_front_temp=[]
490
 
    verts_back_temp=[]
491
 
    
492
 
    # Create front vertices by calculation
493
 
    verts_front_temp = calc_end_verts(size, y_off, thick, debug)
494
 
    # Additional adjustment to the verts needed - 5th & 6th verts
495
 
    # needed because the calc_end_verts creates a rectangluar beam
496
 
    # the insides are inset, for a U channel we need the inside
497
 
    # verts on the open end to match the z-loc of the outside verts 
498
 
    verts_front_temp = adjust_c_beam_verts(verts_front_temp, taper, debug)       
499
 
    
500
 
    # recalculate y_off for other end vertices
501
 
    y_off = 0 - y_off
502
 
    
503
 
    # Create back vertices by calculation
504
 
    verts_back_temp = calc_end_verts(size, y_off, thick, debug)
505
 
    # Additional adjustment to the verts needed - the z location
506
 
    verts_back_temp = adjust_c_beam_verts(verts_back_temp, taper, debug)  
507
 
    
508
 
    # Combine all vertices into a final list of tuples
509
 
    verts_final = verts_front_temp + verts_back_temp   
510
 
  
511
 
    # Print debug info to console
512
 
    if debug:
513
 
        print("\ncreate_C_beam function start")
514
 
        print("\n Front vertices :", verts_front_temp)
515
 
        print("\n Back vertices:", verts_back_temp)
516
 
        print("\n All vertices:", verts_final)
517
 
    
518
 
    # Create front face
519
 
    faces_front_temp = []
520
 
    verts_front_list = []
521
 
    numofverts = len(verts_front_temp)
522
 
    
523
 
    # Build vertex list
524
 
    for index in range(numofverts):
525
 
        verts_front_list.append(index)
526
 
    # problem area   
527
 
    faces_front_temp = create_end_faces(verts_front_list, thick, debug) 
528
 
    # Remove 1st face - only 3 end faces needed
529
 
    faces_front_temp = faces_front_temp[1:4]
530
 
        
531
 
    # Create back face
532
 
    faces_back_temp = []
533
 
    verts_back_list = []
534
 
    numofverts = len(verts_back_temp)
535
 
    
536
 
    # Build vertex list
537
 
    for index in range(numofverts):
538
 
        verts_back_list.append(index + len(verts_back_temp))
539
 
      
540
 
    faces_back_temp = create_end_faces(verts_back_list, thick, debug)
541
 
    # Remove 1st face - only 3 end faces needed
542
 
    faces_back_temp = faces_back_temp[1:4]
543
 
 
544
 
    # Create list of outside vertices for the 3 outside faces
545
 
    numofverts = (len(verts_front_list))
546
 
    verts_front_temp = verts_front_list[0:int(numofverts/2)]
547
 
    verts_back_temp = verts_back_list[0:int(numofverts/2)]
548
 
        
549
 
    faces_side_temp = create_side_faces(verts_front_temp, verts_back_temp, debug)
550
 
    # create_side_faces creates 4 outside faces, we only want 3
551
 
    # so remove the 1st face
552
 
    faces_side_temp  = faces_side_temp[1:]
553
 
    
554
 
    # Create list of inside vertices for the 3 inside faces
555
 
    verts_front_temp = verts_front_list[int(numofverts/2):numofverts]
556
 
    verts_back_temp = verts_back_list[int(numofverts/2):numofverts]
557
 
        
558
 
    faces_side_temp += create_side_faces(verts_front_temp, verts_back_temp, debug)
559
 
    # create_side_faces creates 4 outside faces, we only want 3
560
 
    # so remove the 1st face
561
 
    faces_side_temp  = faces_side_temp[0:3] + faces_side_temp[4:]
562
 
    
563
 
    # fill in top two faces
564
 
    faces_side_temp.append((0, 4, 12, 8))
565
 
    faces_side_temp.append((5, 1, 9, 13))    
566
 
    
567
 
    # Combine all faces 
568
 
    faces_final = faces_front_temp + faces_back_temp + faces_side_temp
569
 
 
570
 
    # Print debug info to console
571
 
    if debug:
572
 
        print("\ncreate_C_beam function") 
573
 
        print("\nAll faces =", faces_final)
574
 
        print("\ncreate_C_beam function ending")
575
 
         
576
 
    return verts_final, faces_final
577
 
 
578
 
 
579
 
def create_L_beam(size, thick, taper, debug):
580
 
    # Creates a L shaped mesh beam object
581
 
    # size - tuple of x,y,z dimensions of beam
582
 
    # thick - thickness, the amount the inner faces will be
583
 
    #           inset from size dimensions
584
 
    # taper - % to taper outside edges by
585
 
    # debug - if true prints values from this function to console
586
 
    
587
 
    # returns:
588
 
    # verts_final - a list of tuples of the x, y, z, location of each vertice
589
 
    # faces_final - a list of tuples of the vertices that make up each face
590
 
    
591
 
    if debug:
592
 
        print("\ncreate_L_beam function starting")
593
 
 
594
 
    # Get offset of vertices from center
595
 
    x_off = size[0] / 2
596
 
    y_off = size[1] / 2
597
 
    z_off = size[2] / 2
598
 
    
599
 
    # Create temporarylists to hold vertices locations
600
 
    verts_front_temp=[]
601
 
    verts_back_temp=[]
602
 
    
603
 
    # Create front vertices by calculation
604
 
    verts_front_temp = [(0 - x_off, 0 - y_off, z_off), \
605
 
        (0 - (x_off - thick), 0 - y_off, z_off), \
606
 
        (0 - (x_off - thick), 0 - y_off, 0 - (z_off - thick)), \
607
 
        (x_off, 0 - y_off, 0 - (z_off - thick)), \
608
 
        (x_off, 0 - y_off, 0 - z_off), \
609
 
        (0 - x_off, 0 - y_off, 0 - z_off)]
610
 
    
611
 
    # Adjust taper
612
 
    vert_outside = verts_front_temp[0]
613
 
    vert_inside = verts_front_temp[1]
614
 
    verts_front_temp[1] = [(calc_taper(vert_outside[0], vert_inside[0], taper)), vert_inside[1],vert_inside[2]]
615
 
   
616
 
    vert_outside = verts_front_temp[4]
617
 
    vert_inside = verts_front_temp[3]
618
 
    verts_front_temp[3] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
619
 
    
620
 
    # Create back vertices by calculation
621
 
    verts_back_temp = [(0 - x_off, y_off, z_off), \
622
 
        (0 - (x_off - thick), y_off, z_off), \
623
 
        (0 - (x_off - thick), y_off, 0 - (z_off - thick)), \
624
 
        (x_off, y_off, 0 - (z_off - thick)), \
625
 
        (x_off, y_off, 0 - z_off), \
626
 
        (0 - x_off, y_off, 0 - z_off)]
627
 
 
628
 
    # Adjust taper
629
 
    vert_outside = verts_back_temp[0]
630
 
    vert_inside = verts_back_temp[1]
631
 
    verts_back_temp[1] = [(calc_taper(vert_outside[0], vert_inside[0], taper)), vert_inside[1],vert_inside[2]]   
632
 
    
633
 
    vert_outside = verts_back_temp[4]
634
 
    vert_inside = verts_back_temp[3]
635
 
    verts_back_temp[3] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))] 
636
 
    
637
 
    verts_final = verts_front_temp + verts_back_temp
638
 
    
639
 
    if debug:
640
 
        print("\n verts_front_temp =", verts_front_temp)
641
 
        print("\n verts_back_temp =", verts_back_temp)
642
 
        print("\n verts_final =", verts_final)
643
 
    
644
 
    # define end faces, only 4 so just coded
645
 
    faces_front_temp = []
646
 
    faces_back_temp = []
647
 
    faces_side_temp = []
648
 
    
649
 
    faces_front_temp = [(0, 1, 2, 5), (2, 3, 4, 5)]
650
 
    faces_back_temp = [(6, 7, 8, 11), (8, 9, 10, 11)]
651
 
    
652
 
    verts_front_list = []
653
 
    verts_back_list = []
654
 
    num_of_verts = len(verts_front_temp)
655
 
    
656
 
    # build lists of back and front verts for create_side_faces function
657
 
    for index in range(num_of_verts):
658
 
        verts_front_list.append(index)
659
 
    for index in range(num_of_verts):
660
 
        verts_back_list.append(index  + 6)
661
 
    
662
 
    faces_side_temp = create_side_faces(verts_front_list, verts_back_list, debug)
663
 
        
664
 
    faces_final = faces_front_temp + faces_back_temp + faces_side_temp
665
 
    
666
 
    if debug:
667
 
        print("\n faces_front_temp =", faces_front_temp)
668
 
        print("\n faces_back_temp =", faces_back_temp)
669
 
        print("\n faces_side_temp =", faces_side_temp)
670
 
        print("\n faces_final =", faces_final)
671
 
        print("\ncreate_L_beam function ending")
672
 
        
673
 
    return verts_final, faces_final
674
 
 
675
 
 
676
 
 
677
 
def create_T_beam(size, thick, taper, debug):
678
 
    # Creates a T shaped mesh beam object
679
 
    # size - tuple of x,y,z dimensions of beam
680
 
    # thick - thickness, the amount the inner faces will be
681
 
    #           inset from size dimensions
682
 
    # taper - % to taper outside edges by
683
 
    # debug - if true prints values from this function to console
684
 
    
685
 
    # returns:
686
 
    # verts_final - a list of tuples of the x, y, z, location of each vertice
687
 
    # faces_final - a list of tuples of the vertices that make up each face
688
 
    debug = 0
689
 
    
690
 
    if debug:
691
 
        print("\ncreate_T_beam function starting")
692
 
 
693
 
    # Get offset of vertices from center
694
 
    x_off = size[0] / 2
695
 
    y_off = size[1] / 2
696
 
    z_off = size[2] / 2
697
 
    thick_off = thick / 2
698
 
 
699
 
    # Create temporarylists to hold vertices locations
700
 
    verts_front_temp=[]
701
 
    verts_back_temp=[]
702
 
    
703
 
    # Create front vertices by calculation
704
 
    verts_front_temp = [(0 - x_off, 0 - y_off, z_off), \
705
 
        (0 - thick_off, 0 - y_off, z_off), \
706
 
        (thick_off, 0 - y_off, z_off), \
707
 
        (x_off, 0 - y_off, z_off), \
708
 
        (x_off, 0 - y_off, z_off - thick), \
709
 
        (thick_off, 0 - y_off, z_off - thick), \
710
 
        (thick_off, 0 - y_off, 0 - z_off), \
711
 
        (0 - thick_off, 0 - y_off, 0 - z_off), \
712
 
        (0 - thick_off, 0 - y_off, z_off - thick), \
713
 
        (0 - x_off, 0 - y_off, z_off - thick)]
714
 
 
715
 
    # Adjust taper
716
 
    vert_outside = verts_front_temp[0]
717
 
    vert_inside = verts_front_temp[9]
718
 
    verts_front_temp[9] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
719
 
 
720
 
    vert_outside = verts_front_temp[3]
721
 
    vert_inside = verts_front_temp[4]
722
 
    verts_front_temp[4] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]  
723
 
 
724
 
    # Adjust taper of bottom of beam, so 0 the center
725
 
    # now becomes vert_outside, and vert_inside is calculated
726
 
    # 1/2 way towards center
727
 
    vert_outside = (0, 0 - y_off, 0 - z_off)
728
 
    vert_inside = verts_front_temp[6]
729
 
    verts_front_temp[6] = [(calc_taper(vert_outside[0], vert_inside[0], taper)), vert_inside[1], vert_inside[2]]  
730
 
 
731
 
    vert_outside = (0, 0 - y_off, 0 - z_off)
732
 
    vert_inside = verts_front_temp[7]
733
 
    verts_front_temp[7] = [(calc_taper(vert_outside[0], vert_inside[0], taper)), vert_inside[1], vert_inside[2]]
734
 
 
735
 
    # Create fack vertices by calculation
736
 
    verts_back_temp = [(0 - x_off, y_off, z_off), \
737
 
        (0 - thick_off, y_off, z_off), \
738
 
        (thick_off, y_off, z_off), \
739
 
        (x_off, y_off, z_off), \
740
 
        (x_off, y_off, z_off - thick), \
741
 
        (thick_off, y_off, z_off - thick), \
742
 
        (thick_off, y_off, 0 - z_off), \
743
 
        (0 - thick_off, y_off, 0 - z_off), \
744
 
        (0 - thick_off, y_off, z_off - thick), \
745
 
        (0 - x_off, y_off, z_off - thick)]
746
 
 
747
 
    # Adjust taper
748
 
    vert_outside = verts_back_temp[0]
749
 
    vert_inside = verts_back_temp[9]
750
 
    verts_back_temp[9] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
751
 
 
752
 
    vert_outside = verts_back_temp[3]
753
 
    vert_inside = verts_back_temp[4]
754
 
    verts_back_temp[4] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
755
 
    
756
 
    # Adjust taper of bottom of beam, so 0 the center
757
 
    # now becomes vert_outside, and vert_inside is calculated
758
 
    # 1/2 way towards center
759
 
    vert_outside = (0, 0 - y_off, 0 - z_off)
760
 
    vert_inside = verts_back_temp[6]
761
 
    verts_back_temp[6] = [(calc_taper(vert_outside[0], vert_inside[0], taper)), vert_inside[1], vert_inside[2]]  
762
 
 
763
 
    vert_outside = (0, 0 - y_off, 0 - z_off)
764
 
    vert_inside = verts_back_temp[7]
765
 
    verts_back_temp[7] = [(calc_taper(vert_outside[0], vert_inside[0], taper)), vert_inside[1], vert_inside[2]]
766
 
        
767
 
    verts_final = verts_front_temp + verts_back_temp
768
 
    
769
 
    
770
 
    # define end faces, only 8 so just coded
771
 
    faces_front_temp = []
772
 
    faces_back_temp = []
773
 
    faces_side_temp = []
774
 
    
775
 
    faces_front_temp = [(0, 1, 8, 9), (1, 2, 5, 8), \
776
 
        (2, 3, 4, 5), (5, 6, 7, 8)]
777
 
        
778
 
    faces_back_temp = [(10, 11, 18, 19), (11, 12, 15, 18), \
779
 
        (12, 13, 14, 15), (15, 16, 17,  18)]
780
 
 
781
 
    verts_front_list = []
782
 
    verts_back_list = []
783
 
    num_of_verts = len(verts_front_temp)
784
 
    
785
 
    # build lists of back and front verts for create_side_faces function
786
 
    for index in range(num_of_verts):
787
 
        verts_front_list.append(index)
788
 
    for index in range(num_of_verts):
789
 
        verts_back_list.append(index  + 10)
790
 
    
791
 
    faces_side_temp = create_side_faces(verts_front_list, verts_back_list, debug)
792
 
    
793
 
    faces_final = faces_front_temp + faces_back_temp + faces_side_temp
794
 
 
795
 
    if debug:
796
 
        print("\ncreate_T_beam function ending")    
797
 
        
798
 
    return verts_final, faces_final
799
 
 
800
 
 
801
 
def create_I_beam(size, thick, taper, debug):
802
 
    # Creates a T shaped mesh beam object
803
 
    # size - tuple of x,y,z dimensions of beam
804
 
    # thick - thickness, the amount the inner faces will be
805
 
    #           inset from size dimensions
806
 
    # taper - % to taper outside edges by
807
 
    # debug - if true prints values from this function to console
808
 
    
809
 
    # returns:
810
 
    # verts_final - a list of tuples of the x, y, z, location of each vertice
811
 
    # faces_final - a list of tuples of the vertices that make up each face
812
 
    debug = 0
813
 
    
814
 
    if debug:
815
 
        print("\ncreate_I_beam function starting")
816
 
 
817
 
    # Get offset of vertices from center
818
 
    x_off = size[0] / 2
819
 
    y_off = size[1] / 2
820
 
    z_off = size[2] / 2
821
 
    thick_off = thick / 2
822
 
 
823
 
    # Create temporarylists to hold vertices locations
824
 
    verts_front_temp=[]
825
 
    verts_back_temp=[]
826
 
    
827
 
    # Create front vertices by calculation
828
 
    verts_front_temp = [(0 - x_off, 0 - y_off, z_off), \
829
 
        (0 - thick_off, 0 - y_off, z_off), \
830
 
        (thick_off, 0 - y_off, z_off), \
831
 
        (x_off, 0 - y_off, z_off), \
832
 
        (x_off, 0 - y_off, z_off - thick), \
833
 
        (thick_off, 0 - y_off, z_off - thick), \
834
 
        (thick_off, 0 - y_off, 0 - z_off + thick), \
835
 
        (x_off, 0 - y_off, 0 - z_off + thick), \
836
 
        (x_off, 0 - y_off, 0 - z_off), \
837
 
        (thick_off, 0 - y_off, 0 - z_off), \
838
 
        (0 - thick_off, 0 - y_off, 0 - z_off), \
839
 
        (0 - x_off, 0 - y_off, 0 - z_off), \
840
 
        (0 - x_off, 0 - y_off, 0 -z_off  + thick), \
841
 
        (0 - thick_off, 0 - y_off, 0 - z_off + thick), \
842
 
        (0 - thick_off, 0 - y_off, z_off - thick), \
843
 
        (0 - x_off, 0 - y_off, z_off - thick)]
844
 
    
845
 
    # Adjust taper
846
 
    vert_outside = verts_front_temp[0]
847
 
    vert_inside = verts_front_temp[15]
848
 
    verts_front_temp[15] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
849
 
    
850
 
    vert_outside = verts_front_temp[3]
851
 
    vert_inside = verts_front_temp[4]
852
 
    verts_front_temp[4] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
853
 
    
854
 
    vert_outside = verts_front_temp[8]
855
 
    vert_inside = verts_front_temp[7]
856
 
    verts_front_temp[7] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
857
 
    
858
 
    vert_outside = verts_front_temp[11]
859
 
    vert_inside = verts_front_temp[12]
860
 
    verts_front_temp[12] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
861
 
 
862
 
    # Create back vertices by calculation
863
 
    verts_back_temp = [(0 - x_off, y_off, z_off), \
864
 
        (0 - thick_off, y_off, z_off), \
865
 
        (thick_off, y_off, z_off), \
866
 
        (x_off, y_off, z_off), \
867
 
        (x_off, y_off, z_off - thick), \
868
 
        (thick_off, y_off, z_off - thick), \
869
 
        (thick_off, y_off, 0 - z_off + thick), \
870
 
        (x_off, y_off, 0 - z_off + thick), \
871
 
        (x_off, y_off, 0 - z_off), \
872
 
        (thick_off, y_off, 0 - z_off), \
873
 
        (0 - thick_off, y_off, 0 - z_off), \
874
 
        (0 - x_off, y_off, 0 - z_off), \
875
 
        (0 - x_off, y_off, 0 -z_off  + thick), \
876
 
        (0 - thick_off, y_off, 0 - z_off + thick), \
877
 
        (0 - thick_off, y_off, z_off - thick), \
878
 
        (0 - x_off, y_off, z_off - thick)]
879
 
 
880
 
    # Adjust taper
881
 
    vert_outside = verts_back_temp[0]
882
 
    vert_inside = verts_back_temp[15]
883
 
    verts_back_temp[15] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
884
 
    
885
 
    vert_outside = verts_back_temp[3]
886
 
    vert_inside = verts_back_temp[4]
887
 
    verts_back_temp[4] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
888
 
    
889
 
    vert_outside = verts_back_temp[8]
890
 
    vert_inside = verts_back_temp[7]
891
 
    verts_back_temp[7] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
892
 
    
893
 
    vert_outside = verts_back_temp[11]
894
 
    vert_inside = verts_back_temp[12]
895
 
    verts_back_temp[12] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]       
896
 
 
897
 
    verts_final = verts_front_temp + verts_back_temp
898
 
 
899
 
 
900
 
# define end faces, only 7 per end, so just coded
901
 
    faces_front_temp = []
902
 
    faces_back_temp = []
903
 
    faces_side_temp = []
904
 
    
905
 
    faces_front_temp = [(0, 1, 14, 15), (1, 2, 5, 14), \
906
 
        (2, 3, 4, 5), (6, 7, 8, 9), \
907
 
        (6, 9, 10, 13), (12, 13, 10, 11), \
908
 
        (5, 6, 13, 14)]
909
 
        
910
 
    faces_back_temp = [(16, 17, 30, 31), (17, 18, 21, 30), \
911
 
        (18, 19, 20, 21), (22, 23, 24, 25), \
912
 
        (22, 25, 26, 29), (28, 29, 26, 27), \
913
 
        (21, 22, 29, 30)]
914
 
        
915
 
    verts_front_list = []
916
 
    verts_back_list = []
917
 
    num_of_verts = len(verts_front_temp)
918
 
    
919
 
    # build lists of back and front verts for create_side_faces function
920
 
    for index in range(num_of_verts):
921
 
        verts_front_list.append(index)
922
 
    for index in range(num_of_verts):
923
 
        verts_back_list.append(index  + 16)
924
 
    
925
 
    faces_side_temp = create_side_faces(verts_front_list, verts_back_list, debug)
926
 
    
927
 
    faces_final = faces_front_temp + faces_back_temp + faces_side_temp   
928
 
    
929
 
    if debug:
930
 
        print("\ncreate_I_beam function ending")
931
 
    
932
 
    return verts_final, faces_final
933
 
 
934
 
        
935
 
 
936
 
# Define "Add_Rectangular_Beam" operator
937
 
########### Needs Work ###############        
938
 
class Add_Rectangular_Beam(bpy.types.Operator):
939
 
    
940
 
    bl_idname = "mesh.primitive_rectangle_add"
941
 
    bl_label = "Add Rectangluar Beam"
942
 
    bl_description = "Create a Rectangular Beam mesh"
943
 
    bl_options = {'REGISTER', 'UNDO'}
944
 
        
945
 
    mesh_z_size = bpy.props.FloatProperty(name = "Height(z)",
946
 
        description = "Height (along the z-axis) of mesh",
947
 
        min = 0.01,
948
 
        max = 100,
949
 
        default = 1)
950
 
        
951
 
    mesh_x_size = bpy.props.FloatProperty(name = "Width(x)",
952
 
        description = "Width (along the x-axis) of mesh",
953
 
        min = 0.01,
954
 
        max = 100,
955
 
        default = .5)
956
 
        
957
 
    mesh_y_size = bpy.props.FloatProperty(name = "Length(y)",
958
 
        description = "Length (along y-axis) of mesh",
959
 
        min = 0.01,
960
 
        max = 100,
961
 
        default = 2)
962
 
            
963
 
    thick_bool = bpy.props.BoolProperty(name = "Hollow",
964
 
        description = "Create a hollow mesh with a defined thickness",
965
 
        default = True)
966
 
 
967
 
    thick = bpy.props.FloatProperty(name = "Thickness",
968
 
        description = "Thickness of hollow mesh",
969
 
        min = 0.01,
970
 
        max = 1,
971
 
        default = 0.1)
972
 
        
973
 
    # generic transform props
974
 
    # required by object_utils.py - part of blender's
975
 
    # code and is what handles alignment amongst other
976
 
    # things.
977
 
    view_align = bpy.props.BoolProperty(
978
 
            name="Align to View",
979
 
            default=False
980
 
            )
981
 
    location = bpy.props.FloatVectorProperty(
982
 
            name="Location",
983
 
            subtype='TRANSLATION',
984
 
            )
985
 
    rotation = bpy.props.FloatVectorProperty(
986
 
            name="Rotation",
987
 
            subtype='EULER',
988
 
            )
989
 
            
990
 
    # Define tool parameter layout
991
 
    def draw(self, context):
992
 
        layout = self.layout
993
 
        layout.prop(self, 'mesh_z_size')
994
 
        layout.prop(self, 'mesh_x_size')
995
 
        layout.prop(self, 'mesh_y_size')
996
 
        layout.prop(self, 'thick_bool')
997
 
        if self.thick_bool:
998
 
            layout.prop(self, 'thick')
999
 
        layout.prop(self, 'view_align')
1000
 
        col = layout.column()
1001
 
        col.prop(self, 'location')
1002
 
        col.prop(self, 'rotation')
1003
 
                
1004
 
    def execute(self, context):
1005
 
        # debug flag - True prints debug info to console
1006
 
        debug = 0
1007
 
        
1008
 
        size = (self.mesh_x_size, self.mesh_y_size, self.mesh_z_size)
1009
 
        if self.thick_bool is True:
1010
 
            thick = self.thick
1011
 
        else:
1012
 
            thick = 0
1013
 
                        
1014
 
        verts, faces = create_rectangular_beam(size, thick, debug)
1015
 
            
1016
 
        if debug:
1017
 
            print("\nCreated Verts:", verts)
1018
 
            print("\nCreated Faces:", faces)
1019
 
                
1020
 
        create_mesh(self, context, "Rectangular Beam", verts, faces, debug)
1021
 
        
1022
 
        recalc_normals(debug)        
1023
 
        
1024
 
        return {'FINISHED'}
1025
 
 
1026
 
'''
1027
 
    def invoke(self, context, event):
1028
 
        #self.align_matrix = align_matrix(context)
1029
 
        self.execute(context)
1030
 
        return {'FINISHED'}    
1031
 
'''
1032
 
 
1033
 
 
1034
 
# Define "Add_C_Beam" operator        
1035
 
class Add_C_Beam(bpy.types.Operator):
1036
 
    
1037
 
    bl_idname = "mesh.primitive_c_beam_add"
1038
 
    bl_label = "Add C or U Channel"
1039
 
    bl_description = "Create a C or U channel mesh"
1040
 
    bl_options = {'REGISTER', 'UNDO'}
1041
 
    
1042
 
        
1043
 
    mesh_z_size = bpy.props.FloatProperty(name = "Height(z)",
1044
 
        description = "Height (along the z-axis) of mesh",
1045
 
        min = 0.01,
1046
 
        max = 100,
1047
 
        default = 1)
1048
 
        
1049
 
    mesh_x_size = bpy.props.FloatProperty(name = "Width(x)",
1050
 
        description = "Width (along the x-axis) of mesh",
1051
 
        min = 0.01,
1052
 
        max = 100,
1053
 
        default = .5)
1054
 
        
1055
 
    mesh_y_size = bpy.props.FloatProperty(name = "Length(y)",
1056
 
        description = "Length (along y-axis) of mesh",
1057
 
        min = 0.01,
1058
 
        max = 100,
1059
 
        default = 2)
1060
 
 
1061
 
    thick = bpy.props.FloatProperty(name = "Thickness",
1062
 
        description = "Thickness of mesh",
1063
 
        min = 0.01,
1064
 
        max = 1,
1065
 
        default = 0.1)
1066
 
 
1067
 
    taper = bpy.props.IntProperty(name = "Taper",
1068
 
        description = "Percentage to taper outside edges, 0 = no taper, 100 = full taper",
1069
 
        min = 0,
1070
 
        max = 100,
1071
 
        default = 0)        
1072
 
 
1073
 
    type = bpy.props.BoolProperty(name = "U-shaped",
1074
 
        description = "Create the beam in a U orientation rather than the defualt C orientation", 
1075
 
        default = True)
1076
 
                
1077
 
    # generic transform props
1078
 
    # required by object_utils.py - part of blender's
1079
 
    # code and is what handles alignment amongst other
1080
 
    # things.
1081
 
    view_align = bpy.props.BoolProperty(
1082
 
            name="Align to View",
1083
 
            default=False
1084
 
            )
1085
 
    location = bpy.props.FloatVectorProperty(
1086
 
            name="Location",
1087
 
            subtype='TRANSLATION',
1088
 
            )
1089
 
    rotation = bpy.props.FloatVectorProperty(
1090
 
            name="Rotation",
1091
 
            subtype='EULER',
1092
 
            )
1093
 
 
1094
 
    # Define tool parameter layout
1095
 
    def draw(self, context):
1096
 
        layout = self.layout
1097
 
        layout.prop(self, 'mesh_z_size')
1098
 
        layout.prop(self, 'mesh_x_size')
1099
 
        layout.prop(self, 'mesh_y_size')
1100
 
        layout.prop(self, 'thick')
1101
 
        layout.prop(self, 'taper')
1102
 
        layout.prop(self, 'type')
1103
 
        layout.prop(self, 'view_align')
1104
 
        col = layout.column()
1105
 
        col.prop(self, 'location')
1106
 
        col.prop(self, 'rotation')
1107
 
        
1108
 
                
1109
 
    def execute(self, context):
1110
 
        # debug flag - True prints debug info to console
1111
 
        debug = 0
1112
 
        
1113
 
        # if type == true beam is U chanel, otherwise it's a C
1114
 
        if self.type:
1115
 
            size = (self.mesh_x_size, self.mesh_y_size, self.mesh_z_size)
1116
 
            mesh_name = "U Beam"
1117
 
        else:
1118
 
            size = (self.mesh_z_size, self.mesh_y_size, self.mesh_x_size)
1119
 
            mesh_name = "C Beam"
1120
 
                        
1121
 
        verts, faces = create_C_beam(size, self.thick, self.taper, debug)      
1122
 
 
1123
 
        if debug:
1124
 
            print("\nCreated Verts:", verts)
1125
 
            print("\nCreated Faces:", faces)
1126
 
                
1127
 
        create_mesh(self, context, mesh_name, verts, faces, debug)
1128
 
        
1129
 
        recalc_normals(debug)
1130
 
           
1131
 
        if not self.type:
1132
 
        # C-type beam is actually created as a u-type beam
1133
 
        # so rotate 90 degrees on y-axis to make a c-type
1134
 
        # and apply rotation to reset those values
1135
 
        # if self.type is true, do nothing as beam is alreay u-type.
1136
 
        # rotation value is in radians
1137
 
            bpy.ops.transform.rotate(value=[1.570796], constraint_axis=[False, True, False])
1138
 
            bpy.ops.object.transform_apply(location=False, rotation =True, scale=False)
1139
 
        
1140
 
        return {'FINISHED'}
1141
 
 
1142
 
'''
1143
 
    def invoke(self, context, event):
1144
 
        #self.align_matrix = align_matrix(context)
1145
 
        self.execute(context)
1146
 
        return {'FINISHED'}
1147
 
'''
1148
 
    
1149
 
 
1150
 
# Define "Add_L_Beam" operator    
1151
 
class Add_L_Beam(bpy.types.Operator):
1152
 
    
1153
 
    bl_idname = "mesh.primitive_l_beam_add"
1154
 
    bl_label = "Add L Beam"
1155
 
    bl_description = "Create a L shaped mesh"
1156
 
    bl_options = {'REGISTER', 'UNDO'}
1157
 
 
1158
 
    mesh_z_size = bpy.props.FloatProperty(name = "Height(z)",
1159
 
        description = "Height (along the z-axis) of mesh",
1160
 
        min = 0.01,
1161
 
        max = 100,
1162
 
        default = 1)
1163
 
        
1164
 
    mesh_x_size = bpy.props.FloatProperty(name = "Width(x)",
1165
 
        description = "Width (along the x-axis) of mesh",
1166
 
        min = 0.01,
1167
 
        max = 100,
1168
 
        default = .5)
1169
 
        
1170
 
    mesh_y_size = bpy.props.FloatProperty(name = "Length(y)",
1171
 
        description = "Length (along y-axis) of mesh",
1172
 
        min = 0.01,
1173
 
        max = 100,
1174
 
        default = 2)
1175
 
 
1176
 
    thick = bpy.props.FloatProperty(name = "Thickness",
1177
 
        description = "Thickness of mesh",
1178
 
        min = 0.01,
1179
 
        max = 1,
1180
 
        default = 0.1)
1181
 
 
1182
 
    taper = bpy.props.IntProperty(name = "Taper",
1183
 
        description = "Percentage to taper outside edges, 0 = no taper, 100 = full taper",
1184
 
        min = 0,
1185
 
        max = 100,
1186
 
        default = 0)
1187
 
 
1188
 
    # generic transform props
1189
 
    # required by object_utils.py - part of blender's
1190
 
    # code and is what handles alignment amongst other
1191
 
    # things.
1192
 
    view_align = bpy.props.BoolProperty(
1193
 
            name="Align to View",
1194
 
            default=False
1195
 
            )
1196
 
    location = bpy.props.FloatVectorProperty(
1197
 
            name="Location",
1198
 
            subtype='TRANSLATION',
1199
 
            )
1200
 
    rotation = bpy.props.FloatVectorProperty(
1201
 
            name="Rotation",
1202
 
            subtype='EULER',
1203
 
            )
1204
 
 
1205
 
    # Define tool parameter layout
1206
 
    def draw(self, context):
1207
 
        layout = self.layout
1208
 
        layout.prop(self, 'mesh_z_size')
1209
 
        layout.prop(self, 'mesh_x_size')
1210
 
        layout.prop(self, 'mesh_y_size')
1211
 
        layout.prop(self, 'thick')
1212
 
        layout.prop(self, 'taper')
1213
 
        layout.prop(self, 'view_align')
1214
 
        col = layout.column()
1215
 
        col.prop(self, 'location')
1216
 
        col.prop(self, 'rotation')
1217
 
        
1218
 
 
1219
 
    def execute(self, context):
1220
 
        # debug flag - True prints debug info to console
1221
 
        debug = 0 
1222
 
        
1223
 
        size = (self.mesh_x_size, self.mesh_y_size, self.mesh_z_size)
1224
 
                           
1225
 
        verts, faces = create_L_beam(size, self.thick, self.taper, debug)
1226
 
        
1227
 
        if debug:
1228
 
            print("\nCreated Verts:", verts)
1229
 
            print("\nCreated Faces:", faces)
1230
 
                
1231
 
        create_mesh(self, context, "L Beam", verts, faces, debug)
1232
 
        
1233
 
        recalc_normals(debug) 
1234
 
        
1235
 
        return {'FINISHED'}
1236
 
 
1237
 
'''
1238
 
    def invoke(self, context, event):
1239
 
        self.align_matrix = align_matrix(context)
1240
 
        self.execute(context)
1241
 
        return {'FINISHED'}
1242
 
'''
1243
 
    
1244
 
    
1245
 
# Define "Add_T_Beam" operator    
1246
 
class Add_T_Beam(bpy.types.Operator):
1247
 
    
1248
 
    bl_idname = "mesh.primitive_t_beam_add"
1249
 
    bl_label = "Add T Beam"
1250
 
    bl_description = "Create a T shaped mesh"
1251
 
    bl_options = {'REGISTER', 'UNDO'}    
1252
 
 
1253
 
    mesh_z_size = bpy.props.FloatProperty(name = "Height(z)",
1254
 
        description = "Height (along the z-axis) of mesh",
1255
 
        min = 0.01,
1256
 
        max = 100,
1257
 
        default = 1)
1258
 
        
1259
 
    mesh_x_size = bpy.props.FloatProperty(name = "Width(x)",
1260
 
        description = "Width (along the x-axis) of mesh",
1261
 
        min = 0.01,
1262
 
        max = 100,
1263
 
        default = .5)
1264
 
        
1265
 
    mesh_y_size = bpy.props.FloatProperty(name = "Length(y)",
1266
 
        description = "Length (along y-axis) of mesh",
1267
 
        min = 0.01,
1268
 
        max = 100,
1269
 
        default = 2)
1270
 
 
1271
 
    thick = bpy.props.FloatProperty(name = "Thickness",
1272
 
        description = "Thickness of mesh",
1273
 
        min = 0.01,
1274
 
        max = 1,
1275
 
        default = 0.1)
1276
 
 
1277
 
    taper = bpy.props.IntProperty(name = "Taper",
1278
 
        description = "Percentage to taper outside edges, 0 = no taper, 100 = full taper",
1279
 
        min = 0,
1280
 
        max = 100,
1281
 
        default = 0)
1282
 
 
1283
 
    # generic transform props
1284
 
    # required by object_utils.py - part of blender's
1285
 
    # code and is what handles alignment amongst other
1286
 
    # things.
1287
 
    view_align = bpy.props.BoolProperty(
1288
 
            name="Align to View",
1289
 
            default=False
1290
 
            )
1291
 
    location = bpy.props.FloatVectorProperty(
1292
 
            name="Location",
1293
 
            subtype='TRANSLATION',
1294
 
            )
1295
 
    rotation = bpy.props.FloatVectorProperty(
1296
 
            name="Rotation",
1297
 
            subtype='EULER',
1298
 
            )
1299
 
 
1300
 
    # Define tool parameter layout
1301
 
    def draw(self, context):
1302
 
        layout = self.layout
1303
 
        layout.prop(self, 'mesh_z_size')
1304
 
        layout.prop(self, 'mesh_x_size')
1305
 
        layout.prop(self, 'mesh_y_size')
1306
 
        layout.prop(self, 'thick')
1307
 
        layout.prop(self, 'taper')
1308
 
        layout.prop(self, 'view_align')
1309
 
        col = layout.column()
1310
 
        col.prop(self, 'location')
1311
 
        col.prop(self, 'rotation')
1312
 
 
1313
 
 
1314
 
    def execute(self, context):
1315
 
        # debug flag - True prints debug info to console
1316
 
        debug = 0
1317
 
        
1318
 
        size = (self.mesh_x_size, self.mesh_y_size, self.mesh_z_size)
1319
 
                           
1320
 
        verts, faces = create_T_beam(size, self.thick, self.taper, debug)
1321
 
        
1322
 
        if debug:
1323
 
            print("\nCreated Verts:", verts)
1324
 
            print("\nCreated Faces:", faces)
1325
 
                
1326
 
        create_mesh(self, context, "T Beam", verts, faces, debug)
1327
 
        
1328
 
        recalc_normals(debug) 
1329
 
        
1330
 
        return {'FINISHED'}
1331
 
 
1332
 
'''
1333
 
    def invoke(self, context, event):
1334
 
        self.align_matrix = align_matrix(context)
1335
 
        self.execute(context)
1336
 
        return {'FINISHED'}
1337
 
'''
1338
 
    
1339
 
    
1340
 
# Define "Add_I_Beam" operator    
1341
 
class Add_I_Beam(bpy.types.Operator):
1342
 
    
1343
 
    bl_idname = "mesh.primitive_i_beam_add"
1344
 
    bl_label = "Add I Beam"
1345
 
    bl_description = "Create a I shaped mesh"
1346
 
    bl_options = {'REGISTER', 'UNDO'}    
1347
 
 
1348
 
    mesh_z_size = bpy.props.FloatProperty(name = "Height(z)",
1349
 
        description = "Height (along the z-axis) of mesh",
1350
 
        min = 0.01,
1351
 
        max = 100,
1352
 
        default = 1)
1353
 
        
1354
 
    mesh_x_size = bpy.props.FloatProperty(name = "Width(x)",
1355
 
        description = "Width (along the x-axis) of mesh",
1356
 
        min = 0.01,
1357
 
        max = 100,
1358
 
        default = .5)
1359
 
        
1360
 
    mesh_y_size = bpy.props.FloatProperty(name = "Length(y)",
1361
 
        description = "Length (along y-axis) of mesh",
1362
 
        min = 0.01,
1363
 
        max = 100,
1364
 
        default = 2)
1365
 
 
1366
 
    thick = bpy.props.FloatProperty(name = "Thickness",
1367
 
        description = "Thickness of mesh",
1368
 
        min = 0.01,
1369
 
        max = 1,
1370
 
        default = 0.1)
1371
 
 
1372
 
    taper = bpy.props.IntProperty(name = "Taper",
1373
 
        description = "Percentage to taper outside edges, 0 = no taper, 100 = full taper",
1374
 
        min = 0,
1375
 
        max = 100,
1376
 
        default = 0)
1377
 
 
1378
 
    # generic transform props
1379
 
    # required by object_utils.py - part of blender's
1380
 
    # code and is what handles alignment amongst other
1381
 
    # things.
1382
 
    view_align = bpy.props.BoolProperty(
1383
 
            name="Align to View",
1384
 
            default=False
1385
 
            )
1386
 
    location = bpy.props.FloatVectorProperty(
1387
 
            name="Location",
1388
 
            subtype='TRANSLATION',
1389
 
            )
1390
 
    rotation = bpy.props.FloatVectorProperty(
1391
 
            name="Rotation",
1392
 
            subtype='EULER',
1393
 
            )
1394
 
    
1395
 
    # Define tool parameter layout
1396
 
    def draw(self, context):
1397
 
        layout = self.layout
1398
 
        layout.prop(self, 'mesh_z_size')
1399
 
        layout.prop(self, 'mesh_x_size')
1400
 
        layout.prop(self, 'mesh_y_size')
1401
 
        layout.prop(self, 'thick')
1402
 
        layout.prop(self, 'taper')
1403
 
        layout.prop(self, 'view_align')
1404
 
        col = layout.column()
1405
 
        col.prop(self, 'location')
1406
 
        col.prop(self, 'rotation')
1407
 
        
1408
 
 
1409
 
    def execute(self, context):
1410
 
        # debug flag - True prints debug info to console
1411
 
        debug = 0
1412
 
        
1413
 
        size = (self.mesh_x_size, self.mesh_y_size, self.mesh_z_size)
1414
 
                           
1415
 
        verts, faces = create_I_beam(size, self.thick, self.taper, debug)
1416
 
        
1417
 
        if debug:
1418
 
            print("\nCreated Verts:", verts)
1419
 
            print("\nCreated Faces:", faces)
1420
 
                
1421
 
        create_mesh(self, context, "I Beam", verts, faces, debug)
1422
 
        
1423
 
        recalc_normals(debug) 
1424
 
        
1425
 
        return {'FINISHED'}
1426
 
 
1427
 
 
1428
 
'''
1429
 
    def invoke(self, context, event):
1430
 
        self.align_matrix = align_matrix(context)
1431
 
        self.execute(context)
1432
 
        return {'FINISHED'}    
1433
 
'''
1434
 
 
1435
 
 
1436
 
# Register all operators and define menus
1437
 
 
1438
 
class INFO_MT_mesh_beambuilder_add(bpy.types.Menu):
1439
 
    # Define the "Beam Builder" menu
1440
 
    bl_idname = "INFO_MT_mesh_beambuilder_add"
1441
 
    bl_label = "Beam Builder"
1442
 
    
1443
 
    def draw(self, context):
1444
 
        layout = self.layout  
1445
 
        layout.operator_context = 'INVOKE_REGION_WIN'
1446
 
        layout.operator("mesh.primitive_rectangle_add", text = "Rectangluar Beam")  
1447
 
        layout.operator("mesh.primitive_c_beam_add", text = "C or U Channel")
1448
 
        layout.operator("mesh.primitive_l_beam_add", text = "L Shaped Beam")
1449
 
        layout.operator("mesh.primitive_t_beam_add", text = "T Shaped Beam")
1450
 
        layout.operator("mesh.primitive_i_beam_add", text = "I Shaped Beam")
1451
 
        
1452
 
        
1453
 
    
1454
 
# Define menu    
1455
 
def menu_func(self, context):
1456
 
    self.layout.menu("INFO_MT_mesh_beambuilder_add", icon='PLUGIN')
1457
 
 
1458
 
 
1459
 
# Add     
1460
 
def register():
1461
 
    bpy.utils.register_module(__name__)
1462
 
    
1463
 
    # Add BeamBuilder menu to the 'Add Mesh' menu
1464
 
    bpy.types.INFO_MT_mesh_add.append(menu_func)
1465
 
 
1466
 
 
1467
 
# Remove 
1468
 
def unregister():
1469
 
    bpy.utils.unregister_module(__name__)
1470
 
    
1471
 
    # Remove BeamBuilder menu from 'Add Mesh' menu
1472
 
    bpy.types.INFO_MT_mesh_add.remove(menu_func)
1473
 
 
1474
 
 
1475
 
if __name__ == "__main__":
1476
 
    register() 
1477