{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "To do:\n", "\n", "- Parametrize gen_twisted_boundary over boundaries and\n", "do my nested spiral\n", "- Rewrite ram_horn in terms of newer abstractions\n", "- Encode the notions of \"generator which transforms an\n", "existing list of boundaries\", \"generator which transforms\n", "another generator\"\n", "- Work directly with lists of boundaries. The only thing\n", "I ever do with them is apply transforms to all of them, or\n", "join adjacent ones with corresponding elements.\n", "- Why do I get the weird zig-zag pattern on the triangles,\n", "despite larger numbers of them? Is it something in how I\n", "twist the frames?\n", " - How can I compute the *torsion* on a quad? I think it\n", " comes down to this: torsion applied across the quad I'm\n", " triangulating leading to neither diagonal being a\n", " particularly good choice. Subdividing the boundary seems\n", " to help, but other triangulation methods (e.g. turning a\n", " quad to 4 triangles by adding the centroid) could be good\n", " too.\n", " - Facets/edges are just oriented the wrong way...\n", "- I need an actual example of branching/forking. If I simply\n", "split a boundary into sub-boundaries per the rules I already\n", "have in my notes, then this still lets me split any way I want\n", "to without having to worry about joining N boundaries instead\n", "of 2, doesn't it?\n", "\n", "Other notes:\n", "- Picking at random the diagonal on the quad to triangulate with\n", " does seem to turn 'error' just to noise, and in its own way this\n", " is preferable. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import stl.mesh\n", "import numpy\n", "import trimesh\n", "import random\n", "\n", "import meshutil\n", "import examples" ] }, { "cell_type": "code", "execution_count": 2, "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)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# for me to be able to nest this, gen_twisted_boundary has to\n", "# be parametrized over some other boundary (the way )\n", "#gen = examples.gen_inc_y(examples.gen_twisted_boundary())\n", "#mesh = gen2mesh(gen, 100, True)" ] }, { "cell_type": "code", "execution_count": 4, "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 = \"twist_wtf.stl\"\n", "mesh_out.to_stl_mesh().save(mesh_fname)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "face_normals didn't match triangles, ignoring!\n", "/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": 5, "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", "scene.show()" ] } ], "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 }