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:
authorCampbell Barton <ideasman42@gmail.com>2019-09-21 07:47:34 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-09-21 07:49:06 +0300
commitd3811cba7b2072becdb1331c73940dd32dd5b29b (patch)
treee7df5811f7d4687488e8f3cb1604e4ec77e8f425 /io_mesh_ply
parent6a382b66a758b26e684327a29733f6e9656cf529 (diff)
PLY Format: ngon support for import/export
D5865 by @cmbasnett with minor edits.
Diffstat (limited to 'io_mesh_ply')
-rw-r--r--io_mesh_ply/export_ply.py29
-rw-r--r--io_mesh_ply/import_ply.py8
2 files changed, 17 insertions, 20 deletions
diff --git a/io_mesh_ply/export_ply.py b/io_mesh_ply/export_ply.py
index b14641be..db79e950 100644
--- a/io_mesh_ply/export_ply.py
+++ b/io_mesh_ply/export_ply.py
@@ -45,10 +45,6 @@ def save_mesh(
file = open(filepath, "w", encoding="utf8", newline="\n")
fw = file.write
- # Be sure tessellated loop trianlges are available!
- if not mesh.loop_triangles and mesh.polygons:
- mesh.calc_loop_triangles()
-
has_uv = bool(mesh.uv_layers)
has_vcol = bool(mesh.vertex_colors)
@@ -85,9 +81,9 @@ def save_mesh(
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.loop_triangles))]
+ ply_faces = [[] for f in range(len(mesh.polygons))]
vert_count = 0
- for i, f in enumerate(mesh.loop_triangles):
+ for i, f in enumerate(mesh.polygons):
smooth = not use_normals or f.use_smooth
if not smooth:
@@ -95,9 +91,15 @@ def save_mesh(
normal_key = rvec3d(normal)
if has_uv:
- uv = [active_uv_layer[l].uv[:] for l in f.loops]
+ uv = [
+ active_uv_layer[l].uv[:]
+ for l in range(f.loop_start, f.loop_start + f.loop_total)
+ ]
if has_vcol:
- col = [active_col_layer[l].color[:] for l in f.loops]
+ col = [
+ active_col_layer[l].color[:]
+ for l in range(f.loop_start, f.loop_start + f.loop_total)
+ ]
pf = ply_faces[i]
for j, vidx in enumerate(f.vertices):
@@ -156,7 +158,7 @@ def save_mesh(
"property uchar blue\n"
"property uchar alpha\n")
- fw("element face %d\n" % len(mesh.loop_triangles))
+ fw("element face %d\n" % len(mesh.polygons))
fw("property list uchar uint vertex_indices\n")
fw("end_header\n")
@@ -171,10 +173,11 @@ def save_mesh(
fw("\n")
for pf in ply_faces:
- if len(pf) == 3:
- fw("3 %d %d %d\n" % tuple(pf))
- else:
- fw("4 %d %d %d %d\n" % tuple(pf))
+ # fw(f"{len(pf)} {' '.join(str(x) for x in pf)}\n")
+ fw("%d" % len(pf))
+ for v in pf:
+ fw(" %d" % v)
+ fw("\n")
file.close()
print("writing %r done" % filepath)
diff --git a/io_mesh_ply/import_ply.py b/io_mesh_ply/import_ply.py
index 0e02951e..d0deee0a 100644
--- a/io_mesh_ply/import_ply.py
+++ b/io_mesh_ply/import_ply.py
@@ -318,13 +318,7 @@ def load_ply_mesh(filepath, ply_name):
if b'face' in obj:
for f in obj[b'face']:
ind = f[findex]
- len_ind = len(ind)
- if len_ind <= 4:
- add_face(verts, ind, uvindices, colindices)
- else:
- # Fan fill the face
- for j in range(len_ind - 2):
- add_face(verts, (ind[0], ind[j + 1], ind[j + 2]), uvindices, colindices)
+ add_face(verts, ind, uvindices, colindices)
if b'tristrips' in obj:
for t in obj[b'tristrips']: