1
# ##### BEGIN GPL LICENSE BLOCK #####
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.
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.
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.
17
# ##### END GPL LICENSE BLOCK #####
20
"name": "Beam Builder",
21
"description": "Creates various types of beams.",
22
"author": "revolt_randy",
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"}
32
# Creates a rectangluar, 'C', 'L', 'T', or 'I' - type beam.
37
# v0.1 - Script only generates a multi-sided mesh object,
38
# initial release for testing. 3/12/11
40
# v0.1.1 - Added 'C'-type beam, updated to work with
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.
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
60
from bpy_extras import object_utils
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
70
# Actually create mesh and object
71
mesh = bpy.data.meshes.new(name)
73
# add verts & faces to object
74
mesh.from_pydata(verts, [], faces)
75
mesh.update(calc_edges=True)
78
print("create_mesh function called and finished")
80
return object_utils.object_data_add(context, mesh, operator=self)
83
def recalc_normals(debug):
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
90
if bpy.context.mode != 'EDIT_MESH':
91
bpy.ops.object.editmode_toggle()
93
bpy.ops.mesh.normals_make_consistent()
94
bpy.ops.object.editmode_toggle()
98
bpy.ops.mesh.normals_make_consistent()
105
def create_end_faces(verts_list, thick, debug):
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
113
# faces - a list of tuples defining the end faces
117
num_of_verts = len(verts_list)
120
sides = 4 # sides - number of sides to mesh *added because of code re-write
123
# has thickness, so build end faces
124
num_of_verts = int(num_of_verts / 2)
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])
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])
139
faces.append(tuple(faces_temp))
142
#this code may not be needed, depends upon rewrite...
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]
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))
158
for index in range(num_of_verts):
159
faces_temp.append(verts_list[index])
160
faces.append(tuple(faces_temp))
162
# print debug info to console
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")
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
181
# new_faces - a list of tuples defining the faces bridged between front_verts & back_verts
183
# Number of faces to create
184
num_of_faces = (len(front_verts))
187
# add first value to end of lists for looping
188
front_verts.append(front_verts[0])
189
back_verts.append(back_verts[0])
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)
196
# print debug info to console
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")
206
def calc_end_verts(size, y_off, thick, debug):
207
# Calculates vertex location for end of mesh
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
216
# verts - a list of tuples of the x,y,z location of each vertex
221
print ("\ncalc_end_verts Function Starts\n")
222
print("\nsize = ",size)
223
print("y_off = ",y_off)
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))
230
x_pos = 0 - size[0]/2
231
z_pos = 0 + size[2]/2
232
verts.append((x_pos, y_off, z_pos))
234
x_pos = 0 - size[0]/2
235
z_pos = 0 - size[2]/2
236
verts.append((x_pos, y_off, z_pos))
238
x_pos = 0 + size[0]/2
239
z_pos = 0 - size[2]/2
240
verts.append((x_pos, y_off, z_pos))
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)
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))
255
x_pos = 0 - size[0]/2
256
z_pos = 0 + size[2]/2
257
verts.append((x_pos, y_off, z_pos))
259
x_pos = 0 - size[0]/2
260
z_pos = 0 - size[2]/2
261
verts.append((x_pos, y_off, z_pos))
263
x_pos = 0 + size[0]/2
264
z_pos = 0 - size[2]/2
265
verts.append((x_pos, y_off, z_pos))
268
print ("verts :", verts)
269
print ("\ncalc_end_verts Function Ends.\n\n")
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
281
# verts - the corrected list of tuples of the adjustec vertex locations
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.
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]
296
# vert_z has the z value to be used in the 5th & 6th verts
297
# get value of 5th vert
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)
306
vert_new = (vert_x,vert_temp[1],vert_z)
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)
315
# update 5th vert with new value
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
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)
334
vert_new = (vert_x,vert_temp[1],vert_z)
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)
342
# update 6th vert with new value
346
print("\n adjust_c_beam_verts function ending")
347
print("verts =", verts)
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
360
# adjusted_vert - the calculated vertex
362
#print("outer_vert =",outer_vert,"inner_vert",inner_vert)
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
368
# calcuate taper & adjust vertex
369
vert_delta = inner_vert - outer_vert
370
adjusted_vert = outer_vert + ((vert_delta/100) * taper)
372
#print("adjusted_vert =", adjusted_vert)
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
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
387
# Create temporarylists to hold vertices locations
391
#calculate y offset from center for front vertices
395
# Create front vertices by calculation
396
verts_front_temp = calc_end_verts(size, y_off, thick, debug)
398
# re-calculate y offset from center for back vertices
401
# Create back vertices by calculation
402
verts_back_temp = calc_end_verts(size, y_off, thick, debug)
404
# Combine all vertices into a final list of tuples
405
verts_final = verts_front_temp + verts_back_temp
407
# Print debug info to console
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)
415
faces_front_temp = []
416
verts_front_list = []
417
numofverts = len(verts_front_temp)
420
for index in range(numofverts):
421
verts_front_list.append(index)
423
faces_front_temp = create_end_faces(verts_front_list, thick, debug)
428
numofverts = len(verts_back_temp)
431
for index in range(numofverts):
432
verts_back_list.append(index + len(verts_back_temp))
434
faces_back_temp = create_end_faces(verts_back_list, thick, debug)
439
# better code needed here???
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)]
446
faces_side_temp = create_side_faces(verts_front_temp, verts_back_temp, debug)
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]
452
faces_side_temp += create_side_faces(verts_front_temp, verts_back_temp, debug)
454
# Create list of only outside faces
455
faces_side_temp = create_side_faces(verts_front_list, verts_back_list, debug)
458
faces_final = faces_front_temp + faces_back_temp + faces_side_temp
460
# print debug info to console
462
print("\ncreate_multi_side_box Function")
463
print("\nAll faces :",faces_final)
464
print("\ncreate_multi_side_box Function Ends\n\n")
466
return verts_final, faces_final
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
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
481
# print debug info to console
483
print ("\ncreate_C_beam - function called")
485
# Get y offset of vertices from center
488
# Create temporarylists to hold vertices locations
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)
500
# recalculate y_off for other end vertices
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)
508
# Combine all vertices into a final list of tuples
509
verts_final = verts_front_temp + verts_back_temp
511
# Print debug info to console
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)
519
faces_front_temp = []
520
verts_front_list = []
521
numofverts = len(verts_front_temp)
524
for index in range(numofverts):
525
verts_front_list.append(index)
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]
534
numofverts = len(verts_back_temp)
537
for index in range(numofverts):
538
verts_back_list.append(index + len(verts_back_temp))
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]
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)]
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:]
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]
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:]
563
# fill in top two faces
564
faces_side_temp.append((0, 4, 12, 8))
565
faces_side_temp.append((5, 1, 9, 13))
568
faces_final = faces_front_temp + faces_back_temp + faces_side_temp
570
# Print debug info to console
572
print("\ncreate_C_beam function")
573
print("\nAll faces =", faces_final)
574
print("\ncreate_C_beam function ending")
576
return verts_final, faces_final
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
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
592
print("\ncreate_L_beam function starting")
594
# Get offset of vertices from center
599
# Create temporarylists to hold vertices locations
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)]
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]]
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))]
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)]
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]]
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))]
637
verts_final = verts_front_temp + verts_back_temp
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)
644
# define end faces, only 4 so just coded
645
faces_front_temp = []
649
faces_front_temp = [(0, 1, 2, 5), (2, 3, 4, 5)]
650
faces_back_temp = [(6, 7, 8, 11), (8, 9, 10, 11)]
652
verts_front_list = []
654
num_of_verts = len(verts_front_temp)
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)
662
faces_side_temp = create_side_faces(verts_front_list, verts_back_list, debug)
664
faces_final = faces_front_temp + faces_back_temp + faces_side_temp
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")
673
return verts_final, faces_final
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
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
691
print("\ncreate_T_beam function starting")
693
# Get offset of vertices from center
697
thick_off = thick / 2
699
# Create temporarylists to hold vertices locations
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)]
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))]
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))]
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]]
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]]
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)]
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))]
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))]
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]]
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]]
767
verts_final = verts_front_temp + verts_back_temp
770
# define end faces, only 8 so just coded
771
faces_front_temp = []
775
faces_front_temp = [(0, 1, 8, 9), (1, 2, 5, 8), \
776
(2, 3, 4, 5), (5, 6, 7, 8)]
778
faces_back_temp = [(10, 11, 18, 19), (11, 12, 15, 18), \
779
(12, 13, 14, 15), (15, 16, 17, 18)]
781
verts_front_list = []
783
num_of_verts = len(verts_front_temp)
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)
791
faces_side_temp = create_side_faces(verts_front_list, verts_back_list, debug)
793
faces_final = faces_front_temp + faces_back_temp + faces_side_temp
796
print("\ncreate_T_beam function ending")
798
return verts_final, faces_final
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
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
815
print("\ncreate_I_beam function starting")
817
# Get offset of vertices from center
821
thick_off = thick / 2
823
# Create temporarylists to hold vertices locations
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)]
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))]
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))]
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))]
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))]
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)]
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))]
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))]
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))]
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))]
897
verts_final = verts_front_temp + verts_back_temp
900
# define end faces, only 7 per end, so just coded
901
faces_front_temp = []
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), \
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), \
915
verts_front_list = []
917
num_of_verts = len(verts_front_temp)
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)
925
faces_side_temp = create_side_faces(verts_front_list, verts_back_list, debug)
927
faces_final = faces_front_temp + faces_back_temp + faces_side_temp
930
print("\ncreate_I_beam function ending")
932
return verts_final, faces_final
936
# Define "Add_Rectangular_Beam" operator
937
########### Needs Work ###############
938
class Add_Rectangular_Beam(bpy.types.Operator):
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'}
945
mesh_z_size = bpy.props.FloatProperty(name = "Height(z)",
946
description = "Height (along the z-axis) of mesh",
951
mesh_x_size = bpy.props.FloatProperty(name = "Width(x)",
952
description = "Width (along the x-axis) of mesh",
957
mesh_y_size = bpy.props.FloatProperty(name = "Length(y)",
958
description = "Length (along y-axis) of mesh",
963
thick_bool = bpy.props.BoolProperty(name = "Hollow",
964
description = "Create a hollow mesh with a defined thickness",
967
thick = bpy.props.FloatProperty(name = "Thickness",
968
description = "Thickness of hollow mesh",
973
# generic transform props
974
# required by object_utils.py - part of blender's
975
# code and is what handles alignment amongst other
977
view_align = bpy.props.BoolProperty(
978
name="Align to View",
981
location = bpy.props.FloatVectorProperty(
983
subtype='TRANSLATION',
985
rotation = bpy.props.FloatVectorProperty(
990
# Define tool parameter layout
991
def draw(self, context):
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')
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')
1004
def execute(self, context):
1005
# debug flag - True prints debug info to console
1008
size = (self.mesh_x_size, self.mesh_y_size, self.mesh_z_size)
1009
if self.thick_bool is True:
1014
verts, faces = create_rectangular_beam(size, thick, debug)
1017
print("\nCreated Verts:", verts)
1018
print("\nCreated Faces:", faces)
1020
create_mesh(self, context, "Rectangular Beam", verts, faces, debug)
1022
recalc_normals(debug)
1027
def invoke(self, context, event):
1028
#self.align_matrix = align_matrix(context)
1029
self.execute(context)
1034
# Define "Add_C_Beam" operator
1035
class Add_C_Beam(bpy.types.Operator):
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'}
1043
mesh_z_size = bpy.props.FloatProperty(name = "Height(z)",
1044
description = "Height (along the z-axis) of mesh",
1049
mesh_x_size = bpy.props.FloatProperty(name = "Width(x)",
1050
description = "Width (along the x-axis) of mesh",
1055
mesh_y_size = bpy.props.FloatProperty(name = "Length(y)",
1056
description = "Length (along y-axis) of mesh",
1061
thick = bpy.props.FloatProperty(name = "Thickness",
1062
description = "Thickness of mesh",
1067
taper = bpy.props.IntProperty(name = "Taper",
1068
description = "Percentage to taper outside edges, 0 = no taper, 100 = full taper",
1073
type = bpy.props.BoolProperty(name = "U-shaped",
1074
description = "Create the beam in a U orientation rather than the defualt C orientation",
1077
# generic transform props
1078
# required by object_utils.py - part of blender's
1079
# code and is what handles alignment amongst other
1081
view_align = bpy.props.BoolProperty(
1082
name="Align to View",
1085
location = bpy.props.FloatVectorProperty(
1087
subtype='TRANSLATION',
1089
rotation = bpy.props.FloatVectorProperty(
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')
1109
def execute(self, context):
1110
# debug flag - True prints debug info to console
1113
# if type == true beam is U chanel, otherwise it's a C
1115
size = (self.mesh_x_size, self.mesh_y_size, self.mesh_z_size)
1116
mesh_name = "U Beam"
1118
size = (self.mesh_z_size, self.mesh_y_size, self.mesh_x_size)
1119
mesh_name = "C Beam"
1121
verts, faces = create_C_beam(size, self.thick, self.taper, debug)
1124
print("\nCreated Verts:", verts)
1125
print("\nCreated Faces:", faces)
1127
create_mesh(self, context, mesh_name, verts, faces, debug)
1129
recalc_normals(debug)
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)
1143
def invoke(self, context, event):
1144
#self.align_matrix = align_matrix(context)
1145
self.execute(context)
1150
# Define "Add_L_Beam" operator
1151
class Add_L_Beam(bpy.types.Operator):
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'}
1158
mesh_z_size = bpy.props.FloatProperty(name = "Height(z)",
1159
description = "Height (along the z-axis) of mesh",
1164
mesh_x_size = bpy.props.FloatProperty(name = "Width(x)",
1165
description = "Width (along the x-axis) of mesh",
1170
mesh_y_size = bpy.props.FloatProperty(name = "Length(y)",
1171
description = "Length (along y-axis) of mesh",
1176
thick = bpy.props.FloatProperty(name = "Thickness",
1177
description = "Thickness of mesh",
1182
taper = bpy.props.IntProperty(name = "Taper",
1183
description = "Percentage to taper outside edges, 0 = no taper, 100 = full taper",
1188
# generic transform props
1189
# required by object_utils.py - part of blender's
1190
# code and is what handles alignment amongst other
1192
view_align = bpy.props.BoolProperty(
1193
name="Align to View",
1196
location = bpy.props.FloatVectorProperty(
1198
subtype='TRANSLATION',
1200
rotation = bpy.props.FloatVectorProperty(
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')
1219
def execute(self, context):
1220
# debug flag - True prints debug info to console
1223
size = (self.mesh_x_size, self.mesh_y_size, self.mesh_z_size)
1225
verts, faces = create_L_beam(size, self.thick, self.taper, debug)
1228
print("\nCreated Verts:", verts)
1229
print("\nCreated Faces:", faces)
1231
create_mesh(self, context, "L Beam", verts, faces, debug)
1233
recalc_normals(debug)
1238
def invoke(self, context, event):
1239
self.align_matrix = align_matrix(context)
1240
self.execute(context)
1245
# Define "Add_T_Beam" operator
1246
class Add_T_Beam(bpy.types.Operator):
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'}
1253
mesh_z_size = bpy.props.FloatProperty(name = "Height(z)",
1254
description = "Height (along the z-axis) of mesh",
1259
mesh_x_size = bpy.props.FloatProperty(name = "Width(x)",
1260
description = "Width (along the x-axis) of mesh",
1265
mesh_y_size = bpy.props.FloatProperty(name = "Length(y)",
1266
description = "Length (along y-axis) of mesh",
1271
thick = bpy.props.FloatProperty(name = "Thickness",
1272
description = "Thickness of mesh",
1277
taper = bpy.props.IntProperty(name = "Taper",
1278
description = "Percentage to taper outside edges, 0 = no taper, 100 = full taper",
1283
# generic transform props
1284
# required by object_utils.py - part of blender's
1285
# code and is what handles alignment amongst other
1287
view_align = bpy.props.BoolProperty(
1288
name="Align to View",
1291
location = bpy.props.FloatVectorProperty(
1293
subtype='TRANSLATION',
1295
rotation = bpy.props.FloatVectorProperty(
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')
1314
def execute(self, context):
1315
# debug flag - True prints debug info to console
1318
size = (self.mesh_x_size, self.mesh_y_size, self.mesh_z_size)
1320
verts, faces = create_T_beam(size, self.thick, self.taper, debug)
1323
print("\nCreated Verts:", verts)
1324
print("\nCreated Faces:", faces)
1326
create_mesh(self, context, "T Beam", verts, faces, debug)
1328
recalc_normals(debug)
1333
def invoke(self, context, event):
1334
self.align_matrix = align_matrix(context)
1335
self.execute(context)
1340
# Define "Add_I_Beam" operator
1341
class Add_I_Beam(bpy.types.Operator):
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'}
1348
mesh_z_size = bpy.props.FloatProperty(name = "Height(z)",
1349
description = "Height (along the z-axis) of mesh",
1354
mesh_x_size = bpy.props.FloatProperty(name = "Width(x)",
1355
description = "Width (along the x-axis) of mesh",
1360
mesh_y_size = bpy.props.FloatProperty(name = "Length(y)",
1361
description = "Length (along y-axis) of mesh",
1366
thick = bpy.props.FloatProperty(name = "Thickness",
1367
description = "Thickness of mesh",
1372
taper = bpy.props.IntProperty(name = "Taper",
1373
description = "Percentage to taper outside edges, 0 = no taper, 100 = full taper",
1378
# generic transform props
1379
# required by object_utils.py - part of blender's
1380
# code and is what handles alignment amongst other
1382
view_align = bpy.props.BoolProperty(
1383
name="Align to View",
1386
location = bpy.props.FloatVectorProperty(
1388
subtype='TRANSLATION',
1390
rotation = bpy.props.FloatVectorProperty(
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')
1409
def execute(self, context):
1410
# debug flag - True prints debug info to console
1413
size = (self.mesh_x_size, self.mesh_y_size, self.mesh_z_size)
1415
verts, faces = create_I_beam(size, self.thick, self.taper, debug)
1418
print("\nCreated Verts:", verts)
1419
print("\nCreated Faces:", faces)
1421
create_mesh(self, context, "I Beam", verts, faces, debug)
1423
recalc_normals(debug)
1429
def invoke(self, context, event):
1430
self.align_matrix = align_matrix(context)
1431
self.execute(context)
1436
# Register all operators and define menus
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"
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")
1455
def menu_func(self, context):
1456
self.layout.menu("INFO_MT_mesh_beambuilder_add", icon='PLUGIN')
1461
bpy.utils.register_module(__name__)
1463
# Add BeamBuilder menu to the 'Add Mesh' menu
1464
bpy.types.INFO_MT_mesh_add.append(menu_func)
1469
bpy.utils.unregister_module(__name__)
1471
# Remove BeamBuilder menu from 'Add Mesh' menu
1472
bpy.types.INFO_MT_mesh_add.remove(menu_func)
1475
if __name__ == "__main__":