Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
threevis
threevis
Commits
67755fd8
Commit
67755fd8
authored
Feb 22, 2018
by
Dario Seyb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
started working on proper inline documentation
parent
ee25de61
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
11 deletions
+34
-11
meshvis/context.py
meshvis/context.py
+26
-10
meshvis/immediate.py
meshvis/immediate.py
+4
-0
meshvis/mesh.py
meshvis/mesh.py
+4
-1
No files found.
meshvis/context.py
View file @
67755fd8
import
pythreejs
as
three
import
numpy
as
np
from
ipywidgets
import
HTML
,
Text
...
...
@@ -10,10 +9,15 @@ from .mesh import *
class
Context
(
object
):
"""
This is a module docstring
The Context represents everything that's drawn in one output window.
The output of any draw* call gets added to the window. This allows you to draw multiple models in one output window.
"""
def
__init__
(
self
,
width
=
600
,
height
=
400
,
background_color
=
'#dddddd'
):
def
__init__
(
self
,
width
=
600
,
height
=
400
,
background_color
=
'#dddddd'
):
"""
Initialize a new Context.
"""
self
.
camera
=
three
.
PerspectiveCamera
(
position
=
[
1
,
1
,
1
],
fov
=
20
,
children
=
[
three
.
DirectionalLight
(
color
=
'#ffffff'
,
position
=
[
-
30
,
50
,
10
],
intensity
=
1.0
)])
...
...
@@ -37,14 +41,11 @@ class Context(object):
self
.
click_picker
.
observe
(
on_picked
,
names
=
[
'point'
])
def
draw_sphere
(
self
):
mesh_obj
=
three
.
Mesh
(
three
.
SphereBufferGeometry
(
20
,
16
,
16
),
three
.
MeshPhysicalMaterial
(
color
=
'red'
),
position
=
[
0
,
0
,
0
])
self
.
scene
.
add
(
mesh_obj
)
def
draw
(
self
,
obj
,
shading
=
'flat'
,
z_offset
=
0.5
,
texture
=
None
,
point_size
=
1
,
perspective
=
False
,
line_width
=
1
):
"""
Draw the given object. Not all named parameters are relevant for all object types.
"""
obj
.
prepare_render
()
if
isinstance
(
obj
,
Mesh
):
...
...
@@ -60,6 +61,10 @@ class Context(object):
def
draw_faces
(
self
,
vertices
,
face_indices
,
normals
=
None
,
colors
=
None
,
uvs
=
None
,
shading
=
'flat'
,
z_offset
=
0.5
,
texture
=
None
):
"""
Draw a triangle mesh described by a list of vertex positions and face indices.
face_indices is expected to be a n x 3 matrix.
"""
assert
(
len
(
face_indices
)
>
0
and
len
(
vertices
)
>
0
)
...
...
@@ -123,6 +128,10 @@ class Context(object):
return
self
def
draw_edges
(
self
,
vertices
,
edge_indices
=
None
,
colors
=
None
,
uvs
=
None
,
z_offset
=
0
,
texture
=
None
,
linewidth
=
1
):
"""
Draw a list of edges described by a list of vertex positions and edge indices.
edge_indices is expected to be a n x 2 matrix. If no indices are given, a continous line is connecting the vertices is drawn.
"""
mat
=
three
.
LineBasicMaterial
(
color
=
'#000000'
)
mat
.
linewidth
=
linewidth
...
...
@@ -171,6 +180,9 @@ class Context(object):
return
self
def
draw_vertices
(
self
,
vertices
,
colors
=
None
,
uvs
=
None
,
point_size
=
1
,
z_offset
=
0
,
texture
=
None
,
perspective
=
False
):
"""
Draw a list of unconnected vertices.
"""
vertices
=
np
.
array
(
vertices
)
matColor
=
colors
...
...
@@ -211,6 +223,10 @@ class Context(object):
return
self
def
display
(
self
):
"""
Display a window containing all the previous draw calls.
"""
center
=
(
self
.
minCorner
+
self
.
maxCorner
)
*
0.5
distance
=
max
(
np
.
linalg
.
norm
(
center
-
self
.
minCorner
),
np
.
linalg
.
norm
(
center
-
self
.
maxCorner
))
self
.
camera
.
position
=
tuple
(
np
.
array
(
self
.
camera
.
position
)
*
distance
*
5
)
...
...
meshvis/immediate.py
View file @
67755fd8
"""
Immediate drawing without explicitely creating a context.
"""
from
.context
import
Context
def
display_faces
(
vertices
,
face_indices
,
normals
=
None
,
colors
=
None
,
uvs
=
None
,
...
...
meshvis/mesh.py
View file @
67755fd8
...
...
@@ -2,7 +2,10 @@ import numpy as np
from
.mesh_helper
import
calculateFaceNormals
,
calculatePointNormals
class
Mesh
():
"""
A polygonal mesh. Faces can have varying valence.
"""
def
__init__
(
self
,
vertices
,
face_indices
,
normals
=
None
,
colors
=
None
,
uvs
=
None
):
self
.
normals
=
normals
self
.
colors
=
colors
...
...
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