ここからが “昆虫生成 OS” の核心だね。
「昆虫 IR → OBJ 生成のための Mesh IR をどう設計するか」
これは OS の中で最も重要なレイヤーのひとつ。

あなたの OS はこういう 5 層構造だった:

  1. Semantic IR(意味:種名・特徴)
  2. Structural IR(節・付属肢・階層)
  3. Geometry IR(primitive:sphere, cylinder, capsule…)
  4. MotionPatch IR(動きのパッチ)
  5. Mesh IR → OBJ Export(三角形メッシュ)

今日は 4 → 5 の間にある Mesh IR を正式に設計する。


🧩 Mesh IR の役割

Mesh IR は 「primitive 形状を三角形メッシュに変換するための中間表現」。

  • Geometry IR は「抽象形状」
  • Mesh IR は「頂点・法線・UV・面」
  • OBJ は「Mesh IR をテキスト化したもの」

つまり Mesh IR は OBJ の前段階で、動き(MotionPatch)も適用済みの形状。


🌟 Mesh IR の正式スキーマ(OS レベル)

{
  "mesh": {
    "parts": [
      {
        "id": "thorax",
        "vertices": [[0,0,0], [0.1,0,0], ...],
        "normals":  [[0,1,0], [0.7,0.2,0], ...],
        "uv":       [[0,0], [1,0], ...],
        "faces":    [[1,2,3], [3,4,1], ...],
        "material": "body",
        "origin": [0,0,0],
        "parent": "head"
      }
    ],
    "materials": {
      "body": {
        "color": [0.2, 0.2, 0.2],
        "smooth": true
      }
    }
  }
}

🧬 Mesh IR の構成要素(詳解)

1. parts[]

OBJ の “o” や “g” に相当する単位。
昆虫の各パーツ(head, thorax, leg1_L など)が 1 つの part になる。

含むもの:

  • vertices: 頂点座標(ローカル空間)
  • normals: 法線ベクトル
  • uv: UV 座標
  • faces: 三角形(1-based index)
  • origin: パーツのローカル原点(MotionPatch の pivot)
  • parent: 階層構造(Motor6D の Part0/Part1 に使う)
  • material: マテリアル名

2. materials{}

OBJ の .mtl に相当。

  • color
  • smooth
  • metallic
  • transparency

などを含める。


🐛 Geometry IR → Mesh IR の変換ルール

昆虫は primitive で構成されるので、
各 primitive を三角形化するルールを OS に持たせる。


✔ sphere(球)

入力:

{ "shape": "sphere", "radius": 0.12 }

Mesh IR 生成:

  • subdivided icosphere
  • resolution = 16〜32
  • 頂点数 ≈ 256〜1024

✔ cylinder(円柱)

入力:

{ "shape": "cylinder", "radius": 0.02, "length": 0.15 }

Mesh IR:

  • radial segments = 12〜24
  • height segments = 1〜4
  • 両端は cap(円盤)を三角形化

✔ capsule(カプセル)

入力:

{ "shape": "capsule", "radius": 0.1, "length": 0.25 }

Mesh IR:

  • cylinder + hemisphere × 2
  • hemisphere は subdivided sphere の半分

✔ plane(翅)

入力:

{ "shape": "plane", "size": [0.3, 0.1] }

Mesh IR:

  • quad → 2 triangles
  • UV は [0,0]〜[1,1]
  • 翅脈(veins)は別レイヤーで overlay 可能

🔥 MotionPatch の適用タイミング

MotionPatch は Mesh IR に適用される。

例:wing_flap

axis = [1,0,0]
range_deg = [-45,45]

Mesh IR の vertices[] を pivot(origin)を中心に回転させる。

OBJ は MotionPatch 適用後の形状を出力する。

Roblox では:

  • OBJ → MeshPart(静的形状)
  • MotionPatch → Motor6D(動き)

という 2 系統で動く。


🧩 Mesh IR の最終まとめ

Mesh IR は:

  • OBJ の前段階
  • MotionPatch 適用後の形状
  • Roblox 以外のバックエンドにも対応可能
  • 構造 IR と Geometry IR の橋渡し

含むもの:

  • parts(頂点・法線・UV・faces)
  • materials
  • origin(pivot)
  • parent(階層)
  • 動き適用後の最終形状

🌟 次に進めるべきはどれ?

  • Mesh IR → OBJ Export の仕様(v/vt/vn/f の生成)
  • MotionPatch → Mesh IR の変形アルゴリズム(rotate/hinge/oscillate)
  • Roblox Loader(OBJ + MotionPatch → Model + Motor6D)
  • 昆虫 IR → Mesh IR の変換コード(Lua or Python)

どれを深掘りしたい?