2
$\begingroup$

Apologies if some of my terminology is off - I'll happily update the answer if anyone points incorrect terms out to me!

I'm using Blender 2.76

I've created a mesh; which I would like to 'close' by adding in additional faces (or surfaces; or polygons ... not sure what to call them!)

enter image description here

Blender file: https://drive.google.com/open?id=0B_1YtzapYF0LX09DNFhoMHJPaUU

The faces parallel to the x are also open; but as those are curved; I'm just trying to full along the y axis for now.

I got the below data out of the console:

>>> mysurf.type
'MESH'

>>> mysurf.data.polygons.data
bpy.data.meshes['Mesh']

Yellow box is the face I want to add. And there are many of these running down the y axis.

I've constructed the mesh pragmatically; so I know the co-ordinates of the vertexes I want to connect with a face; so perhaps there is a simple command to add it in?

$\endgroup$
  • 1
    $\begingroup$ Please add a blendfile of your mesh, the specific structure will determine the best way to do this (bridge, grid fill, manual algorithm, etc) $\endgroup$ – TLousky Aug 8 '17 at 17:50
  • $\begingroup$ I couldn't see a way to upload it here; so I added a public link in google drive with the full blender file. $\endgroup$ – brent Aug 8 '17 at 18:22
2
$\begingroup$

I would not say "simple". With an understanding of how you constructed the mesh in question it would probably be possible to algorithmically generate the vertex indices for the new faces.

Without the algorithm all I can supply to you is the basic code of how to add faces to an existing mesh:

Here is an extract from http://web.purplefrog.com/~thoth/blender/python-cookbook/add-to-mesh.html that illustrates several idioms for modifying a mesh using bmesh. You are chiefly interested in the bm.faces.new( vertex_index_array ) technique.

import bpy
import bmesh


def mission1(scn):

    obj = scn.objects.active
    if bpy.context.mode == 'EDIT_MESH':
        bm = bmesh.from_edit_mesh(obj.data)
    else:
        bm = bmesh.new()
        bm.from_object(obj, scn)

    v2 = bm.verts.new( [0,7,0] )

    bm.verts.ensure_lookup_table()

    v1 = bm.verts[3]

    e1 = bm.edges.new( [v1, v2] )

    f1 = bm.faces.new( [v1, v2, bm.verts[7]])

    if bpy.context.mode == 'EDIT_MESH':
        bmesh.update_edit_mesh(obj.data)
    else:
        bm.to_mesh(obj.data)

    obj.data.update()

mission1(bpy.context.scene)

If you are willing to try without python, consider using Bridge Edge Loops: How can I automatically create edges according to the number of vertices?

$\endgroup$
  • $\begingroup$ Hi; thank you for the response; I just need to find time to get back to it -- side projects :) $\endgroup$ – brent Aug 11 '17 at 12:40
  • $\begingroup$ bm.faces.new & understanding the mesh where the points that set me on my path to success thanks! I put some extra details in a separate answer. But I did not give enough information in my question to be able to come up with those, so they are just for anyone else who might find them useful $\endgroup$ – brent Aug 13 '17 at 9:58
1
$\begingroup$

As Bob pointed out, knowing my mesh was key to finding a script.

The relevant (and not mentioned in the original question) points in my mesh:

1.) edges of the mesh I wanted to add faces between where where all very close to z = 0; and where the closest to z=0 in the entire mesh 2.) The top and bottom y co-ords were aligned; so I could get two edges (and hence 4 vertex's) by sorting edges by the y co-ord

... which gives the beautiful piece of python (sarcasm intended)

topAndBottomStringEdges = sorted(list(filter(lambda thisEdge: thisEdge.verts[0].co[0] < 0.0001 and thisEdge.verts[1].co[0] < 0.0001, bm.edges)), key=lambda edge: edge.verts[0].co[1])

... which I read as `get all the edges where both vertex's in the edge are very close to x=0; and sort those edges by their first y co-ord

I then walked through that list of edges, two at a time; and build a face

for i in range(lengthTB -1):
    print("i: " + str(i))
    a = i * 2
    b = i * 2 + 1
    vertsA = sorted(topAndBottomStringEdges[a].verts, key=lambda vert: vert.co[1])
    vertsB = sorted(topAndBottomStringEdges[b].verts, key=lambda vert: vert.co[1])

    print("vertsA [0] Y: " + str(vertsA[0].co[1]))
    print("vertsA [1] Y: " + str(vertsA[1].co[1]))
    print("vertsB [0] Y: " + str(vertsB[0].co[1]))
    print("vertsB [1] Y: " + str(vertsB[1].co[1]))
    print("")

    bm.faces.new([vertsB[0], vertsA[0], vertsA[1], vertsB[1]])
    bm.faces.ensure_lookup_table()

bmesh.update_edit_mesh(obj.data)

Maybe there is a much better way todo it?

$\endgroup$
  • $\begingroup$ The exact tactic a person would use depends on the nature of the mesh. A lot of the constructions I make are very mathematically regular and I can calculate the vertex indices with simple formulas. Other times they are not so predictable and I have to come up with heuristics, or do searches like yours. $\endgroup$ – Mutant Bob Aug 14 '17 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.