Commit 5c9cc9f1 authored by Dario Seyb's avatar Dario Seyb

fixed whitespace (I think)

parent 5eed0f8f
......@@ -8,11 +8,11 @@ from .indexed_attribute import *
from .mesh_helper import calculateFaceNormals, calculatePointNormals
class Context(object):
def __init__(self, width=600, height=400, background_color = '#dddddd'):
self.camera = three.PerspectiveCamera(position=[1,1,1], fov=20,
children=[three.DirectionalLight(color='#ffffff', position=[-30, 50, 10], intensity=1.0)])
self.camera = three.PerspectiveCamera(position=[1,1,1], fov=20,
children=[three.DirectionalLight(color='#ffffff', position=[-30, 50, 10], intensity=1.0)])
self.camera.aspect = width/float(height)
self.minCorner = np.array([ 100000.0, 100000.0, 100000.0])
......@@ -34,13 +34,13 @@ 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'),
mesh_obj = three.Mesh(three.SphereBufferGeometry(20, 16, 16),
three.MeshPhysicalMaterial(color='red'),
position=[0, 0, 0])
self.scene.add(mesh_obj)
def draw_faces(self, vertices, face_indices, normals=None, colors=None, uvs=None,
shading='flat', z_offset=0.5, texture=None):
def draw_faces(self, vertices, face_indices, normals=None, colors=None, uvs=None,
shading='flat', z_offset=0.5, texture=None):
assert(len(face_indices) > 0 and len(vertices) > 0)
......@@ -62,7 +62,7 @@ class Context(object):
mat.polygonOffsetFactor = z_offset
mat.polygonOffsetUnits = 0.1
if normals is 'vertex':
if normals is 'vertex':
normals = calculatePointNormals(vertices, face_indices)
elif normals is 'face':
normals = calculateFaceNormals(vertices, face_indices)
......@@ -86,7 +86,7 @@ class Context(object):
mat.vertexColors = 'VertexColors'
mat.color = 'white'
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))
......@@ -98,12 +98,12 @@ class Context(object):
mesh_obj = three.Mesh(geometry=mesh_geom, material=mat)
self.minCorner = np.minimum(self.minCorner, vertices.min(axis=0))
self.maxCorner = np.maximum(self.maxCorner, vertices.max(axis=0))
self.scene.add(mesh_obj)
return self
def draw_edges(self, vertices, edge_indices=None, colors=None, uvs=None, z_offset=0, linewidth=1):
mat = three.LineBasicMaterial(color='#000000')
mat.linewidth = linewidth
......@@ -135,14 +135,14 @@ class Context(object):
mat.vertexColors = 'VertexColors'
mat.color = 'white'
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)
mesh_obj = three.LineSegments(geometry=geom, material=mat)
self.minCorner = np.minimum(self.minCorner, vertices.min(axis=0))
self.maxCorner = np.maximum(self.maxCorner, vertices.max(axis=0))
......@@ -150,7 +150,7 @@ class Context(object):
return self
def draw_vertices(self, vertices, colors=None, point_size=1, z_offset=0, perspective=False):
vertices = np.array(vertices)
matColor = colors
......@@ -189,6 +189,6 @@ class Context(object):
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)
self.orbit_controls.target = tuple(center)
self.orbit_controls.target = tuple(center)
display(self.renderer)
\ No newline at end of file
......@@ -2,7 +2,7 @@ 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])
......@@ -14,19 +14,19 @@ def resolve_attributes(face_indices, attribs):
final_attributes = []
for attrib in attribs:
if attrib is None:
if attrib is None:
final_attributes.append(None)
continue
resolved_attrib = attrib.resolve(face_indices)
final_attributes.append(stretch_attribute(face_indices, resolved_attrib))
return final_attributes
def stretch_attribute(face_indices, resolved_attrib):
vs_per_face = len(face_indices[0])
stretched_attrib = [None] * (len(face_indices) * vs_per_face)
for val in resolved_attrib:
stretched_attrib[val[0] * vs_per_face + val[1]] = val[2]
......@@ -41,7 +41,7 @@ def find(element, list_element):
class UniformAttribute(object):
def __init__(self, value):
self.value = value
def resolve(self, face_indices):
result = []
for f_idx, face in enumerate(face_indices):
......@@ -58,16 +58,16 @@ class IndexedAttribute(object):
class PointAttribute(IndexedAttribute):
def __init__(self, values, indices = None):
if indices is None:
if indices is None:
indices = range(0, len(values))
super(PointAttribute, self).__init__(values, indices)
def resolve(self, face_indices):
result = []
vertex_to_face = dict()
for fidx, face in enumerate(face_indices):
for index_in_face, vidx in enumerate(face):
if vidx not in vertex_to_face:
if vidx not in vertex_to_face:
vertex_to_face[vidx] = []
vertex_to_face[vidx].append((fidx, index_in_face))
......@@ -76,15 +76,15 @@ class PointAttribute(IndexedAttribute):
if idx in vertex_to_face:
for occurence in vertex_to_face[idx]:
result.append((occurence[0], occurence[1], val))
return result
class FaceAttribute(IndexedAttribute):
def __init__(self, values, indices = None):
if indices is None:
if indices is None:
indices = range(0, len(values))
super(FaceAttribute, self).__init__(values, indices)
def resolve(self, face_indices):
result = []
for i, val in enumerate(self.values):
......@@ -98,22 +98,22 @@ class FaceAttribute(IndexedAttribute):
class HalfEdgeAttribute(IndexedAttribute):
def __init__(self, values, indices):
super(HalfEdgeAttribute, self).__init__(values, indices)
def resolve(self, face_indices):
result = []
for i, val in enumerate(self.values):
idx = self.indices[i]
# find all faces that contain the vertex
for f_idx, face in enumerate(face_indices):
# check if edge is in face
start_idx_in_face = find(idx[0], face)
end_idx_in_face = find(idx[1], face)
# both ends need to be in the face
if start_idx_in_face is None or end_idx_in_face is None:
if start_idx_in_face is None or end_idx_in_face is None:
continue
# and the edge needs to point in the right direction
if (start_idx_in_face + 1) % len(face) is not end_idx_in_face:
continue
......
......@@ -22,7 +22,7 @@ def calculateNormalEdges(vertices, face_indices, normals, length):
edge_vertices = []
edge_indices = []
for i, vert in enumerate(vertices):
norm = np.array(resolved_normals[i])
vert = np.array(vert)
......@@ -39,17 +39,17 @@ def calculateFaceNormals(vertices, face_indices):
v1 = np.array(vertices[face[0]])
v2 = np.array(vertices[face[1]])
v3 = np.array(vertices[face[2]])
v12 = np.subtract(v2, v1)
v13 = np.subtract(v3, v1)
norm = np.cross(v12, v13)
norm = norm / np.linalg.norm(norm)
values.append(norm)
return FaceAttribute(values)
def calculatePointNormals(vertices, face_indices):
def calculatePointNormals(vertices, face_indices):
normals = np.zeros_like(vertices)
counts = np.zeros(vertices.shape[0])
......@@ -57,10 +57,10 @@ def calculatePointNormals(vertices, face_indices):
v1 = np.array(vertices[face[0]])
v2 = np.array(vertices[face[1]])
v3 = np.array(vertices[face[2]])
v12 = np.subtract(v2, v1)
v13 = np.subtract(v3, v1)
norm = np.cross(v12, v13)
normals[face[0]] += norm
......
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