ご説明いただいた手順をまねてアニメーションを作ってみたところ、確かにずれた位置を中心にハンマーが振動しました。
この現象については、ちょっと調査不十分で不確かではあるのですが、「AnimationUtility-SetAdditiveReferencePose - Unity スクリプトリファレンス 」にある...
By default, an animation clip used in an additive layer uses the pose at time 0 as its reference pose.
との記述が関係あるかもしれません。今回のアニメーションクリップは最初のフレームでハンマーが最大に傾いた状態になっていますので、そこが基準姿勢だということになってしまったんでしょうかね...?
あの項目は外部ソフトで作成したアニメーションの場合はインポート設定のクリップ固有のプロパティ として設定できるようなのですが、Unity上で作成したアニメーションの場合はどうすればいいのかわからず、仕方ないのでEditorフォルダを作って下記スクリプトを入れ...
C#
1 using UnityEditor ;
2 using UnityEngine ;
3
4 public class ReferencePoseConfigurator : EditorWindow
5 {
6 private AnimationClip clip ;
7 private AnimationClip referenceClip ;
8 private float clipLength ;
9 private int clipFrameCount ;
10 private float time ;
11 private int frame ;
12 private float modifiedTime ;
13 private int modifiedFrame ;
14 private ConfigurationMode configurationMode ;
15
16 private void OnGUI ( )
17 {
18 if ( this . clip == null )
19 {
20 EditorGUILayout . HelpBox ( "No clip selected." , MessageType . Error ) ;
21 return ;
22 }
23 EditorGUILayout . LabelField ( "Name" , this . clip . name ) ;
24 if ( this . referenceClip != this . clip )
25 {
26 EditorGUILayout . HelpBox (
27 $ "This clip refers to another clip \"{this.referenceClip!.name}\" as the reference pose source. This is not supported." ,
28 MessageType . Error ) ;
29 return ;
30 }
31 this . configurationMode = ( ConfigurationMode ) EditorGUILayout . EnumPopup ( "Set by" , this . configurationMode ) ! ;
32 if ( this . configurationMode == ConfigurationMode . Frame )
33 {
34 this . modifiedFrame = EditorGUILayout . IntSlider (
35 "Reference Frame" ,
36 this . modifiedFrame ,
37 0 ,
38 this . clipFrameCount ) ;
39 this . modifiedTime = this . modifiedFrame / this . clip . frameRate ;
40 }
41 else
42 {
43 this . modifiedTime = EditorGUILayout . Slider ( "Reference Time" , this . modifiedTime , 0 , this . clipLength ) ;
44 this . modifiedFrame = Mathf . RoundToInt ( this . modifiedTime * this . clip . frameRate ) ;
45 }
46 using ( new EditorGUI . DisabledScope ( this . modifiedTime == this . time ) )
47 {
48 if ( GUILayout . Button ( "Apply" ) )
49 {
50 this . time = this . modifiedTime ;
51 this . frame = this . modifiedFrame ;
52 Undo . RecordObject ( this . clip , "Set Additive Reference Pose" ) ;
53 AnimationUtility . SetAdditiveReferencePose ( this . clip , this . clip , this . time ) ;
54 }
55 }
56 }
57
58 private void OnSelectionChange ( )
59 {
60 this . ReadClipData ( ) ;
61 this . Repaint ( ) ;
62 }
63
64 private void ReadClipData ( )
65 {
66 this . clip = Selection . activeObject as AnimationClip ;
67 if ( this . clip == null )
68 {
69 return ;
70 }
71 var currentSettings = AnimationUtility . GetAnimationClipSettings ( this . clip ) ;
72 this . referenceClip = currentSettings ! . additiveReferencePoseClip ;
73 if ( this . referenceClip == null )
74 {
75 this . referenceClip = this . clip ;
76 }
77 if ( this . referenceClip != this . clip )
78 {
79 return ;
80 }
81 this . clipLength = this . clip . length ;
82 this . clipFrameCount = Mathf . RoundToInt ( this . clipLength * this . clip . frameRate ) ;
83 this . time = currentSettings . additiveReferencePoseTime ;
84 this . frame = Mathf . RoundToInt ( this . time * this . clip . frameRate ) ;
85 this . modifiedTime = this . time ;
86 this . modifiedFrame = this . frame ;
87 }
88
89 [ MenuItem ( "Utility/Animation/Configure Reference Pose" ) ]
90 private static void Init ( )
91 {
92 var window = GetWindow < ReferencePoseConfigurator > ( ) ! ;
93 window . titleContent = new GUIContent ( "Configure Reference Pose" ) ;
94 window . ReadClipData ( ) ;
95 window . Show ( ) ;
96 }
97
98 private enum ConfigurationMode
99 {
100 Time ,
101 Frame
102 }
103 }
メニューに追加された「Utility」→「Animation」→「Configure Reference Pose」で設定ウィンドウを開き、ベルのアニメーションクリップを選択して、ハンマーが中心に到達する2フレーム目を基準姿勢にするよう設定したところ...
どうやら中心を基準に振動するようになったようでした。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/02/27 03:53