{"id":19132428,"url":"https://github.com/taichi-dev/meshtaichi","last_synced_at":"2026-03-04T08:02:44.122Z","repository":{"id":62638553,"uuid":"536008336","full_name":"taichi-dev/meshtaichi","owner":"taichi-dev","description":"MeshTaichi: A Compiler for Efficient Mesh-based Operations (SIGGRAPH Asia 2022)","archived":false,"fork":false,"pushed_at":"2023-03-31T14:59:03.000Z","size":8540,"stargazers_count":244,"open_issues_count":4,"forks_count":12,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-03T02:09:33.638Z","etag":null,"topics":["geometry-processing","mesh","siggraph-asia","simulation","taichi"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/taichi-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-13T07:27:06.000Z","updated_at":"2025-04-02T13:12:38.000Z","dependencies_parsed_at":"2024-11-09T06:28:22.990Z","dependency_job_id":null,"html_url":"https://github.com/taichi-dev/meshtaichi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/taichi-dev/meshtaichi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taichi-dev%2Fmeshtaichi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taichi-dev%2Fmeshtaichi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taichi-dev%2Fmeshtaichi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taichi-dev%2Fmeshtaichi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/taichi-dev","download_url":"https://codeload.github.com/taichi-dev/meshtaichi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taichi-dev%2Fmeshtaichi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30075918,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T08:01:56.766Z","status":"ssl_error","status_checked_at":"2026-03-04T08:00:42.919Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["geometry-processing","mesh","siggraph-asia","simulation","taichi"],"created_at":"2024-11-09T06:18:13.241Z","updated_at":"2026-03-04T08:02:44.106Z","avatar_url":"https://github.com/taichi-dev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MeshTaichi: A Compiler for Efficient Mesh-based Operations (SIGGRAPH Asia 2022)\n\n*Chang Yu\\*, Yi Xu\\*, Ye Kuang, Yuanming Hu, Tiantian Liu (\\* indicates equal contribution)*\n\n![](./pics/teaser.png)\n\n[[Paper]](https://changyu.io/papers/yu2022meshtaichi.pdf) [[Video]](https://www.youtube.com/watch?v=vjBrk7k8SPE) [[Full Talk]](https://www.youtube.com/watch?v=ISSyVKOfS4o)\n\nThe MeshTaichi framework is now officially part of [Taichi](https://github.com/taichi-dev/taichi) and can be installed by `pip`. This repo only contains examples.\n\n### **A mesh compiler that provides an intuitive programming model for efficient mesh-based operations**\n\nMeshes are an indispensable representation in many graphics applications because they provide conformal spatial discretizations. However, mesh-based operations are often slow due to unstructured memory access patterns. We propose MeshTaichi, a novel mesh compiler that provides an intuitive programming model for efficient mesh-based operations. Our programming model hides the complex indexing system from users and allows users to write mesh-based operations using reference-style neighborhood queries. Our compiler achieves its high performance by exploiting data locality. We partition input meshes and prepare the wanted relations by inspecting users’ code during compile time. During run time, we further utilize on-chip memory (shared memory on GPU and L1 cache on CPU) to access the wanted attributes of mesh elements efficiently. Our compiler decouples low-level optimization options with computations, so that users can explore different localized data attributes and different memory orderings without changing their computation code. As a result, users can write concise code using our programming model to generate efficient mesh-based computations on both CPU and GPU backends.\n\n## **Installation**\n\nInstall the latest Taichi and meshtaichi extension by:\n\n```shell\npython3 -m pip install -U taichi meshtaichi_patcher\n```\n\n## **Usage**\n\nWe demonstrate the usage of MeshTaichi using an explicit finite element method example with the Neo-Hookean model following the course note [[Sifakis and Barbic 2012]](http://viterbi-web.usc.edu/~jbarbic/femdefo/). The First Piola-Kirchhoff stress tensor is given as:\n\n![](http://latex.codecogs.com/svg.latex?P(F)=\\\\mu\\\\left(F-F^{-T}\\\\right)+\\\\lambda\\\\log(J)F^{-T}) (Eq.1)\n\nwhere 𝐹 describes the deformation gradient, 𝐽 is the determinant of\n𝐹 , and 𝜇 and 𝜆 are the Lamé coefficients.\n\n### **Describing the Mesh Data**\n\nWe need to define mesh data structures before applying them to computations. We provide the following APIs to create our new mesh instance:\n\n```python\nimport taichi as ti\nimport meshtaichi_patcher as Patcher\n# load model file 'bunny.mesh' as tetrahedron mesh and initialize Cell-Vertex relation.\nmesh = Patcher.load_mesh(\"bunny.mesh\", relations=[\"CV\"])\n```\n\nUsers can instantiate a mesh with an external file. Our compiler can instantiate triangle meshes using surface representation formats like “.obj” and “.ply” files, or volumetric representation formats like “.mesh” file.\n\nParameter `relations` is a list of relations, e.g `['FV', 'VV']` means initializing Face-Vert and Vertex-Vertex relations, where `'V'` for Vertex, `'E'` for Edge, `'F'` for Face, and `'C'` for Cell.\n\nThe next step is to define the attributes for each mesh element. The type of a mesh attribute can be a scalar, a vector, a matrix, or their corresponding quantized versions. In this FEM example, each vertex has three attributes: the position `pos`, the velocity `vel` and the force applied to it `force`. All three attributes are floating-point type three-dimensional vectors based on the Taichi type system. Each (tetrahedral-)cell in the mesh has two attributes: the rest-pose volume `w` which is a floating-point scalar, and the inverted rest-pose shape matrix `B` which is a 3 × 3 matrix. The code snippet defining the mesh elements is listed below.\n\n```python\n mesh.verts.place({'pos' : ti.math.vec3,\n                   'vel' : ti.math.vec3,\n                   'force' : ti.math.vec3})\n mesh.cells.place({'B' : ti.math.mat3,\n                   'w' : ti.f32})\n```\n\n**Note**: For most mesh-based applications, the position of vertices is a crucial attribute provided by the mesh file. We provide the following API to get the vertex position of the current mesh to a NumPy array and load into a mesh attribute:\n\n```\nmesh.verts.pos.from_numpy(mesh.get_position_as_numpy())\n```\n\n### **Computing on a Mesh**\n\nThe mesh computations are declared within a `mesh-for` of a kernel, which can be as simple as shown below.\n\n``` python\n# parallel loop over all mesh cells\nfor c in mesh.cells:\n  ...\n# parallel loop over all mesh vertices\nfor v in mesh.verts:\n  ...\n```\n\nA `mesh-for` has very similar syntax as a `range-for` which loops over the indices in an interval. It is specified with a mesh object’s element type (e.g., cells or vertices). Each element inside a mesh is queried with an index-free reference style. The elements’ indices and their corresponding memory addresses are hidden from the users. Our compiler parallelizes the outermost `mesh-for` loops with high-performance kernels, so that the looped mesh elements are efficiently computed in parallel.\n\nMost mesh-based operations involve not only the attributes of an element, but the attributes of the neighboring elements as well. Our compiler allows users to access neighbor attributes either with reference-based queries using another nested sequential `mesh-for` loop or with index-based queries using a `range-for` loop as shown below.\n\n``` python\nfor c in mesh.cells:\n  total_force = c.verts[0].force\n  # reference-based access\n  for v in c.verts:\n    total_force += v.force\n```\n\n``` python\nfor c in mesh.cells:\n  total_force = c.verts[0].force\n  # index-based access\n  for i in range(c.verts.size):\n    total_force += c.verts[i].force\n```\n\nNow we have the way to access the neighbors. Let us wrap everything up and write a `substep()` function to calculate the force (according to Eq. 1) and perform explicit time integration in a finite element simulation:\n\n``` python\n@ti.kernel\ndef substep():\n  for c in mesh.cells:\n    Ds0 = c.verts[0].pos - c.verts[3].pos\n    Ds1 = c.verts[1].pos - c.verts[3].pos\n    Ds2 = c.verts[2].pos - c.verts[3].pos\n    F = ti.Matrix(Ds0, Ds1, Ds2).transpose() @ c.B\n    J = F.determinant()\n    F_ti = F.transpose().inverse()\n    P = (F - F_ti) * mu + F_ti * la * ti.log(J)\n    H = -c.w * P @ c.B.transpose()\n    c.verts[0].force += H[:, 0]\n    c.verts[1].force += H[:, 1]\n    c.verts[2].force += H[:, 2]\n    c.verts[3].force += -H[:, 0] - H[:, 1] - H[:, 2]\n  \n  for v in mesh.verts:\n    # assuming unit mass for simplicity\n    v.vel += dt * v.force \n    v.pos += dt * v.vel\n```\n\n### **Interacting with Non-mesh Data**\n\nRecall that we visit all elements in a `mesh-for` using their references, users do not need to bookkeep their corresponding indices. However, there are cases where the indices of elements are wanted. In these cases, we refer users to visit the `id` attribute of an element. We demonstrate an example to export the positions of vertices to an external multi-dimensional array as follows:\n\n``` python\n# An 1D array of len(mesh.verts) 3D f32 vectors\npos_ex = ti.Vector.field(3, ti.f32, shape=len(mesh.verts))\n\n# export using id attribute\n@ti.kernel\ndef export():\n  for v in mesh.verts:\n    pos_ex[v.id] = v.pos\n\n# export using built-in method\npos_ex.copy_from(mesh.verts.pos)\n```\n\n**For more details of the usage of our programming language, please refer to our paper or see the examples in this repo.**\n\nWe test MeshTaichi on a variety of physically-based simulation and geometry processing applications with both triangle and tetrahedron meshes. MeshTaichi achieves a consistent speedup ranging from 1.4× to 6×, compared to state-of-the-art mesh data structures and compilers.\n\n## How to run\n\n### Mass Spring (Section 8.1)\n\n![ms_pic](./pics/ms_teaser.jpg)\n\nTo reproduce the mass-spring system:\n\n``` bash\ncd mass_spring \u0026\u0026 python3 ms.py --model models/armadillo0.1.node --arch [cpu/cuda]\n```\n\nFor more details, please refer to this [documentation](mass_spring/README.md).\n\n### Projective Dynamics (Section 8.4)\n\n![pd_pic](./pics/pd_teaser.jpg)\n\nTo reproduce the projective dynamics:\n\n``` bash\ncd projective_dynamics \u0026\u0026 python3 pd.py --model models/deer.1.node --arch [cpu/cuda]\n```\n\nFor more details, please refer to this [documentation](projective_dynamics/README.md).\n\n### XPBD Cloth Simulation (Section 8.5)\n\n![xpbd_pic](./pics/xpbd_teaser.jpg)\n\nTo reproduce the XPBD cloth simulation:\n\n``` bash\ncd xpbd_cloth \u0026\u0026 python3 models/gen_cloth.py \u0026\u0026 mkdir results \u0026\u0026 python3 run_multiple.py --output ./results  --arch [cpu/cuda]\n```\n\nFor more details, please refer to this [documentation](xpbd_cloth/README.md).\n\n### Mesh-Grid Hybrid Simulation (Section 8.6)\n\n![mpm_pic](./pics/mpm_teaser.jpg)\n\nTo reproduce the mesh-grid hybrid simulation:\n\n``` bash\ncd lag_mpm \u0026\u0026 mkdir results \u0026\u0026 python3 run.py --output ./results \u0026\u0026 python3 render_particles.py\n```\n\nFor more details, please refer to this [documentation](lag_mpm/README.md).\n\n### Vertex Normal (Section 8.2)\n\nTo reproduce the vertex normal:\n\n``` bash\ncd vertex_normal \u0026\u0026 python3 normal.py --model models/bunny.obj --arch [cpu/cuda]\n```\n\n### Geodesic Distance (Section 8.3)\n\nTo reproduce the geodesic distance:\n\n``` bash\ncd geodesic_distance \u0026\u0026 python3 geodesic.py --model models/yog.obj --output colored.obj --arch [cpu/cuda]\n```\n\n## Bibtex\n\n```bibtex\n@article{Yu2022MeshTaichi,\n    title = {MeshTaichi: A Compiler for Efficient Mesh-based Operations},\n    author = {Yu, Chang and Xu, Yi and Kuang, Ye and Hu, Yuanming and Liu, Tiantian},\n    journal = {ACM Transactions on Graphics (TOG)},\n    volume = {41},\n    number = {6},\n    year = {2022},\n    issue_date = {December 2022},\n    publisher = {Association for Computing Machinery},\n    address = {New York, NY, USA},\n    issn = {0730-0301},\n    url = {https://doi.org/10.1145/3550454.3555430},\n    doi = {10.1145/3550454.3555430},\n    month = {dec},\n    articleno = {252},\n    numpages = {18}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaichi-dev%2Fmeshtaichi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaichi-dev%2Fmeshtaichi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaichi-dev%2Fmeshtaichi/lists"}