Commit 174dacff authored by Dario Seyb's avatar Dario Seyb

better shading

parent d950e0e6
......@@ -2,13 +2,15 @@
"cells": [
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"execution_count": 1,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "acf4a18369ac43e4b888569f36146bdf",
"model_id": "d813d85f9c45487c84559edd73d51d9c",
"version_major": 2,
"version_minor": 0
},
......@@ -28,7 +30,7 @@
"</p>\n"
],
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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(children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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'#dddddd', 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={'index': BufferAttribute(array=array([ 0, 1, 2, ..., 3439, 3436, 3440], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-0.283628, 2.931106, -0.140772],\n",
"Renderer(background='#dddddd', camera=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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(intensity=0.5, position=(-3.0, 5.0, 1.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'#dddddd', 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={'index': BufferAttribute(array=array([ 0, 1, 2, ..., 3439, 3436, 3440], dtype=uint16), normalized=False), '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",
......@@ -46,7 +48,7 @@
" ...,\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=3.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())"
" [-0.708084, 1.391306, -0.0961 ]], dtype=float32), normalized=False)}), material=PointsMaterial(color=u'red', map=None, size=5.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": {},
......@@ -59,13 +61,13 @@
"m = om.TriMesh()\n",
"om.read_mesh(m, \"C:\\Users\\dario\\OneDrive\\Dokumente\\ANIMVR\\Import\\Models\\Mickey_Mouse.obj\")\n",
"\n",
"ctx = meshvis.Context()\n",
"ctx = meshvis.Context(width=640, height=480)\n",
"\n",
"ctx.draw_faces(m.points(), m.face_indices(), hidden=True)\n",
"ctx.draw_faces(m.points(), m.face_indices(), shading='hidden')\n",
"\n",
"ctx.draw_edges(m.points(), m.face_indices())\n",
"\n",
"ctx.draw_vertices(m.points(), point_size=3, colors='red')\n",
"ctx.draw_vertices(m.points(), point_size=5, colors='red')\n",
"\n",
"ctx.display()"
]
......@@ -78,7 +80,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5460164864a84b4eaa05121ba21e88ac",
"model_id": "3dcb19928c724c05aa9949e2f52e1f8b",
"version_major": 2,
"version_minor": 0
},
......@@ -98,10 +100,13 @@
"</p>\n"
],
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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(children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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'#dddddd', 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, 3], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[0., 0., 0.],\n",
"Renderer(background='#dddddd', camera=PerspectiveCamera(aspect=1.5, children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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.5, children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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'#dddddd', 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([[1., 0., 0.],\n",
" [0., 1., 0.],\n",
" [0., 0., 1.],\n",
" [1., 0., 1.]], dtype=float32)), 'index': BufferAttribute(array=array([0, 1, 2, 3], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[0., 0., 0.],\n",
" [1., 0., 0.],\n",
" [1., 1., 0.],\n",
" [0., 1., 0.]], dtype=float32), normalized=False)}), material=LineBasicMaterial(color=u'#000000', polygonOffset=True, polygonOffsetFactor=0.001, polygonOffsetUnits=0.1), 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())"
" [0., 1., 0.]], dtype=float32), normalized=False)}), material=LineBasicMaterial(color=u'white', polygonOffset=True, polygonOffsetFactor=0.001, polygonOffsetUnits=0.1, 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))), 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": {},
......@@ -109,7 +114,22 @@
}
],
"source": [
"meshvis.display_edges([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], [[0, 1], [2,3]])"
"\n",
"vcolors = [\n",
" [1, 0, 0],\n",
" [0, 1, 0],\n",
" [0, 0, 1],\n",
" [1, 0, 1]\n",
"]\n",
"\n",
"fcolors = [\n",
" [1, 0, 0],\n",
" [0, 0, 1]\n",
"]\n",
"\n",
"meshvis.display_edges([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], \n",
" [[0, 1], [2,3]], \n",
" per_vertex_colors = vcolors)"
]
},
{
......@@ -120,7 +140,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "75b7d67e17b0427484fc4782fd2fa298",
"model_id": "4ddd51d1babd4ac8b8c4fc7f93523362",
"version_major": 2,
"version_minor": 0
},
......@@ -140,8 +160,8 @@
"</p>\n"
],
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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(children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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'#dddddd', 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={'color': BufferAttribute(array=array([1., 1., 0.], dtype=float32)), 'position': BufferAttribute(array=array([[0., 0., 0.],\n",
" [1., 1., 1.]], dtype=float32), normalized=False)}), material=PointsMaterial(color=u'#dddddd', map=None, size=10.0, sizeAttenuation=False, 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))), 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())"
"Renderer(background='#dddddd', camera=PerspectiveCamera(aspect=1.5, children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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.5, children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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'#dddddd', 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., 0., 0.],\n",
" [1., 0., 0.]], dtype=float32), normalized=False)}), material=PointsMaterial(color=u'blue', map=None, size=10.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": {},
......@@ -149,15 +169,89 @@
}
],
"source": [
"meshvis.display_vertices([[0,0,0],[1,1,1]], [1,1,0], point_size=10)"
"meshvis.display_vertices([[0,0,0],[1,0, 0]], colors='blue', point_size=10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4b39b21a50c840e9889e98951b01e6e8",
"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(children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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(children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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'#dddddd', 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([[1., 0., 0.],\n",
" [0., 1., 0.],\n",
" [0., 0., 1.],\n",
" [1., 0., 1.]], dtype=float32)), 'index': BufferAttribute(array=array([0, 1, 2, 0, 2, 3], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-1., -1., 1.],\n",
" [ 1., -1., 1.],\n",
" [ 1., 1., 1.],\n",
" [-1., 1., 1.]], 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)), Points(geometry=BufferGeometry(attributes={'color': BufferAttribute(array=array([[1., 0., 0.],\n",
" [0., 1., 0.],\n",
" [0., 0., 1.],\n",
" [1., 0., 1.]], dtype=float32)), 'position': BufferAttribute(array=array([[-1., -1., 1.],\n",
" [ 1., -1., 1.],\n",
" [ 1., 1., 1.],\n",
" [-1., 1., 1.]], dtype=float32), normalized=False)}), material=PointsMaterial(color=u'#dddddd', map=None, size=5.0, sizeAttenuation=False, 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))), 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": [
"verts = [\n",
" # Front face\n",
" [-1.0, -1.0, 1.0],\n",
" [ 1.0, -1.0, 1.0],\n",
" [ 1.0, 1.0, 1.0],\n",
" [-1.0, 1.0, 1.0],\n",
"]\n",
"\n",
"indices = [\n",
" [0, 1, 2], [0, 2, 3], # front\n",
"]\n",
"\n",
"vcolors = [\n",
" [1, 0, 0],\n",
" [0, 1, 0],\n",
" [0, 0, 1],\n",
" [1, 0, 1]\n",
"]\n",
"\n",
"fcolors = [\n",
" [1, 0, 0],\n",
" [0, 0, 1]\n",
"]\n",
"\n",
"ctx = meshvis.Context(width=300, height=300)\n",
"\n",
"ctx.draw_faces(verts, indices, per_vertex_colors=vcolors)\n",
"\n",
"ctx.draw_vertices(verts, point_size=5, colors=vcolors)\n",
"\n",
"ctx.display()"
]
}
],
"metadata": {
......
......@@ -2,13 +2,15 @@
"cells": [
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"execution_count": 1,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "acf4a18369ac43e4b888569f36146bdf",
"model_id": "d813d85f9c45487c84559edd73d51d9c",
"version_major": 2,
"version_minor": 0
},
......@@ -28,7 +30,7 @@
"</p>\n"
],
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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(children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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'#dddddd', 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={'index': BufferAttribute(array=array([ 0, 1, 2, ..., 3439, 3436, 3440], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-0.283628, 2.931106, -0.140772],\n",
"Renderer(background='#dddddd', camera=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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(intensity=0.5, position=(-3.0, 5.0, 1.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'#dddddd', 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={'index': BufferAttribute(array=array([ 0, 1, 2, ..., 3439, 3436, 3440], dtype=uint16), normalized=False), '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",
......@@ -46,7 +48,7 @@
" ...,\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=3.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())"
" [-0.708084, 1.391306, -0.0961 ]], dtype=float32), normalized=False)}), material=PointsMaterial(color=u'red', map=None, size=5.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": {},
......@@ -59,13 +61,13 @@
"m = om.TriMesh()\n",
"om.read_mesh(m, \"C:\\Users\\dario\\OneDrive\\Dokumente\\ANIMVR\\Import\\Models\\Mickey_Mouse.obj\")\n",
"\n",
"ctx = meshvis.Context()\n",
"ctx = meshvis.Context(width=640, height=480)\n",
"\n",
"ctx.draw_faces(m.points(), m.face_indices(), hidden=True)\n",
"ctx.draw_faces(m.points(), m.face_indices(), shading='hidden')\n",
"\n",
"ctx.draw_edges(m.points(), m.face_indices())\n",
"\n",
"ctx.draw_vertices(m.points(), point_size=3, colors='red')\n",
"ctx.draw_vertices(m.points(), point_size=5, colors='red')\n",
"\n",
"ctx.display()"
]
......@@ -78,7 +80,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5460164864a84b4eaa05121ba21e88ac",
"model_id": "3dcb19928c724c05aa9949e2f52e1f8b",
"version_major": 2,
"version_minor": 0
},
......@@ -98,10 +100,13 @@
"</p>\n"
],
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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(children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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'#dddddd', 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, 3], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[0., 0., 0.],\n",
"Renderer(background='#dddddd', camera=PerspectiveCamera(aspect=1.5, children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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.5, children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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'#dddddd', 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([[1., 0., 0.],\n",
" [0., 1., 0.],\n",
" [0., 0., 1.],\n",
" [1., 0., 1.]], dtype=float32)), 'index': BufferAttribute(array=array([0, 1, 2, 3], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[0., 0., 0.],\n",
" [1., 0., 0.],\n",
" [1., 1., 0.],\n",
" [0., 1., 0.]], dtype=float32), normalized=False)}), material=LineBasicMaterial(color=u'#000000', polygonOffset=True, polygonOffsetFactor=0.001, polygonOffsetUnits=0.1), 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())"
" [0., 1., 0.]], dtype=float32), normalized=False)}), material=LineBasicMaterial(color=u'white', polygonOffset=True, polygonOffsetFactor=0.001, polygonOffsetUnits=0.1, 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))), 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": {},
......@@ -109,7 +114,22 @@
}
],
"source": [
"meshvis.display_edges([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], [[0, 1], [2,3]])"
"\n",
"vcolors = [\n",
" [1, 0, 0],\n",
" [0, 1, 0],\n",
" [0, 0, 1],\n",
" [1, 0, 1]\n",
"]\n",
"\n",
"fcolors = [\n",
" [1, 0, 0],\n",
" [0, 0, 1]\n",
"]\n",
"\n",
"meshvis.display_edges([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], \n",
" [[0, 1], [2,3]], \n",
" per_vertex_colors = vcolors)"
]
},
{
......@@ -120,7 +140,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "75b7d67e17b0427484fc4782fd2fa298",
"model_id": "4ddd51d1babd4ac8b8c4fc7f93523362",
"version_major": 2,
"version_minor": 0
},
......@@ -140,8 +160,8 @@
"</p>\n"
],
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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(children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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'#dddddd', 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={'color': BufferAttribute(array=array([1., 1., 0.], dtype=float32)), 'position': BufferAttribute(array=array([[0., 0., 0.],\n",
" [1., 1., 1.]], dtype=float32), normalized=False)}), material=PointsMaterial(color=u'#dddddd', map=None, size=10.0, sizeAttenuation=False, 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))), 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())"
"Renderer(background='#dddddd', camera=PerspectiveCamera(aspect=1.5, children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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.5, children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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'#dddddd', 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., 0., 0.],\n",
" [1., 0., 0.]], dtype=float32), normalized=False)}), material=PointsMaterial(color=u'blue', map=None, size=10.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": {},
......@@ -149,15 +169,89 @@
}
],
"source": [
"meshvis.display_vertices([[0,0,0],[1,1,1]], [1,1,0], point_size=10)"
"meshvis.display_vertices([[0,0,0],[1,0, 0]], colors='blue', point_size=10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4b39b21a50c840e9889e98951b01e6e8",
"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(children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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(children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.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'#dddddd', 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([[1., 0., 0.],\n",
" [0., 1., 0.],\n",
" [0., 0., 1.],\n",
" [1., 0., 1.]], dtype=float32)), 'index': BufferAttribute(array=array([0, 1, 2, 0, 2, 3], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-1., -1., 1.],\n",
" [ 1., -1., 1.],\n",
" [ 1., 1., 1.],\n",
" [-1., 1., 1.]], 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)), Points(geometry=BufferGeometry(attributes={'color': BufferAttribute(array=array([[1., 0., 0.],\n",
" [0., 1., 0.],\n",
" [0., 0., 1.],\n",
" [1., 0., 1.]], dtype=float32)), 'position': BufferAttribute(array=array([[-1., -1., 1.],\n",
" [ 1., -1., 1.],\n",
" [ 1., 1., 1.],\n",
" [-1., 1., 1.]], dtype=float32), normalized=False)}), material=PointsMaterial(color=u'#dddddd', map=None, size=5.0, sizeAttenuation=False, 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))), 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": [
"verts = [\n",
" # Front face\n",
" [-1.0, -1.0, 1.0],\n",
" [ 1.0, -1.0, 1.0],\n",
" [ 1.0, 1.0, 1.0],\n",
" [-1.0, 1.0, 1.0],\n",
"]\n",
"\n",
"indices = [\n",
" [0, 1, 2], [0, 2, 3], # front\n",
"]\n",
"\n",
"vcolors = [\n",
" [1, 0, 0],\n",
" [0, 1, 0],\n",
" [0, 0, 1],\n",
" [1, 0, 1]\n",
"]\n",
"\n",
"fcolors = [\n",
" [1, 0, 0],\n",
" [0, 0, 1]\n",
"]\n",
"\n",
"ctx = meshvis.Context(width=300, height=300)\n",
"\n",
"ctx.draw_faces(verts, indices, per_vertex_colors=vcolors)\n",
"\n",
"ctx.draw_vertices(verts, point_size=5, colors=vcolors)\n",
"\n",
"ctx.display()"
]
}
],
"metadata": {
......
......@@ -3,33 +3,53 @@ import numpy as np
from IPython.display import display
class Context(object):
def __init__(self):
def __init__(self, width=600, height=400, background_color = '#dddddd'):
self.camera = three.PerspectiveCamera(position=[3,3,3], fov=20,
children=[three.DirectionalLight(color='#ffffff', position=[-3, 5, 1], intensity=0.5)])
self.camera.aspect = width/float(height)
self.scene = three.Scene(children=[three.AmbientLight(color='#dddddd')])
self.scene.background = '#dddddd'
self.scene.background = background_color
self.orbit_controls = three.OrbitControls(controlling=self.camera)
self.renderer = three.Renderer(camera=self.camera, background='black', background_opacity=1,
self.renderer = three.Renderer(camera=self.camera, background=background_color, background_opacity=1,
scene=self.scene, controls=[self.orbit_controls],
width=600, height=400 )
width=width, height=height, antialias=True )
def draw_faces(self, vertices, face_indices, normals=None, per_vertex_colors=None, per_face_colors=None,
hidden=False, shading='flat', z_offset=0.5):
shading='flat', z_offset=0.5):
mesh_geom = three.BufferGeometry(attributes=dict(
attributes=dict(
position = three.BufferAttribute(np.asarray(vertices, dtype=np.float32), normalized=False),
index = three.BufferAttribute(np.asarray(face_indices, dtype='uint16').ravel(), normalized=False),
))
index = three.BufferAttribute(np.asarray(face_indices, dtype=np.uint16).ravel(), normalized=False),
)
mat = three.MeshLambertMaterial(color='#dddddd', colorWrite=not hidden)
mat = three.MeshLambertMaterial(color='#dddddd', colorWrite=shading is not 'hidden')
mat.wireframe = shading is 'wireframe'
if z_offset is not 0:
mat.polygonOffset = True
mat.polygonOffsetFactor = z_offset
mat.polygonOffsetUnits = 0.1
colors = None
if per_vertex_colors is not None:
mat.vertexColors = 'VertexColors'
colors = per_vertex_colors
if per_face_colors is not None:
mat.vertexColors = 'FaceColors'
colors = per_face_colors
if colors is not None:
mat.color = 'white'
attributes['color'] = three.BufferAttribute(np.asarray(colors, dtype=np.float32))
mesh_geom = three.BufferGeometry(attributes=attributes)
mesh_obj = three.Mesh(geometry=mesh_geom, material=mat)
self.scene.add(mesh_obj)
......@@ -52,6 +72,20 @@ class Context(object):
mat.polygonOffsetFactor = z_offset
mat.polygonOffsetUnits = 0.1
colors = None
if per_vertex_colors is not None:
mat.vertexColors = 'VertexColors'
colors = per_vertex_colors
if per_edge_colors is not None:
mat.vertexColors = 'FaceColors'
colors = per_edge_colors
if colors is not None:
mat.color = 'white'
attributes['color'] = three.BufferAttribute(np.asarray(colors, dtype=np.float32))
geom = three.BufferGeometry(attributes = attributes)
mesh_obj = three.LineSegments(geometry=geom, material=mat)
......
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