Commit 3ff4f00f authored by Dario Seyb's avatar Dario Seyb

fixed normal edge calculation for non-tri faces

parent 70cd9627
......@@ -11,7 +11,7 @@
"import numpy as np\n",
"\n",
"m = om.PolyMesh()\n",
"om.read_mesh(m, 'models/spot_quadrangulated.obj')\n",
"om.read_mesh(m, 'models/model_mixed_valence.obj')\n",
"\n",
"vertices = m.points()\n",
"faces = m.face_vertex_indices()\n",
......@@ -19,8 +19,17 @@
"\n",
"mesh = meshvis.Mesh(vertices, faces)\n",
"mesh.colors = meshvis.FaceAttribute(np.random.rand(len(faces), 3))\n",
"mesh.normals = meshvis.calculateFaceNormals(vertices, faces)\n",
"\n",
"meshvis.Context().draw(mesh).draw(meshvis.EdgeList(vertices, edges)).draw(meshvis.PointList(vertices), point_size=5).display()\n",
"normal_vis_verts, normal_vis_edges = meshvis.calculateNormalEdges(vertices, faces, mesh.normals, 1)\n",
"\n",
"ctx = meshvis.Context()\n",
"\n",
"ctx.draw(mesh).draw(meshvis.EdgeList(vertices, edges)).draw(meshvis.PointList(vertices, colors='#aaaaaa'), point_size=3)\n",
"\n",
"ctx.draw_edges(normal_vis_verts, normal_vis_edges)\n",
"\n",
"ctx.display()\n",
"\n"
]
}
......
......@@ -11,7 +11,7 @@
"import numpy as np\n",
"\n",
"m = om.PolyMesh()\n",
"om.read_mesh(m, 'models/spot_quadrangulated.obj')\n",
"om.read_mesh(m, 'models/model_mixed_valence.obj')\n",
"\n",
"vertices = m.points()\n",
"faces = m.face_vertex_indices()\n",
......@@ -19,8 +19,17 @@
"\n",
"mesh = meshvis.Mesh(vertices, faces)\n",
"mesh.colors = meshvis.FaceAttribute(np.random.rand(len(faces), 3))\n",
"mesh.normals = meshvis.calculateFaceNormals(vertices, faces)\n",
"\n",
"meshvis.Context().draw(mesh).draw(meshvis.EdgeList(vertices, edges)).draw(meshvis.PointList(vertices), point_size=5).display()\n",
"normal_vis_verts, normal_vis_edges = meshvis.calculateNormalEdges(vertices, faces, mesh.normals, 1)\n",
"\n",
"ctx = meshvis.Context()\n",
"\n",
"ctx.draw(mesh).draw(meshvis.EdgeList(vertices, edges)).draw(meshvis.PointList(vertices, colors='#aaaaaa'), point_size=3)\n",
"\n",
"ctx.draw_edges(normal_vis_verts, normal_vis_edges)\n",
"\n",
"ctx.display()\n",
"\n"
]
}
......
# Blender v2.79 (sub 0) OBJ File: ''
# www.blender.org
v -1.000000 -1.000000 1.260390
v -1.000000 1.000000 1.191139
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v -1.000000 0.000000 1.887504
v 2.246086 -1.000000 1.000000
v 2.246086 1.000000 1.000000
v 2.246086 -1.000000 -1.000000
v 2.246086 1.000000 -1.000000
vn -1.0000 0.0000 0.0000
vn 0.0000 0.0000 -1.0000
vn 0.0000 1.0000 0.0000
vn 0.2681 0.0167 0.9632
vn 0.0000 -1.0000 0.0000
vn 1.0000 0.0000 0.0000
vn 0.0000 0.0000 1.0000
s off
f 1//1 9//1 2//1 4//1 3//1
f 3//2 4//2 8//2 13//2 12//2 7//2
f 8//3 6//3 11//3 13//3
f 5//4 6//4 2//4 9//4 1//4
f 3//5 7//5 5//5 1//5
f 4//3 6//3 8//3
f 4//3 2//3 6//3
f 12//6 13//6 11//6 10//6
f 6//7 5//7 10//7 11//7
f 5//5 7//5 12//5 10//5
......@@ -10,10 +10,8 @@ def calculateNormalEdges(vertices, face_indices, normals, length):
resolved_normals = normals.values
face_centers = []
for face in face_indices:
v1 = np.array(vertices[face[0]])
v2 = np.array(vertices[face[1]])
v3 = np.array(vertices[face[2]])
face_centers.append((v1 + v2 + v3)/3)
face_vertices = vertices[face]
face_centers.append(np.average(face_vertices, axis=0, weights=face!=-1))
vertices = face_centers
else:
resolved_normals = resolve_attributes(face_indices, [normals])[0]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment