Commit 8e07b402 authored by Dario Seyb's avatar Dario Seyb

added camera rotation to API and calling update on the controls to set the...

added camera rotation to API and calling update on the controls to set the initial position/rotation
parent bfbe19ef
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import threevis\n",
"import openmesh as om\n",
"import numpy as np\n",
"\n",
"from ipywidgets import interact\n",
"\n",
"m = om.read_polymesh('models/bunny.obj')\n",
"\n",
"vertices = m.points()\n",
"faces = m.face_vertex_indices()\n",
"\n",
"mesh = threevis.Mesh(vertices, faces, \n",
" normals = threevis.calculate_face_normals(vertices, faces))\n",
"\n",
"\n",
"\n",
"ctx = threevis.Context()\n",
"\n",
"@interact(y_rot=(0,360,1), z_pos=(0.1, 10, 0.01))\n",
"def g(y_rot, z_pos):\n",
" ctx.set_camera(((0, 0.1, z_pos), (0, y_rot, 0)))\n",
"\n",
"ctx.draw(mesh)\n",
"ctx.display()\n"
]
}
],
"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
}
......@@ -6,6 +6,7 @@ from IPython.display import display
from .indexed_attribute import *
from .mesh_helper import calculate_face_normals, calculate_point_normals
from .mesh import *
import math
class Context(object):
"""
......@@ -250,6 +251,19 @@ class Context(object):
def get_camera_position(self):
return self.camera.position
def set_camera_rotation(self, rotation):
self.camera.rotation = ( math.radians(rotation[0]), math.radians(rotation[1]), math.radians(rotation[2]), 'XYZ')
def get_camera_rotation(self):
return math.degrees(self.camera.rotation[0]), math.degrees(self.camera.rotation[1]), math.degrees(self.camera.rotation[2])
def set_camera(self, transform):
self.set_camera_position(transform[0])
self.set_camera_rotation(transform[1])
def get_camera(self):
return self.get_camera_position(), self.get_camera_rotation()
def show_bounds(self):
self.bounds_enabled = True
return self
......@@ -281,6 +295,8 @@ class Context(object):
self.camera.position = tuple( np.array(self.camera.position) * distance * 5)
self.orbit_controls.target = tuple(center)
if self.bounds_enabled:
extends = self.maxCorner - self.minCorner
boxEdges = [self.minCorner,
......@@ -295,4 +311,9 @@ class Context(object):
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)
self.orbit_controls.enabled = False
# Manually calling update on the controls to make sure they are all set up
self.orbit_controls.exec_three_obj_method("update")
display(self.renderer)
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