Skip to content

Instantly share code, notes, and snippets.

Created June 10, 2013 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5750782 to your computer and use it in GitHub Desktop.
Save anonymous/5750782 to your computer and use it in GitHub Desktop.
test
def mesh_append_face( obj, bm, vertex_list, uv_list, texture_name ):
# add vertices and uvs before creating the new face
for vert in vertex_list:
bm.verts.new((*vert))
bm.faces.new( ( bm.verts[i] for i in range( -len( vertex_list ), 0)) )
# add uvs to the new face
uv_layer = bm.loops.layers.uv.verify()
bm.faces.layers.tex.verify()
face = bm.faces[-1]
for i, loop in enumerate(face.loops):
loop[uv_layer].uv = uv_list[i]
# assign material
try:
material_names = [ m.name for m in obj.data.materials ]
material_id = material_names.index(texture_name)
except ValueError:
obj.data.materials.append(bpy.data.materials[texture_name])
material_id = len(obj.data.materials) - 1
face.material_index = material_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment