Commit 9c3d736b authored by Dario Seyb's avatar Dario Seyb

nicer face normal display

parent f6162ac9
......@@ -8,15 +8,18 @@
},
"outputs": [
{
"ename": "TypeError",
"evalue": "Cannot cast ufunc add output from dtype('float64') to dtype('int32') with casting rule 'same_kind'",
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-1-93ec749cebc3>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mctx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmeshvis\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mContext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mwidth\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m640\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mheight\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m480\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 9\u001b[1;33m \u001b[0mnormals\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmeshvis\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcalculatePointNormals\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvertices\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mm\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpoints\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mface_indices\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mm\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mface_vertex_indices\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 10\u001b[0m ctx.draw_faces(m.points(), m.face_vertex_indices(), \n\u001b[0;32m 11\u001b[0m \u001b[0mnormals\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnormals\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\dev\\meshvis\\meshvis\\mesh_helper.pyc\u001b[0m in \u001b[0;36mcalculatePointNormals\u001b[1;34m(vertices, face_indices)\u001b[0m\n\u001b[0;32m 50\u001b[0m \u001b[0mnorm\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnorm\u001b[0m \u001b[1;33m/\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlinalg\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnorm\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnorm\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 51\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 52\u001b[1;33m \u001b[0mvalues\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mface\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+=\u001b[0m \u001b[0mnorm\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 53\u001b[0m \u001b[0mvalues\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mface\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+=\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 54\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mTypeError\u001b[0m: Cannot cast ufunc add output from dtype('float64') to dtype('int32') with casting rule 'same_kind'"
"\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-1-76bf9396fe4c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[0mnormals\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'vertex'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[0mcolors\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmeshvis\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mUniformAttribute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\u001b[1;33m shading = 'flat')\n\u001b[0m\u001b[0;32m 13\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 14\u001b[0m ctx.draw_edges(m.points(), m.ev_indices(), \n",
"\u001b[1;32mc:\\dev\\meshvis\\meshvis\\context.pyc\u001b[0m in \u001b[0;36mdraw_faces\u001b[1;34m(self, vertices, face_indices, normals, colors, uvs, shading, z_offset)\u001b[0m\n\u001b[0;32m 54\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 55\u001b[0m \u001b[1;31m# Resolve the given attributes, it's ok if they are None\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 56\u001b[1;33m \u001b[0mresolved_attribs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresolve_attributes\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mface_indices\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mnormals\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolors\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0muvs\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 57\u001b[0m \u001b[0mresolved_normals\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresolved_attribs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 58\u001b[0m \u001b[0mresolved_colors\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresolved_attribs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\dev\\meshvis\\meshvis\\indexed_attribute.pyc\u001b[0m in \u001b[0;36mresolve_attributes\u001b[1;34m(face_indices, attribs)\u001b[0m\n\u001b[0;32m 19\u001b[0m \u001b[1;32mcontinue\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 20\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 21\u001b[1;33m \u001b[0mresolved_attrib\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mattrib\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mresolve\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mface_indices\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 22\u001b[0m \u001b[0mfinal_attributes\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstretch_attribute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mface_indices\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mresolved_attrib\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 23\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\dev\\meshvis\\meshvis\\indexed_attribute.pyc\u001b[0m in \u001b[0;36mresolve\u001b[1;34m(self, face_indices)\u001b[0m\n\u001b[0;32m 70\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mf_idx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mface\u001b[0m \u001b[1;32min\u001b[0m \u001b[0menumerate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mface_indices\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 71\u001b[0m \u001b[1;31m# check if vertex is in face\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 72\u001b[1;33m \u001b[0midx_in_face\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfind\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0midx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mface\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 73\u001b[0m \u001b[1;31m# if yes, add value for vertex in that face\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 74\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0midx_in_face\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\dev\\meshvis\\meshvis\\indexed_attribute.pyc\u001b[0m in \u001b[0;36mfind\u001b[1;34m(element, list_element)\u001b[0m\n\u001b[0;32m 35\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mfind\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0melement\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlist_element\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 36\u001b[0m \u001b[0mindex_element\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwhere\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlist_element\u001b[0m\u001b[1;33m==\u001b[0m\u001b[0melement\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 37\u001b[1;33m \u001b[1;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mindex_element\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mindex_element\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 38\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 39\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mKeyboardInterrupt\u001b[0m: "
]
}
],
......@@ -25,14 +28,15 @@
"import openmesh as om\n",
"import numpy as np\n",
"m = om.TriMesh()\n",
"om.read_mesh(m, \"C:/dev/openmesh-python/tests/TestFiles/cube-minimal-vertex-colors-after-vertex-definition.obj\")\n",
"om.read_mesh(m, \"C:/Users/dario/OneDrive/Dokumente/ANIMVR/Import/Models/Mickey_Mouse.obj\")\n",
"\n",
"ctx = meshvis.Context(width=640, height=480)\n",
"\n",
"normals = meshvis.calculatePointNormals(vertices=m.points(), face_indices=m.face_vertex_indices())\n",
"normals = meshvis.calculateFaceNormals(m.points(), m.face_vertex_indices())\n",
"ctx.draw_faces(m.points(), m.face_vertex_indices(), \n",
" normals = normals,\n",
" colors = meshvis.UniformAttribute([0, 0, 1]))\n",
" colors = meshvis.UniformAttribute([0, 0, 1]),\n",
" shading = 'flat')\n",
"\n",
"ctx.draw_edges(m.points(), m.ev_indices(), \n",
" colors = meshvis.FaceAttribute(np.random.rand(len(m.ev_indices()), 3)),\n",
......
......@@ -8,16 +8,75 @@
},
"outputs": [
{
"ename": "TypeError",
"evalue": "'tuple' object does not support item assignment",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-1-93ec749cebc3>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mctx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmeshvis\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mContext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mwidth\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m640\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mheight\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m480\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 9\u001b[1;33m \u001b[0mnormals\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmeshvis\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcalculatePointNormals\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvertices\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mm\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpoints\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mface_indices\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mm\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mface_vertex_indices\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 10\u001b[0m ctx.draw_faces(m.points(), m.face_vertex_indices(), \n\u001b[0;32m 11\u001b[0m \u001b[0mnormals\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnormals\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\dev\\meshvis\\meshvis\\mesh_helper.pyc\u001b[0m in \u001b[0;36mcalculatePointNormals\u001b[1;34m(vertices, face_indices)\u001b[0m\n\u001b[0;32m 50\u001b[0m \u001b[0mnorm\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnorm\u001b[0m \u001b[1;33m/\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlinalg\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnorm\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnorm\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 51\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 52\u001b[1;33m \u001b[0mvalues\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mface\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+=\u001b[0m \u001b[0mnorm\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 53\u001b[0m \u001b[0mvalues\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mface\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+=\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 54\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
]
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "40e1183488374653b59b2f649157dc05",
"version_major": 2,
"version_minor": 0
},
"text/html": [
"<p>Failed to display Jupyter Widget of type <code>Renderer</code>.</p>\n",
"<p>\n",
" If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n",
" that the widgets JavaScript is still loading. If this message persists, it\n",
" likely means that the widgets JavaScript library is either not installed or\n",
" not enabled. See the <a href=\"https://ipywidgets.readthedocs.io/en/stable/user_install.html\">Jupyter\n",
" Widgets Documentation</a> for setup instructions.\n",
"</p>\n",
"<p>\n",
" If you're reading this message in another frontend (for example, a static\n",
" rendering on GitHub or <a href=\"https://nbviewer.jupyter.org/\">NBViewer</a>),\n",
" it may mean that your frontend doesn't currently support widgets.\n",
"</p>\n"
],
"text/plain": [
"Renderer(background='#dddddd', camera=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(3.0, 3.0, 3.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), controls=[OrbitControls(controlling=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(3.0, 3.0, 3.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)))], scene=Scene(background=u'#dddddd', children=(AmbientLight(color=u'#aaaaaa', quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(3.0, 3.0, 3.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), Mesh(geometry=BufferGeometry(attributes={'color': BufferAttribute(array=array([[0., 0., 1.],\n",
" [0., 0., 1.],\n",
" [0., 0., 1.],\n",
" ...,\n",
" [0., 0., 1.],\n",
" [0., 0., 1.],\n",
" [0., 0., 1.]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 20457, 20458, 20459], dtype=uint16), normalized=False), 'normal': BufferAttribute(array=array([[ 0.20979331, 0.07998422, -0.9744687 ],\n",
" [ 0.20979331, 0.07998422, -0.9744687 ],\n",
" [ 0.20979331, 0.07998422, -0.9744687 ],\n",
" ...,\n",
" [-0.13065 , 0.8949016 , -0.4267104 ],\n",
" [-0.13065 , 0.8949016 , -0.4267104 ],\n",
" [-0.13065 , 0.8949016 , -0.4267104 ]], dtype=float32)), 'position': BufferAttribute(array=array([[-0.283628, 2.931106, -0.140772],\n",
" [-0.22873 , 2.855558, -0.135154],\n",
" [-0.34671 , 2.856239, -0.160498],\n",
" ...,\n",
" [ 0.280426, 0.4863 , -0.003152],\n",
" [ 0.332014, 0.467158, -0.059092],\n",
" [ 0.216602, 0.471758, -0.014108]], dtype=float32), normalized=False)}), material=MeshLambertMaterial(alphaMap=None, aoMap=None, color=u'white', emissiveMap=None, envMap=None, lightMap=None, map=None, polygonOffset=True, polygonOffsetFactor=0.5, polygonOffsetUnits=0.1, specularMap=None, vertexColors='VertexColors'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), LineSegments(geometry=BufferGeometry(attributes={'color': BufferAttribute(array=array([[0.9325565 , 0.16986644, 0.6348343 ],\n",
" [0.9325565 , 0.16986644, 0.6348343 ],\n",
" [0.03978208, 0.81539804, 0.52545714],\n",
" ...,\n",
" [0.5830377 , 0.16484123, 0.0814902 ],\n",
" [0.19853802, 0.6814414 , 0.01031223],\n",
" [0.19853802, 0.6814414 , 0.01031223]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 20569, 20570, 20571], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-0.283628, 2.931106, -0.140772],\n",
" [-0.22873 , 2.855558, -0.135154],\n",
" [-0.22873 , 2.855558, -0.135154],\n",
" ...,\n",
" [ 0.157628, 0.430178, -0.130118],\n",
" [ 0.216602, 0.471758, -0.014108],\n",
" [ 0.332014, 0.467158, -0.059092]], dtype=float32), normalized=False)}), material=LineBasicMaterial(color=u'white', linewidth=3.0, vertexColors='VertexColors'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), LineSegments(geometry=BufferGeometry(attributes={'index': BufferAttribute(array=array([ 0, 1, 2, ..., 13637, 13638, 13639], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-0.286356 , 2.8809676 , -0.14547466],\n",
" [-0.26537666, 2.888966 , -0.24292153],\n",
" [-0.295662 , 2.8398848 , -0.15085067],\n",
" ...,\n",
" [ 0.2812651 , 0.5552246 , -0.09855373],\n",
" [ 0.27634734, 0.475072 , -0.02545067],\n",
" [ 0.26328233, 0.56456214, -0.06812171]], dtype=float32), normalized=False)}), material=LineBasicMaterial(color=u'#000000'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), Points(geometry=BufferGeometry(attributes={'position': BufferAttribute(array=array([[-0.283628, 2.931106, -0.140772],\n",
" [-0.22873 , 2.855558, -0.135154],\n",
" [-0.34671 , 2.856239, -0.160498],\n",
" ...,\n",
" [-0.675122, 1.403736, -0.094798],\n",
" [-0.700144, 1.367866, -0.036312],\n",
" [-0.708084, 1.391306, -0.0961 ]], dtype=float32), normalized=False)}), material=PointsMaterial(color=u'red', map=None, size=4.0, sizeAttenuation=False), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0))), fog=None, overrideMaterial=None, quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), shadowMap=WebGLShadowMap())"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
......@@ -25,14 +84,15 @@
"import openmesh as om\n",
"import numpy as np\n",
"m = om.TriMesh()\n",
"om.read_mesh(m, \"C:/dev/openmesh-python/tests/TestFiles/cube-minimal-vertex-colors-after-vertex-definition.obj\")\n",
"om.read_mesh(m, \"C:/Users/dario/OneDrive/Dokumente/ANIMVR/Import/Models/Mickey_Mouse.obj\")\n",
"\n",
"ctx = meshvis.Context(width=640, height=480)\n",
"\n",
"normals = meshvis.calculatePointNormals(vertices=m.points(), face_indices=m.face_vertex_indices())\n",
"normals = meshvis.calculateFaceNormals(m.points(), m.face_vertex_indices())\n",
"ctx.draw_faces(m.points(), m.face_vertex_indices(), \n",
" normals = normals,\n",
" colors = meshvis.UniformAttribute([0, 0, 1]))\n",
" colors = meshvis.UniformAttribute([0, 0, 1]),\n",
" shading = 'flat')\n",
"\n",
"ctx.draw_edges(m.points(), m.ev_indices(), \n",
" colors = meshvis.FaceAttribute(np.random.rand(len(m.ev_indices()), 3)),\n",
......
......@@ -3,7 +3,7 @@ import pythreejs as three
import numpy as np
from IPython.display import display
from .indexed_attribute import *
from .mesh_helper import calculateFaceNormals
from .mesh_helper import calculateFaceNormals, calculatePointNormals
class Context(object):
def __init__(self, width=600, height=400, background_color = '#dddddd'):
......@@ -33,8 +33,13 @@ class Context(object):
face_indices = np.array(face_indices)
mat = None
# Setup Material
mat = three.MeshLambertMaterial(color='#dddddd', colorWrite=shading is not 'hidden')
if shading == 'flat' or shading == 'hidden' or shading == 'wireframe':
mat = three.MeshLambertMaterial(color='#dddddd', colorWrite=shading is not 'hidden')
elif shading == 'phong':
mat = three.MeshPhongMaterial(color='#dddddd')
mat.wireframe = shading is 'wireframe'
if z_offset is not 0:
......@@ -42,7 +47,9 @@ class Context(object):
mat.polygonOffsetFactor = z_offset
mat.polygonOffsetUnits = 0.1
if normals is None:
if normals is 'vertex':
normals = calculatePointNormals(vertices, face_indices)
elif normals is 'face':
normals = calculateFaceNormals(vertices, face_indices)
# Resolve the given attributes, it's ok if they are None
......
......@@ -3,8 +3,21 @@ import numpy as np
def calculateNormalEdges(vertices, face_indices, normals, length):
resolved_normals = resolve_attributes(face_indices, [normals])[0]
vertices, face_indices = stretch_vertices(vertices, face_indices)
resolved_normals = None
if isinstance(normals, FaceAttribute):
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)
vertices = face_centers
else:
resolved_normals = resolve_attributes(face_indices, [normals])[0]
vertices, face_indices = stretch_vertices(vertices, face_indices)
edge_vertices = []
edge_indices = []
......@@ -36,7 +49,7 @@ def calculateFaceNormals(vertices, face_indices):
return FaceAttribute(values)
def calculatePointNormals(vertices, face_indices):
def calculatePointNormals(vertices, face_indices):
values = [(np.array([0.0, 0.0, 0.0]), 0)] * len(vertices)
for face in face_indices:
v1 = np.array(vertices[face[0]])
......@@ -47,7 +60,6 @@ def calculatePointNormals(vertices, face_indices):
v13 = np.subtract(v3, v1)
norm = np.cross(v12, v13)
values[face[0]] = ( values[face[0]][0] + norm, values[face[0]][1] + 1)
values[face[1]] = ( values[face[1]][0] + norm, values[face[1]][1] + 1)
......
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