00001 //------------------------------------------------------------------------------ 00002 // Lamp : Open source game middleware 00003 // Copyright (C) 2004 Junpei Ohtani ( Email : junpee@users.sourceforge.jp ) 00004 // 00005 // This library is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // This library is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with this library; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 //------------------------------------------------------------------------------ 00019 00020 /** @file 00021 * キャラクタメッシュヘッダ 00022 * @author Junpee 00023 */ 00024 00025 #ifndef CHARACTER_MESH_H_ 00026 #define CHARACTER_MESH_H_ 00027 00028 #include <Graphics/Mesh/Mesh.h> 00029 00030 namespace Lamp{ 00031 00032 //------------------------------------------------------------------------------ 00033 /** 00034 * キャラクタメッシュ 00035 * 00036 * デフォームはソフトウェアで行う。理由は以下に。 00037 * MaxVertexBlendMatrixIndexのハードウェア対応数が少ない。 00038 * この点はVS3とかで行列テクスチャにアクセスできれば解決するかも。 00039 * マルチパスレンダリング(影等)を行う際に複数回デフォームを行うことになる。 00040 */ 00041 class CharacterMesh : public Mesh{ 00042 friend class MeshManager; 00043 public: 00044 //-------------------------------------------------------------------------- 00045 /// 最大頂点あたりウェイト数 00046 static const int maxWeightPerVertex = 4; 00047 00048 //-------------------------------------------------------------------------- 00049 /** 00050 * キャラクタメッシュかどうか 00051 * @return キャラクタメッシュならtrue 00052 */ 00053 virtual bool isCharacterMesh() const{ return true; } 00054 00055 //-------------------------------------------------------------------------- 00056 /** 00057 * コピー 00058 * @param copyMask コピーマスク 00059 * @return コピーされたメッシュ 00060 */ 00061 virtual Mesh* copy(u_int copyMask = 0) const{ 00062 return copyCharacterMesh(copyMask); 00063 } 00064 00065 /** 00066 * キャラクタメッシュのコピー 00067 * @param copyMask コピーマスク 00068 * @return コピーされたメッシュ 00069 */ 00070 virtual CharacterMesh* copyCharacterMesh(u_int copyMask = 0) const; 00071 00072 //-------------------------------------------------------------------------- 00073 /** 00074 * 法線の正規化を必要とするか 00075 * @return 法線の正規化を必要とするならtrue 00076 */ 00077 virtual bool requireNormalize() const{ 00078 // GPUで法線の正規化を行う 00079 return true; 00080 } 00081 00082 //-------------------------------------------------------------------------- 00083 /** 00084 * デバイスオブジェクトの無効化 00085 */ 00086 virtual void invalidateGraphicsDeviceObjects(){ 00087 SafeRelease(vertexBuffer_); 00088 SafeRelease(vertexDeclaration_); 00089 vertexSize_ = 0; 00090 } 00091 00092 //-------------------------------------------------------------------------- 00093 protected: 00094 /** 00095 * コンストラクタ 00096 * @param name 名前 00097 * @param scene シーン 00098 */ 00099 CharacterMesh(const String& name, Scene* scene); 00100 00101 /** 00102 * デストラクタ 00103 */ 00104 virtual ~CharacterMesh(); 00105 00106 //-------------------------------------------------------------------------- 00107 /** 00108 * 走査 00109 * @param parentMatrix 親行列 00110 * @param parentEnabled 親が有効か 00111 * @param parentScaled 親がスケールを使用しているか 00112 * @param parentChanged 親に変更があったか 00113 */ 00114 virtual void traverse(const Matrix34& parentMatrix, bool parentEnabled, 00115 bool parentScaled, bool parentChanged); 00116 00117 //-------------------------------------------------------------------------- 00118 // キャラクタ変形 00119 //-------------------------------------------------------------------------- 00120 /** 00121 * キャラクタ変形 00122 * @return キャラクタ変形を行ったらtrue 00123 */ 00124 virtual bool characterDeform(); 00125 00126 //-------------------------------------------------------------------------- 00127 /** 00128 * 変形 00129 */ 00130 virtual void deform(); 00131 00132 /** 00133 * スキニング変形 00134 * @param positionDeformMatrixArray 位置変形行列配列 00135 */ 00136 virtual void skinningDeformP(const Matrix34* positionDeformMatrixArray); 00137 00138 /** 00139 * スキニング変形 00140 * @param positionDeformMatrixArray 位置変形行列配列 00141 */ 00142 virtual void skinningDeformPN(const Matrix34* positionDeformMatrixArray); 00143 00144 /** 00145 * スキニング変形 00146 * @param positionDeformMatrixArray 位置変形行列配列 00147 * @param normalDeformMatrixArray 法線変形行列配列 00148 */ 00149 virtual void skinningDeformPN(const Matrix34* positionDeformMatrixArray, 00150 const Matrix33* normalDeformMatrixArray); 00151 00152 /** 00153 * スティッチング変形 00154 * @param positionDeformMatrixArray 位置変形行列配列 00155 */ 00156 virtual void stitchingDeformP(const Matrix34* positionDeformMatrixArray); 00157 00158 /** 00159 * スティッチング変形 00160 * @param positionDeformMatrixArray 位置変形行列配列 00161 */ 00162 virtual void stitchingDeformPN(const Matrix34* positionDeformMatrixArray); 00163 00164 /** 00165 * スティッチング変形 00166 * @param positionDeformMatrixArray 位置変形行列配列 00167 * @param normalDeformMatrixArray 法線変形行列配列 00168 */ 00169 virtual void stitchingDeformPN(const Matrix34* positionDeformMatrixArray, 00170 const Matrix33* normalDeformMatrixArray); 00171 00172 /** 00173 * 頂点バッファセットアップ 00174 * @return 成功すればtrueを返す 00175 */ 00176 virtual bool setupVertexBuffer(); 00177 00178 //-------------------------------------------------------------------------- 00179 // グラフィックスバッファ 00180 //-------------------------------------------------------------------------- 00181 /** 00182 * 頂点記述の構築 00183 * @return 成功すればtrueを返す 00184 */ 00185 virtual bool createVertexDeclaration(); 00186 00187 00188 /** 00189 * 頂点バッファの構築 00190 * @return 成功すればtrueを返す 00191 */ 00192 virtual bool createVertexBuffer(); 00193 00194 //-------------------------------------------------------------------------- 00195 // 変形バッファアクセス 00196 //-------------------------------------------------------------------------- 00197 /** 00198 * 変形頂点記述の取得 00199 * @return 変形頂点記述 00200 */ 00201 virtual Direct3DVertexDeclaration* getDeformedVertexDeclaration(){ 00202 if(vertexDeclaration_ == NULL){ createVertexDeclaration(); } 00203 return vertexDeclaration_; 00204 } 00205 00206 /** 00207 * 変形頂点サイズの取得 00208 * @return 変形頂点サイズ 00209 */ 00210 virtual int getDeformedVertexSize(){ 00211 if(vertexDeclaration_ == NULL){ createVertexDeclaration(); } 00212 return vertexSize_; 00213 } 00214 00215 /** 00216 * 変形頂点バッファの構築 00217 * @return 変形頂点バッファ 00218 */ 00219 virtual Direct3DVertexBuffer* getDeformedVertexBuffer(){ 00220 if(vertexBuffer_ == NULL){ createVertexBuffer(); } 00221 return vertexBuffer_; 00222 } 00223 00224 //-------------------------------------------------------------------------- 00225 /// 頂点記述 00226 Direct3DVertexDeclaration* vertexDeclaration_; 00227 /// 頂点バッファ 00228 Direct3DVertexBuffer* vertexBuffer_; 00229 /// 頂点サイズ 00230 int vertexSize_; 00231 00232 /// 変形済み頂点数 00233 int deformedVertexCount_; 00234 /// 変形済み位置 00235 Vector3* deformedPosition_; 00236 /// 変形済み法線 00237 Vector3* deformedNormal_; 00238 00239 }; 00240 00241 //------------------------------------------------------------------------------ 00242 } // End of namespace Lamp 00243 #endif // End of CHARACTER_MESH_H_ 00244 //------------------------------------------------------------------------------ 00245