1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: gfx_ResSkeleton.h 4 5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain proprietary 8 information of Nintendo and/or its licensed developers and are protected by 9 national and international copyright laws. They may not be disclosed to third 10 parties or copied or duplicated in any form, in whole or in part, without the 11 prior written consent of Nintendo. 12 13 The content herein is highly confidential and should be handled accordingly. 14 15 $Revision: $ 16 *---------------------------------------------------------------------------*/ 17 18 #ifndef NW_GFX_RESSKELETON_H_ 19 #define NW_GFX_RESSKELETON_H_ 20 21 #include <nw/ut/ut_ResUtil.h> 22 #include <nw/ut/ut_ResDictionary.h> 23 #include <nw/math/math_ResTypes.h> 24 #include <nw/gfx/res/gfx_ResSceneObject.h> 25 #include <nw/gfx/res/gfx_ResTypeInfo.h> 26 27 namespace nw { 28 namespace gfx { 29 namespace res { 30 31 //! @details :private 32 struct ResBoneData 33 { 34 enum Flag 35 { 36 FLAG_IS_IDENTITY = 0x1 << 0, 37 FLAG_IS_TRANSLATE_ZERO = 0x1 << 1, 38 FLAG_IS_ROTATE_ZERO = 0x1 << 2, 39 FLAG_IS_SCALE_ONE = 0x1 << 3, 40 FLAG_IS_UNIFORM_SCALE = 0x1 << 4, 41 FLAG_IS_SEGMENTSCALE_COMPENSATE = 0x1 << 5, 42 FLAG_IS_NEED_RENDERING = 0x1 << 6, 43 FLAG_IS_LOCAL_MATRIX_CALCULATE = 0x1 << 7, 44 FLAG_IS_WORLD_MATRIX_CALCULATE = 0x1 << 8, 45 FLAG_HAS_SKINNING_MATRIX = 0x1 << 9 46 }; 47 48 nw::ut::BinString toName; 49 nw::ut::ResU32 m_Flags; 50 nw::ut::ResS32 m_Index; 51 nw::ut::ResS32 m_ParentBoneIndex; 52 nw::ut::Offset toParentBone; 53 nw::ut::Offset toChildBone; 54 nw::ut::Offset toPrevSibling; 55 nw::ut::Offset toNextSibling; 56 nw::ut::ResTransform3 m_Transform; 57 nw::ut::ResMtx34 m_LocalMatrix; 58 nw::ut::ResMtx34 m_WorldMatrix; // 行列計算用のバッファへ正式対応後、削除予定。 59 nw::ut::ResMtx34 m_InverseBaseMatrix; 60 nw::ut::ResS32 m_BillboardMode; 61 nw::ut::ResS32 m_UserDataDicCount; 62 nw::ut::Offset toUserDataDic; 63 }; 64 65 //! @details :private 66 struct ResSkeletonData : public ResSceneObjectData 67 { 68 enum Flag 69 { 70 FLAG_MODEL_COORDINATE = 0x1 << 0, 71 FLAG_TRANSLATE_ANIMATION_ENABLED = 0x1 << 1 72 }; 73 74 nw::ut::ResS32 m_BonesDicCount; 75 nw::ut::Offset toBonesDic; 76 nw::ut::Offset toRootBone; 77 nw::ut::ResS32 m_ScalingRule; 78 nw::ut::ResU32 m_Flags; 79 }; 80 81 //-------------------------------------------------------------------------- 82 //! @brief スケルタルモデルのボーンを表すバイナリリソースクラスです。 83 //--------------------------------------------------------------------------- 84 class ResBone : public nw::ut::ResCommon< ResBoneData > 85 { 86 public: 87 88 //! ビルボードの種類の定義です。 89 enum BillboardMode 90 { 91 BILLBOARD_MODE_OFF, //!< ビルボード処理を行いません。 92 BILLBOARD_MODE_WORLD, //!< Z 軸が視点軸と平行となるように回転させます。 93 BILLBOARD_MODE_WORLD_VIEWPOINT, //!< Z 軸が視点方向に向くように回転させます。 94 BILLBOARD_MODE_SCREEN, //!< Z 軸が視点軸と平行で、Y 軸が画面上方向になるように回転させます。 95 BILLBOARD_MODE_SCREEN_VIEWPOINT, //!< Z 軸が視点方向に向くき、Y 軸が画面上方向になるように回転させます。 96 BILLBOARD_MODE_Y_AXIAL, //!< Z 軸が視点軸と平行となるように Y 軸だけ 回転させます。 97 BILLBOARD_MODE_Y_AXIAL_VIEWPOINT //!< Z 軸が視点方向に向くように Y 軸だけ 回転させます。 98 }; 99 100 NW_RES_CTOR( ResBone ) 101 102 //--------------------------------------------------------------------------- 103 //! @fn void SetWorldMatrix(const nw::math::MTX34 & value) 104 //! @brief ワールドマトリクスを設定します。 105 //--------------------------------------------------------------------------- 106 //--------------------------------------------------------------------------- 107 //! @fn void SetTransform(const nw::math::Transform3 & value) 108 //! @brief トランスフォーム情報を設定します。 109 //--------------------------------------------------------------------------- 110 //--------------------------------------------------------------------------- 111 //! @fn void SetParentBoneIndex(s32 value) 112 //! @brief 親ボーンのインデックス番号を設定します。 113 //--------------------------------------------------------------------------- 114 //--------------------------------------------------------------------------- 115 //! @fn void SetLocalMatrix(const nw::math::MTX34 & value) 116 //! @brief ローカルマトリクスを設定します。 117 //--------------------------------------------------------------------------- 118 //--------------------------------------------------------------------------- 119 //! @fn void SetInverseBaseMatrix(const nw::math::MTX34 & value) 120 //! @brief ベースマトリクスの逆行列を設定します。 121 //--------------------------------------------------------------------------- 122 //--------------------------------------------------------------------------- 123 //! @fn void SetIndex(s32 value) 124 //! @brief インデックス番号を設定します。 125 //--------------------------------------------------------------------------- 126 //--------------------------------------------------------------------------- 127 //! @fn void SetFlags(u32 value) 128 //! @brief フラグの値を設定します。 129 //! 設定されなかったフラグは無効になります。 130 //--------------------------------------------------------------------------- 131 //--------------------------------------------------------------------------- 132 //! @fn void EnableFlags(u32 value) 133 //! @brief 指定された Flag の値を有効にします。 134 //! 設定されなかったフラグは変更されません。 135 //--------------------------------------------------------------------------- 136 //--------------------------------------------------------------------------- 137 //! @fn void DisableFlags(u32 value) 138 //! @brief 指定された Flag の値を無効にします。 139 //! 設定されなかったフラグは変更されません。 140 //--------------------------------------------------------------------------- 141 //--------------------------------------------------------------------------- 142 //! @fn void SetBillboardMode(BillboardMode value) 143 //! @brief ビルボード表示のモードを設定します。 144 //--------------------------------------------------------------------------- 145 //--------------------------------------------------------------------------- 146 //! @fn nw::math::MTX34 & GetWorldMatrix() 147 //! @brief ワールドマトリクスを取得します。 148 //--------------------------------------------------------------------------- 149 //--------------------------------------------------------------------------- 150 //! @fn nw::math::Transform3 & GetTransform() 151 //! @brief トランスフォーム情報を取得します。 152 //--------------------------------------------------------------------------- 153 //--------------------------------------------------------------------------- 154 //! @fn ResBone GetPrevSibling() 155 //! @brief 前の兄弟ボーンを取得します。 156 //--------------------------------------------------------------------------- 157 //--------------------------------------------------------------------------- 158 //! @fn s32 GetParentBoneIndex() const 159 //! @brief 親ボーンのインデックス番号を取得します。 160 //--------------------------------------------------------------------------- 161 //--------------------------------------------------------------------------- 162 //! @fn ResBone GetParentBone() 163 //! @brief 親ボーンを取得します。 164 //--------------------------------------------------------------------------- 165 //--------------------------------------------------------------------------- 166 //! @fn ResBone GetNextSibling() 167 //! @brief 次の兄弟ボーンを取得します。 168 //--------------------------------------------------------------------------- 169 //--------------------------------------------------------------------------- 170 //! @fn const char * GetName() const 171 //! @brief 名前を取得します。 172 //--------------------------------------------------------------------------- 173 //--------------------------------------------------------------------------- 174 //! @fn nw::math::MTX34 & GetLocalMatrix() 175 //! @brief ローカルマトリクスを取得します。 176 //--------------------------------------------------------------------------- 177 //--------------------------------------------------------------------------- 178 //! @fn nw::math::MTX34 & GetInverseBaseMatrix() 179 //! @brief ベースマトリクスの逆行列を取得します。 180 //--------------------------------------------------------------------------- 181 //--------------------------------------------------------------------------- 182 //! @fn s32 GetIndex() const 183 //! @brief インデックス番号を取得します。 184 //--------------------------------------------------------------------------- 185 //--------------------------------------------------------------------------- 186 //! @fn u32 GetFlags() const 187 //! @brief フラグの値を取得します。 188 //--------------------------------------------------------------------------- 189 //--------------------------------------------------------------------------- 190 //! @fn ResBone GetChildBone() 191 //! @brief 子ボーンを取得します。 192 //--------------------------------------------------------------------------- 193 //--------------------------------------------------------------------------- 194 //! @fn BillboardMode GetBillboardMode() const 195 //! @brief ビルボード表示のモードを取得します。 196 //--------------------------------------------------------------------------- 197 NW_RES_FIELD_STRING_DECL( Name ) // GetName() 198 NW_RES_FIELD_FLAGS_DECL( u32, Flags ) // GetFlags(), SetFlags(), EnableFlags(), DisableFlags() 199 NW_RES_FIELD_PRIMITIVE_DECL( s32, Index ) // GetIndex(), SetIndex() 200 NW_RES_FIELD_PRIMITIVE_DECL( s32, ParentBoneIndex ) // GetParentBoneIndex(), SetParentBoneIndex() 201 NW_RES_FIELD_CLASS_DECL( ResBone, ParentBone ) // GetParentBone() 202 NW_RES_FIELD_CLASS_DECL( ResBone, ChildBone ) // GetChildBone() 203 NW_RES_FIELD_CLASS_DECL( ResBone, PrevSibling ) // GetPrevSibling() 204 NW_RES_FIELD_CLASS_DECL( ResBone, NextSibling ) // GetNextSibling() 205 NW_RES_FIELD_STRUCT_DECL( nw::math::Transform3, Transform ) // GetTransform() 206 NW_RES_FIELD_STRUCT_DECL( nw::math::MTX34, LocalMatrix ) // GetLocalMatrix() 207 NW_RES_FIELD_STRUCT_DECL( nw::math::MTX34, WorldMatrix ) // 行列計算用のバッファへ正式対応後、削除予定。 208 NW_RES_FIELD_STRUCT_DECL( nw::math::MTX34, InverseBaseMatrix ) // GetInverseBaseMatrix() 209 NW_RES_FIELD_PRIMITIVE_DECL( BillboardMode, BillboardMode ) // GetBillboardMode(), SetBillboardMode() 210 211 //--------------------------------------------------------------------------- 212 //! @fn s32 GetUserDataIndex(const char * key) const 213 //! @brief ユーザデータの辞書データ中でのインデックス番号を取得します。 214 //--------------------------------------------------------------------------- 215 //--------------------------------------------------------------------------- 216 //! @fn s32 GetUserDataCount() const 217 //! @brief ユーザデータの要素数を取得します。 218 //--------------------------------------------------------------------------- 219 //--------------------------------------------------------------------------- 220 //! @fn nw::ut::ResMetaData GetUserData(int idx) 221 //! @brief ユーザデータを取得します。 222 //--------------------------------------------------------------------------- 223 NW_RES_FIELD_CLASS_DIC_DECL( nw::ut::ResMetaData, UserData, nw::ut::ResDicPatricia ) // GetMetaData(int idx), GetMetaData(const char*), GetMetaDataIndex(const char*), GetMetaDataCount() 224 }; 225 typedef nw::ut::ResArrayPatricia<ResBone>::type ResBoneArray; 226 227 228 //-------------------------------------------------------------------------- 229 //! @brief ボーンを束ねるスケルトンを表すバイナリリソースクラスです。 230 //--------------------------------------------------------------------------- 231 class ResSkeleton : public ResSceneObject 232 { 233 public: 234 enum Flag 235 { 236 FLAG_MODEL_COORDINATE = 0x1 << 0, 237 FLAG_TRANSLATE_ANIMATION_ENABLED = 0x1 << 1 238 }; 239 240 enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResSkeleton) }; 241 enum { SIGNATURE = NW_RES_SIGNATURE32('CSKL') }; 242 243 NW_RES_CTOR_INHERIT( ResSkeleton, ResSceneObject ) 244 245 //--------------------------------------------------------------------------- 246 //! @fn void SetScalingRule(s32 value) 247 //! @brief スケールの方式を設定します。 248 //--------------------------------------------------------------------------- 249 //--------------------------------------------------------------------------- 250 //! @fn void SetFlags(u32 value) 251 //! @brief Flag の値を設定します。 252 //! ワールド座標、モデル座標などを設定できます。 253 //! 設定されなかったフラグは無効になります。 254 //--------------------------------------------------------------------------- 255 //--------------------------------------------------------------------------- 256 //! @fn void EnableFlags(u32 value) 257 //! @brief 指定された Flag の値を有効にします。 258 //! 設定されなかったフラグは変更されません。 259 //--------------------------------------------------------------------------- 260 //--------------------------------------------------------------------------- 261 //! @fn void DisableFlags(u32 value) 262 //! @brief 指定された Flag の値を無効にします。 263 //! 設定されなかったフラグは変更されません。 264 //--------------------------------------------------------------------------- 265 //--------------------------------------------------------------------------- 266 //! @fn s32 GetScalingRule() const 267 //! @brief スケールの方式を取得します。 268 //--------------------------------------------------------------------------- 269 //--------------------------------------------------------------------------- 270 //! @fn ResBone GetRootBone() 271 //! @brief ルートのボーンを取得します。 272 //--------------------------------------------------------------------------- 273 //--------------------------------------------------------------------------- 274 //! @fn u32 GetFlags() const 275 //! @brief フラグの値を取得します。 276 //--------------------------------------------------------------------------- 277 //--------------------------------------------------------------------------- 278 //! @fn s32 GetBonesIndex(const char * key) const 279 //! @brief ボーンの辞書データ中でのインデックス番号を取得します。 280 //--------------------------------------------------------------------------- 281 //--------------------------------------------------------------------------- 282 //! @fn s32 GetBonesCount() const 283 //! @brief ボーンの要素数を取得します。 284 //--------------------------------------------------------------------------- 285 //--------------------------------------------------------------------------- 286 //! @fn ResBone GetBones(int idx) 287 //! @brief ボーンを取得します。 288 //--------------------------------------------------------------------------- 289 NW_RES_FIELD_CLASS_DIC_DECL( ResBone, Bones, nw::ut::ResDicPatricia ) // GetBones(int idx), GetBones(const char*), GetBonesIndex(const char*), GetBonesCount() 290 NW_RES_FIELD_CLASS_DECL( ResBone, RootBone ) // GetRootBone() 291 NW_RES_FIELD_PRIMITIVE_DECL( s32, ScalingRule ) // GetScalingRule(), SetScalingRule() 292 NW_RES_FIELD_FLAGS_DECL( u32, Flags ) // GetFlags(), SetFlags(), EnableFlags(), DisableFlags() 293 }; 294 295 } // namespace res 296 } // namespace gfx 297 } // namespace nw 298 299 #endif // NW_GFX_RESSKELETON_H_ 300