Compare commits

...

4 Commits

Author SHA1 Message Date
izzy lyseggen 4a8a0ca6c7 Merge pull request #66 from specklesystems/jm/ngons
Ngon Support
2021-11-29 10:54:20 +00:00
izzy lyseggen 3c0d1eba65 style: remove old comment re face error
(was resolved in #35)
2021-11-29 10:52:02 +00:00
JR-Morgan 14aaf4f064 N-gon ToSpeckle should now work! 2021-11-25 16:54:35 +00:00
JR-Morgan 10bf3e3af5 Experimenting with n-gon sending 2021-11-25 13:55:18 +00:00
3 changed files with 16 additions and 38 deletions
+1
View File
@@ -5,6 +5,7 @@ __pycache__/
# editor
.vscode
.idea
# dev
.venv
+11 -33
View File
@@ -24,40 +24,18 @@ def add_faces(smesh, bmesh, smooth=False):
if sfaces and len(sfaces) > 0:
i = 0
# TODO: why does `faces.new()` seem to fail so often?
while i < len(sfaces):
if sfaces[i] == 0:
i += 1
try:
f = bmesh.faces.new(
(
bmesh.verts[int(sfaces[i])],
bmesh.verts[int(sfaces[i + 1])],
bmesh.verts[int(sfaces[i + 2])],
)
)
f.smooth = smooth
except Exception as e:
_report(f"Failed to create face for mesh {smesh.id} \n{e}")
i += 3
elif sfaces[i] == 1:
i += 1
try:
f = bmesh.faces.new(
(
bmesh.verts[int(sfaces[i])],
bmesh.verts[int(sfaces[i + 1])],
bmesh.verts[int(sfaces[i + 2])],
bmesh.verts[int(sfaces[i + 3])],
)
)
f.smooth = smooth
except Exception as e:
_report(f"Failed to create face for mesh {smesh.id} \n{e}")
i += 4
else:
print("Invalid face length.\n" + str(sfaces[i]))
break
n = sfaces[i]
if n < 3:
n += 3 # 0 -> 3, 1 -> 4
i += 1
try:
f = bmesh.faces.new([bmesh.verts[int(x)] for x in sfaces[i : i + n]])
f.smooth = smooth
except Exception as e:
_report(f"Failed to create face for mesh {smesh.id} \n{e}")
i += n
bmesh.faces.ensure_lookup_table()
bmesh.verts.index_update()
+4 -5
View File
@@ -14,8 +14,6 @@ def export_mesh(blender_object, data, scale=1.0):
verts = [tuple(mat @ x.co * scale) for x in data.vertices]
# TODO: add n-gon support, using tessfaces for now
# faces = [x.vertices for x in data.loop_triangles]
faces = [p.vertices for p in data.polygons]
unit_system = bpy.context.scene.unit_settings.system
@@ -34,12 +32,13 @@ def export_mesh(blender_object, data, scale=1.0):
sm.textureCoordinates.extend([vt.uv.x, vt.uv.y])
for f in faces:
if len(f) == 3:
n = len(f)
if n == 3:
sm.faces.append(0)
elif len(f) == 4:
elif n == 4:
sm.faces.append(1)
else:
continue
sm.faces.append(n)
sm.faces.extend(f)
return [sm]