{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import meshutil\n",
"import stl.mesh\n",
"import numpy\n",
"import trimesh"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"b1 = numpy.array([\n",
" [0, 0, 0],\n",
" [1, 0, 0],\n",
" [1, 1, 0],\n",
" [0, 1, 0],\n",
"], dtype=numpy.float64)\n",
"b2 = numpy.array(b1 + [0,0,1])\n",
"\n",
"testmesh = meshutil.join_boundary_simple(b1, b2)\n",
"testmesh.to_stl_mesh().save(\"simple.stl\")"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [],
"source": [
"mesh_fname = \"cube_test.stl\"\n",
"\n",
"# center at (0,0,0) for sanity reasons\n",
"center = meshutil.Transform().translate(-0.5, -0.5, -0.5)\n",
"base = meshutil.cube(open_xz=False).transform(center)\n",
"\n",
"xform = center.translate(-0.5,1.5,-0.5).scale(0.5)\n",
"ang = 0.15\n",
"l2 = meshutil.cube_distort(ang, open_xz=False)\n",
"\n",
"mesh = base\n",
"for layer in range(2):\n",
" for i in range(4):\n",
" m = l2.transform(xform.rotate([0,1,0], i*numpy.pi/2))\n",
" mesh = mesh.concat(m)\n",
" xform = xform.rotate([-1,0,1], ang).scale(1.0).translate(0, 0.7, 0)\n",
"\n",
"# Work around some annoying-ass trimesh/threejs bug:\n",
"wtf = meshutil.Transform().scale(0.1).translate(5,0,0)\n",
"base = base.transform(wtf)\n",
"mesh = mesh.concat(base)\n",
"mesh.to_stl_mesh().save(mesh_fname)"
]
},
{
"cell_type": "code",
"execution_count": 66,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"face_normals didn't match triangles, ignoring!\n"
]
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# TODO: Just use the mesh data directly (no sense in saving & re-loading)\n",
"m = trimesh.load_mesh(mesh_fname)\n",
"#m.show()\n",
"scene = trimesh.Scene([m])\n",
"# Seems to do nothing:\n",
"# scene.camera_transform = scene.camera.look_at(m.vertices, distance=10)\n",
"scene.show()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1. , 0. , 0. , -0.07059288],\n",
" [ 0. , 1. , 0. , 0.09608653],\n",
" [-0. , 0. , 1. , 2.14795328],\n",
" [ 0. , 0. , 0. , 1. ]])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"scene.camera_transform"
]
},
{
"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.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}