0
$\begingroup$

I'm trying to use "faces.new()" to fill a hole in mesh, Strangely when I use the function the newly create face looks like this:

enter image description here

Code:

import bpy, bmesh

obj = bpy.context.object.data
bm = bmesh.from_edit_mesh(bpy.context.active_object.data)

v = [v for v in bm.verts if v.select]

bm.faces.new(v)
bmesh.update_edit_mesh(obj)

Thanks in advance.

$\endgroup$
  • $\begingroup$ Check the normals and directions of the normals. Recalculate if needed with Ctrl+N whilst on edit mode $\endgroup$ – Reuben X Aug 17 '18 at 22:26
  • $\begingroup$ @ReubenX Checked the normals and recalculated it, but no difference. $\endgroup$ – user48739 Aug 18 '18 at 9:03
1
$\begingroup$

The contextual create operator.

Rather than calculate the winding order to create face with bm.faces.new(verts) let the operator do it for you.

bmesh.ops.contextual_create

Contextual Create.

This is basically F-key, it creates new faces from vertices, makes stuff from edge nets, makes wire edges, etc. It also dissolves faces.

Three verts become a triangle, four become a quad. Two become a wire edge.

import bpy
import bmesh

ob = bpy.context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)

verts = [v for v in bm.verts if v.select]
bmesh.ops.contextual_create(bm, geom=verts)

bmesh.update_edit_mesh(me)
$\endgroup$
0
$\begingroup$

The order that vertices are listed when defining the face, determines the order that they are connected. This tutorial can help explain it.

Say we have four vertices to make a face, with indexes of 0,1,2,3 going clockwise.

bm.faces.new([v[0], v[1], v[3], v[2]])

will give you the bowtie effect that you have, while

bm.faces.new([v[0], v[1], v[2], v[3]])

will give you the square face you are expecting.

I expect the only way to automate this is to walk around the selection to determine the connected order. A vertex lists what edges it creates in link_edges, from vert[0] an edge that includes another selected vert gives you the second vert, then that vert has an edge with another selected vert...

$\endgroup$

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.