{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "8dafad6b-6ae0-4042-8b26-4110c33d7c07", "metadata": {}, "outputs": [], "source": [ "# File: stack.ipynb\n", "# Code: Claude Code and Codex\n", "# Review: Ryoichi Ando (ryoichi.ando@zozo.com)\n", "# License: Apache v2.0" ] }, { "cell_type": "code", "execution_count": null, "id": "b187458e-24ce-4d33-8fad-ddd1c248499c", "metadata": {}, "outputs": [], "source": [ "from frontend import App\n", "\n", "# create an app\n", "app = App.create(\"stack\")\n", "\n", "# create a square sheet mesh\n", "V, F = app.mesh.square(res=128, ex=[1, 0, 0], ey=[0, 0, 1])\n", "app.asset.add.tri(\"sheet\", V, F)\n", "\n", "# create a sphere tetrahedral mesh\n", "V, F, T = app.mesh.icosphere(r=0.25, subdiv_count=4).tetrahedralize()\n", "app.asset.add.tet(\"sphere\", V, F, T)\n", "\n", "# create a scene\n", "scene = app.scene.create()\n", "\n", "# add invisible floor\n", "scene.add.invisible.wall([0, 0, 0], [0, 1, 0])\n", "\n", "# add stacked sheets with rotation\n", "n, space = 10, 0.05\n", "for i in range(n):\n", " y = (i + 1) * space\n", " deg = i * 90 / n\n", " obj = scene.add(\"sheet\")\n", " obj.at(0, y, 0).jitter().rotate(deg, \"y\")\n", " obj.param.set(\"strain-limit\", 0.05).set(\"bend\", 2.5).set(\"friction\", 0.5)\n", "\n", "# add heavy sphere with downward velocity to crash through sheets\n", "sphere = scene.add(\"sphere\").at(0, 1, 0).velocity(0, -5, 0)\n", "sphere.param.set(\"density\", 5e4)\n", "\n", "# compile the scene and report stats\n", "scene = scene.build().report()\n", "\n", "# preview the initial scene\n", "scene.preview()" ] }, { "cell_type": "code", "execution_count": null, "id": "f1dcff97-9d59-4772-acdc-e43ae5142b06", "metadata": {}, "outputs": [], "source": [ "# create a new session with the compiled scene\n", "session = app.session.create(scene)\n", "\n", "# set session parameters\n", "session.param.set(\"frames\", 120).set(\"friction-mode\", \"max\")\n", "\n", "# build this session\n", "session = session.build()" ] }, { "cell_type": "code", "execution_count": null, "id": "e4e0775f-cb2c-415e-afef-ddecc393adc6", "metadata": {}, "outputs": [], "source": [ "# start the simulation and live-preview the results\n", "session.start().preview()\n", "\n", "# also show simulation logs in realtime\n", "session.stream()" ] }, { "cell_type": "code", "execution_count": null, "id": "63a8883d-714a-474a-9ee0-0846f2b84365", "metadata": {}, "outputs": [], "source": [ "# create an animation from the simulation results\n", "session.animate()" ] }, { "cell_type": "code", "execution_count": null, "id": "5face31e-4a26-472f-b455-969ec0bc8190", "metadata": {}, "outputs": [], "source": [ "# export the animation to file\n", "session.export.animation()" ] }, { "cell_type": "code", "execution_count": null, "id": "f4615e45-ea8c-434f-9452-c235068fb404", "metadata": {}, "outputs": [], "source": [ "# this is for CI\n", "if app.ci:\n", " assert session.finished()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12.3" } }, "nbformat": 4, "nbformat_minor": 5 }