Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
threevis
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
11
Issues
11
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
threevis
threevis
Commits
3b9dd711
Commit
3b9dd711
authored
Feb 01, 2018
by
Dario Seyb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hooked up attributes to context functions
parent
bbc3901e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
135 additions
and
251 deletions
+135
-251
examples/.ipynb_checkpoints/Untitled-checkpoint.ipynb
examples/.ipynb_checkpoints/Untitled-checkpoint.ipynb
+18
-167
examples/Untitled.ipynb
examples/Untitled.ipynb
+45
-36
meshvis/__init__.py
meshvis/__init__.py
+1
-1
meshvis/context.py
meshvis/context.py
+46
-35
meshvis/immediate.py
meshvis/immediate.py
+6
-6
meshvis/indexed_attribute.py
meshvis/indexed_attribute.py
+19
-6
No files found.
examples/.ipynb_checkpoints/Untitled-checkpoint.ipynb
View file @
3b9dd711
...
...
@@ -2,67 +2,27 @@
"cells": [
{
"cell_type": "code",
"execution_count":
15
,
"execution_count":
null
,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "14c96cf5e14a4567ba6aee66f6bfeb31",
"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(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, 0, 2, 3, 5, 4, 7, 5, 7, 6, 6, 2, 1, 6, 1, 5, 3, 7, 4, 3,\n",
" 4, 0, 7, 3, 2, 7, 2, 6, 5, 1, 0, 5, 0, 4], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-1., -1., -1.],\n",
" [ 1., -1., -1.],\n",
" [ 1., 1., -1.],\n",
" [-1., 1., -1.],\n",
" [-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'#dddddd', colorWrite=False, emissiveMap=None, envMap=None, lightMap=None, map=None, polygonOffset=True, polygonOffsetFactor=0.5, polygonOffsetUnits=0.1, specularMap=None), 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([[-1., -1., -1.],\n",
" [ 1., -1., -1.],\n",
" [ 1., 1., -1.],\n",
" [-1., 1., -1.],\n",
" [-1., -1., 1.],\n",
" [ 1., -1., 1.],\n",
" [ 1., 1., 1.],\n",
" [-1., 1., 1.]], 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": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"import meshvis\n",
"import openmesh as om\n",
"import numpy as np\n",
"m = om.TriMesh()\n",
"om.read_mesh(m, \"
/home/dseyb/git/openmesh-python/tests/TestFiles/cube-minimal-normals.ply
\")\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",
"
ctx.draw_faces(m.points(), m.face_vertex_indices(), shading='hidden'
)\n",
"
m.face_colors(
)\n",
"\n",
"#ctx.draw_edges(m.points(), m.ev_indices())\n",
"ctx.draw_faces(m.points(), m.face_vertex_indices(), \n",
" normals = meshvis.FaceAttribute(m.face_normals()),\n",
" colors = meshvis.PointAttribute(np.random.rand(len(m.points()),3)))\n",
"\n",
"ctx.draw_edges(m.points(), m.ev_indices())\n",
"\n",
"ctx.draw_vertices(m.points(), point_size=5, colors='red')\n",
"\n",
...
...
@@ -71,45 +31,9 @@
},
{
"cell_type": "code",
"execution_count":
2
,
"execution_count":
null
,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "72c8803bfd1f4a7eaee4bac39454a9d6",
"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.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'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": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"\n",
"vcolors = [\n",
...
...
@@ -126,96 +50,23 @@
"\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)"
" colors = vcolors)"
]
},
{
"cell_type": "code",
"execution_count":
4
,
"execution_count":
null
,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0e1762e519fa4ef68dfd9a9e962be650",
"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.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": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"meshvis.display_vertices([[0,0,0],[1,0, 0]], colors='blue', point_size=10)"
]
},
{
"cell_type": "code",
"execution_count":
4
,
"execution_count":
null
,
"metadata": {},
"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"
}
],
"outputs": [],
"source": [
"verts = [\n",
" # Front face\n",
...
...
@@ -267,7 +118,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.1
3
"
"version": "2.7.1
4
"
}
},
"nbformat": 4,
...
...
examples/Untitled.ipynb
View file @
3b9dd711
...
...
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count":
7
,
"execution_count":
12
,
"metadata": {
"scrolled": false
},
...
...
@@ -10,7 +10,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "
b65183b0ba9145dcb55ab172a64e0f0a
",
"model_id": "
f37a56dfa0214ba09de2d351e9e396dd
",
"version_major": 2,
"version_minor": 0
},
...
...
@@ -30,19 +30,31 @@
"</p>\n"
],
"text/plain": [
"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",
"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={'color': BufferAttribute(array=array([[0.09565583, 0.7409057 , 0.26450714],\n",
" [0.09565583, 0.7409057 , 0.26450714],\n",
" [0.09565583, 0.7409057 , 0.26450714],\n",
" ...,\n",
" [0.57517904, 0.53038496, 0.31865656],\n",
" [0.57517904, 0.53038496, 0.31865656],\n",
" [0.57517904, 0.53038496, 0.31865656]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 20457, 20458, 20459], dtype=uint16), normalized=False), 'normal': BufferAttribute(array=array([[0., 0., 0.],\n",
" [0., 0., 0.],\n",
" [0., 0., 0.],\n",
" ...,\n",
" [0., 0., 0.],\n",
" [0., 0., 0.],\n",
" [0., 0., 0.]], 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.675122, 1.403736, -0.094798],\n",
" [-0.700144, 1.367866, -0.036312],\n",
" [-0.708084, 1.391306, -0.0961 ]], dtype=float32), normalized=False)}), material=MeshLambertMaterial(alphaMap=None, aoMap=None, color=u'#dddddd', colorWrite=False, emissiveMap=None, envMap=None, lightMap=None, map=None, polygonOffset=True, polygonOffsetFactor=0.5, polygonOffsetUnits=0.1, specularMap=None), 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, 1, ..., 3435, 3440, 3436], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-0.283628, 2.931106, -0.140772],\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={'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",
" [-0.34671 , 2.856239, -0.160498],\n",
" ...,\n",
" [
-0.675122, 1.403736, -0.09479
8],\n",
" [
-0.700144, 1.367866, -0.036312
],\n",
" [
-0.708084, 1.391306, -0.0961
]], 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.157628, 0.430178, -0.13011
8],\n",
" [
0.216602, 0.471758, -0.014108
],\n",
" [
0.332014, 0.467158, -0.059092
]], 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",
...
...
@@ -58,12 +70,17 @@
"source": [
"import meshvis\n",
"import openmesh as om\n",
"import numpy as np\n",
"m = om.TriMesh()\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",
"ctx.draw_faces(m.points(), m.face_vertex_indices(), shading='hidden')\n",
"m.face_colors()\n",
"\n",
"ctx.draw_faces(m.points(), m.face_vertex_indices(), \n",
" normals = meshvis.FaceAttribute(m.face_normals()),\n",
" colors = meshvis.FaceAttribute(np.random.rand(len(m.face_normals()),3)))\n",
"\n",
"ctx.draw_edges(m.points(), m.ev_indices())\n",
"\n",
...
...
@@ -74,13 +91,13 @@
},
{
"cell_type": "code",
"execution_count":
2
,
"execution_count":
6
,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "
c8a705ab47cb4ce6a7bcfd5e4459fc8
c",
"model_id": "
f1bd944ff5ca4a319f73d72453d4ce4
c",
"version_major": 2,
"version_minor": 0
},
...
...
@@ -101,12 +118,12 @@
],
"text/plain": [
"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",
" [
1., 0
., 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",
" [
0
., 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'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())"
" [0., 1., 0.]], dtype=float32), normalized=False)}), material=LineBasicMaterial(color=u'white', 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": {},
...
...
@@ -129,18 +146,18 @@
"\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
)"
"
colors = meshvis.FaceAttribute(fcolors)
)"
]
},
{
"cell_type": "code",
"execution_count":
3
,
"execution_count":
7
,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "
703dd68cfece4d5aa3ed20871bbda1a5
",
"model_id": "
1b076eb0bdaf49cdb412b244b2aaf263
",
"version_major": 2,
"version_minor": 0
},
...
...
@@ -174,13 +191,13 @@
},
{
"cell_type": "code",
"execution_count":
4
,
"execution_count":
10
,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "
dd25e52e709c4356a94f837e59dac0ed
",
"model_id": "
183c659c6f1b41c89e5cbe6bb85ec7f4
",
"version_major": 2,
"version_minor": 0
},
...
...
@@ -201,11 +218,15 @@
],
"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",
" [1., 0., 0.],\n",
" [1., 0., 0.],\n",
" [0., 0., 1.],\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",
" [
0., 0., 1.]], dtype=float32)), 'index': BufferAttribute(array=array([0, 1, 2, 3, 4, 5
], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-1., -1., 1.],\n",
" [ 1., -1., 1.],\n",
" [ 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",
...
...
@@ -246,7 +267,7 @@
"\n",
"ctx = meshvis.Context(width=300, height=300)\n",
"\n",
"ctx.draw_faces(verts, indices,
per_vertex_colors=vcolors
)\n",
"ctx.draw_faces(verts, indices,
colors= meshvis.FaceAttribute(fcolors)
)\n",
"\n",
"ctx.draw_vertices(verts, point_size=5, colors=vcolors)\n",
"\n",
...
...
@@ -259,18 +280,6 @@
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.14"
}
},
"nbformat": 4,
...
...
meshvis/__init__.py
View file @
3b9dd711
...
...
@@ -7,4 +7,4 @@ except ImportError as error:
from
.context
import
*
from
.immediate
import
*
from
.indexed_attribute
import
UniformAttribute
,
PointAttribute
,
FaceAttribute
,
HalfEdgeAttribute
,
resolve_attributes
from
.indexed_attribute
import
UniformAttribute
,
PointAttribute
,
FaceAttribute
,
HalfEdgeAttribute
meshvis/context.py
View file @
3b9dd711
...
...
@@ -2,6 +2,7 @@
import
pythreejs
as
three
import
numpy
as
np
from
IPython.display
import
display
from
.indexed_attribute
import
*
class
Context
(
object
):
def
__init__
(
self
,
width
=
600
,
height
=
400
,
background_color
=
'#dddddd'
):
...
...
@@ -18,16 +19,13 @@ class Context(object):
scene
=
self
.
scene
,
controls
=
[
self
.
orbit_controls
],
width
=
width
,
height
=
height
,
antialias
=
True
)
def
draw_faces
(
self
,
vertices
,
face_indices
,
normals
=
None
,
per_vertex_colors
=
None
,
per_face_color
s
=
None
,
def
draw_faces
(
self
,
vertices
,
face_indices
,
normals
=
None
,
colors
=
None
,
uv
s
=
None
,
shading
=
'flat'
,
z_offset
=
0.5
):
attributes
=
dict
(
position
=
three
.
BufferAttribute
(
np
.
asarray
(
vertices
,
dtype
=
np
.
float32
),
normalized
=
False
),
index
=
three
.
BufferAttribute
(
np
.
asarray
(
face_indices
,
dtype
=
np
.
uint16
).
ravel
(),
normalized
=
False
),
)
face_indices
=
np
.
array
(
face_indices
)
# Setup Material
mat
=
three
.
MeshLambertMaterial
(
color
=
'#dddddd'
,
colorWrite
=
shading
is
not
'hidden'
)
mat
.
wireframe
=
shading
is
'wireframe'
if
z_offset
is
not
0
:
...
...
@@ -35,19 +33,31 @@ 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_face_colors
is
not
None
:
mat
.
vertexColors
=
'FaceColors'
colors
=
per_face_colors
# Resolve the given attributes, it's ok if they are None
resolved_attribs
=
resolve_attributes
(
face_indices
,
[
normals
,
colors
,
uvs
])
resolved_normals
=
resolved_attribs
[
0
]
resolved_colors
=
resolved_attribs
[
1
]
resolved_uvs
=
resolved_attribs
[
2
]
# De-index our vertices
vertices
,
face_indices
=
stretch_vertices
(
vertices
,
face_indices
)
if
colors
is
not
None
:
# Create attributes dictionary, always use at least position and index
attributes
=
dict
(
position
=
three
.
BufferAttribute
(
np
.
asarray
(
vertices
,
dtype
=
np
.
float32
),
normalized
=
False
),
index
=
three
.
BufferAttribute
(
np
.
asarray
(
face_indices
,
dtype
=
np
.
uint16
).
ravel
(),
normalized
=
False
),
)
if
resolved_colors
is
not
None
:
mat
.
vertexColors
=
'VertexColors'
mat
.
color
=
'white'
attributes
[
'color'
]
=
three
.
BufferAttribute
(
np
.
asarray
(
colors
,
dtype
=
np
.
float32
))
attributes
[
'color'
]
=
three
.
BufferAttribute
(
np
.
asarray
(
resolved_colors
,
dtype
=
np
.
float32
))
if
resolved_normals
is
not
None
:
attributes
[
'normal'
]
=
three
.
BufferAttribute
(
np
.
asarray
(
resolved_normals
,
dtype
=
np
.
float32
))
if
resolved_uvs
is
not
None
:
attributes
[
'uv'
]
=
three
.
BufferAttribute
(
np
.
asarray
(
resolved_uvs
,
dtype
=
np
.
float32
))
mesh_geom
=
three
.
BufferGeometry
(
attributes
=
attributes
)
...
...
@@ -56,15 +66,7 @@ class Context(object):
self
.
scene
.
add
(
mesh_obj
)
return
self
def
draw_edges
(
self
,
vertices
,
edge_indices
=
None
,
per_vertex_colors
=
None
,
per_edge_colors
=
None
,
z_offset
=
0
):
if
edge_indices
is
None
:
edge_indices
=
zip
(
np
.
arange
(
0
,
len
(
vertices
)
-
1
),
np
.
arange
(
1
,
len
(
vertices
)))
attributes
=
dict
(
position
=
three
.
BufferAttribute
(
np
.
asarray
(
vertices
,
dtype
=
np
.
float32
),
normalized
=
False
),
index
=
three
.
BufferAttribute
(
np
.
asarray
(
edge_indices
,
dtype
=
np
.
uint16
).
ravel
(),
normalized
=
False
),
)
def
draw_edges
(
self
,
vertices
,
edge_indices
=
None
,
colors
=
None
,
uvs
=
None
,
z_offset
=
0
):
mat
=
three
.
LineBasicMaterial
(
color
=
'#000000'
)
...
...
@@ -73,19 +75,28 @@ class Context(object):
mat
.
polygonOffsetFactor
=
z_offset
mat
.
polygonOffsetUnits
=
0.1
colors
=
None
if
edge_indices
is
None
:
edge_indices
=
zip
(
np
.
arange
(
0
,
len
(
vertices
)
-
1
),
np
.
arange
(
1
,
len
(
vertices
)))
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
:
resolved_attribs
=
resolve_attributes
(
edge_indices
,
[
colors
,
uvs
])
resolved_colors
=
resolved_attribs
[
0
]
resolved_uvs
=
resolved_attribs
[
1
]
vertices
,
edge_indices
=
stretch_vertices
(
vertices
,
edge_indices
)
attributes
=
dict
(
position
=
three
.
BufferAttribute
(
np
.
asarray
(
vertices
,
dtype
=
np
.
float32
),
normalized
=
False
),
index
=
three
.
BufferAttribute
(
np
.
asarray
(
edge_indices
,
dtype
=
np
.
uint16
).
ravel
(),
normalized
=
False
),
)
if
resolved_colors
is
not
None
:
mat
.
vertexColors
=
'VertexColors'
mat
.
color
=
'white'
attributes
[
'color'
]
=
three
.
BufferAttribute
(
np
.
asarray
(
colors
,
dtype
=
np
.
float32
))
attributes
[
'color'
]
=
three
.
BufferAttribute
(
np
.
asarray
(
resolved_colors
,
dtype
=
np
.
float32
))
if
resolved_uvs
is
not
None
:
attributes
[
'uv'
]
=
three
.
BufferAttribute
(
np
.
asarray
(
resolved_uvs
,
dtype
=
np
.
float32
))
geom
=
three
.
BufferGeometry
(
attributes
=
attributes
)
...
...
meshvis/immediate.py
View file @
3b9dd711
from
.context
import
*
def
display_faces
(
vertices
,
face_indices
,
normals
=
None
,
per_vertex_colors
=
None
,
per_face_colors
=
None
,
shading
=
'flat'
,
z_offset
=
0
):
Context
().
draw_faces
(
vertices
,
face_indices
,
normals
,
per_vertex_colors
,
per_face_color
s
,
shading
,
z_offset
).
display
()
def
display_faces
(
vertices
,
face_indices
,
normals
=
None
,
colors
=
None
,
uvs
=
None
,
shading
=
'flat'
,
z_offset
=
0.5
):
Context
().
draw_faces
(
vertices
,
face_indices
,
normals
,
colors
,
uv
s
,
shading
,
z_offset
).
display
()
def
display_edges
(
vertices
,
edge_indices
=
None
,
per_vertex_colors
=
None
,
per_edge_colors
=
None
,
z_offset
=
1e-3
):
Context
().
draw_edges
(
vertices
,
edge_indices
,
per_vertex_colors
,
per_edge_color
s
,
z_offset
).
display
()
def
display_edges
(
vertices
,
edge_indices
=
None
,
colors
=
None
,
uvs
=
None
,
z_offset
=
0
):
Context
().
draw_edges
(
vertices
,
edge_indices
,
colors
,
uv
s
,
z_offset
).
display
()
def
display_vertices
(
vertices
,
colors
=
None
,
point_size
=
1
,
z_offset
=
0
):
Context
().
draw_vertices
(
vertices
,
colors
,
point_size
,
z_offset
).
display
()
def
display_vertices
(
vertices
,
colors
=
None
,
point_size
=
1
,
z_offset
=
0
,
perspective
=
False
):
Context
().
draw_vertices
(
vertices
,
colors
,
point_size
,
z_offset
,
perspective
).
display
()
meshvis/indexed_attribute.py
View file @
3b9dd711
import
numpy
as
np
def
stretch_vertices
(
vertices
,
face_indices
):
stretched_verts
=
[]
for
face
in
face_indices
:
for
vidx
in
face
:
stretched_verts
.
append
(
vertices
[
vidx
])
return
stretched_verts
,
range
(
0
,
len
(
stretched_verts
))
def
resolve_attributes
(
face_indices
,
attribs
):
final_attributes
=
[]
for
attrib
in
attribs
:
if
attrib
is
None
:
final_attributes
.
append
(
None
)
continue
resolved_attrib
=
attrib
.
resolve
(
face_indices
)
final_attributes
.
append
(
stretch_attribute
(
face_indices
,
resolved_attrib
))
...
...
@@ -19,11 +33,10 @@ def stretch_attribute(face_indices, resolved_attrib):
return
stretched_attrib
def
find
(
element
,
list_element
):
try
:
index_element
=
list_element
.
index
(
element
)
return
index_element
except
ValueError
:
return
None
index_element
=
np
.
where
(
list_element
==
element
)
if
len
(
index_element
[
0
])
>
0
:
return
index_element
[
0
][
0
]
return
None
class
UniformAttribute
(
object
):
def
__init__
(
self
,
value
):
...
...
@@ -39,7 +52,7 @@ class UniformAttribute(object):
class
IndexedAttribute
(
object
):
def
__init__
(
self
,
values
,
indices
):
assert
(
len
(
values
)
is
len
(
indices
))
assert
(
len
(
values
)
==
len
(
indices
))
self
.
values
=
values
self
.
indices
=
indices
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment