Commit e22c09a6 authored by Dario Seyb's avatar Dario Seyb

removed checkpoints from tracking

parent 5cc88905
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Combined Camera\n",
"\n",
"A combined camera allows you to easily switch between a perspective camera and an orthographic camera."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from pythreejs import *\n",
"from IPython.display import display"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"mesh1 = Mesh(SphereBufferGeometry(20, 16, 16), MeshPhysicalMaterial(color='red'), position=[-20, 0, 0])\n",
"mesh2 = Mesh(SphereBufferGeometry(20, 16, 16), MeshPhysicalMaterial(color='green'), position=[20, 0, 0])"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"view_width = 600\n",
"view_height = 400\n",
"camera = CombinedCamera(position=[0, 0, 60], width=view_width, height=view_height)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e92db2bb7f02499bb24f79af5f03be32",
"version_major": 2,
"version_minor": 0
},
"text/html": [
"<p>Failed to display Jupyter Widget of type <code>Renderer</code>.</p>\n",
"<p>\n",
" If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n",
" that the widgets JavaScript is still loading. If this message persists, it\n",
" likely means that the widgets JavaScript library is either not installed or\n",
" not enabled. See the <a href=\"https://ipywidgets.readthedocs.io/en/stable/user_install.html\">Jupyter\n",
" Widgets Documentation</a> for setup instructions.\n",
"</p>\n",
"<p>\n",
" If you're reading this message in another frontend (for example, a static\n",
" rendering on GitHub or <a href=\"https://nbviewer.jupyter.org/\">NBViewer</a>),\n",
" it may mean that your frontend doesn't currently support widgets.\n",
"</p>\n"
],
"text/plain": [
"Renderer(camera=CombinedCamera(height=400.0, position=(0.0, 0.0, 60.0), projectionMatrix=(1.4296712803397058, 0.0, 0.0, 0.0, 0.0, 2.1445069205095586, 0.0, 0.0, 0.0, 0.0, -1.00010000500025, -1.0, 0.0, 0.0, -0.200010000500025, 0.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), type=u'PerspectiveCamera', up=(0.0, 1.0, 0.0), width=600.0), controls=[OrbitControls(controlling=CombinedCamera(height=400.0, position=(0.0, 0.0, 60.0), projectionMatrix=(1.4296712803397058, 0.0, 0.0, 0.0, 0.0, 2.1445069205095586, 0.0, 0.0, 0.0, 0.0, -1.00010000500025, -1.0, 0.0, 0.0, -0.200010000500025, 0.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), type=u'PerspectiveCamera', up=(0.0, 1.0, 0.0), width=600.0))], scene=Scene(children=(Mesh(geometry=SphereBufferGeometry(heightSegments=16, radius=20.0, type=u'SphereBufferGeometry', widthSegments=16), material=MeshPhysicalMaterial(alphaMap=None, aoMap=None, bumpMap=None, color=u'red', defines={'PHYSICAL': ''}, displacementMap=None, emissiveMap=None, envMap=None, lightMap=None, map=None, metalnessMap=None, normalMap=None, normalScale=(1.0, 1.0), roughnessMap=None, type=u'MeshPhysicalMaterial'), position=(-20.0, 0.0, 0.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), Mesh(geometry=SphereBufferGeometry(heightSegments=16, radius=20.0, type=u'SphereBufferGeometry', widthSegments=16), material=MeshPhysicalMaterial(alphaMap=None, aoMap=None, bumpMap=None, color=u'green', defines={'PHYSICAL': ''}, displacementMap=None, emissiveMap=None, envMap=None, lightMap=None, map=None, metalnessMap=None, normalMap=None, normalScale=(1.0, 1.0), roughnessMap=None, type=u'MeshPhysicalMaterial'), position=(20.0, 0.0, 0.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), PointLight(position=(-100.0, 100.0, 100.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), AmbientLight(intensity=0.4, quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), CombinedCamera(height=400.0, position=(0.0, 0.0, 60.0), projectionMatrix=(1.4296712803397058, 0.0, 0.0, 0.0, 0.0, 2.1445069205095586, 0.0, 0.0, 0.0, 0.0, -1.00010000500025, -1.0, 0.0, 0.0, -0.200010000500025, 0.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), type=u'PerspectiveCamera', up=(0.0, 1.0, 0.0), width=600.0)), fog=None, overrideMaterial=None, quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), shadowMap=WebGLShadowMap())"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"key_light = PointLight(position=[-100, 100, 100])\n",
"ambient_light = AmbientLight(intensity=0.4)\n",
"scene = Scene(children=[mesh1, mesh2, key_light, ambient_light, camera])\n",
"renderer = Renderer(scene=scene, camera=camera, controls=[OrbitControls(controlling=camera)],\n",
" width=view_width, height=view_height)\n",
"display(renderer)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"camera.mode = 'orthographic'"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"camera.mode = 'perspective'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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",
"version": "2.7.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import threevis\n",
"import openmesh as om\n",
"import numpy as np\n",
"\n",
"m = om.read_polymesh('models/model_mixed_valence.obj')\n",
"\n",
"vertices = m.points()\n",
"faces = m.face_vertex_indices()\n",
"edges = m.ev_indices()\n",
"\n",
"mesh = threevis.Mesh(vertices, faces)\n",
"mesh.colors = threevis.FaceAttribute(np.random.rand(len(faces), 3))\n",
"mesh.normals = threevis.calculatePointNormals(vertices, faces)\n",
"\n",
"\n",
"normal_vis_verts, normal_vis_edges = threevis.calculateNormalEdges(vertices, faces, mesh.normals, 0.5)\n",
"\n",
"ctx = threevis.Context()\n",
"\n",
"ctx.draw(mesh).draw(threevis.EdgeList(vertices, edges)).draw(threevis.PointList(vertices, colors='#aaaaaa'), point_size=3)\n",
"\n",
"ctx.draw_edges(normal_vis_verts, normal_vis_edges)\n",
"\n",
"ctx.display()\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.3rc1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import threevis\n",
"import openmesh as om\n",
"import numpy as np\n",
"m = om.read_trimesh(\"models/bunny.obj\")\n",
"\n",
"ctx = threevis.Context(width=640, height=480)\n",
"\n",
"texture = threevis.ImageTexture(imageUri='textures/checkerboard.png')\n",
"\n",
"vertices = m.points()\n",
"faces = m.face_vertex_indices()\n",
"\n",
"normals = threevis.calculatePointNormals(vertices, faces)\n",
"colors = threevis.FaceAttribute(np.random.rand(len(faces), 3))\n",
"uvs = threevis.PointAttribute(m.vertex_texcoords2D())\n",
"\n",
"ctx.draw_faces(vertices, faces, \n",
" normals = normals,\n",
" colors = colors,\n",
" uvs = uvs,\n",
" shading = 'flat')\n",
"\n",
"ctx.draw_edges(vertices, m.ev_indices(), \n",
" colors = threevis.FaceAttribute(np.random.rand(len(m.ev_indices()), 3)),\n",
" linewidth=3)\n",
"\n",
"normal_vis_verts, normal_vis_edges = threevis.calculateNormalEdges(vertices, faces, normals, 0.005)\n",
"\n",
"ctx.draw_edges(normal_vis_verts, normal_vis_edges)\n",
"\n",
"ctx.draw_vertices(vertices, point_size=4, colors='red')\n",
"\n",
"ctx.display()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"threevis.display_vertices([[0,0,0],[1,0, 0]], colors='blue', point_size=10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"verts = [\n",
" # Front face\n",
" [-1.0, -1.0, 1.0],\n",
" [ 1.0, -1.0, 1.0],\n",
" [ 1.0, 1.0, 1.0],\n",
" [-1.0, 1.0, 1.0],\n",
"]\n",
"\n",
"indices = [\n",
" [0, 1, 2], [0, 2, 3], # front\n",
"]\n",
"\n",
"vcolors = [\n",
" [1, 0, 0],\n",
" [0, 1, 0],\n",
" [0, 0, 1],\n",
" [1, 0, 1]\n",
"]\n",
"\n",
"fcolors = [\n",
" [1, 0, 0],\n",
" [0, 0, 1]\n",
"]\n",
"\n",
"uvs = [\n",
" [0, 0],\n",
" [1, 0],\n",
" [1, 1],\n",
" [0, 1]\n",
"]\n",
"\n",
"ctx = threevis.Context(width=300, height=300)\n",
"\n",
"ctx.draw_faces(verts, indices, \n",
" colors = threevis.PointAttribute(vcolors),\n",
" uvs = threevis.PointAttribute(uvs),\n",
" texture = threevis.ImageTexture(imageUri='textures/checkerboard.png'))\n",
"\n",
"ctx.draw_vertices(verts, point_size=5, colors=vcolors)\n",
"\n",
"ctx.display()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import threevis\n",
"vcolors = [\n",
" [1, 0, 0],\n",
" [0, 1, 0],\n",
" [0, 0, 1],\n",
" [1, 0, 1]\n",
"]\n",
"\n",
"fcolors = [\n",
" [1, 0, 0],\n",
" [0, 0, 1]\n",
"]\n",
"\n",
"threevis.display_edges([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], \n",
" [[0, 1], [2,3]], \n",
" colors = threevis.PointAttribute(vcolors))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.3rc1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2018-01-31T10:39:40.664620Z",
"start_time": "2018-01-31T10:39:40.015581Z"
}
},
"outputs": [],
"source": [
"from pythreejs import *\n",
"import numpy as np\n",
"from IPython.display import display\n",
"from ipywidgets import HTML, Text\n",
"from traitlets import link, dlink, Bool\n",
"import openmesh as om"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2018-01-31T10:39:40.736679Z",
"start_time": "2018-01-31T10:39:40.665776Z"
}
},
"outputs": [],
"source": [
"mesh = om.read_trimesh('models/bunny.obj')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2018-01-31T10:40:14.056198Z",
"start_time": "2018-01-31T10:40:13.983550Z"
}
},
"outputs": [],
"source": [
"#vertexcolors = np.asarray([(0,0,0), (0,0,1), (0,1,0), (1,0,0), (0,1,1), (1,0,1), (1,1,0), (1,1,1)])\n",
"#facecolors = [[vertexcolors[i] for i in f] for f in faces]\n",
"cubeGeometry = Geometry(vertices=mesh.points().tolist(), faces=mesh.face_vertex_indices().tolist())\n",
"\n",
"myobjectCube = Mesh(geometry=cubeGeometry, material = MeshLambertMaterial())\n",
"cCube = PerspectiveCamera(position=[3, 3, 3], fov=20,\n",
" children=[DirectionalLight(color='#ffffff', position=[-3, 5, 1], intensity=0.5)])\n",
"hover_point = Mesh(geometry=SphereGeometry(radius=0.005), material=MeshLambertMaterial(color='hotpink'))\n",
"sceneCube = Scene(children=[myobjectCube, hover_point, AmbientLight(color='#dddddd')])\n",
"\n",
"\n",
"click_picker = Picker(controlling=myobjectCube, root=myobjectCube, event='dblclick')\n",
"obc = OrbitControls(controlling=cCube)\n",
"\n",
"rendererCube = Renderer(camera=cCube, background='black', background_opacity=1,\n",
" scene = sceneCube, controls=[obc, click_picker])\n",
"\n",
"link((hover_point, 'position'), (click_picker, 'point'))\n",
"\n",
"h = HTML()\n",
"def g(change):\n",
" h.value = 'point {}'.format(change['new'])\n",
" obc.target = change['new']\n",
"g({'new': hover_point.position})\n",
"\n",
"click_picker.observe(g, names=['point'])\n",
"display(h)\n",
"display(rendererCube)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.3rc1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
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