From 566588d63f4b88367fba2e1b95a1b1538a7bf5ff Mon Sep 17 00:00:00 2001 From: utagestudio Date: Thu, 26 Nov 2026 02:14:35 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E3=83=AB=E3=83=BC=E3=83=97?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=AF=E3=83=AA=E3=83=83=E3=83=97=E3=81=AE?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=83=AA=E3=83=83=E3=83=97=E3=82=92=E3=82=B7?= =?UTF-8?q?=E3=83=BC=E3=83=B3=E3=81=AE=E7=B5=82=E3=82=8F=E3=82=8A=E3=81=BE?= =?UTF-8?q?=E3=81=A7=E7=B9=B0=E3=82=8A=E8=BF=94=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unity の Loop Time のクリップ(.anim の m_LoopTime と、モデルの .meta の loopTime)は、NLA のストリップの 繰り返し(repeat)をシーンのフレーム範囲の終わりまでにする。NLA はストリップの範囲の外を評価しないので、 .anim の Action に付けていた Cycles モディファイアーだけでは、実際にはループしていなかった。 まとめたアーマチュアにトラックを写すときも回数を引き継ぐ。 Co-Authored-By: Claude Opus 5.5 --- tests/expectations_synthetic_anim.json | 3 ++- tests/expectations_synthetic_anim_scene.json | 4 ++-- tests/expectations_synthetic_motion.json | 3 ++- unitypackage_loader/blender/animation.py | 3 +++ unitypackage_loader/blender/fbx_motion.py | 19 ++++++++++++++++++- unitypackage_loader/blender_manifest.toml | 2 +- 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/tests/expectations_synthetic_anim.json b/tests/expectations_synthetic_anim.json index acd68f0..26ff6d6 100644 --- a/tests/expectations_synthetic_anim.json +++ b/tests/expectations_synthetic_anim.json @@ -31,7 +31,8 @@ { "track": "HatOff", "object": "Hat", "seconds": 0, "hidden": false }, { "track": "HatOff", "object": "Hat", "seconds": 0.75, "hidden": true }, { "track": "Wave", "object": "Body", "seconds": 0, "hidden": true }, - { "track": "DoorOpen", "object": "Door", "rotation_delta": { "from": 0, "to": 1, "axis": [0, 0, 1], "degrees": -90 } }, + { "track": "DoorOpen", "object": "Door", "rotation_delta": { "from": 0, "to": 0.5, "axis": [0, 0, 1], "degrees": -45 } }, + { "track": "DoorOpen", "object": "Door", "rotation_delta": { "from": 0, "to": 1.5, "axis": [0, 0, 1], "degrees": -45 } }, { "track": "DoorOpen", "object": "Knob", "seconds": 0, "distance_to": "Door", "distance": 111.8034 } ] } diff --git a/tests/expectations_synthetic_anim_scene.json b/tests/expectations_synthetic_anim_scene.json index b963d1a..ae7a307 100644 --- a/tests/expectations_synthetic_anim_scene.json +++ b/tests/expectations_synthetic_anim_scene.json @@ -55,13 +55,13 @@ "object": "Door", "rotation_delta": { "from": 0, - "to": 1, + "to": 0.5, "axis": [ 0, 0, 1 ], - "degrees": -90 + "degrees": -45 } }, { diff --git a/tests/expectations_synthetic_motion.json b/tests/expectations_synthetic_motion.json index b478962..d4994ea 100644 --- a/tests/expectations_synthetic_motion.json +++ b/tests/expectations_synthetic_motion.json @@ -18,7 +18,8 @@ "values": [ { "track": "Walk_Start", "object": "Rig", "seconds": 0.2, "bone_direction": { "bone": "Spine", "vector": [0, -0.2938, 0.9559] } }, { "track": "Walk", "object": "Rig", "seconds": 0.5, "bone_direction": { "bone": "Spine", "vector": [0, -0.7071, 0.7071] } }, - { "track": "Walk", "object": "Rig", "seconds": 1, "bone_direction": { "bone": "Spine", "vector": [0, -1, 0] } }, + { "track": "Walk", "object": "Rig", "seconds": 1.5, "bone_direction": { "bone": "Spine", "vector": [0, -0.7071, 0.7071] } }, + { "track": "Rig|run_take", "object": "Rig", "seconds": 1.5, "bone_direction": { "bone": "Spine", "vector": [0, -0.5039, 0.8638] } }, { "track": "Rig|run_take", "object": "Rig", "seconds": 0, "bone_direction": { "bone": "Spine", "vector": [0, 0.4961, 0.8682] } }, { "track": "Rig|run_take", "object": "Rig", "seconds": 1, "bone_direction": { "bone": "Spine", "vector": [0, -0.5039, 0.8638] } }, { "track": "CharRig|wave_take", "object": "CharRig", "seconds": 1, "bone_direction": { "bone": "Spine", "vector": [0, -0.7071, 0.7071] } } diff --git a/unitypackage_loader/blender/animation.py b/unitypackage_loader/blender/animation.py index 18d080a..53fd656 100644 --- a/unitypackage_loader/blender/animation.py +++ b/unitypackage_loader/blender/animation.py @@ -34,6 +34,7 @@ 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 @@ -205,6 +206,8 @@ def _add_track(self, datablock, action, slot, name: str) -> None: 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 # 各種のカーブ ------------------------------------------------------ diff --git a/unitypackage_loader/blender/fbx_motion.py b/unitypackage_loader/blender/fbx_motion.py index 7151610..074c9cd 100644 --- a/unitypackage_loader/blender/fbx_motion.py +++ b/unitypackage_loader/blender/fbx_motion.py @@ -15,6 +15,7 @@ from __future__ import annotations +import math import re from dataclasses import dataclass, field @@ -63,6 +64,7 @@ class _Clip: action: bpy.types.Action start: float # Blender のフレーム(Action の中の範囲) end: float + loop: bool = False def _slot_owner(slot, objects: list[bpy.types.Object]): @@ -184,7 +186,7 @@ def _clips(self, info: ModelImporterInfo | None, cached: dict[str, bpy.types.Act if count: self.stats.state += 1 continue - clips.append(_Clip(setting.name, action, setting.first_frame + ANIM_OFFSET, setting.last_frame + ANIM_OFFSET)) + clips.append(_Clip(setting.name, action, setting.first_frame + ANIM_OFFSET, setting.last_frame + ANIM_OFFSET, setting.loop)) return clips def _add_track(self, owner: bpy.types.ID, clip: _Clip, slot) -> None: @@ -196,9 +198,23 @@ def _add_track(self, owner: bpy.types.ID, clip: _Clip, slot) -> None: if strip.action_slot != slot: strip.action_slot = slot set_strip_range(strip, clip.start, clip.end) + if clip.loop: + loop_strip(strip, self.scene) track.mute = not active +def loop_strip(strip, scene: bpy.types.Scene) -> None: + """ループするクリップ(Unity の Loop Time)のストリップを、シーンのフレーム範囲の終わりまで繰り返す。 + + NLA はストリップの範囲の外を評価しない(Action の Cycles モディファイアーは範囲の中でしか働かない)ので、繰り返しの回数で表す。 + """ + length = strip.action_frame_end - strip.action_frame_start + if length <= 0: + return + span = scene.frame_end - strip.frame_start + 1 + strip.repeat = float(max(1, math.ceil(span / length))) + + def set_strip_range(strip, start: float, end: float) -> None: """ストリップが使う Action の範囲を変え、ストリップの長さをそれに合わせる(置く位置は変えない)。""" begin = strip.frame_start @@ -304,6 +320,7 @@ def copy_track(animation_data, track, strip, action: bpy.types.Action) -> None: if slot is not None and new_strip.action_slot != slot: new_strip.action_slot = slot set_strip_range(new_strip, strip.action_frame_start, strip.action_frame_end) + new_strip.repeat = strip.repeat new_track.mute = track.mute or has_active diff --git a/unitypackage_loader/blender_manifest.toml b/unitypackage_loader/blender_manifest.toml index 773e6fd..92f5289 100644 --- a/unitypackage_loader/blender_manifest.toml +++ b/unitypackage_loader/blender_manifest.toml @@ -1,7 +1,7 @@ schema_version = "1.0.0" id = "unitypackage_loader" -version = "1.18.0-dev.10" +version = "1.18.0-dev.11" name = "Unitypackage Importer" tagline = "Import meshes, materials and textures from .unitypackage files" maintainer = "utagestudio" From 889088d865aad4a69f17c0f00e45369f004e506f Mon Sep 17 00:00:00 2001 From: utagestudio Date: Thu, 26 Nov 2026 02:14:35 +0900 Subject: [PATCH 2/2] =?UTF-8?q?docs:=20=E3=83=AB=E3=83=BC=E3=83=97?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=AF=E3=83=AA=E3=83=83=E3=83=97=E3=81=AE?= =?UTF-8?q?=E6=89=B1=E3=81=84=E3=82=92=E6=9B=B8=E3=81=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- DESIGN.md | 5 +++-- README.md | 5 +++-- README_ja.md | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/DESIGN.md b/DESIGN.md index 80672c8..02fc04d 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -1091,7 +1091,8 @@ def run(ctx, filepath, opts) -> Report: - **Action と NLA**(`blender/animation.py`): クリップごとに Action を 1 つ作り(`unity_clip_guid` / `unity_clip_path`)、対象のデータブロック (オブジェクトかシェイプキーの Key)ごとにスロットを作る(Blender 4.4 以降のスロット付き Action)。対象ごとにクリップの名前の NLA トラックを ミュートで足すので、読み込んだ直後の見た目は変わらない。キーはクリップの開始からの秒 × シーンのフレームレートで、ストリップはシーンの開始フレームに置く。 - ループするクリップ(`m_LoopTime`)の F カーブには Cycles モディファイアーを付ける。 + ループするクリップ(`m_LoopTime`)は、ストリップの繰り返し(`repeat`)をシーンのフレーム範囲の終わりまでにする(`fbx_motion.loop_strip`)。 + NLA はストリップの範囲の外を評価しないので、F カーブの Cycles モディファイアー(これも付ける。Action を直接再生するとき用)だけではループしない。 - シェイプキー: 値を 1/100 にしてキーと接線をそのままベジェにする。100 を超える重みは `slider_max` を広げる。 - 表示: `hide_viewport` / `hide_render` を階段(CONSTANT)で、値が 0.5 未満なら隠す。`m_IsActive` は Unity の階層での子孫にも当てる (スキンメッシュはアーマチュアの子孫にしない)。 @@ -1139,7 +1140,7 @@ Blender の FBX インポーターはテイクごとにテイクの名前の Act アーマチュアの数を `clip_notes` に出す。 - FBX インポーターは、アニメーションを読むかどうかによらずシーンのフレームレートをファイルのものにする(今までと同じ)。 フレームレートの違う FBX を続けて読むと、先に読んだ FBX のモーションの速さがずれる(未対応)。 -- ループ(`loopTime`)はまだ NLA に反映しない(ストリップは範囲の終わりで止まる)。 +- ループ(`loopTime`)は、`.anim` と同じくストリップの繰り返しにする(`loop_strip`。まとめたアーマチュアに写すときも回数を引き継ぐ)。 ### 4.8 `blender/textures.py` diff --git a/README.md b/README.md index a51f10d..3ebb721 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,8 @@ When several motion-only models (no meshes, one armature) share the same skeleto that has all the motions as NLA tracks (Models only). An FBX without a skin uses its default pose as the rest pose, so the rest pose differs from file to file; the keys are converted so that each motion keeps its pose on the remaining armature. A skeleton that lacks some bones (for example weapon bones) is merged too; the missing bones stay at rest. -When a scene places the same model many times, the actions of its takes are shared. +When a scene places the same model many times, the actions of its takes are shared. Looping clips (Loop Time in Unity) +repeat their strip until the end of the scene's frame range. #### Generic `.anim` clips @@ -201,7 +202,7 @@ Generic animation clips (`.anim`) in the package become one action per clip. The A clip does not say which model it belongs to, so the importer looks for the imported object under which the most curve paths resolve, and treats it as the object the clip is played on (all placements of the same model get the clip). Each clip gets an NLA track on every object or shape key it animates. Keys start at the scene's start frame and use the scene's frame rate. -Looping clips get a Cycles modifier on their F-curves. +Looping clips (Loop Time in Unity) repeat their strip until the end of the scene's frame range. Clips that only switch a state are skipped: clips whose values never change, or that end within 0.1 seconds. Unity's Animator uses such clips as states and makes the motion with transitions (outfit toggles and expressions of VRChat avatars, diff --git a/README_ja.md b/README_ja.md index 26a71a7..9143f2c 100644 --- a/README_ja.md +++ b/README_ja.md @@ -169,7 +169,8 @@ FBX の中のアニメーションのテイク(モーション集や、`モデ 同じ骨格のモーションだけのモデル(メッシュが無く、アーマチュアが 1 体)が複数あれば、1 体のアーマチュアにまとめて、全モーションを NLA トラックとして並べます(Models 単位)。スキンの無い FBX はファイルの既定の姿勢をレストにするので、レスト姿勢はファイルごとに 違います。残すアーマチュアでも同じ姿勢になるよう、キーを変換します。一部のボーン(武器用のボーンなど)が無い骨格もまとめます -(無いボーンはレストのまま)。シーンで同じモデルを何度も置くときは、テイクの Action を共有します。 +(無いボーンはレストのまま)。シーンで同じモデルを何度も置くときは、テイクの Action を共有します。ループするクリップ(Unity の Loop Time)は、 +シーンのフレーム範囲の終わりまでストリップを繰り返します。 #### Generic な `.anim` @@ -181,7 +182,7 @@ NLA トラックとして並べます(Models 単位)。スキンの無い FB クリップは対象のモデルを持たないので、カーブの階層パスがいちばん多く当てはまる読み込んだオブジェクトを、クリップを再生する オブジェクトとみなします(同じモデルを複数置いていれば、すべてに付けます)。動かすオブジェクトとシェイプキーごとに -NLA トラックを足します。キーはシーンの開始フレームから、シーンのフレームレートで並べます。ループするクリップの F カーブには Cycles モディファイアーを付けます。 +NLA トラックを足します。キーはシーンの開始フレームから、シーンのフレームレートで並べます。ループするクリップ(Unity の Loop Time)は、シーンのフレーム範囲の終わりまでストリップを繰り返します。 状態を切り替えるだけのクリップ(値が変わらないもの、0.1 秒以下で終わるもの)は読み込みません。Unity の Animator はこうしたクリップを ステートとして使い、動きは遷移で作ります(VRChat のアバターの衣装の切り替えや表情、車両のハンドルの角度など)。