Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2018-10-09 20:08:04 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2018-10-10 18:25:48 +0300
commit227fafdfcf4fb441ba1b8477331d543d2cf087af (patch)
tree26a0ac762d8985007286884992194c690696cb46 /io_mesh_ply
parentadb4f822ca2383ec269c529d62419f3e6998bd48 (diff)
Update for removal of tessfaces.
This ports the already working addons. The disabled x3d, psk, lwo, 3ds, raw, dxf addons still need to be converted.
Diffstat (limited to 'io_mesh_ply')
-rw-r--r--io_mesh_ply/export_ply.py26
-rw-r--r--io_mesh_ply/import_ply.py62
2 files changed, 44 insertions, 44 deletions
diff --git a/io_mesh_ply/export_ply.py b/io_mesh_ply/export_ply.py
index b6ab8810..b50b6544 100644
--- a/io_mesh_ply/export_ply.py
+++ b/io_mesh_ply/export_ply.py
@@ -44,12 +44,12 @@ def save_mesh(filepath,
file = open(filepath, "w", encoding="utf8", newline="\n")
fw = file.write
- # Be sure tessface & co are available!
- if not mesh.tessfaces and mesh.polygons:
- mesh.calc_tessface()
+ # Be sure tessellated loop trianlges are available!
+ if not mesh.loop_triangles and mesh.polygons:
+ mesh.calc_loop_triangles()
- has_uv = bool(mesh.tessface_uv_textures)
- has_vcol = bool(mesh.tessface_vertex_colors)
+ has_uv = bool(mesh.uv_layers)
+ has_vcol = bool(mesh.vertex_colors)
if not has_uv:
use_uv_coords = False
@@ -62,7 +62,7 @@ def save_mesh(filepath,
has_vcol = False
if has_uv:
- active_uv_layer = mesh.tessface_uv_textures.active
+ active_uv_layer = mesh.uv_layers.active
if not active_uv_layer:
use_uv_coords = False
has_uv = False
@@ -70,7 +70,7 @@ def save_mesh(filepath,
active_uv_layer = active_uv_layer.data
if has_vcol:
- active_col_layer = mesh.tessface_vertex_colors.active
+ active_col_layer = mesh.vertex_colors.active
if not active_col_layer:
use_colors = False
has_vcol = False
@@ -84,9 +84,9 @@ def save_mesh(filepath,
ply_verts = [] # list of dictionaries
# vdict = {} # (index, normal, uv) -> new index
vdict = [{} for i in range(len(mesh_verts))]
- ply_faces = [[] for f in range(len(mesh.tessfaces))]
+ ply_faces = [[] for f in range(len(mesh.loop_triangles))]
vert_count = 0
- for i, f in enumerate(mesh.tessfaces):
+ for i, f in enumerate(mesh.loop_triangles):
smooth = not use_normals or f.use_smooth
if not smooth:
@@ -94,11 +94,9 @@ def save_mesh(filepath,
normal_key = rvec3d(normal)
if has_uv:
- uv = active_uv_layer[i]
- uv = uv.uv1, uv.uv2, uv.uv3, uv.uv4
+ uv = [active_uv_layer[l].uv[:] for l in f.loops]
if has_vcol:
- col = active_col_layer[i]
- col = col.color1[:], col.color2[:], col.color3[:], col.color4[:]
+ col = [active_col_layer[l].color[:] for l in f.loops]
pf = ply_faces[i]
for j, vidx in enumerate(f.vertices):
@@ -156,7 +154,7 @@ def save_mesh(filepath,
"property uchar blue\n"
"property uchar alpha\n")
- fw("element face %d\n" % len(mesh.tessfaces))
+ fw("element face %d\n" % len(mesh.loop_triangles))
fw("property list uchar uint vertex_indices\n")
fw("end_header\n")
diff --git a/io_mesh_ply/import_ply.py b/io_mesh_ply/import_ply.py
index a106f6e4..f05e1caa 100644
--- a/io_mesh_ply/import_ply.py
+++ b/io_mesh_ply/import_ply.py
@@ -263,9 +263,9 @@ def load_ply_mesh(filepath, ply_name):
def add_face(vertices, indices, uvindices, colindices):
mesh_faces.append(indices)
if uvindices:
- mesh_uvs.append([(vertices[index][uvindices[0]], vertices[index][uvindices[1]]) for index in indices])
+ mesh_uvs.extend([(vertices[index][uvindices[0]], vertices[index][uvindices[1]]) for index in indices])
if colindices:
- mesh_colors.append([(vertices[index][colindices[0]] * colmultiply[0],
+ mesh_colors.extend([(vertices[index][colindices[0]] * colmultiply[0],
vertices[index][colindices[1]] * colmultiply[1],
vertices[index][colindices[2]] * colmultiply[2],
vertices[index][colindices[3]] * colmultiply[3],
@@ -317,35 +317,37 @@ def load_ply_mesh(filepath, ply_name):
mesh.edges.foreach_set("vertices", [a for e in obj[b'edge'] for a in (e[eindex1], e[eindex2])])
if mesh_faces:
- mesh.tessfaces.add(len(mesh_faces))
- mesh.tessfaces.foreach_set("vertices_raw", unpack_face_list(mesh_faces))
-
- if uvindices or colindices:
- if uvindices:
- uvlay = mesh.tessface_uv_textures.new()
- if colindices:
- vcol_lay = mesh.tessface_vertex_colors.new()
-
- if uvindices:
- for i, f in enumerate(uvlay.data):
- ply_uv = mesh_uvs[i]
- for j, uv in enumerate(f.uv):
- uv[0], uv[1] = ply_uv[j]
-
- if colindices:
- for i, f in enumerate(vcol_lay.data):
- # XXX, colors dont come in right, needs further investigation.
- ply_col = mesh_colors[i]
- if len(ply_col) == 4:
- f_col = f.color1, f.color2, f.color3, f.color4
- else:
- f_col = f.color1, f.color2, f.color3
+ loops_vert_idx = []
+ faces_loop_start = []
+ faces_loop_total = []
+ lidx = 0
+ for f in mesh_faces:
+ nbr_vidx = len(f)
+ loops_vert_idx.extend(f)
+ faces_loop_start.append(lidx)
+ faces_loop_total.append(nbr_vidx)
+ lidx += nbr_vidx
+
+ mesh.loops.add(len(loops_vert_idx))
+ mesh.polygons.add(len(mesh_faces))
+
+ mesh.loops.foreach_set("vertex_index", loops_vert_idx)
+ mesh.polygons.foreach_set("loop_start", faces_loop_start)
+ mesh.polygons.foreach_set("loop_total", faces_loop_total)
+
+ if uvindices:
+ uv_layer = mesh.uv_layers.new()
+ for i, uv in enumerate(uv_layer.data):
+ uv.uv = mesh_uvs[i]
+
+ if colindices:
+ vcol_lay = mesh.vertex_colors.new()
- for j, col in enumerate(f_col):
- col[0] = ply_col[j][0]
- col[1] = ply_col[j][1]
- col[2] = ply_col[j][2]
- col[3] = ply_col[j][3]
+ for i, col in enumerate(vcol_lay.data):
+ col.color[0] = mesh_colors[i][0]
+ col.color[1] = mesh_colors[i][1]
+ col.color[2] = mesh_colors[i][2]
+ col.color[3] = mesh_colors[i][3]
mesh.update()
mesh.validate()