IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

DirectX Discussion :

Directx10 et fichiers format .x


Sujet :

DirectX

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Mars 2006
    Messages : 143
    Par défaut Directx10 et fichiers format .x
    Bonjour,
    Je passe en DX10

    et je ne trouve pas d'exemples dans le SDK jun2010 de gestion de fichiers au format .x, ni de fonctions associées dans ID3DX10Mesh

    Le format '.x' est t-il toujours valide avec DX10 ? supporté par Microsoft ?
    Ne vont-il pas l'abandonner ?

    J'utilisais la fonction D3DXLoadMeshFromX(...) dans ma classe Mesh DX9.

    Est ce que je peux continuer à l'utiliser en DX10 sans problème de compatibilité sachant que cette fonction est définie dans d3dx9mesh .h ?

    Il faut choisir quoi comme format pour assurer la pérennité de l'application au niveau du format des mesh ?

  2. #2
    Membre extrêmement actif

    Profil pro
    Inscrit en
    Février 2006
    Messages
    2 401
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 2 401
    Par défaut
    microsoft a toujours conseillé de ne pas trop utilisé le format .x, ainsi que son successeur le .sdkmesh, la raison derrière tout ça c'est que même si ces formats sont pratiques pour jouer avec directx, ils sont incomplets et les boites de jeux vidéos ne l'utilisent jamais; ils utilisent des formats maison pour pouvoir protéger leurs modèles ainsi que les animations qui sont assez chers à produire.

    donc comme choix tu as la conversion des .x en .sdkmesh avec meshconvert (répertoire utilities) soit l'écriture d'un loader de .x en dx10.

    ps: un support des .x pour dx10 a l'air d'être inclus dans le nvsdk avec nvut

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Mars 2006
    Messages : 143
    Par défaut
    quel format libre préconises tu d'utiliser pour les mesh ?

    j'utilise 3DSMAX pour la génération

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Mars 2006
    Messages : 143
    Par défaut
    après avoir consulté le net,

    il apparait que le format .x soit très apprécié par les développeurs de jeu qui veulent un format libre

    les alternatives semblent les formats .obj et .fbx

    comme d'habitude, on change de version, il faut réécrire pour suivre

    Je finis par me demander si il n'y a pas une volonté de rendre difficile d'accès la programmation d'animations avec un format libre ?

    abandon de formats, pas de doc, pas de rétro-compatibilité, etc ...

    des avis ?

  5. #5
    Membre extrêmement actif

    Profil pro
    Inscrit en
    Février 2006
    Messages
    2 401
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 2 401
    Par défaut
    je vais être extrêmement pessimiste, il n'y a rien de valable en export depuis 3dsmax.

    je m'explique :

    - obj : beaucoup de limitation, pas d'animation.
    - 3ds : format vieillissant.
    - collada : format intéressant (mais lourd) sur le papier mais les différentes implémentations dans les logiciels de modélisation font que finalement ce format n'est pas facilement exploitable.
    - fbx : format sous la coupe d'autodesk, j'ai pas lu en détail les droits.
    - vrml : pas d'animation, jamais compris pourquoi il a été utilisé.

    le reste c'est de toute façon du "sans animation" et je n'en connais pas les droits.

    le plus facile serait surement de garder .x et d'écrire/utiliser un loader, il parait qu'il y en a en open source.

    je n'ai pas d'autre solution dans mes cartons.

    ps: pour répondre à ta question sur la volonté de restreindre la programmation d'animation, je dirai oui et non, les animations de personnages sont en majorité faite à base de motion capture, qui coute des millions, donc les studios protègent leurs modèles, et donc n'utilisent pas de formats ouverts.

    les seuls qui ouvrent c'est chez id-software, les formats .md? (.md2, .md3, .md5) sont bien documentés.

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Mars 2006
    Messages : 143
    Par défaut
    je vais étudier tout ça

    plusieurs mail semblent conforter ton avis, utiliser un loader maison à partie de fichiers .x.

    Si il y en a un open-source, tant mieux voila une bonne base de travail.

    Je vais regarder dans le SDK NVidia et sur le net

    Quel bordel quand même !

    merci pour tes réponses

  7. #7
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Mars 2006
    Messages : 143
    Par défaut
    aprés avoir cherché sur le net j'ai trouvé un article sur gamedev.net

    http://www.gamedev.net/community/for...ply_id=2747161

    permettant de convertir un mesh ID3DXMesh en ID3DX10Mesh

    j'ai donc écrit du code qui convertit un mesh DX9 en mesh DX10

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
     
     
    // basé sur le code : http://www.gamedev.net/community/forums/mod/journal/journal.asp?jn=316777&reply_id=2747161
    // Desc:convertit un ID3DXMesh (DX9) en ID3DX10Mesh (DX10)
    //-----------------------------
    #include "DXUT.h"
     
    #include <windows.h>
    #include <atlbase.h>				// pour COM
     
    #include <strsafe.h>
    #pragma warning( disable: 4996 )	// pas d'avertissements de fonctions obosolètes
     
    // include entêtes D3D10
    //--------------------------
    #include <d3d10.h>
    #include <d3dx10.h>
    #include <d3dx9.h>
     
    // macros
    #define WIDEN( w ) WIDEN2( w )
    #define WIDEN2( w )	L ##w
     
    #define INFO_OUT( text ) OutputDebugString( L"(INFO) : " WIDEN( __FUNCTION__ ) L"() - " text L"\n" )
    #define ERR_OUT( text ) OutputDebugString( L"(ERROR) : " WIDEN( __FUNCTION__ ) L"() - " text L"\n" )
    #define WARN_OUT( text ) OutputDebugString( L"(WARNING) : " WIDEN( __FUNCTION__ ) L"() - " text L"\n" )
     
    #ifndef SAFE_RELEASE
    #define SAFE_RELEASE( p ) {if(p){(p)->Release();(p)=NULL;}}
    #endif
    #ifndef SAFE_DELETE
    #define SAFE_DELETE( p ) {if(p){delete(p);(p)=NULL;}}
    #endif
    #ifndef SAFE_DELETE_ARRAY
    #define SAFE_DELETE_ARRAY( p ) {if(p){delete[](p);(p)=NULL;}}
    #endif
     
    void ComputeSizeAsString( WCHAR *wc, UINT wcLen, SIZE_T bytes );
     
     
    #include "MeshDX9ToDX10.h"
     
    namespace MeshConvert
    {
    	HRESULT			ConvertDeclaration( const D3DVERTEXELEMENT9 original[ MAX_FVF_DECL_SIZE ],
    	D3D10_INPUT_ELEMENT_DESC output[ MAX_FVF_DECL_SIZE ] );
    	LPCSTR			ConvertSemantic( const D3DDECLUSAGE& d3d9Form );
    	DXGI_FORMAT		ConvertDeclType( const D3DDECLTYPE& d3d9Form );
    	HRESULT			CopyIndexBufferData( ID3DXMesh* pMesh9, ID3DX10Mesh* pMesh10 );
    	HRESULT			CopyVertexBufferData( ID3DXMesh* pMesh9, ID3DX10Mesh* pMesh10 );
    	HRESULT			ConfigureAttributeTable( ID3DXMesh* pMesh9, ID3DX10Mesh* pMesh10 );
     
    	//-----------------------------------------------------------------------------
    	// Nom:	CreateD3DX10MeshFromD3DX9Mesh()
    	// Desc: créé un mesh DX10 depuis un mesh DX9, copie et convertit les infos du mesh DX9 vers un mesh DX10
    	// convertit déclaration, et sémantique des buffer, table d'attributs, copie vertex et index buffer
    	//-----------------------------------------------------------------------------
    	HRESULT CreateD3DX10MeshFromD3DX9Mesh( ID3DXMesh* pInMeshDX9, ID3DX10Mesh** pOutMesh10, ID3D10Device *pDevice )
    	{
    		// Check the parameters
    		if( (NULL == pInMeshDX9) || (NULL == pDevice) )
    		{
    			ERR_OUT( L"ERREUR !!! CreateD3DX10MeshFromD3DX9Mesh() un ou plusieurs paramètres sont NULL" );
    			return E_INVALIDARG;
    		}
     
     
    		// acquiert déclaration du mesh DX9
    		D3DVERTEXELEMENT9 OriginalDeclaration[ MAX_FVF_DECL_SIZE ];
    		if( FAILED( pInMeshDX9->GetDeclaration( OriginalDeclaration ) ) )
    		{
    			ERR_OUT( L"ERREUR !!! CreateD3DX10MeshFromD3DX9Mesh() ne peut obtenir la déclaration du mesh DX9" );
    			return E_FAIL;
    		}
    		else
    			INFO_OUT( L"CreateD3DX10MeshFromD3DX9Mesh() acquisition déclaration mesh D3DX9 OK" );
     
    		// convertit la déclaration du vertex buffer
    		D3D10_INPUT_ELEMENT_DESC NewDeclaration[ MAX_FVF_DECL_SIZE ];
    		ZeroMemory( NewDeclaration, sizeof( NewDeclaration ) );
     
    		if( FAILED( ConvertDeclaration( OriginalDeclaration, NewDeclaration ) ) )
    		{
    			ERR_OUT( L"ERREUR !!! CreateD3DX10MeshFromD3DX9Mesh() ne peut convertir la déclaration D3D9 en déclaration D3D10" );
    			return E_FAIL;
    		}
    		else
    			INFO_OUT( L"CreateD3DX10MeshFromD3DX9Mesh() conversion déclaration mesh D3DX9 OK" );
     
    		// calcule le nombre d'élements dans la déclaration DX9
    		UINT DeclSize = D3DXGetDeclLength( OriginalDeclaration );
     
    		// convertit les mesh options
    		UINT NewOptions = 0;
     
    		if( 0 != (pInMeshDX9->GetOptions() & D3DXMESH_32BIT) )	// indice en 32 bits, si ils ne le sont pas
    			NewOptions = D3DX10_MESH_32_BIT;
     
    		// créé le DX10 Mesh
    		if( FAILED( D3DX10CreateMesh( 
    			pDevice, 
    			NewDeclaration, 
    			DeclSize, 
    			"POSITION", 
    			pInMeshDX9->GetNumVertices(), 
    			pInMeshDX9->GetNumFaces(), 
    			NewOptions, 
    			pOutMesh10 
    			) ) )
    		{
    			ERR_OUT( L"ERREUR !!! CreateD3DX10MeshFromD3DX9Mesh() ne peut créér le ID3DX10Mesh object!" );
    			return E_FAIL;
    		}
    		else
    		{
    			INFO_OUT( L"CreateD3DX10MeshFromD3DX9Mesh(): Création D3DX10 mesh basé sur l'input du mesh DX9   OK" );
     
    			WCHAR wcMeshInfo[512];
    			StringCchPrintf( wcMeshInfo, 512,	L"(INFO) : D3DX10 mesh nb vertices: %d nb faces: %d \n",
    				(*pOutMesh10)->GetVertexCount(),
    				(*pOutMesh10)->GetFaceCount()
    				);
     
    			OutputDebugString( wcMeshInfo );
    		}
     
    		// copie mesh data D3D9 vers le mesh D3D10
    		if( FAILED( CopyIndexBufferData( pInMeshDX9, *pOutMesh10 ) ) )
    		{
    			ERR_OUT( L"ERREUR !!! CreateD3DX10MeshFromD3DX9Mesh() copie index buffer D3X9 mesh vers D3DX10 mesh." );
    			return E_FAIL;
    		}
    		else
    			INFO_OUT( L"CreateD3DX10MeshFromD3DX9Mesh() CopyIndexBufferData() mesh DX9 -> mesh DX10 OK" );
     
    		if( FAILED( CopyVertexBufferData( pInMeshDX9, *pOutMesh10 ) ) )
    		{
    			ERR_OUT( L"ERREUR CreateD3DX10MeshFromD3DX9Mesh() copie vertex vertex buffer de D3DX9 mesh vers D3DX10 mesh échoué" );
    			return E_FAIL;
    		}
    		else
    			INFO_OUT( L"CreateD3DX10MeshFromD3DX9Mesh() CopyVertexBufferData() mesh DX9 -> mesh DX10 OK" );
     
     
    		// table d'attributs
    		if( FAILED( ConfigureAttributeTable( pInMeshDX9, *pOutMesh10 ) ) )
    		{
    			ERR_OUT( L"ERREUR !!! CreateD3DX10MeshFromD3DX9Mesh() configuration table d'attributs pour le nouveau mesh DX10 échouée" );
    			return E_FAIL;
    		}
    		else
    			INFO_OUT( L"CreateD3DX10MeshFromD3DX9Mesh() ConfigureAttributeTable() mesh DX9 -> mesh DX10 OK" );
     
    		// génére la table d'adjacence
    		if( FAILED( (*pOutMesh10)->GenerateAdjacencyAndPointReps( 0.0f ) ) )
    		{
    			ERR_OUT( L"ERREUR !!! CreateD3DX10MeshFromD3DX9Mesh() génération du buffer d'adajcence D3DX10 mesh échoué" );
    			return E_FAIL;
    		}
    		else
    			INFO_OUT( L"CreateD3DX10MeshFromD3DX9Mesh() GenerateAdjacencyAndPointReps()  mesh DX10 OK" );
     
     
    		// optimise le mesh
    		if( FAILED( (*pOutMesh10)->Optimize( D3DX10_MESHOPT_COMPACT | D3DX10_MESHOPT_ATTR_SORT | D3DX10_MESHOPT_VERTEX_CACHE, NULL, NULL ) ) )
    		{
    			ERR_OUT( L"ERREUR !!! CreateD3DX10MeshFromD3DX9Mesh() optimisation mesh (compact, attribute sort, vertex cache) échoué" );
    			return E_FAIL;
    		}
    		else
    			INFO_OUT( L"CreateD3DX10MeshFromD3DX9Mesh() Optimize()  mesh DX10 OK" );
     
     
    		INFO_OUT( L"CreateD3DX10MeshFromD3DX9Mesh() création D3DX10 mesh depuis D3DX9 mesh OK" );
     
    		return S_OK;
    	}
     
    	//-----------------------------------------------------------------------------
    	// Nom:	ConvertDeclaration()
    	// Desc: convertit la déclaration de format du vertex buffer mesh DX9 vers mesh DX10
    	//-----------------------------------------------------------------------------
    	HRESULT ConvertDeclaration( const D3DVERTEXELEMENT9 original[ MAX_FVF_DECL_SIZE ], D3D10_INPUT_ELEMENT_DESC output[ MAX_FVF_DECL_SIZE ] )
    	{
    		for( UINT i = 0; i < D3DXGetDeclLength( original ); ++i )
    		{
    			// Convert this element
    			output[i].SemanticName			= ConvertSemantic( static_cast< D3DDECLUSAGE >( original[i].Usage ) );
    			output[i].SemanticIndex			= original[i].UsageIndex;
    			output[i].AlignedByteOffset		= original[i].Offset;
    			output[i].InputSlot				= original[i].Stream;
    			output[i].InputSlotClass		= D3D10_INPUT_PER_VERTEX_DATA;
    			output[i].InstanceDataStepRate	= 0;
    			output[i].Format				= ConvertDeclType( static_cast< D3DDECLTYPE >( original[i].Type ) );
    		}
     
    		return S_OK;
    	}
     
     
    	//---------------------------------------------------------------------------------------------------
    	// Nom:	CopyIndexBufferData()
    	// Desc: convertit semantique de description de vertex buffer layout , depuis mesh DX9 vers mesh DX10
    	//----------------------------------------------------------------------------------------------------
    	LPCSTR ConvertSemantic( const D3DDECLUSAGE& d3d9Form )
    	{
    		switch( d3d9Form )
    		{
    		case D3DDECLUSAGE_POSITION:				return "POSITION";
    		case D3DDECLUSAGE_BLENDWEIGHT:			return "BLENDWEIGHT";
    		case D3DDECLUSAGE_BLENDINDICES:			return "BLENDINDICES";
    		case D3DDECLUSAGE_NORMAL:				return "NORMAL";
    		case D3DDECLUSAGE_PSIZE:				return "PSIZE";
    		case D3DDECLUSAGE_TEXCOORD:				return "TEXCOORD";
    		case D3DDECLUSAGE_TANGENT:				return "TANGENT";
    		case D3DDECLUSAGE_BINORMAL:				return "BINORMAL";
    		case D3DDECLUSAGE_TESSFACTOR:			return "TESSFACTOR";
    		case D3DDECLUSAGE_POSITIONT:			return "POSITIONT";
    		case D3DDECLUSAGE_COLOR:				return "COLOR";
    		case D3DDECLUSAGE_FOG:					return "FOG";
    		case D3DDECLUSAGE_DEPTH:				return "DEPTH";
    		case D3DDECLUSAGE_SAMPLE:				return "SAMPLE";
    		default:								return "UNKNOWN";
    		}
    	}
     
    	//---------------------------------------------------------------------------------------------------
    	// Nom:	ConvertDeclType()
    	// Desc: convertit le type de la déclaration, depuis mesh DX9 vers mesh DX10
    	//----------------------------------------------------------------------------------------------------
    	DXGI_FORMAT	ConvertDeclType( const D3DDECLTYPE& d3d9Form )
    	{
    		switch( d3d9Form )
    		{
    		case D3DDECLTYPE_FLOAT1:				return DXGI_FORMAT_R32_FLOAT;
    		case D3DDECLTYPE_FLOAT2:				return DXGI_FORMAT_R32G32_FLOAT;
    		case D3DDECLTYPE_FLOAT3:				return DXGI_FORMAT_R32G32B32_FLOAT;
    		case D3DDECLTYPE_FLOAT4:				return DXGI_FORMAT_R32G32B32A32_FLOAT;
    		case D3DDECLTYPE_D3DCOLOR:				return DXGI_FORMAT_R8G8B8A8_UNORM;
    		case D3DDECLTYPE_UBYTE4:				return DXGI_FORMAT_R8G8B8A8_UINT;
    		case D3DDECLTYPE_SHORT2:				return DXGI_FORMAT_R16G16_SINT;
    		case D3DDECLTYPE_SHORT4:				return DXGI_FORMAT_R16G16B16A16_SINT;
    		case D3DDECLTYPE_UBYTE4N:				return DXGI_FORMAT_R8G8B8A8_UNORM;
    		case D3DDECLTYPE_SHORT2N:				return DXGI_FORMAT_R16G16_SNORM;
    		case D3DDECLTYPE_SHORT4N:				return DXGI_FORMAT_R16G16B16A16_SNORM;
    		case D3DDECLTYPE_USHORT2N:				return DXGI_FORMAT_R16G16_UNORM;
    		case D3DDECLTYPE_USHORT4N:				return DXGI_FORMAT_R16G16B16A16_UNORM;
    		case D3DDECLTYPE_UDEC3:					return DXGI_FORMAT_R10G10B10A2_UINT;
    		case D3DDECLTYPE_DEC3N:					return DXGI_FORMAT_R10G10B10A2_UNORM;
    		case D3DDECLTYPE_FLOAT16_2:				return DXGI_FORMAT_R16G16_FLOAT;
    		case D3DDECLTYPE_FLOAT16_4:				return DXGI_FORMAT_R16G16B16A16_FLOAT;
     
    		case D3DDECLTYPE_UNUSED:
    		default:								return DXGI_FORMAT_UNKNOWN;
    		}
    	}
     
    	//-----------------------------------------------------------------------------
    	// Nom:	CopyIndexBufferData()
    	// Desc: copie index buffer mesh DX9 vers mesh DX10
    	//-----------------------------------------------------------------------------
    		HRESULT CopyIndexBufferData( ID3DXMesh* pMesh9, ID3DX10Mesh* pMesh10 )
    	{
    		// verify inputs
    		if( (NULL == pMesh9) || (NULL == pMesh10) )
    		{
    			ERR_OUT( L"les 2 mesh d'input doivent être non-NULL." );
     
    			return E_INVALIDARG;
    		}
     
    		CComPtr< ID3DX10MeshBuffer > pIBuffer10;
     
    		if( FAILED( pMesh10->GetIndexBuffer( &pIBuffer10 ) ) )
    		{
    			ERR_OUT( L"ERREUR !!!  acquisition D3DX10 mesh index buffer." );
     
    			return E_FAIL;
    		}
     
    		// switch depending on 16 or 32 bit indices..
    		if( 0 != (pMesh10->GetFlags() & D3DX10_MESH_32_BIT) )
    		{
    			INFO_OUT( L"INFO: les indices ne sont pas en  32 bit form, conversion des indices..." );
     
    			// vetification taille index buffer prévue
    			if( pIBuffer10->GetSize() != (pMesh10->GetFaceCount() * 3 * sizeof( unsigned __int32 ) ) )
    			{
    				ERR_OUT( L"ERREUR !!! le nombre de bytes de l'index buffer ne correspond pas à la taille attendue!" );
    				return E_FAIL;
    			}
     
    			SIZE_T stRawIndices10 = 0;
    			unsigned __int32 *pRawIndices10 = NULL;
     
    			if( SUCCEEDED( pIBuffer10->Map( reinterpret_cast< void** >( &pRawIndices10 ), &stRawIndices10 ) ) )
    			{
    				// verrouillage buffers pour la copie
    				unsigned __int32 *pRawIndices9 = NULL;
    				if( SUCCEEDED( pMesh9->LockIndexBuffer( 0, reinterpret_cast< LPVOID* >( &pRawIndices9 ) ) ) )
    				{
    					memcpy_s(	pRawIndices10, 
    						stRawIndices10, 
    						pRawIndices9, 
    						pMesh9->GetNumFaces() * 3 * sizeof( unsigned __int32 ) 
    						);
     
    					// Tidy up
    					pMesh9->UnlockIndexBuffer( );
    				}
    				else
    				{
    					ERR_OUT( L"ERREUR !!! impossible de verrouiller le D3DX9 mesh index buffer!" );
    					pIBuffer10->Unmap(); // libération buffer
    					return E_FAIL;
    				}
     
    				// // libération buffer
    				pIBuffer10->Unmap( );
    			}
    			else
    			{
    				ERR_OUT( L"ERREUR !!! Map() D3DX10 index buffer!" );
    				return E_FAIL;
    			}
    		}
    		else
    		{
    			INFO_OUT( L"INFO: conversion des indices 16 bits..." );
     
    			if( pIBuffer10->GetSize() != (pMesh10->GetFaceCount() * 3 * sizeof( unsigned __int16 ) ) )
    			{
    				ERR_OUT( L"ERREUR !!! erreur taille prévue indice buffer !" );
    				return E_FAIL;
    			}
     
    			SIZE_T stRawIndices10 = 0;
    			unsigned __int16 *pRawIndices10 = NULL;
     
    			if( SUCCEEDED( pIBuffer10->Map( reinterpret_cast< void** >( &pRawIndices10 ), &stRawIndices10 ) ) )
    			{
    				// verrouillage index buffer
    				unsigned __int16 *pRawIndices9 = NULL;
    				if( SUCCEEDED( pMesh9->LockIndexBuffer( 0, reinterpret_cast< LPVOID* >( &pRawIndices9 ) ) ) )
    				{
    					memcpy_s(	pRawIndices10, 
    						stRawIndices10, 
    						pRawIndices9, 
    						pMesh9->GetNumFaces() * 3 * sizeof( unsigned __int16 ) 
    						);
     
    					// libération
    					pMesh9->UnlockIndexBuffer( );
    				}
    				else
    				{
    					ERR_OUT( L"ERREUR !!! impossible de verrouiller le D3DX9 mesh index buffer!" );
    					pIBuffer10->Unmap( );
    					return E_FAIL;
    				}
     
    				// libération
    				pIBuffer10->Unmap( );
    			}
    			else
    			{
    				ERR_OUT( L"ERREUR !!! Map() D3DX10 index buffer!" );
    				return E_FAIL;
    			}
    		}
     
     
    		return S_OK;
    	}
     
     
    	//-----------------------------------------------------------------------------
    	// Nom:	CopyVertexBufferData()
    	// Desc: copie vertex buffer mesh DX9 vers mesh DX10 vertexbuffer[0]
    	//-----------------------------------------------------------------------------
    	HRESULT CopyVertexBufferData( ID3DXMesh* pMesh9, ID3DX10Mesh* pMesh10 )
    	{
    		if( (NULL == pMesh9) || (NULL == pMesh10) )
    		{
    			ERR_OUT( L"ERREUR !!! pointeur mesh(es) non valide(s) !" );
    			return E_INVALIDARG;
    		}
     
    		// les D3DX10 meshes peuvent avoir de multiples VB, 1 seul pour les mesh D3DX9
    		if( 1 != pMesh10->GetVertexBufferCount( ) )
    		{
    			ERR_OUT( L"ERREUR !!! le D3DX10 mesh a plus d'un vertex buffer." );
     
    			return E_FAIL;
    		}
     
    		// acquiert le  vb du mesh DX10
    		CComPtr< ID3DX10MeshBuffer > pVBuffer10;
    		if( SUCCEEDED( pMesh10->GetVertexBuffer( 0, &pVBuffer10 ) ) )
    		{
    			SIZE_T stRawVertices10 = 0;
    			unsigned __int8 *pRawVertices10 = NULL;
     
    			if( SUCCEEDED( pVBuffer10->Map( reinterpret_cast< void** >( &pRawVertices10 ), &stRawVertices10 ) ) )
    			{
    				// verrouillage et copie VB9 vers VB10
    				unsigned __int8 *pRawVertices9 = NULL;
    				if( SUCCEEDED( pMesh9->LockVertexBuffer( 0, reinterpret_cast< LPVOID* >( &pRawVertices9 ) ) ) )
    				{
    					memcpy_s(
    						pRawVertices10,
    						stRawVertices10,
    						pRawVertices9,
    						pMesh9->GetNumBytesPerVertex() * pMesh9->GetNumVertices()
    						);
     
    					pMesh9->UnlockVertexBuffer( );
    				}
    				else
    				{
    					ERR_OUT( L"ERREUR !!! verrouillage D3DX9 mesh vertex buffer échoué!" );
    					pVBuffer10->Unmap( );
    					return E_FAIL;
    				}
     
    				pVBuffer10->Unmap( );
    			}
    			else
    			{
    				ERR_OUT( L"ERREUR !!! verrouillage VB10 Map()" );
    				return E_FAIL;
    			}
    		}
    		else
    		{
    			ERR_OUT( L"ERREUR !!! acquisition D3DX10 mesh vertex buffer échouée!" );
    			return E_FAIL;
    		}
     
    		return S_OK;
    	}
     
    	//-----------------------------------------------------------------------------
    	// Nom:	ConfigureAttributeTable()
    	// Desc: convertit table d'attributs mesh DX9 vers mesh DX10
    	//-----------------------------------------------------------------------------
    	HRESULT ConfigureAttributeTable( ID3DXMesh* pMesh9, ID3DX10Mesh* pMesh10 )
    	{
    		// verify inputs
    		if( (NULL == pMesh9) || (NULL == pMesh10) )
    		{
    			ERR_OUT( L"ERREUR !!! pointeur mesh(es) non valide(s) !" );
    			return E_INVALIDARG;
    		}
     
    		DWORD dwInputTableSize = 0;
     
    		if( FAILED( pMesh9->GetAttributeTable( NULL, &dwInputTableSize ) ) )
    		{
    			ERR_OUT( L"ERREUR !!! impossible d'acquérir la table d'attributs mesh DX9" );
    			return E_FAIL;
    		}
     
    		if( 0 == dwInputTableSize )
    		{
    			// The incoming mesh doesn't have an attribute table
    			INFO_OUT( L"table d'attributs D3DX9 mesh vide, création d'une table par défaut" );
     
    			D3DX10_ATTRIBUTE_RANGE defTable;
    			defTable.AttribId		= 0;
    			defTable.FaceCount		= pMesh10->GetFaceCount( );
    			defTable.FaceStart		= 0;
    			defTable.VertexCount	= pMesh10->GetVertexCount( );
    			defTable.VertexStart	= 0;
     
    			if( FAILED( pMesh10->SetAttributeTable( &defTable, 1 ) ) )
    			{
    				ERR_OUT( L"ERREUR !!! impossible de stocker la table d'attributs dans le mesh D3DX10" );
    				return E_FAIL;
    			}
    		}
    		else
    		{
    			D3DXATTRIBUTERANGE *pInputAttrTable = new D3DXATTRIBUTERANGE[ dwInputTableSize ];
    			if( FAILED( pMesh9->GetAttributeTable( pInputAttrTable, &dwInputTableSize ) ) )
    			{
    				ERR_OUT( L"ERREUR !!! impossible d'acquérir la table d'attributs mesh DX9" );
    				SAFE_DELETE_ARRAY( pInputAttrTable );
    				return E_FAIL;
    			}
     
    			D3DX10_ATTRIBUTE_RANGE *pNewAttrTable = new D3DX10_ATTRIBUTE_RANGE[ dwInputTableSize ];
     
    			for( DWORD i = 0; i < dwInputTableSize; ++i )
    			{
    				pNewAttrTable[i].AttribId		= pInputAttrTable[i].AttribId;
    				pNewAttrTable[i].FaceCount		= pInputAttrTable[i].FaceCount;
    				pNewAttrTable[i].FaceStart		= pInputAttrTable[i].FaceStart;
    				pNewAttrTable[i].VertexCount	= pInputAttrTable[i].VertexCount;
    				pNewAttrTable[i].VertexStart	= pInputAttrTable[i].VertexStart;
    			}
    			SAFE_DELETE_ARRAY( pInputAttrTable );
     
    			if( FAILED( pMesh10->SetAttributeTable( pNewAttrTable, static_cast< UINT >( dwInputTableSize ) ) ) )
    			{
    				ERR_OUT( L"ERREUR !!! impossible de copier la table d'attributs depuis le mesh DX9" );
    				SAFE_DELETE_ARRAY( pNewAttrTable );
    				return E_FAIL;
    			}
    			SAFE_DELETE_ARRAY( pNewAttrTable );
    		}
     
    		// créé la table d'attributs du mesh DX10
    		if( FAILED( pMesh10->GenerateAttributeBufferFromTable( ) ) )
    		{
    			ERR_OUT( L"ERREUR !!! impossible de générer la table d'attributs DX10 depuis la table DX9" );
    			return E_FAIL;
    		}
     
    		return S_OK;
    	}
    	//-----------------------------------------------------------------------------
     
     
    }; // fin de namespace
    tout semble Ok, mais quand je veux mapper l'entrée de l'indice buffer avant de dessiner le mesh, j'obtient une erreur de corruption d'index buffer

    D3D10: CORRUPTION: ID3D10Device::IASetIndexBuffer: First parameter is corrupt. [ MISCELLANEOUS CORRUPTION #13: CORRUPTED_PARAMETER1 ]
    D3D10: **BREAK** enabled for the previous D3D10 message, which was: [ MISCELLANEOUS CORRUPTION #13: CORRUPTED_PARAMETER1 ]

    voici le code concerné :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
     
    	HRESULT hr = E_FAIL;
     
     
    	// définit l'input layout shader
        const D3D10_INPUT_ELEMENT_DESC descMeshLayout[] =
        {
            { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
            { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
            { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        };
        UINT iNBElements = sizeof( descMeshLayout ) / sizeof( descMeshLayout[0] );
     
        // créé le input layout
        D3D10_PASS_DESC PassDesc;
        g_pTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc );
        VerifHR( pd3dDevice->CreateInputLayout( 
    		descMeshLayout, 
    		iNBElements, 
    		PassDesc.pIAInputSignature,
            PassDesc.IAInputSignatureSize, 
    		&g_pMeshVertexLayout 
    		) );
     
    	if ( hr == S_OK )
    		OutputDebugString( TEXT("g_pMeshVertexLayout création OK \n") );
     
        // map le input layout au shader
        pd3dDevice->IASetInputLayout( g_pMeshVertexLayout);
     
    	// fixe les variables du shader
    	g_pDiffuseVariable->SetResource( g_pBackgroundRV );
     
        // obtient la technique du shader    
    	// obtient les variables du shader
        g_pTechnique = g_pSimpleMeshEffect->GetTechniqueByName( "RenduMesh" );									// nom de la technique
        g_pWorldVariable = g_pSimpleMeshEffect->GetVariableByName( "matWorld" )->AsMatrix();					// matrice du monde
        g_pViewVariable = g_pSimpleMeshEffect->GetVariableByName( "matView" )->AsMatrix();						// matrice de vue
        g_pProjectionVariable = g_pSimpleMeshEffect->GetVariableByName( "matProj" )->AsMatrix();				// matrice de projection
        g_pMeshColorVariable = g_pSimpleMeshEffect->GetVariableByName( "vMeshColor" )->AsVector();				// correcteur couleur mesh
        g_pDiffuseVariable = g_pSimpleMeshEffect->GetVariableByName( "txDiffuse" )->AsShaderResource();			// couleur diffuse
    	g_fShaderContrastVariable = g_pSimpleMeshEffect->GetVariableByName( "vShaderContrast" )->AsScalar();		// contaste shader
    	g_fShaderBrightnessVariable = g_pSimpleMeshEffect->GetVariableByName( "vShaderBrightness" )->AsScalar();	// luminosité shader
     
    	VerifHR( g_fShaderContrastVariable->SetFloat( g_fShaderContrast ) );			// assigne valeur contraste shader
    	VerifHR( g_fShaderBrightnessVariable->SetFloat( g_fShaderBrightness ) );		// assigne valeur luminosité shader
     
     
    	// fixe les entrées du shader
     
    	// vertex buffer
        UINT Strides[1];
        UINT Offsets[1];
        ID3D10Buffer* pMeshVB[1];
      	VerifHR( pMeshDX10->GetVertexBuffer( 0, (ID3DX10MeshBuffer**)&pMeshVB ) );	// acquiert VB[0] du mesh
    	if ( hr == S_OK )
    		OutputDebugString( TEXT("pMeshDX10->GetVertexBuffer() OK \n") );
     
    	ID3DX10MeshBuffer* pVB0 = (ID3DX10MeshBuffer*) pMeshVB[0];	// acquiert VB 0 du mesh
    	int iBufferCount = pMeshDX10->GetVertexBufferCount();		// nombre de buffers dans le mesh
    	int iNbVertex = pMeshDX10->GetVertexCount();				// nombre de vertices
    	int iMeshBufferSize = pVB0->GetSize();						// taille du vb
     
    	Strides[0] = iMeshBufferSize / iNbVertex;					// calcul stride
    	Offsets[0] = 0;
    	pd3dDevice->IASetVertexBuffers( 0, 1,  &pMeshVB[0], Strides, Offsets );						// bind vertex buffer
     
     
     
     
    	// index buffer
    	ID3D10Buffer* pIB10[1];
    	VerifHR( pMeshDX10->GetIndexBuffer( (ID3DX10MeshBuffer**)&pIB10) );
    	if ( hr == S_OK )
    		OutputDebugString( TEXT("pMeshDX10->GetIndexBuffer() OK \n") );
     
    	int iNbIndices = ( (ID3DX10MeshBuffer*)pIB10[0])->GetSize();
     
    	// bind index buffer	
    	pd3dDevice->IASetIndexBuffer( 
    		(ID3D10Buffer*)&pIB10[0],
    		DXGI_FORMAT_R32_UINT,
    		0 
    		);
    dans l'exemple du tutorial11
    dans CDXUTMesh::CreateFromMemory( ID3D10Device* pDev10,
    IDirect3DDevice9* pDev9,
    BYTE* pData,
    UINT DataBytes,
    bool bCreateAdjacencyIndices,
    bool bCopyStatic,
    SDKMESH_CALLBACKS10* pLoaderCallbacks10,
    SDKMESH_CALLBACKS9* pLoaderCallbacks9 )

    il font un bricolage sur les indices :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
     
           //BYTE* pIndices = NULL;
                //m_ppIndices[i]
                UINT *ind = ( UINT * )m_ppIndices[currentMesh->IndexBuffer];
                FLOAT *verts =  ( FLOAT* )m_ppVertices[currentMesh->VertexBuffers[0]];
                UINT stride = (UINT)m_pVertexBufferArray[currentMesh->VertexBuffers[0]].StrideBytes;
                assert (stride % 4 == 0);
                stride /=4;
                for (UINT vertind = IndexStart; vertind < IndexStart + IndexCount; ++vertind) {
                    UINT current_ind=0;
                    if (indsize == 2) {
                        UINT ind_div2 = vertind / 2;
                        current_ind = ind[ind_div2];
                        if (vertind %2 ==0) {
                            current_ind = current_ind << 16;
                            current_ind = current_ind >> 16;
                        }else {
                            current_ind = current_ind >> 16;
                        }
                    }else {
                        current_ind = ind[vertind];
                    }
                    tris++;
                    D3DXVECTOR3 *pt = (D3DXVECTOR3*)&(verts[stride * current_ind]);
                    if (pt->x < lower.x) {
                        lower.x = pt->x;
                    }
                    if (pt->y < lower.y) {
                        lower.y = pt->y;
                    }
                    if (pt->z < lower.z) {
                        lower.z = pt->z;
                    }
                    if (pt->x > upper.x) {
                        upper.x = pt->x;
                    }
                    if (pt->y > upper.y) {
                        upper.y = pt->y;
                    }
                    if (pt->z > upper.z) {
                        upper.z = pt->z;
                    }
                    //BYTE** m_ppVertices;
                    //BYTE** m_ppIndices;
                }
                //pd3dDeviceContext->DrawIndexed( IndexCount, IndexStart, VertexStart );
            }
    est ce que mon problème peut venir de là ?

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 15/01/2007, 21h33
  2. Ifstream > Lecture d'un fichier > Format
    Par Zenol dans le forum SL & STL
    Réponses: 15
    Dernier message: 19/12/2005, 11h04
  3. Lecture simple de fichiers formatés
    Par enicnath dans le forum Général Python
    Réponses: 4
    Dernier message: 10/10/2005, 14h44
  4. lecture simple de fichiers formatés
    Par enicnath dans le forum Langage
    Réponses: 7
    Dernier message: 06/10/2005, 18h06
  5. Lire un fichier format dos
    Par Roma dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 24/05/2005, 17h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo