[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2368] contrib/py/scripts/addons/ add_mesh_beam_builder.py: moving beam builder to contrib
Brendon Murphy
meta.androcto1 at gmail.com
Wed Sep 28 11:35:06 CEST 2011
Revision: 2368
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2368
Author: meta-androcto
Date: 2011-09-28 09:35:05 +0000 (Wed, 28 Sep 2011)
Log Message:
-----------
moving beam builder to contrib
Welcome :)
Added Paths:
-----------
contrib/py/scripts/addons/add_mesh_beam_builder.py
Added: contrib/py/scripts/addons/add_mesh_beam_builder.py
===================================================================
--- contrib/py/scripts/addons/add_mesh_beam_builder.py (rev 0)
+++ contrib/py/scripts/addons/add_mesh_beam_builder.py 2011-09-28 09:35:05 UTC (rev 2368)
@@ -0,0 +1,1375 @@
+bl_info = {
+ "name": "Beam Builder",
+ "description": "Creates various types of beams.",
+ "author": "revolt_randy",
+ "version": (0, 1, 2),
+ "blender": (2, 5, 6),
+ "api": 35968,
+ "location": "View3D > Add > Mesh",
+ "warning": "Currently under development.",
+ "wiki_url": "",
+ "tracker_url": "",
+ "category": "Add Mesh"}
+
+# Version History
+#
+# v0.1 - Script only generates a multi-sided mesh object,
+# initial release for testing. 3/12/11
+#
+# v0.1.1 - Added 'C'-type beam, updated to work with
+# api r35499. 3/13/11
+#
+# v0.1.2 - Totally changed the way beams are created, size
+# is now calculated based off width, length, & height
+# (x,y,z). Added ability to taper beams as well.
+# Add 'L' - type beam
+# Add 'T' - type beam
+# Add 'I' - type beam
+
+# Creates a rectangluar, or 'C', or 'L' or 'T' or 'I' - type beam.
+
+import bpy
+import math
+import mathutils
+#import space_info
+
+# The following bit of code was taken from spindle.py
+# a script by Campbell Barton that creates a spindle mesh.
+# The script was found someplace at blender.org
+# Code determines the align_matrix to align the new object to
+def align_matrix(context):
+ loc = mathutils.Matrix.Translation(context.scene.cursor_location)
+ obj_align = context.user_preferences.edit.object_align
+ if (context.space_data.type == 'VIEW_3D'
+ and obj_align == 'VIEW'):
+ rot = context.space_data.region_3d.view_matrix.rotation_part().invert().resize4x4()
+ else:
+ rot = mathutils.Matrix()
+ align_matrix = loc * rot
+ return align_matrix
+
+
+def create_mesh (name, verts, faces, align_matrix):
+ # Creates mesh and object
+ # name - name of object to create
+ # verts - a list of vertex tuples
+ # faces - a list of face tuples
+ # align_matrix - alignment of the mesh based on user prefs - see above code
+
+ # Check if in edit mode, if so, get name of active object and enter object mode
+ if bpy.context.mode == 'EDIT_MESH':
+ # toggle to object mode
+ bpy.ops.object.editmode_toggle()
+ # get name of active object
+ obj_act = bpy.context.scene.objects.active
+ #print ("\n\nTRAP WORKS", "\nactive object =", obj_act)
+ else:
+ obj_act = False
+
+ # Unselect any objects
+ bpy.ops.object.select_all(action="DESELECT")
+
+ # Actually create mesh and object
+ mesh = bpy.data.meshes.new(name)
+ obj = bpy.data.objects.new(name, mesh)
+
+ # add verts & faces to object
+ mesh.from_pydata(verts, [], faces)
+ mesh.update(calc_edges=True)
+
+ # Move object to 3d cursor & align
+ #obj.location = bpy.context.scene.cursor_location
+ obj.matrix_world = align_matrix
+
+ # link object to scene
+ bpy.context.scene.objects.link(obj)
+
+ #print(obj_act, obj)
+
+ # Were we in edit mode - if so need to join new mesh to active mesh object
+ if obj_act:
+ bpy.ops.object.select_all(action="DESELECT")
+ # Select first object
+ obj_act.select = True
+ # Select new object
+ obj.select = True
+ # Join objects
+ bpy.ops.object.join()
+
+ #print("\n\n2nd TRAP Works")
+
+ else:
+ # Not in edit mode, so just make new object active object
+ bpy.context.scene.objects.active = obj
+ obj.select = True
+
+ # Enter edit mode
+ bpy.ops.object.editmode_toggle()
+
+ # Recalcuate normals
+ bpy.ops.mesh.normals_make_consistent()
+
+ # Return to object mode if mesh created in object mode
+ if not obj_act:
+ bpy.ops.object.editmode_toggle()
+
+ return
+
+
+def create_end_faces(verts_list, thick, debug):
+ # Create End Faces
+ # verts_list - list of vertices
+ # thick - if true object is hollow, so construct loop of end faces
+ # instead of a solid end face
+ # debug - if true prints values from this function to console
+
+ # returns:
+ # faces - a list of tuples defining the end faces
+
+ faces = []
+
+ num_of_verts = len(verts_list)
+ faces_temp = []
+
+ sides = 4 # sides - number of sides to mesh *added because of code re-write
+
+ if thick:
+ # has thickness, so build end faces
+ num_of_verts = int(num_of_verts / 2)
+
+ # Create a list of the front faces
+ for index in range(num_of_verts):
+ if index == (num_of_verts - 1):
+ faces_temp.append(verts_list[index])
+ faces_temp.append(verts_list[index-index])
+ faces_temp.append(verts_list[index+1])
+ faces_temp.append(verts_list[index*2+1])
+ else:
+ faces_temp.append(verts_list[index])
+ faces_temp.append(verts_list[index+1])
+ faces_temp.append(verts_list[index+num_of_verts+1])
+ faces_temp.append(verts_list[index+num_of_verts])
+
+ faces.append(tuple(faces_temp))
+ faces_temp = []
+ else:
+ #this code may not be needed, depends upon rewrite...
+ if sides > 4:
+ # more than 4 sides, so replace last list item (center vert) with first list item
+ # for looping and building faces
+ center_vert = verts_list[num_of_verts - 1]
+ verts_list[num_of_verts - 1] = verts_list[0]
+
+ for index in range(int(num_of_verts - 1)):
+ faces_temp.append(verts_list[index])
+ faces_temp.append(verts_list[index + 1])
+ faces_temp.append(center_vert)
+ faces.append(tuple(faces_temp))
+ faces_temp = []
+
+ else:
+ # create 1 end face
+ for index in range(num_of_verts):
+ faces_temp.append(verts_list[index])
+ faces.append(tuple(faces_temp))
+
+ # print debug info to console
+ if debug:
+ print("\ncreate_end_faces Function Starts")
+ print("\n End Face Verts list :", verts_list)
+ print("\n End Faces: ", faces)
+ print("\ncreate_end_faces Function Ends\n\n")
+
+ return faces
+
+
+def create_side_faces(front_verts, back_verts, debug):
+ # Create side faces - simple bridging of front_verts & back_verts vertices,
+ # both front_verts & back_verts must be ordered in same direction
+ # with respect to y-axis
+ # front_verts - a list of front face vertices
+ # back_verts - a list of back face vertices
+ # debug - if true prints values from this function to console
+
+ # returns:
+ # new_faces - a list of tuples defining the faces bridged between front_verts & back_verts
+
+ # Number of faces to create
+ num_of_faces = (len(front_verts))
+ new_faces = []
+
+ # add first value to end of lists for looping
+ front_verts.append(front_verts[0])
+ back_verts.append(back_verts[0])
+
+ # Build the new_faces list with tuples defining each face
+ for index in range(num_of_faces):
+ facestemp = (front_verts[index], front_verts[index+1], back_verts[index+1], back_verts[index])
+ new_faces.append(facestemp)
+
+ # print debug info to console
+ if debug:
+ print("\ncreate_side_faces Function Starts")
+ print("\n Number of faces to create: ", num_of_faces)
+ print("\n New faces :", new_faces)
+ print("\ncreate_side_faces Function Ends\n\n")
+
+ return new_faces
+
+
+def calc_end_verts(size, y_off, thick, debug):
+ # Calculates vertex location for end of mesh
+
+ # size - tuple of x,y,z dimensions of mesh to create
+ # y_off - y offset, lets function know where to create verts on y-axis
+ # thick - thickness, if not zero this is the thickness of a hollow mesh
+ # with the inner faces inset from size dimensions
+ # debug - if true prints values from this function to console
+
+ # returns:
+ # verts - a list of tuples of the x,y,z location of each vertex
+
+ verts = []
+
+ if debug:
+ print ("\ncalc_end_verts Function Starts\n")
+
+ print("\nsize = ",size)
+ print("y_off = ",y_off)
+
+ # Create vertices by calculation
+ x_pos = 0 + size[0]/2
+ z_pos = 0 + size[2]/2
+ verts.append((x_pos, y_off, z_pos))
+
+ x_pos = 0 - size[0]/2
+ z_pos = 0 + size[2]/2
+ verts.append((x_pos, y_off, z_pos))
+
+ x_pos = 0 - size[0]/2
+ z_pos = 0 - size[2]/2
+ verts.append((x_pos, y_off, z_pos))
+
+ x_pos = 0 + size[0]/2
+ z_pos = 0 - size[2]/2
+ verts.append((x_pos, y_off, z_pos))
+
+ if thick:
+ # has thickness, so calculate inside vertices
+ #### not too sure about this, but it does work the way the
+ #### solidify modifier works, so leaving as is for now
+ x_pos = size[0] - (thick * 2)
+ z_pos = size[2] - (thick * 2)
+ size = (x_pos, y_off, z_pos)
+
+ # Create vertices by calculation
+ x_pos = 0 + size[0]/2
+ z_pos = 0 + size[2]/2
+ verts.append((x_pos, y_off, z_pos))
+
+ x_pos = 0 - size[0]/2
+ z_pos = 0 + size[2]/2
+ verts.append((x_pos, y_off, z_pos))
+
+ x_pos = 0 - size[0]/2
+ z_pos = 0 - size[2]/2
+ verts.append((x_pos, y_off, z_pos))
+
+ x_pos = 0 + size[0]/2
+ z_pos = 0 - size[2]/2
+ verts.append((x_pos, y_off, z_pos))
+
+ if debug:
+ print ("verts :", verts)
+ print ("\ncalc_end_verts Function Ends.\n\n")
+
+ return verts
+
+
+def adjust_c_beam_verts(verts, taper, debug):
+ # Adjusts verts produced to correct c beam shape
+ # verts - a list of tuples of vertex locations for one end of beam
+ # taper - % to taper outside verts by
+ # debug - if true values are printed to console for debugging
+
+ # returns:
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list