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
4d0cd287
Commit
4d0cd287
authored
Feb 23, 2018
by
Dario Seyb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added some basic bounds
parent
a8559d26
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
1 deletion
+100
-1
examples/BoundsExample.ipynb
examples/BoundsExample.ipynb
+51
-0
examples/ClippedDrawing.ipynb
examples/ClippedDrawing.ipynb
+12
-1
meshvis/context.py
meshvis/context.py
+37
-0
No files found.
examples/BoundsExample.ipynb
0 → 100644
View file @
4d0cd287
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import meshvis\n",
"import openmesh as om\n",
"import numpy as np\n",
"\n",
"m = om.PolyMesh()\n",
"\n",
"om.read_mesh(m, 'models/bunny.obj')\n",
"\n",
"vertices = m.points()\n",
"faces = m.face_vertex_indices()\n",
"\n",
"\n",
"mesh = meshvis.Mesh(vertices, faces, \n",
" normals = meshvis.calculateFaceNormals(vertices, faces))\n",
"\n",
"ctx = meshvis.Context()\n",
"ctx.draw(mesh, shading='flat', clipping_planes=[meshvis.Plane((1.0, 0.0, 0.0) , 0)])\n",
"ctx.showBounds()\n",
"ctx.display()"
]
}
],
"metadata": {
"kernelspec": {
"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"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
examples/ClippedDrawing.ipynb
View file @
4d0cd287
...
...
@@ -21,8 +21,19 @@
"mesh = meshvis.Mesh(vertices, faces, \n",
" normals = meshvis.calculateFaceNormals(vertices, faces))\n",
"\n",
"meshvis.display(mesh, shading='flat', clipping_planes=[meshvis.Plane((1.0, 0.0, 0.0) , 0)])"
"ctx = meshvis.Context()\n",
"ctx.draw(mesh, shading='flat', clipping_planes=[meshvis.Plane((1.0, 0.0, 0.0) , 0)])\n",
"ctx.display()\n",
"\n",
"ctx.setCameraPosition([0.2, 0, 0])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
...
...
meshvis/context.py
View file @
4d0cd287
...
...
@@ -41,6 +41,8 @@ class Context(object):
self
.
click_picker
.
observe
(
on_picked
,
names
=
[
'point'
])
self
.
show_bounds
=
False
def
draw
(
self
,
obj
,
shading
=
'flat'
,
z_offset
=
0.5
,
texture
=
None
,
point_size
=
1
,
perspective
=
False
,
line_width
=
1
,
clipping_planes
=
[]):
"""
Draw the given object. Not all named parameters are relevant for all object types.
...
...
@@ -234,6 +236,27 @@ class Context(object):
self
.
scene
.
add
(
mesh_obj
)
return
self
def
setCameraPosition
(
self
,
position
):
self
.
camera
.
position
=
tuple
(
position
)
def
showBounds
(
self
):
self
.
show_bounds
=
True
def
hideBounds
(
self
):
self
.
show_bounds
=
False
def
setBounds
(
self
,
val
):
self
.
show_bounds
=
val
def
draw_text
(
self
,
text
,
position
=
(
0
,
0
,
0
),
color
=
'white'
,
size
=
100
,
height
=
1
):
"""
Draw a text object at the specified location with a given height
"""
height
*=
len
(
text
)
sm
=
three
.
SpriteMaterial
(
map
=
three
.
TextTexture
(
string
=
text
,
color
=
color
,
size
=
size
,
squareTexture
=
True
))
sprite
=
three
.
Sprite
(
material
=
sm
,
position
=
tuple
(
position
),
scaleToTexture
=
True
,
scale
=
[
height
,
height
,
1
])
self
.
scene
.
add
(
sprite
)
def
display
(
self
):
"""
Display a window containing all the previous draw calls.
...
...
@@ -244,4 +267,18 @@ class Context(object):
self
.
camera
.
position
=
tuple
(
np
.
array
(
self
.
camera
.
position
)
*
distance
*
5
)
self
.
orbit_controls
.
target
=
tuple
(
center
)
if
self
.
show_bounds
:
extends
=
self
.
maxCorner
-
self
.
minCorner
boxEdges
=
[
self
.
minCorner
,
self
.
minCorner
+
[
extends
[
0
],
0
,
0
],
self
.
minCorner
+
[
0
,
extends
[
1
],
0
],
self
.
minCorner
+
[
0
,
0
,
extends
[
2
]]]
self
.
draw_edges
(
boxEdges
,
[[
0
,
1
],
[
0
,
2
],
[
0
,
3
]],
FaceAttribute
([[
1
,
0
,
0
],
[
0
,
1
,
0
],
[
0
,
0
,
1
]]))
self
.
draw_text
(
str
(
map
(
lambda
v
:
round
(
v
,
3
),
self
.
minCorner
)),
self
.
minCorner
-
[
0
,
extends
[
1
]
*
0.1
,
0
],
color
=
'black'
,
height
=
extends
[
1
]
/
25
)
self
.
draw_text
(
str
(
round
(
extends
[
0
],
3
)),
(
boxEdges
[
0
]
*
0.25
+
boxEdges
[
1
]
*
0.75
),
color
=
'black'
,
height
=
extends
[
1
]
/
20
)
self
.
draw_text
(
str
(
round
(
extends
[
1
],
3
)),
(
boxEdges
[
0
]
*
0.25
+
boxEdges
[
2
]
*
0.75
),
color
=
'black'
,
height
=
extends
[
1
]
/
20
)
self
.
draw_text
(
str
(
round
(
extends
[
2
],
3
)),
(
boxEdges
[
0
]
*
0.25
+
boxEdges
[
3
]
*
0.75
),
color
=
'black'
,
height
=
extends
[
1
]
/
20
)
display
(
self
.
renderer
)
\ No newline at end of file
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