Skip to content

Instantly share code, notes, and snippets.

View taigama's full-sized avatar

Khang Dinh Hoang taigama

View GitHub Profile
@taigama
taigama / UnitySubMeshesExtractor.cs
Created November 4, 2024 11:04
Improved version of https://gist.github.com/simonwittber/0297a2a8127efddd818d624ce14bd6a8 . With this one, you can extract all sub meshes (inside a Combined Mesh) which be used in a GameObject.
public static class UnitySubMeshesExtractor
{
public static Mesh ExtractSubMesh(Mesh m, int meshIndex, int count, Transform meshRenderHolder)
{
Vector3 pos = meshRenderHolder.position;
Quaternion rot = meshRenderHolder.rotation;
rot.y = -rot.y;// correct the translation calculation
var vertices = m.vertices;
var normals = m.normals;