00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #pragma once
00054
00055 class SceneAnimator;
00056
00057 #include <stdlib.h>
00058 #include <aiScene.h>
00059
00060 #define NO_OF_DIRECTIONAL_LIGHTS 1
00061
00062 namespace boost
00063 {
00064 namespace serialization
00065 {
00066 class access;
00067 }
00068 }
00069
00070 namespace AssimpRendererD3d
00071 {
00072 class AssetHelper;
00073 }
00074
00075
00077
00080 class AssimpRendererD3d::AssetHelper
00081 {
00082 friend class boost::serialization::access;
00083 friend class AssimpRenderer;
00084 friend class CMaterialManager;
00085 friend class CMeshRenderer;
00086
00087 public:
00088 bool SetAmbientLight(D3DCOLOR ambientLight);
00089 bool SetDirectionalLight(unsigned int lightIndex, D3DCOLOR lightColor, const aiVector3D& lightDir);
00090 bool SetDirectionalLightDirection(unsigned int lightIndex, const aiVector3D& lightDir);
00091 bool SetDirectionalLightColor(unsigned int lightIndex, D3DCOLOR lightColor);
00092 bool SetSpecularShininessModificator(float modificator);
00093 bool SetSpecularStrengthModificator(float modificator);
00094
00095 bool operator == (const AssetHelper& otherAsset);
00096 bool operator != (const AssetHelper& otherAsset);
00097
00098 private:
00099 enum
00100 {
00101
00102 ORIGINAL = 0x0u,
00103
00104
00105 SMOOTH = 0x1u,
00106
00107
00108 HARD = 0x2u,
00109 };
00110
00111
00112 AssetHelper()
00113 {
00114 mAnimator = NULL;
00115 apcMeshes = NULL;
00116 pcScene = NULL;
00117 numMeshes = 0;
00118
00119
00120 lightDirs[0] = aiVector3D(1.0f, 1.0f, 1.0f);
00121 lightDirs[1] = aiVector3D(1.0f, 1.0f, 1.0f);
00122 lightColors[0] = D3DCOLOR(D3DCOLOR_XRGB(255, 255, 255));
00123 lightColors[1] = D3DCOLOR(D3DCOLOR_XRGB(255, 255, 255));
00124 lightDirIntensity = 1.0f;
00125 lightAmbient = D3DCOLOR_XRGB(127, 127, 127);
00126 lightShininessModificator = 1.0f;
00127 lightSpecularStrengthModificator = 1.0f;
00128 }
00129
00130 template<class Archive>
00131 void serialize(Archive & ar, const unsigned int version);
00132
00133
00134
00135
00136
00137
00138 struct Vertex
00139 {
00140 aiVector3D vPosition;
00141 aiVector3D vNormal;
00142
00143 D3DCOLOR dColorDiffuse;
00144 aiVector3D vTangent;
00145 aiVector3D vBitangent;
00146 aiVector2D vTextureUV;
00147 aiVector2D vTextureUV2;
00148 unsigned char mBoneIndices[4];
00149 unsigned char mBoneWeights[4];
00150
00152 static D3DVERTEXELEMENT9* GetDeclarationElements()
00153 {
00154 static D3DVERTEXELEMENT9 decl[] =
00155 {
00156 { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
00157 { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
00158 { 0, 24, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
00159 { 0, 28, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
00160 { 0, 40, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },
00161 { 0, 52, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
00162 { 0, 60, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
00163 { 0, 68, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0 },
00164 { 0, 72, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0 },
00165 D3DDECL_END()
00166 };
00167
00168 return decl;
00169 }
00170
00171 Vertex ()
00172 :
00173 vPosition (0.0f, 0.0f, 0.0f),
00174 vNormal (0.0f, 0.0f, 0.0f),
00175 dColorDiffuse (0),
00176 vTangent (0.0f, 0.0f, 0.0f),
00177 vBitangent (0.0f, 0.0f, 0.0f),
00178 vTextureUV (0.0f, 0.0f),
00179 vTextureUV2 (0.0f, 0.0f)
00180 {}
00181
00182 template<class Archive>
00183 void serialize(Archive & ar, const unsigned int version);
00184 };
00185
00186
00187
00188
00189
00190
00191 class MeshHelper
00192 {
00193 public:
00194
00195 MeshHelper ()
00196 :
00197 piVB (NULL),
00198 piIB (NULL),
00199 vertexBuffer (NULL),
00200 indexBuffer (NULL),
00201 piEffect (NULL),
00202 piDiffuseTexture (NULL),
00203 piDiffuseTexture2 (NULL),
00204 piSpecularTexture (NULL),
00205 piAmbientTexture (NULL),
00206 piNormalTexture (NULL),
00207 piEmissiveTexture (NULL),
00208 piOpacityTexture (NULL),
00209 piShininessTexture (NULL),
00210 pvOriginalNormals (NULL),
00211 bSharedFX (false),
00212 numVertices (0),
00213 primitiveTypes (0),
00214 bHM (false)
00215 {}
00216
00217 ~MeshHelper ()
00218 {
00219
00220
00221 }
00222
00223 template<class Archive>
00224 void serialize(Archive & ar, const unsigned int version);
00225
00226 bool operator == (const AssetHelper::MeshHelper& otherMesh);
00227 bool operator != (const AssetHelper::MeshHelper& otherMesh);
00228
00229
00230
00231 aiShadingMode eShadingMode;
00232
00233
00234 IDirect3DVertexBuffer9* piVB;
00235
00236
00237
00238
00239 IDirect3DIndexBuffer9* piIB;
00240
00241
00242 AssetHelper::Vertex* vertexBuffer;
00243
00244
00245 unsigned int* indexBuffer;
00246
00247
00248
00249 ID3DXEffect* piEffect;
00250 bool bSharedFX;
00251
00252
00253
00254
00255 aiString texturePathDiffuse;
00256 aiString texturePathDiffuse2;
00257 aiString texturePathSpecular;
00258 aiString texturePathAmbient;
00259 aiString texturePathEmissive;
00260 aiString texturePathNormal;
00261 aiString texturePathOpacity;
00262 aiString texturePathShininess;
00263
00264
00265 bool bHM;
00266
00267
00271 unsigned int numFaces;
00272
00273
00274 IDirect3DTexture9* piDiffuseTexture;
00275 IDirect3DTexture9* piDiffuseTexture2;
00276 IDirect3DTexture9* piSpecularTexture;
00277 IDirect3DTexture9* piAmbientTexture;
00278 IDirect3DTexture9* piEmissiveTexture;
00279 IDirect3DTexture9* piNormalTexture;
00280 IDirect3DTexture9* piOpacityTexture;
00281 IDirect3DTexture9* piShininessTexture;
00282
00283
00284 D3DXVECTOR4 vDiffuseColor;
00285 D3DXVECTOR4 vSpecularColor;
00286 D3DXVECTOR4 vAmbientColor;
00287 D3DXVECTOR4 vEmissiveColor;
00288
00289
00290 float fOpacity;
00291
00292
00293 float fShininess;
00294
00295
00296 float fSpecularStrength;
00297
00298
00299 aiVector3D* pvOriginalNormals;
00300
00301
00302 unsigned int numVertices;
00303
00304 unsigned int indexBufferLength;
00305
00306
00307 unsigned int primitiveTypes;
00308
00309 };
00310
00311
00312 MeshHelper** apcMeshes;
00313
00314
00315 aiScene* pcScene;
00316
00317
00318 SceneAnimator* mAnimator;
00319
00320
00321 aiString g_szFileName;
00322
00323
00324
00325 unsigned int numMeshes;
00326
00327
00328 aiVector3D lightDirs[NO_OF_DIRECTIONAL_LIGHTS];
00329 D3DCOLOR lightColors[NO_OF_DIRECTIONAL_LIGHTS];
00330 float lightDirIntensity;
00331 D3DCOLOR lightAmbient;
00332
00333 float lightShininessModificator;
00334 float lightSpecularStrengthModificator;
00335
00336 };
00337
00338
00339
00340
00341
00342
00343 namespace AssimpRendererD3d
00344 {
00345 template<class Archive>
00346 void AssetHelper::serialize(Archive & ar, const unsigned int version)
00347 {
00348
00349
00350
00351
00352 ar & numMeshes;
00353
00354
00355
00356
00357 ar & pcScene;
00358
00359 if (!apcMeshes)
00360 {
00361 apcMeshes = new AssimpRendererD3d::AssetHelper::MeshHelper*[numMeshes];
00362 for (unsigned int i=0; i<numMeshes; ++i)
00363 {
00364 apcMeshes[i] = 0;
00365 }
00366 }
00367
00368 for (unsigned int i=0; i<numMeshes; ++i)
00369 {
00370 if (apcMeshes[i] == 0)
00371 apcMeshes[i] = new AssimpRendererD3d::AssetHelper::MeshHelper();
00372
00373 ar & *apcMeshes[i];
00374 }
00375
00376 }
00377
00378 template<class Archive>
00379 void AssetHelper::Vertex::serialize(Archive & ar, const unsigned int version)
00380 {
00381 ar & vPosition;
00382 ar & vNormal;
00383
00384 ar & dColorDiffuse;
00385 ar & vTangent;
00386 ar & vBitangent;
00387 ar & vTextureUV;
00388 ar & vTextureUV2;
00389
00390 ar & mBoneIndices[0];
00391 ar & mBoneIndices[1];
00392 ar & mBoneIndices[2];
00393 ar & mBoneIndices[3];
00394
00395 ar & mBoneWeights[0];
00396 ar & mBoneWeights[1];
00397 ar & mBoneWeights[2];
00398 ar & mBoneWeights[3];
00399 }
00400
00401
00402
00403 template<class Archive>
00404 void AssetHelper::MeshHelper::serialize(Archive & ar, const unsigned int version)
00405 {
00406
00407 ar & texturePathDiffuse;
00408 ar & texturePathDiffuse2;
00409 ar & texturePathSpecular;
00410 ar & texturePathAmbient;
00411 ar & texturePathEmissive;
00412 ar & texturePathNormal;
00413 ar & texturePathOpacity;
00414 ar & texturePathShininess;
00415
00416 ar & bHM;
00417 ar & fShininess;
00418 ar & fSpecularStrength;
00419 ar & fOpacity;
00420 ar & bSharedFX;
00421 ar & eShadingMode;
00422
00423 ar & vDiffuseColor;
00424 ar & vSpecularColor;
00425 ar & vEmissiveColor;
00426 ar & vAmbientColor;
00427
00428 ar & numFaces;
00429 ar & numVertices;
00430 ar & primitiveTypes;
00431
00432
00433 if (vertexBuffer == 0)
00434 vertexBuffer = new AssimpRendererD3d::AssetHelper::Vertex[numVertices];
00435
00436
00437 AssimpRendererD3d::AssetHelper::Vertex* pVertex = vertexBuffer;
00438 for (unsigned int i=0; i < numVertices; ++i)
00439 {
00440 ar & *pVertex;
00441 pVertex++;
00442 }
00443
00444
00445 ar & indexBufferLength;
00446
00447 if (indexBuffer == 0)
00448 {
00449 indexBuffer = new unsigned int[indexBufferLength];
00450 }
00451 unsigned int* pIndex = indexBuffer;
00452 for (unsigned int i=0; i < indexBufferLength; ++i)
00453 {
00454 ar & *pIndex;
00455 pIndex++;
00456 }
00457 }
00458
00459 }