Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Generic な `.anim`(シェイプキー・表示の切り替え・オブジェクトの Transform)は、ミュートした NLA トラックの Action にする(`core/animation.py`。#209)。
値が変わらないか 0.1 秒以下で終わる、状態を切り替えるだけのクリップ(Animator のステート用)は読み込まない。
FBX の中のテイクは、.meta の clipAnimations どおりのクリップにして同じく NLA に並べ、同じ骨格のモーションだけのモデルは
レストの違いを変換して 1 体のアーマチュアにまとめる(`blender/fbx_motion.py`。#276)。オプションは Animation(Muted / Active / None)。
レストの違いを変換して 1 体のアーマチュアにまとめる(`blender/fbx_motion.py` と `rig_merge.py`。NLA への置き方は両方で `nla.py`。#276)。オプションは Animation(Muted / Active / None)。

## 設計の要点(詳細は DESIGN.md)

Expand Down Expand Up @@ -51,7 +51,7 @@
```
unitypackage_loader/ Extension 本体(blender_manifest.toml、Blender 4.5 以降の Extension 形式)
core/ bpy 非依存。単体テスト可能。bpy を import しないこと
blender/ bpy 依存(importer / options / log / prepare / model_import / session_materials / scene_placement / scene_objects / terrain / unity_meshes / animation / fbx_motion / materials / nodes / textures / toon_group / outline)
blender/ bpy 依存(importer / options / log / prepare / model_import / session_materials / scene_placement / scene_objects / terrain / unity_meshes / animation / fbx_motion / rig_merge / nla / materials / nodes / textures / toon_group / outline)
operators/ File > Import、モデル選択ダイアログ、再構築、アウトライン
ui/ Preferences、サイドバー "UPI" タブ
tests/ unittest(bpy 不要)+ Blender 上の統合テスト+合成パッケージ生成
Expand Down
12 changes: 7 additions & 5 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,9 @@ unitypackage_loader/
│ ├─ terrain.py # Terrain のメッシュと塗り分けのマテリアル(SessionTerrains。#205)
│ ├─ unity_meshes.py # Unity の Mesh アセットから作るメッシュ(SessionMeshes。#216)
│ ├─ animation.py # クリップの Action と NLA トラック(ClipImporter。#209)
│ ├─ fbx_motion.py # モデルのテイクのクリップへの分割、モーションだけのアーマチュアのまとめ(MotionBuilder。#276)
│ ├─ fbx_motion.py # モデルのテイクのクリップへの分割(MotionBuilder。#276)
│ ├─ rig_merge.py # モーションだけのアーマチュアのまとめとレストの違いの変換(merge_motion_rigs。#276)
│ ├─ nla.py # クリップを NLA のトラックに置く共通処理(Active のときのミュート・ループ。#281)
│ ├─ log.py # 捕まえて続けた例外のログ(Verbose Console Log はオペレーターが渡す)
│ ├─ scene_objects.py # シーンの Empty・ライト・カメラ・複製・行列の当てはめ(計算は core/model_space.py)・非表示
│ ├─ materials.py # ノード生成
Expand Down Expand Up @@ -1096,8 +1098,8 @@ def run(ctx, filepath, opts) -> Report:
どのオブジェクトのものか決められないので付けない(Medieval Village の風車など。Animator Controller から引けば決められるが、今は読まない)。
- **Action と NLA**(`blender/animation.py`): クリップごとに Action を 1 つ作り(`unity_clip_guid` / `unity_clip_path`)、対象のデータブロック
(オブジェクトかシェイプキーの Key)ごとにスロットを作る(Blender 4.4 以降のスロット付き Action)。対象ごとにクリップの名前の NLA トラックを
ミュートで足すので、読み込んだ直後の見た目は変わらない。キーはクリップの開始からの秒 × シーンのフレームレートで、ストリップはシーンの開始フレームに置く。
ループするクリップ(`m_LoopTime`)は、ストリップの繰り返し(`repeat`)をシーンのフレーム範囲の終わりまでにする(`fbx_motion.loop_strip`)。
ミュートで足すので(`nla.add_track`。モデルのテイクと共通)、読み込んだ直後の見た目は変わらない。キーはクリップの開始からの秒 × シーンのフレームレートで、ストリップはシーンの開始フレームに置く。
ループするクリップ(`m_LoopTime`)は、ストリップの繰り返し(`repeat`)をシーンのフレーム範囲の終わりまでにする(`nla.loop_strip`)。
NLA はストリップの範囲の外を評価しないので、F カーブの Cycles モディファイアー(これも付ける。Action を直接再生するとき用)だけではループしない。
- シェイプキー: 値を 1/100 にしてキーと接線をそのままベジェにする。100 を超える重みは `slider_max` を広げる。
- 表示: `hide_viewport` / `hide_render` を階段(CONSTANT)で、値が 0.5 未満なら隠す。`m_IsActive` は Unity の階層での子孫にも当てる
Expand Down Expand Up @@ -1131,7 +1133,7 @@ Blender の FBX インポーターはテイクごとにテイクの名前の Act
ときと同じにする)。Action には `unity_take` / `unity_take_model` を残す。
- **使い回し**: シーンで同じモデルを配置ごとに読み直すときは、最初に読んだときの Action を使い、新しく作られた分は消す。
前の読み込みが失敗して Action が消えていたら作り直す。
- **アーマチュアのまとめ**(`merge_motion_rigs`。Models 単位): メッシュが無く、アーマチュアが 1 体で、トラックを持つモデルを
- **アーマチュアのまとめ**(`blender/rig_merge.py` の `merge_motion_rigs`。Models 単位): メッシュが無く、アーマチュアが 1 体で、トラックを持つモデルを
モーションだけのモデルとし、骨格(ボーンの名前と親の組)が含まれる関係にあり、置き場所(親のワールドの行列)が同じものを
1 体にまとめる。残すのはボーンがいちばん多く、その中で先に読んだもの。
- スキンの無い FBX はファイルの既定の姿勢をレストにするので、レストはファイルごとに違う(32 RPG Animations では指のボーンで
Expand All @@ -1146,7 +1148,7 @@ Blender の FBX インポーターはテイクごとにテイクの名前の Act
アーマチュアの数を `clip_notes` に出す。
- FBX インポーターは、アニメーションを読むかどうかによらずシーンのフレームレートをファイルのものにする(今までと同じ)。
フレームレートの違う FBX を続けて読むと、先に読んだ FBX のモーションの速さがずれる(未対応)。
- ループ(`loopTime`)は、`.anim` と同じくストリップの繰り返しにする(`loop_strip`。まとめたアーマチュアに写すときも回数を引き継ぐ)。
- ループ(`loopTime`)は、`.anim` と同じくストリップの繰り返しにする(`nla.loop_strip`。まとめたアーマチュアに写すときも回数を引き継ぐ。`nla.copy_track`)。

### 4.8 `blender/textures.py`

Expand Down
24 changes: 24 additions & 0 deletions tests/expectations_synthetic_anim_active.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"options": {
"unit": "MODELS",
"animation": "ACTIVE"
},
"errors": 0,
"clips": {
"count": 4,
"unmuted": {
"Face": ["Smile"],
"Hat": ["HatOff"],
"Door": ["DoorOpen"],
"Knob": ["DoorOpen"],
"Body": ["Wave"]
},
"tracks": {
"Face": ["Smile"],
"Hat": ["HatOff"],
"Door": ["DoorOpen"],
"Knob": ["DoorOpen"],
"Body": ["Wave"]
}
}
}
1 change: 1 addition & 0 deletions tests/integration_runs.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
{ "package": "synthetic_mesh.unitypackage", "expectations": "expectations_synthetic_mesh_models.json", "note": "FBX のマテリアルの画像が作者の PC のパスを指すモデル" },
{ "package": "synthetic_anim.unitypackage", "expectations": "expectations_synthetic_anim.json", "note": ".anim の Action(シェイプキー・表示の切り替え・Transform)と、読み込まないクリップの内訳" },
{ "package": "synthetic_anim.unitypackage", "expectations": "expectations_synthetic_anim_scene.json", "note": "シーンに 2 か所置いたモデルの両方にクリップを付ける" },
{ "package": "synthetic_anim.unitypackage", "expectations": "expectations_synthetic_anim_active.json", "note": "Animation が Active なら、.anim のトラックもオブジェクトごとに最初の 1 本だけミュートを外す" },
{ "package": "synthetic_anim.unitypackage", "expectations": "expectations_synthetic_anim_off.json", "note": "Animation を None にすると Action を作らない" },
{ "package": "synthetic_motion.unitypackage", "expectations": "expectations_synthetic_motion.json", "note": "モデルのテイクを .meta のクリップで分け、同じ骨格のモーションだけのアーマチュアをレストを変換してまとめる" },
{ "package": "synthetic_motion.unitypackage", "expectations": "expectations_synthetic_motion_active.json", "note": "Animation が Active なら、オブジェクトごとに最初のトラックだけミュートを外す" },
Expand Down
20 changes: 4 additions & 16 deletions unitypackage_loader/blender/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
そのままベジェ(階段は CONSTANT)にする。GameObject の非アクティブは、Unity の階層での子孫にも当てる。
- Transform は Unity のローカルの値をフレームごとに求め、オブジェクトの行列にしてから位置・回転・スケールのキーにする
(行列の対応は ``core/model_space.local_basis``)。ボーンを対象にしたカーブは読み込まない(#270)。
- 対象ごとに、クリップの名前の NLA トラックをミュートで足す。読み込んだ直後の見た目は変わらない。
- 対象ごとに、クリップの名前の NLA トラックを足す(``nla.add_track``)。既定はミュートで、読み込んだ直後の見た目は変わらない。
"""

from __future__ import annotations
Expand All @@ -34,9 +34,9 @@
from ..core.animation_targets import Binding, TargetObject, TargetTree, bind_paths
from ..core.model_space import ModelUnits, local_basis, local_values
from ..core.transform import IDENTITY, UNITY_TO_BLENDER, Mat4, inverse_affine
from .fbx_motion import loop_strip
from .log import warn_skipped
from .model_import import FBX_NODE_PROP, MODEL_GUID_PROP, node_name
from .nla import MODE_ACTIVE, add_track

CLIP_GUID_PROP = "unity_clip_guid"
# GameObject の行列に、向きや形を足して置いたオブジェクト(Transform のカーブを当てない)
Expand Down Expand Up @@ -94,7 +94,6 @@ def __init__(self, session, collection: bpy.types.Collection):
self.scene = session.scene
render = self.scene.render
self.fps = render.fps / (render.fps_base or 1.0)
self.frame_start = self.scene.frame_start
self.stats = ClipStats()
self._units: dict[str, ModelUnits | None] = {}
self._tree: TargetTree | None = None
Expand Down Expand Up @@ -195,21 +194,10 @@ def slot_for(datablock: bpy.types.ID, id_type: str, label: str):
bpy.data.actions.remove(action)
return "bones" if bones else "none"
for datablock, slot in users.items():
self._add_track(datablock, action, slot, clip.name or entry.name)
add_track(datablock, clip.name or entry.name, action, slot, self.scene,
active=self.session.opts.animation == MODE_ACTIVE, loop=action.use_cyclic)
return "loaded"

def _add_track(self, datablock, action, slot, name: str) -> None:
animation_data = datablock.animation_data or datablock.animation_data_create()
track = animation_data.nla_tracks.new()
active = self.session.opts.animation == "ACTIVE" and not any(not t.mute for t in animation_data.nla_tracks)
track.name = name
nla_strip = track.strips.new(name, self.frame_start, action)
if nla_strip.action_slot != slot:
nla_strip.action_slot = slot
if action.use_cyclic:
loop_strip(nla_strip, self.scene)
track.mute = not active

# 各種のカーブ ------------------------------------------------------

def _frame(self, time: float, clip: AnimationClip) -> float:
Expand Down
Loading
Loading