rna api changes

- mesh.add_geometry(v, e, f)  --> mesh.vertices.add(tot), mesh.edges.add(tot), mesh.faces.add(tot)
- mesh.add_material(mat) --> mesh.materials.link(mat)

changed material.link so it always adds a material even if it exists in the list, this behavior is good for users but not scripts since it can mess up indicies (some formats may have the same material set twice).
This commit is contained in:
Campbell Barton
2010-08-26 22:44:05 +00:00
parent 9089b68073
commit 50bce31dbb
10 changed files with 140 additions and 44 deletions

View File

@@ -334,7 +334,8 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
bmesh = bpy.data.meshes.new(contextObName)
if myContextMesh_vertls:
bmesh.add_geometry(len(myContextMesh_vertls)//3, 0, len(myContextMesh_facels))
bmesh.vertices.add(len(myContextMesh_vertls)//3)
bmesh.faces.add(len(myContextMesh_facels))
bmesh.vertices.foreach_set("co", myContextMesh_vertls)
eekadoodle_faces = []
@@ -350,12 +351,13 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
for mat_idx, (matName, faces) in enumerate(myContextMeshMaterials.items()):
if matName is None:
bmesh.add_material(None)
bmat = None
else:
bmat = MATDICT[matName][1]
bmesh.add_material(bmat) # can be None
img = TEXTURE_DICT.get(bmat.name)
bmesh.materials.link(bmat) # can be None
if uv_faces and img:
for fidx in faces:
bmesh.faces[fidx].material_index = mat_idx

View File

@@ -673,10 +673,11 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v
# make sure the list isnt too big
for material in materials:
me.add_material(material)
me.materials.link(material)
#me.vertices.extend([(0,0,0)]) # dummy vert
me.add_geometry(len(verts_loc), 0, len(faces))
me.vertices.add(len(verts_loc))
me.faces.add(len(faces))
# verts_loc is a list of (x, y, z) tuples
me.vertices.foreach_set("co", unpack_list(verts_loc))
@@ -768,7 +769,7 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v
if CREATE_EDGES:
me.add_geometry(0, len(edges), 0)
me.edges.add(len(edges))
# edges should be a list of (a, b) tuples
me.edges.foreach_set("vertices", unpack_list(edges))

View File

@@ -306,7 +306,9 @@ class Mesh(bpy_types.ID):
Make a mesh from a list of verts/edges/faces
Until we have a nicer way to make geometry, use this.
"""
self.add_geometry(len(verts), len(edges), len(faces))
self.vertices.add(len(verts))
self.edges.add(len(edges))
self.faces.add(len(faces))
verts_flat = [f for v in verts for f in v]
self.vertices.foreach_set("co", verts_flat)
@@ -318,8 +320,11 @@ class Mesh(bpy_types.ID):
def treat_face(f):
if len(f) == 3:
return f[0], f[1], f[2], 0
elif f[3] == 0:
if f[2] == 0:
return f[2], f[0], f[1], 0
else:
return f[0], f[1], f[2], 0
elif f[2] == 0 or f[3] == 0:
return f[3], f[0], f[1], f[2]
return f

View File

@@ -121,7 +121,9 @@ class AddTorus(bpy.types.Operator):
mesh = bpy.data.meshes.new("Torus")
mesh.add_geometry(int(len(verts_loc) / 3), 0, int(len(faces) / 4))
mesh.vertices.add(len(verts_loc) // 3)
mesh.faces.add(len(faces) // 4)
mesh.vertices.foreach_set("co", verts_loc)
mesh.faces.foreach_set("vertices_raw", faces)
mesh.update()

View File

@@ -499,11 +499,13 @@ class MakeDupliFace(bpy.types.Operator):
for data, objects in linked.items():
face_verts = [axis for obj in objects for v in matrix_to_quat(obj.matrix_world) for axis in v]
faces = list(range(int(len(face_verts) / 3)))
faces = list(range(len(face_verts) // 3))
mesh = bpy.data.meshes.new(data.name + "_dupli")
mesh.add_geometry(int(len(face_verts) / 3), 0, int(len(face_verts) / (4 * 3)))
mesh.vertices.add(len(face_verts) // 3)
mesh.faces.add(len(face_verts) // 12)
mesh.vertices.foreach_set("co", face_verts)
mesh.faces.foreach_set("vertices_raw", faces)
mesh.update() # generates edge data