Commit 67755fd8 authored by Dario Seyb's avatar Dario Seyb

started working on proper inline documentation

parent ee25de61
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)
......
"""
Immediate drawing without explicitely creating a context.
"""
from .context import Context
def display_faces(vertices, face_indices, normals=None, colors=None, uvs=None,
......
......@@ -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
......
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