{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import stl.mesh\n", "import numpy\n", "import trimesh\n", "import random\n", "import itertools\n", "\n", "import meshutil\n", "import meshgen\n", "import examples" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import cProfile, pstats" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "#mesh = examples.ram_horn()\n", "#mesh = examples.twist()\n", "#mesh = examples.twist_nonlinear()\n", "#mesh = examples.twist_from_gen()\n", "#mesh = examples.twisty_torus(1000)\n", "#mesh = examples.ram_horn2()\n", "mesh = examples.branch_test()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "def spiral3():\n", " b = numpy.array([\n", " [0, 0, 0],\n", " [1, 0, 0],\n", " [1, 0, 1],\n", " [0, 0, 1],\n", " ], dtype=numpy.float64) - [0.5, 0, 0.5]\n", " b *= 0.3\n", " b = meshutil.subdivide_boundary(b)\n", " b = meshutil.subdivide_boundary(b)\n", " bs = [b]\n", " # since it needs a generator:\n", " gen1 = itertools.repeat(bs)\n", " gen2 = meshgen.gen_twisted_boundary(gen1, ang=-0.2, dx0=0.5)\n", " gen3 = meshgen.gen_twisted_boundary(gen2, ang=0.07, dx0=1)\n", " gen4 = meshgen.gen_twisted_boundary(gen3, ang=-0.03, dx0=3)\n", " gen = meshgen.gen_inc_y(gen4, dy=0.1)\n", " mesh = meshgen.gen2mesh(\n", " gen, count=500, flip_order=True, close_first=True, close_last=True)\n", " return mesh\n", "\n", "def profile():\n", " pr = cProfile.Profile()\n", " pr.enable()\n", " spiral3()\n", " pr.disable()\n", " ps = pstats.Stats(pr)\n", " return ps\n", "\n", "#ps = profile()\n", "#ps.sort_stats('tottime').print_stats()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# Work around some annoying-ass trimesh/threejs bug:\n", "wtf = meshutil.Transform().scale(0.1).translate(20,0,0)\n", "center = meshutil.Transform().translate(-0.5, -0.5, -0.5)\n", "base = meshutil.cube(open_xz=False).transform(center)\n", "base = base.transform(wtf)\n", "mesh_out = mesh\n", "# to enable:\n", "#mesh_out = mesh_out.concat(base)\n", "\n", "mesh_fname = \"spiral_nested3.stl\"\n", "mesh_out.to_stl_mesh().save(mesh_fname)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/hodapp/.local/lib/python3.6/site-packages/IPython/core/display.py:694: UserWarning: Consider using IPython.display.IFrame instead\n", " warnings.warn(\"Consider using IPython.display.IFrame instead\")\n" ] }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = trimesh.Trimesh(vertices=mesh.v, faces=mesh.f)\n", "# Also acceptable:\n", "#m = trimesh.load_mesh(mesh_fname)\n", "\n", "#m.show()\n", "scene = trimesh.Scene([m])\n", "scene.show()" ] }, { "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 }