Commit 0c945e9b authored by frankie's avatar frankie 💬

blender script to add internal structures to primitves

parent 97407752
'''
editor script to generate edges between opposites vertices in a mesh
will work efficiently on regular primitives, do not expect awesome results on custom meshes...
'''
import bpy
import mathutils
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
obj = bpy.context.active_object
mesh = obj.data
surface_vertices = []
for v in mesh.vertices:
v.select = False
for p in mesh.polygons:
for vid in p.vertices:
if not vid in surface_vertices:
surface_vertices.append(vid)
print( surface_vertices )
edge_added = 0
# seeking opposite vertices
for vid in surface_vertices:
opposite_pos = mathutils.Vector(mesh.vertices[vid].co)
opposite_pos.negate()
#print(mesh.vertices[vid].co, '<>', opposite_pos)
# seeking opposite
smallest = 0
opposite = -1
for voi in range(0,len(mesh.vertices)):
if voi == vid:
continue
v = mesh.vertices[voi]
d = (v.co - opposite_pos).magnitude
if opposite == -1 or d < smallest:
smallest = d
opposite = voi
#print( vid, ' > ', opposite, ' - ', smallest )
if smallest > 1e-5:
continue
# is there already an edge kinking these 2 vertices?
edge_found = False
for e in mesh.edges:
if e.vertices[0] == vid and e.vertices[1] == opposite:
print( 'found edge:', vid, '>', opposite )
edge_found = True
break
if e.vertices[0] == opposite and e.vertices[1] == vid:
print( 'found edge:', vid, '>', opposite )
edge_found = True
break
if not edge_found:
print( 'lets add an edge for:', vid, '>', opposite )
mesh.vertices[vid].select = True
mesh.vertices[opposite].select = True
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
bpy.ops.mesh.edge_face_add()
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
edge_added += 1
print( 'edge_added: ', edge_added )
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment