Commit 5370c2c2 authored by Dario Seyb's avatar Dario Seyb

automatic centering

parent f66f0105
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {
"scrolled": false
},
......@@ -10,7 +10,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d78baa643f694c9a8dfe4b107fa23140",
"model_id": "f00a5235179a4f5c8c71d99c795979ef",
"version_major": 2,
"version_minor": 0
},
......@@ -30,13 +30,13 @@
"</p>\n"
],
"text/plain": [
"Renderer(background='#dddddd', camera=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(3.0, 3.0, 3.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), controls=[OrbitControls(controlling=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(3.0, 3.0, 3.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)))], scene=Scene(background=u'#dddddd', children=(AmbientLight(color=u'#aaaaaa', quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(3.0, 3.0, 3.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=BufferGeometry(attributes={'color': BufferAttribute(array=array([[0.23248161, 0.6580202 , 0.67279756],\n",
" [0.23248161, 0.6580202 , 0.67279756],\n",
" [0.23248161, 0.6580202 , 0.67279756],\n",
"Renderer(background='#dddddd', camera=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(0.13295613955334604, 0.13295613955334604, 0.13295613955334604), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), controls=[OrbitControls(controlling=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(0.13295613955334604, 0.13295613955334604, 0.13295613955334604), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), target=(-0.016805611188265124, 0.10981325821101032, -0.0013969168554233066))], scene=Scene(background=u'#dddddd', children=(AmbientLight(color=u'#aaaaaa', quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(0.13295613955334604, 0.13295613955334604, 0.13295613955334604), 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=BufferGeometry(attributes={'color': BufferAttribute(array=array([[0.10657822, 0.1982002 , 0.21706074],\n",
" [0.10657822, 0.1982002 , 0.21706074],\n",
" [0.10657822, 0.1982002 , 0.21706074],\n",
" ...,\n",
" [0.74864453, 0.61769456, 0.59280473],\n",
" [0.74864453, 0.61769456, 0.59280473],\n",
" [0.74864453, 0.61769456, 0.59280473]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 14901, 14902, 14903], dtype=uint16), normalized=False), 'normal': BufferAttribute(array=array([[-0.8607535 , 0.1269212 , -0.4929447 ],\n",
" [0.1028768 , 0.68745416, 0.3252007 ],\n",
" [0.1028768 , 0.68745416, 0.3252007 ],\n",
" [0.1028768 , 0.68745416, 0.3252007 ]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 14901, 14902, 14903], dtype=uint16), normalized=False), 'normal': BufferAttribute(array=array([[-0.8607535 , 0.1269212 , -0.4929447 ],\n",
" [-0.8924592 , -0.02002691, -0.45068336],\n",
" [-0.8525913 , -0.13340487, -0.50526357],\n",
" ...,\n",
......@@ -48,25 +48,25 @@
" ...,\n",
" [-0.05290982, 0.05704307, 0.02098841],\n",
" [-0.05816759, 0.05998519, 0.02260606],\n",
" [-0.0550398 , 0.0573097 , 0.0169909 ]], dtype=float32), normalized=False)}), material=MeshLambertMaterial(alphaMap=None, aoMap=None, color=u'white', emissiveMap=None, envMap=None, lightMap=None, map=None, polygonOffset=True, polygonOffsetFactor=0.5, polygonOffsetUnits=0.1, specularMap=None, vertexColors='VertexColors'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), LineSegments(geometry=BufferGeometry(attributes={'color': BufferAttribute(array=array([[0.41986996, 0.5942799 , 0.44914556],\n",
" [0.41986996, 0.5942799 , 0.44914556],\n",
" [0.1897525 , 0.11455698, 0.6038935 ],\n",
" [-0.0550398 , 0.0573097 , 0.0169909 ]], dtype=float32), normalized=False)}), material=MeshLambertMaterial(alphaMap=None, aoMap=None, color=u'white', emissiveMap=None, envMap=None, lightMap=None, map=None, polygonOffset=True, polygonOffsetFactor=0.5, polygonOffsetUnits=0.1, specularMap=None, vertexColors='VertexColors'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), LineSegments(geometry=BufferGeometry(attributes={'color': BufferAttribute(array=array([[0.6257505 , 0.2116082 , 0.8848519 ],\n",
" [0.6257505 , 0.2116082 , 0.8848519 ],\n",
" [0.5772543 , 0.00963263, 0.21164967],\n",
" ...,\n",
" [0.07761359, 0.5742296 , 0.32884943],\n",
" [0.18359563, 0.20241594, 0.10445441],\n",
" [0.18359563, 0.20241594, 0.10445441]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 14943, 14944, 14945], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-0.08656194, 0.14249188, 0.00843268],\n",
" [0.68013966, 0.58714706, 0.7767872 ],\n",
" [0.59187627, 0.8779615 , 0.06428586],\n",
" [0.59187627, 0.8779615 , 0.06428586]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 14943, 14944, 14945], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-0.08656194, 0.14249188, 0.00843268],\n",
" [-0.08969839, 0.13971257, 0.01377476],\n",
" [-0.08969839, 0.13971257, 0.01377476],\n",
" ...,\n",
" [-0.0550398 , 0.0573097 , 0.0169909 ],\n",
" [-0.05290982, 0.05704307, 0.02098841],\n",
" [-0.0550398 , 0.0573097 , 0.0169909 ]], dtype=float32), normalized=False)}), material=LineBasicMaterial(color=u'white', linewidth=3.0, vertexColors='VertexColors'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), LineSegments(geometry=BufferGeometry(attributes={'index': BufferAttribute(array=array([ 0, 1, 2, ..., 29805, 29806, 29807], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-0.08656194, 0.14249188, 0.00843268],\n",
" [-0.09516948, 0.14376108, 0.00350323],\n",
" [-0.09086571, 0.14312649, 0.00596796],\n",
" [-0.08969839, 0.13971257, 0.01377476],\n",
" ...,\n",
" [-0.06090486, 0.05099568, 0.02602601],\n",
" [-0.05953623, 0.05549044, 0.02431604],\n",
" [-0.0550398 , 0.0573097 , 0.0169909 ],\n",
" [-0.0585605 , 0.04812175, 0.01877592]], dtype=float32), normalized=False)}), material=LineBasicMaterial(color=u'#000000'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), Points(geometry=BufferGeometry(attributes={'position': BufferAttribute(array=array([[-0.00341018, 0.13031957, 0.02175437],\n",
" [-0.05680015, 0.05271573, 0.01788341]], dtype=float32), normalized=False)}), material=LineBasicMaterial(color=u'#000000'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), Points(geometry=BufferGeometry(attributes={'position': BufferAttribute(array=array([[-0.00341018, 0.13031957, 0.02175437],\n",
" [-0.08171916, 0.15250145, 0.02965609],\n",
" [-0.03054348, 0.12477885, 0.00109834],\n",
" ...,\n",
......
......@@ -2,81 +2,22 @@
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d78baa643f694c9a8dfe4b107fa23140",
"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(background='#dddddd', camera=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(3.0, 3.0, 3.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), controls=[OrbitControls(controlling=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(3.0, 3.0, 3.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)))], scene=Scene(background=u'#dddddd', children=(AmbientLight(color=u'#aaaaaa', quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(position=(-30.0, 50.0, 10.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(3.0, 3.0, 3.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=BufferGeometry(attributes={'color': BufferAttribute(array=array([[0.23248161, 0.6580202 , 0.67279756],\n",
" [0.23248161, 0.6580202 , 0.67279756],\n",
" [0.23248161, 0.6580202 , 0.67279756],\n",
" ...,\n",
" [0.74864453, 0.61769456, 0.59280473],\n",
" [0.74864453, 0.61769456, 0.59280473],\n",
" [0.74864453, 0.61769456, 0.59280473]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 14901, 14902, 14903], dtype=uint16), normalized=False), 'normal': BufferAttribute(array=array([[-0.8607535 , 0.1269212 , -0.4929447 ],\n",
" [-0.8924592 , -0.02002691, -0.45068336],\n",
" [-0.8525913 , -0.13340487, -0.50526357],\n",
" ...,\n",
" [-0.69263035, -0.7083079 , 0.13624643],\n",
" [-0.2737271 , -0.8989508 , 0.34199542],\n",
" [-0.35207012, -0.91879463, 0.17850235]], dtype=float32)), 'position': BufferAttribute(array=array([[-0.08656194, 0.14249188, 0.00843268],\n",
" [-0.08969839, 0.13971257, 0.01377476],\n",
" [-0.08949102, 0.14392582, 0.01248849],\n",
" ...,\n",
" [-0.05290982, 0.05704307, 0.02098841],\n",
" [-0.05816759, 0.05998519, 0.02260606],\n",
" [-0.0550398 , 0.0573097 , 0.0169909 ]], dtype=float32), normalized=False)}), material=MeshLambertMaterial(alphaMap=None, aoMap=None, color=u'white', emissiveMap=None, envMap=None, lightMap=None, map=None, polygonOffset=True, polygonOffsetFactor=0.5, polygonOffsetUnits=0.1, specularMap=None, vertexColors='VertexColors'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), LineSegments(geometry=BufferGeometry(attributes={'color': BufferAttribute(array=array([[0.41986996, 0.5942799 , 0.44914556],\n",
" [0.41986996, 0.5942799 , 0.44914556],\n",
" [0.1897525 , 0.11455698, 0.6038935 ],\n",
" ...,\n",
" [0.07761359, 0.5742296 , 0.32884943],\n",
" [0.18359563, 0.20241594, 0.10445441],\n",
" [0.18359563, 0.20241594, 0.10445441]], dtype=float32)), 'index': BufferAttribute(array=array([ 0, 1, 2, ..., 14943, 14944, 14945], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-0.08656194, 0.14249188, 0.00843268],\n",
" [-0.08969839, 0.13971257, 0.01377476],\n",
" [-0.08969839, 0.13971257, 0.01377476],\n",
" ...,\n",
" [-0.0550398 , 0.0573097 , 0.0169909 ],\n",
" [-0.05290982, 0.05704307, 0.02098841],\n",
" [-0.0550398 , 0.0573097 , 0.0169909 ]], dtype=float32), normalized=False)}), material=LineBasicMaterial(color=u'white', linewidth=3.0, vertexColors='VertexColors'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), LineSegments(geometry=BufferGeometry(attributes={'index': BufferAttribute(array=array([ 0, 1, 2, ..., 29805, 29806, 29807], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-0.08656194, 0.14249188, 0.00843268],\n",
" [-0.09516948, 0.14376108, 0.00350323],\n",
" [-0.08969839, 0.13971257, 0.01377476],\n",
" ...,\n",
" [-0.06090486, 0.05099568, 0.02602601],\n",
" [-0.0550398 , 0.0573097 , 0.0169909 ],\n",
" [-0.0585605 , 0.04812175, 0.01877592]], dtype=float32), normalized=False)}), material=LineBasicMaterial(color=u'#000000'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), Points(geometry=BufferGeometry(attributes={'position': BufferAttribute(array=array([[-0.00341018, 0.13031957, 0.02175437],\n",
" [-0.08171916, 0.15250145, 0.02965609],\n",
" [-0.03054348, 0.12477885, 0.00109834],\n",
" ...,\n",
" [-0.01389549, 0.16787168, -0.02189723],\n",
" [-0.069413 , 0.15121847, -0.04453854],\n",
" [-0.0550398 , 0.0573097 , 0.0169909 ]], dtype=float32), normalized=False)}), material=PointsMaterial(color=u'red', map=None, size=4.0, sizeAttenuation=False), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.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"
"ename": "AttributeError",
"evalue": "'OrbitControls' object has no attribute 'update'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-1-6c2ff8306b9e>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 27\u001b[0m \u001b[0mctx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdraw_vertices\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mm\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpoints\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mpoint_size\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolors\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'red'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 28\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 29\u001b[1;33m \u001b[0mctx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdisplay\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32mc:\\dev\\meshvis\\meshvis\\context.pyc\u001b[0m in \u001b[0;36mdisplay\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 182\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcamera\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mposition\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtuple\u001b[0m\u001b[1;33m(\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcamera\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mposition\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m*\u001b[0m \u001b[0mdistance\u001b[0m \u001b[1;33m*\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 183\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0morbit_controls\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtarget\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtuple\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcenter\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 184\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0morbit_controls\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 185\u001b[0m \u001b[0mdisplay\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrenderer\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mAttributeError\u001b[0m: 'OrbitControls' object has no attribute 'update'"
]
}
],
"source": [
......
......@@ -6,12 +6,16 @@ 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=[3,3,3], fov=20,
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])
self.maxCorner = np.array([-100000.0, -100000.0, -100000.0])
self.scene = three.Scene(children=[three.AmbientLight(color='#aaaaaa'), self.camera])
self.scene.background = background_color
......@@ -82,6 +86,10 @@ class Context(object):
mesh_obj = three.Mesh(geometry=mesh_geom, material=mat)
for vert in vertices:
self.minCorner = np.minimum(self.minCorner, vert)
  • Instead of iterating over the numpy array you can just call vertices.min(axis=1) and vertices.max(axis=1) to get the bounding box corners.

Please register or sign in to reply
self.maxCorner = np.maximum(self.maxCorner, vert)
self.scene.add(mesh_obj)
return self
......@@ -124,6 +132,10 @@ class Context(object):
geom = three.BufferGeometry(attributes = attributes)
mesh_obj = three.LineSegments(geometry=geom, material=mat)
for vert in vertices:
self.minCorner = np.minimum(self.minCorner, vert)
self.maxCorner = np.maximum(self.maxCorner, vert)
self.scene.add(mesh_obj)
return self
......@@ -157,8 +169,17 @@ class Context(object):
geom = three.BufferGeometry(attributes=attributes)
mesh_obj = three.Points(geometry=geom, material=mat)
for vert in vertices:
self.minCorner = np.minimum(self.minCorner, vert)
self.maxCorner = np.maximum(self.maxCorner, vert)
self.scene.add(mesh_obj)
return self
def display(self):
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)
display(self.renderer)
\ No newline at end of file
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