{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/usr/local/lib/python3.7/site-packages/quaternion/calculus.py:475: UserWarning: \n",
"\n",
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",
"Could not import from scipy, which means that derivatives\n",
"and integrals will use less accurate finite-differencing\n",
"techniques. You may want to install scipy.\n",
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",
"\n",
" warnings.warn(warning_text)\n"
]
}
],
"source": [
"import meshutil\n",
"import stl.mesh\n",
"import numpy\n",
"import trimesh"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"c = meshutil.cube(open_xz=False)\n",
"mesh_fname = \"cube_test.stl\"\n",
"#c2 = meshutil.cube_distort(0.3)\n",
"#c2.v = c2.v/2 + [0,1,0]\n",
"#c = c.concat(c2)\n",
"m = c.to_stl_mesh()\n",
"\"\"\"\n",
"c1 = meshutil.cube_distort(0.3)\n",
"c1[\"vectors\"] = c1[\"vectors\"]/2 + [0,1,0]\n",
"c2 = meshutil.cube_distort(0.3)\n",
"c2[\"vectors\"] = c2[\"vectors\"]/2 + [0.5,1,0]\n",
"c3 = meshutil.cube_distort(0.3)\n",
"c3[\"vectors\"] = c3[\"vectors\"]/2 + [0,1,0.5]\n",
"c4 = meshutil.cube_distort(0.3)\n",
"c4[\"vectors\"] = c4[\"vectors\"]/2 + [0.5,1,0.5]\n",
"\"\"\"\n",
"m.save(mesh_fname)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 4., 0., 0., -4.],\n",
" [ 0., 4., 0., 0.],\n",
" [ 0., 0., 4., 0.],\n",
" [ 0., 0., 0., 1.]])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s = meshutil.TransformStack()\n",
"mtx = s.translate(-1, 0, 0).scale(4).rotate().mtx\n",
"#mtx = meshutil.mtx_rotate(numpy.array([0,1,0]), numpy.pi/4) @ meshutil.mtx_scale(2) @ meshutil.mtx_translate(-1, 0, 0)\n",
"#mtx = meshutil.mtx_translate(-1, 0, 0)\n",
"mtx"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"ct = c.transform(mtx)\n",
"c2 = ct.concat(c)\n",
"c2.to_stl_mesh().save(mesh_fname)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"face_normals didn't match triangles, ignoring!\n"
]
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m = trimesh.load_mesh(mesh_fname)\n",
"m.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.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}