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