{ "cells": [ { "cell_type": "code", "execution_count": 230, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 230, "metadata": {}, "output_type": "execute_result" } ], "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\n", "import cage\n", "\n", "import importlib\n", "importlib.reload(examples)" ] }, { "cell_type": "code", "execution_count": 231, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 2]" ] }, "execution_count": 231, "metadata": {}, "output_type": "execute_result" } ], "source": [ "importlib.reload(cage)\n", "c = cage.Cage.from_arrays([[0,0,0], [1,1,1]], [[2,2,2]])\n", "c.splits" ] }, { "cell_type": "code", "execution_count": 232, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1., 1., 1.]])" ] }, "execution_count": 232, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c.verts[1:-1,:]" ] }, { "cell_type": "code", "execution_count": 233, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[0. 0. 0.]\n", " [1. 1. 1.]]\n", "[[2. 2. 2.]]\n" ] } ], "source": [ "for i in c.polys():\n", " print(i)" ] }, { "cell_type": "code", "execution_count": 234, "metadata": {}, "outputs": [], "source": [ "center = meshutil.Transform().translate(-0.5, -0.5, 0)\n", "cage0 = cage.Cage.from_arrays([\n", " [0, 0, 0],\n", " [1, 0, 0],\n", " [1, 1, 0],\n", " [0, 1, 0],\n", "])#.transform(center)" ] }, { "cell_type": "code", "execution_count": 235, "metadata": {}, "outputs": [], "source": [ "cs,_,_ = cage0.subdivide_deprecated()\n", "c1,c2,c3,c4 = cs" ] }, { "cell_type": "code", "execution_count": 236, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0. , 0. , 0. ],\n", " [0.5, 0. , 0. ],\n", " [0.5, 0.5, 0. ],\n", " [0. , 0.5, 0. ]])" ] }, "execution_count": 236, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c1.verts" ] }, { "cell_type": "code", "execution_count": 237, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.5, 0. , 0. ],\n", " [1. , 0. , 0. ],\n", " [1. , 0.5, 0. ],\n", " [0.5, 0.5, 0. ]])" ] }, "execution_count": 237, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c2.verts" ] }, { "cell_type": "code", "execution_count": 238, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.5, 0.5, 0. ],\n", " [1. , 0.5, 0. ],\n", " [1. , 1. , 0. ],\n", " [0.5, 1. , 0. ]])" ] }, "execution_count": 238, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c3.verts" ] }, { "cell_type": "code", "execution_count": 239, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0. , 0.5, 0. ],\n", " [0.5, 0.5, 0. ],\n", " [0.5, 1. , 0. ],\n", " [0. , 1. , 0. ]])" ] }, "execution_count": 239, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c4.verts" ] }, { "cell_type": "code", "execution_count": 240, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[array([3, 1, 2, 1], dtype=uint8),\n", " array([1, 3, 1, 2], dtype=uint8),\n", " array([2, 1, 3, 1], dtype=uint8),\n", " array([1, 2, 1, 3], dtype=uint8)]" ] }, "execution_count": 240, "metadata": {}, "output_type": "execute_result" } ], "source": [ "overlap = cage0.classify_overlap(cs)\n", "overlap" ] }, { "cell_type": "code", "execution_count": 241, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Cage 0:\n", " Vertex 0: type=3 for position [0. 0. 0.]\n", " Vertex 1: type=1 for position [0.5 0. 0. ]\n", " Vertex 2: type=2 for position [0.5 0.5 0. ]\n", " Vertex 3: type=1 for position [0. 0.5 0. ]\n", "Cage 1:\n", " Vertex 0: type=1 for position [0.5 0. 0. ]\n", " Vertex 1: type=3 for position [1. 0. 0.]\n", " Vertex 2: type=1 for position [1. 0.5 0. ]\n", " Vertex 3: type=2 for position [0.5 0.5 0. ]\n", "Cage 2:\n", " Vertex 0: type=2 for position [0.5 0.5 0. ]\n", " Vertex 1: type=1 for position [1. 0.5 0. ]\n", " Vertex 2: type=3 for position [1. 1. 0.]\n", " Vertex 3: type=1 for position [0.5 1. 0. ]\n", "Cage 3:\n", " Vertex 0: type=1 for position [0. 0.5 0. ]\n", " Vertex 1: type=2 for position [0.5 0.5 0. ]\n", " Vertex 2: type=1 for position [0.5 1. 0. ]\n", " Vertex 3: type=3 for position [0. 1. 0.]\n" ] } ], "source": [ "# Pretty-print a little:\n", "for i,(c,ols) in enumerate(zip(cs, overlap)):\n", " print(\"Cage {}:\".format(i))\n", " for j,(vert,ol) in enumerate(zip(c.verts, ols)):\n", " print(\" Vertex {}: type={} for position {}\".format(j, ol, vert))" ] }, { "cell_type": "code", "execution_count": 242, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "DEBUG: Transition from [[0. 0. 0.]\n", " [1. 0. 0.]\n", " [1. 1. 0.]\n", " [0. 1. 0.]] to [[0. 0. 2. ]\n", " [0.5 0. 2. ]\n", " [1. 0. 2. ]\n", " [1. 0.5 2. ]\n", " [1. 1. 2. ]\n", " [0.5 1. 2. ]\n", " [0. 1. 2. ]\n", " [0. 0.5 2. ]]\n" ] } ], "source": [ "cf = cage.CageFork(None,\n", " numpy.array([[0, 0, 0], [0.5, 0, 0], [1, 0, 0], [1, 0.5, 0],\n", " [1, 1, 0], [0.5, 1, 0], [0, 1, 0], [0, 0.5, 0]]) + [0, 0, 2],\n", " [[7, 0, 1], [1, 2, 3], [3, 4, 5], [5, 6, 7]]\n", " )\n", "mesh2 = cf.transition_from(cage0)" ] }, { "cell_type": "code", "execution_count": 243, "metadata": {}, "outputs": [], "source": [ "import cProfile, pstats" ] }, { "cell_type": "code", "execution_count": 244, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "DEBUG: Transition from [[-0.12779038 0.21102174 2.40470962]\n", " [ 0.33806165 0.70938821 2.14156165]\n", " [-0.16030482 0.91209228 1.64319518]\n", " [-0.62615685 0.41372581 1.90634315]] to [[-0.2626621 0.77854269 2.8165879 ]\n", " [-0.12337756 1.0097311 2.62782244]\n", " [ 0.01590698 1.24091952 2.43905698]\n", " [-0.21528143 1.19143859 2.20786857]\n", " [-0.44646984 1.14195767 1.97668016]\n", " [-0.58575438 0.91076926 2.16544562]\n", " [-0.72503892 0.67958085 2.35421108]\n", " [-0.49385051 0.72906177 2.58539949]]\n", "DEBUG: Transition from [[-0.74347748 0.58794149 3.71597464]\n", " [-0.79727882 0.82750482 3.5970103 ]\n", " [-0.90111397 0.6973509 3.38269929]\n", " [-0.84731263 0.45778757 3.50166363]] to [[-1.21682916 0.70882435 3.91083553]\n", " [-1.24891256 0.79437337 3.82882192]\n", " [-1.28099597 0.87992239 3.7468083 ]\n", " [-1.28427431 0.79385876 3.65911734]\n", " [-1.28755265 0.70779513 3.57142638]\n", " [-1.25546925 0.62224611 3.65344 ]\n", " [-1.22338584 0.53669709 3.73545361]\n", " [-1.2201075 0.62276072 3.82314457]]\n", "DEBUG: Transition from [[-1.41904679 0.33918003 4.55662312]\n", " [-1.49259832 0.36362409 4.49218395]\n", " [-1.45056812 0.30486275 4.42174767]\n", " [-1.37701659 0.28041868 4.48618684]] to [[-1.68933192 0.07584281 4.64352898]\n", " [-1.71429045 0.08008304 4.605789 ]\n", " [-1.73924898 0.08432327 4.56804903]\n", " [-1.70515054 0.06722139 4.54331646]\n", " [-1.67105211 0.05011951 4.5185839 ]\n", " [-1.64609358 0.04587928 4.55632388]\n", " [-1.62113504 0.04163905 4.59406386]\n", " [-1.65523348 0.05874093 4.61879642]]\n", "DEBUG: Transition from [[-1.75879046 1.52828884 3.91826404]\n", " [-1.77907869 1.52756421 3.82068411]\n", " [-1.77835406 1.42593032 3.82036248]\n", " [-1.75806582 1.42665495 3.91794241]] to [[-2.14044268 1.51937802 3.93105781]\n", " [-2.14710704 1.50554435 3.8886475 ]\n", " [-2.1537714 1.49171067 3.84623719]\n", " [-2.13779985 1.45011441 3.85631764]\n", " [-2.1218283 1.40851814 3.86639808]\n", " [-2.11516394 1.42235182 3.90880839]\n", " [-2.10849958 1.4361855 3.9512187 ]\n", " [-2.12447113 1.47778176 3.94113825]]\n", "DEBUG: Transition from [[-2.02774586 0.78613143 2.88671916]\n", " [-1.96411549 0.79303302 2.80926343]\n", " [-1.91850973 0.70797367 2.83931112]\n", " [-1.9821401 0.70107208 2.91676685]] to [[-2.22196111 0.61317392 2.64885197]\n", " [-2.18730239 0.60587863 2.62071796]\n", " [-2.15264368 0.59858334 2.59258396]\n", " [-2.13421759 0.56975042 2.6229292 ]\n", " [-2.1157915 0.5409175 2.65327443]\n", " [-2.15045022 0.54821278 2.68140843]\n", " [-2.18510894 0.55550807 2.70954244]\n", " [-2.20353502 0.58434099 2.6791972 ]]\n", "DEBUG: Transition from [[-1.71761816 -0.26532979 3.45944306]\n", " [-1.72739674 -0.21751538 3.37249066]\n", " [-1.62954178 -0.22931009 3.35458064]\n", " [-1.6197632 -0.27712451 3.44153304]] to [[-1.81861384 -0.54813442 3.25391516]\n", " [-1.80945737 -0.52737313 3.2150837 ]\n", " [-1.80030089 -0.50661184 3.17625223]\n", " [-1.75660235 -0.506064 3.1866376 ]\n", " [-1.71290381 -0.50551615 3.19702297]\n", " [-1.72206028 -0.52627744 3.23585444]\n", " [-1.73121675 -0.54703873 3.2746859 ]\n", " [-1.7749153 -0.54758657 3.26430053]]\n", "DEBUG: Transition from [[0.33273772 1.97512805 2.90337296]\n", " [0.27893637 2.07896319 2.66184879]\n", " [0.03937304 1.94880928 2.65532115]\n", " [0.09317438 1.84497413 2.89684532]] to [[ 5.32287262e-02 2.37916340e+00 3.05805689e+00]\n", " [ 6.32353561e-04 2.40218653e+00 2.95098652e+00]\n", " [-5.19640191e-02 2.42520966e+00 2.84391614e+00]\n", " [-1.27162666e-01 2.32956383e+00 2.85767391e+00]\n", " [-2.02361313e-01 2.23391801e+00 2.87143167e+00]\n", " [-1.49764941e-01 2.21089488e+00 2.97850205e+00]\n", " [-9.71685681e-02 2.18787175e+00 3.08557242e+00]\n", " [-2.19699209e-02 2.28351757e+00 3.07181466e+00]]\n", "DEBUG: Transition from [[ 1.09481578e-01 2.64523322e+00 3.90073134e+00]\n", " [ 1.96852406e-02 2.66797393e+00 3.85962291e+00]\n", " [-3.05547260e-03 2.57017380e+00 3.85309179e+00]\n", " [ 8.67408646e-02 2.54743309e+00 3.89420022e+00]] to [[-0.09990301 2.64641837 4.21237531]\n", " [-0.14070451 2.64305751 4.19202537]\n", " [-0.18150602 2.63969665 4.17167542]\n", " [-0.17341697 2.59572519 4.1624974 ]\n", " [-0.16532793 2.55175374 4.15331937]\n", " [-0.12452643 2.5551146 4.17366931]\n", " [-0.08372492 2.55847546 4.19401926]\n", " [-0.09181396 2.60244692 4.20319729]]\n", "DEBUG: Transition from [[-0.21041681 3.04847733 2.66462288]\n", " [-0.28396834 3.00644713 2.61128449]\n", " [-0.3084124 2.94768578 2.68820614]\n", " [-0.23486087 2.98971598 2.74154453]] to [[-0.49244292 3.25521577 2.81511259]\n", " [-0.52601836 3.22791694 2.80174112]\n", " [-0.55959381 3.2006181 2.78836964]\n", " [-0.55126049 3.17275998 2.82254855]\n", " [-0.54292716 3.14490185 2.85672746]\n", " [-0.50935172 3.17220069 2.87009893]\n", " [-0.47577628 3.19949953 2.88347041]\n", " [-0.4841096 3.22735765 2.8492915 ]]\n", "DEBUG: Transition from [[-1.05079225 2.1465857 2.64703003]\n", " [-1.04463562 2.06946796 2.58169183]\n", " [-1.01186141 2.00990788 2.65440841]\n", " [-1.01801805 2.08702562 2.71974661]] to [[-1.36237651 2.02532775 2.73412604]\n", " [-1.35345292 1.98475271 2.71533844]\n", " [-1.34452933 1.94417767 2.69655084]\n", " [-1.31922385 1.93332377 2.73259927]\n", " [-1.29391837 1.92246987 2.76864769]\n", " [-1.30284196 1.96304492 2.78743529]\n", " [-1.31176555 2.00361996 2.80622289]\n", " [-1.33707103 2.01447385 2.77017447]]\n", "DEBUG: Transition from [[-0.83336259 1.79896047 3.67957252]\n", " [-0.88053865 1.78423304 3.59339709]\n", " [-0.81699274 1.70865428 3.57041434]\n", " [-0.76981668 1.72338171 3.65658978]] to [[-1.05076267 1.55381209 3.80219963]\n", " [-1.06133874 1.53874977 3.7612283 ]\n", " [-1.07191482 1.52368746 3.72025698]\n", " [-1.03130013 1.50340616 3.71655505]\n", " [-0.99068544 1.48312485 3.71285311]\n", " [-0.98010937 1.49818717 3.75382444]\n", " [-0.96953329 1.51324948 3.79479576]\n", " [-1.01014798 1.53353079 3.79849769]]\n", "DEBUG: Transition from [[-0.85705489 1.90821162 1.64693271]\n", " [-0.77971211 1.81526522 1.40357228]\n", " [-0.91434668 1.5840904 1.44788536]\n", " [-0.99168946 1.67703679 1.6912458 ]] to [[-1.20609328 2.08615194 1.46419576]\n", " [-1.18636328 2.01321636 1.36776317]\n", " [-1.16663329 1.94028078 1.27133058]\n", " [-1.20308193 1.84311555 1.33704146]\n", " [-1.23953057 1.74595032 1.40275235]\n", " [-1.25926057 1.8188859 1.49918494]\n", " [-1.27899057 1.89182148 1.59561753]\n", " [-1.24254193 1.98898671 1.52990664]]\n", "DEBUG: Transition from [[-1.64569584 2.74360496 1.80582132]\n", " [-1.69287189 2.68005904 1.74340988]\n", " [-1.67814447 2.60448028 1.8090762 ]\n", " [-1.63096841 2.66802619 1.87148763]] to [[-1.92145722 2.81714973 1.9440273 ]\n", " [-1.93804776 2.77931856 1.92506107]\n", " [-1.95463829 2.74148739 1.90609483]\n", " [-1.93086932 2.71590925 1.9355613 ]\n", " [-1.90710036 2.69033112 1.96502778]\n", " [-1.89050982 2.72816229 1.98399401]\n", " [-1.87391929 2.76599346 2.00296025]\n", " [-1.89768825 2.79157159 1.97349378]]\n", "DEBUG: Transition from [[-1.37157745 2.29142615 0.69388887]\n", " [-1.38135603 2.19357118 0.67661684]\n", " [-1.42917044 2.18177647 0.76489743]\n", " [-1.41939186 2.27963143 0.78216946]] to [[-1.65767608 2.35860025 0.57338448]\n", " [-1.66649084 2.31460379 0.57863037]\n", " [-1.6753056 2.27060732 0.58387626]\n", " [-1.6820364 2.27640522 0.62851246]\n", " [-1.6887672 2.28220312 0.67314866]\n", " [-1.67995244 2.32619958 0.66790277]\n", " [-1.67113768 2.37019604 0.66265689]\n", " [-1.66440688 2.36439815 0.61802069]]\n", "DEBUG: Transition from [[-1.633161 1.28583927 1.21268628]\n", " [-1.5676273 1.21132261 1.23152628]\n", " [-1.57087294 1.23295012 1.32990797]\n", " [-1.63640665 1.30746679 1.31106797]] to [[-1.87380601 1.12814033 1.24313882]\n", " [-1.84458004 1.10029995 1.26411518]\n", " [-1.81535407 1.07245958 1.28509155]\n", " [-1.81557636 1.09995498 1.32153904]\n", " [-1.81579866 1.12745037 1.35798652]\n", " [-1.84502463 1.15529075 1.33701016]\n", " [-1.87425061 1.18313112 1.31603379]\n", " [-1.87402831 1.15563572 1.2795863 ]]\n", "DEBUG: Transition from [[-1.83053344 1.65646669 2.09344297]\n", " [-1.80887482 1.57499098 2.04017734]\n", " [-1.72739911 1.5586565 2.09680935]\n", " [-1.74905773 1.64013221 2.15007499]] to [[-2.00727477 1.51492315 2.2856394 ]\n", " [-1.98605816 1.47886262 2.26898208]\n", " [-1.96484155 1.4428021 2.25232475]\n", " [-1.92724935 1.45447431 2.27408402]\n", " [-1.88965714 1.46614652 2.29584329]\n", " [-1.91087375 1.50220705 2.31250062]\n", " [-1.93209036 1.53826757 2.32915795]\n", " [-1.96968257 1.52659536 2.30739867]]\n", "DEBUG: Transition from [[-1.75002234 0.76028326 2.31021592]\n", " [-1.67267956 0.89491783 2.09206692]\n", " [-1.57973317 0.663743 1.98085422]\n", " [-1.65707594 0.52910843 2.19900322]] to [[-2.16305897 0.7679616 2.12188319]\n", " [-2.11255761 0.79598925 2.01560658]\n", " [-2.06205625 0.8240169 1.90932997]\n", " [-2.00188885 0.71726948 1.90795323]\n", " [-1.94172144 0.61052205 1.90657649]\n", " [-1.99222281 0.5824944 2.0128531 ]\n", " [-2.04272417 0.55446675 2.11912971]\n", " [-2.10289157 0.66121418 2.12050645]]\n", "DEBUG: Transition from [[-2.78934158 0.71842309 2.5382463 ]\n", " [-2.78318495 0.68564889 2.44279691]\n", " [-2.7060672 0.62608881 2.46760108]\n", " [-2.71222384 0.65886302 2.56305047]] to [[-3.04297206 0.50237651 2.55847696]\n", " [-3.02875668 0.48182779 2.52037292]\n", " [-3.0145413 0.46127907 2.48226888]\n", " [-2.97506802 0.45089977 2.50268697]\n", " [-2.93559475 0.44052048 2.52310506]\n", " [-2.94981013 0.4610692 2.5612091 ]\n", " [-2.96402551 0.48161792 2.59931313]\n", " [-3.00349879 0.49199721 2.57889504]]\n", "DEBUG: Transition from [[-2.5815931 1.2890641 1.43598402]\n", " [-2.51796273 1.24345834 1.37433346]\n", " [-2.52486432 1.15839899 1.42653852]\n", " [-2.58849469 1.20400476 1.48818907]] to [[-2.82180853 1.20793295 1.22508229]\n", " [-2.7938148 1.17761934 1.20668953]\n", " [-2.76582106 1.14730573 1.18829677]\n", " [-2.7668108 1.12250887 1.22562032]\n", " [-2.76780054 1.09771202 1.26294387]\n", " [-2.79579428 1.12802562 1.28133662]\n", " [-2.82378801 1.15833923 1.29972938]\n", " [-2.82279827 1.18313609 1.26240583]]\n", "DEBUG: Transition from [[-1.98687247 0.25574474 1.19653439]\n", " [-1.88579515 0.25703647 1.19948241]\n", " [-1.88708688 0.21498175 1.2894741 ]\n", " [-1.9881642 0.21369002 1.28652607]] to [[-1.99024039e+00 6.69804091e-03 1.02234241e+00]\n", " [-1.94701814e+00 3.46945314e-03 1.03648040e+00]\n", " [-1.90379589e+00 2.40865375e-04 1.05061839e+00]\n", " [-1.91815896e+00 -5.19759389e-03 1.09308108e+00]\n", " [-1.93252203e+00 -1.06360532e-02 1.13554376e+00]\n", " [-1.97574428e+00 -7.40746539e-03 1.12140577e+00]\n", " [-2.01896654e+00 -4.17887763e-03 1.10726779e+00]\n", " [-2.00460347e+00 1.25958164e-03 1.06480510e+00]]\n", "DEBUG: Transition from [[-2.16791904 -0.15963204 2.18169731]\n", " [-2.10238534 -0.15638639 2.10783346]\n", " [-2.02786868 -0.13475887 2.17342663]\n", " [-2.09340238 -0.13800452 2.24729047]] to [[-2.16326236 -0.4715555 2.16483056]\n", " [-2.12555846 -0.46530675 2.14159306]\n", " [-2.08785455 -0.45905799 2.11835556]\n", " [-2.06853777 -0.43754339 2.15369435]\n", " [-2.04922099 -0.41602879 2.18903315]\n", " [-2.0869249 -0.42227755 2.21227065]\n", " [-2.12462881 -0.4285263 2.23550815]\n", " [-2.14394559 -0.4500409 2.20016935]]\n" ] } ], "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()\n", "mesh = examples.ram_horn_branch()" ] }, { "cell_type": "code", "execution_count": 245, "metadata": {}, "outputs": [], "source": [ "def gen_wave(freq=2.0, a=2.0, d_ph=0.05, count=80):\n", " ph = 0.0\n", " while True:\n", " xs = numpy.linspace(-10, 10, count)\n", " ys = numpy.zeros(count)\n", " zs = (numpy.sin(xs*freq + a*numpy.sin(ph)*numpy.pi) + 2)/2\n", " b1 = numpy.stack((xs,ys,zs), axis=-1)\n", " b2 = numpy.stack((xs,ys,zs - 2), axis=-1)\n", " yield [numpy.vstack((b1, b2[::-1,:]))]\n", " ph += d_ph\n", "\n", "#gen = meshgen.gen_inc_y(gen_wave())\n", "#mesh = meshgen.gen2mesh(gen, 200, False, False, True, True)\n", "# The closing method in gen2mesh is inappropriate because\n", "# my boundary is not convex!" ] }, { "cell_type": "code", "execution_count": 246, "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": 247, "metadata": {}, "outputs": [], "source": [ "# Work around some annoying-ass trimesh/threejs bug:\n", "wtf = meshutil.Transform().scale(0.1).translate(15,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 = \"branch.stl\"\n", "mesh_out.to_stl_mesh().save(mesh_fname)" ] }, { "cell_type": "code", "execution_count": 248, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 248, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = trimesh.Trimesh(vertices=mesh_out.v, faces=mesh_out.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": [] }, { "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 }