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

API graphiques Discussion :

Besoin d'aide avec Cal3D


Sujet :

API graphiques

  1. #1
    Membre averti Avatar de yodaime
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2006
    Messages
    282
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2006
    Messages : 282
    Points : 340
    Points
    340
    Par défaut Besoin d'aide avec Cal3D
    Bonjour,

    J'ai décidé de me lancé dans l'animation squelettale et pour cela j'ai choisi la bibliothèque Cal3D.

    Première question : pensez vous que se soit un bon choix ?

    Deuxième question : est ce que quelqu'un pourrait m'aider pour compiler Cal3D et ensuite l'utiliser ?

    Je pense avoir réussi à la compiler mais je ne sais pas trop ce que l'on doit obtenir et surtout ce que l'on doit en faire.

    Merci d'avance pour votre aide.

  2. #2
    Rédacteur
    Avatar de Laurent Gomila
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2003
    Messages
    10 651
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2003
    Messages : 10 651
    Points : 15 920
    Points
    15 920
    Par défaut
    1. C'était un bon choix il y a quelques années, maintenant je ne sais pas si la bibliothèque est toujours d'actualité mais je pense que oui. En tout cas je pense qu'elle est un très bon moyen de démarrer les animations squelettales, car c'est vraiment pas facile à gérer lorsqu'on débarque.

    2. Tu n'as pas trouvé de tutoriels ? Je crois me souvenir qu'elle est livrée avec un SDK assez riche en doc et en exemples.

  3. #3
    Rédacteur
    Avatar de bafman
    Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    2 574
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Novembre 2003
    Messages : 2 574
    Points : 5 323
    Points
    5 323
    Par défaut
    la dernière fois que je l'ai essayé, c'était un joyeux bordel pour réussir à la compiler, et tous les plugins d'export étaient pour des version antérieurs, donc perso, j'ai été assez déçu...
    * Il est infiniment plus simple de faire rapidement un code qui marche que de faire un code rapide qui marche
    * pour faciliter les recherches, n'oubliez pas de voter pour les réponses pertinentes
    Mes articles

  4. #4
    Membre averti Avatar de yodaime
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2006
    Messages
    282
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2006
    Messages : 282
    Points : 340
    Points
    340
    Par défaut
    Bonjour,

    1- Que me conseillerais tu d'autre pour faire de l'animation squelettale ?

    2- Le seul tuto que j'ai vu c'est un tuto pour modeliser un perso avec 3ds max et ensuite l'exporter au format Cal3d. Pas vu de SDK non plus. Je vais chercher.

    Sinon personne pour me dire ce que l'on doit obtenir une fois compilé ?

    Merci d'avance.

  5. #5
    Rédacteur
    Avatar de Laurent Gomila
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2003
    Messages
    10 651
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2003
    Messages : 10 651
    Points : 15 920
    Points
    15 920
    Par défaut
    Personnellement je ne connais pas d'autres bibliothèques de ce genre, mais ça fait un moment que je ne m'y suis pas intéressé de près.

    Sinon personne pour me dire ce que l'on doit obtenir une fois compilé ?
    Ben ça dépend de comment tu la compiles, mais soit une .DLL et un .LIB (bibliothèque dynamique), soit juste un .LIB (bibliothèque statique).
    Tu as déjà utilisé une bibliothèque ?

  6. #6
    Membre averti Avatar de yodaime
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2006
    Messages
    282
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2006
    Messages : 282
    Points : 340
    Points
    340
    Par défaut
    Ok, donc j'ai bien la lib et la dll.

    Tu as déjà utilisé une bibliothèque ?
    Je t'avouerai que non. Je sais juste qu'il faut ajouter la lib et la dll a mon projet ainsi que le header cal3d.h pour que cela marche.

  7. #7
    Membre averti Avatar de yodaime
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2006
    Messages
    282
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2006
    Messages : 282
    Points : 340
    Points
    340
    Par défaut
    Bonjour !

    Bon ben finalement j'ai reussi a la compiler avec Visual et Devcpp.

    J'ai commenceé à coder en m'aidant du user guide de Cal3D et aussi du code du miniviewer Cal3D ( disponible sur leur site ) qui permet de voir un modele que l'on a exporter à partir d'un logiciel de modélisation 3D.

    J'arrive pas encore à afficher un personnage animer, juste les différents points du squelette.

    Bref j'ai encore pas mal de boulot et je me rend compte qu'il va falloir que je bosse l'OpenGL.

    En tout cas merci à tous !

    Je ferme pas le post je viendrai donner des nouvelles et je pense que j'aurai d'autre question.

    PS : Si quelqu'un a un bon tuto, un bout de code ou un peu d'aide à donner sur Cal3D, je suis prenneur et je l'en remercie d'avance.

  8. #8
    Membre averti Avatar de yodaime
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2006
    Messages
    282
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2006
    Messages : 282
    Points : 340
    Points
    340
    Par défaut
    Bonjour !

    Comme promis je reviens vers vous.

    J'ai un drole de problème. J'essaye d'afficher un modele statique avec Cal3D ( cally, celui fournit sur le site ).

    J'arrive a loader le squelette et a l'afficher.

    Ensuite, j'ai loader les mesh et que je les ai attaché puis j'essaye d'afficher mon modele en utilisant la fonction renderModel fournit dans le code du miniviewer.

    Le problème est qu'il ne m'affiche que la queue de cheval du personnage et rien d'autre !

    Je vois pas d'ou vient le problème cependant je pencherai pour un problème d'affichage au niveau d'OpenGL

    Voici ce que j'obtient ( les fils blanc c'est juste que je relie les différents points du squelette ) :



    voici ce que je devrait obtenir :



    et enfin voici mon code :
    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
     
    #include <stdlib.h>
    #include <stdio.h>
    #include <cstdlib>
    #include <SDL/SDL.h>
    #include <SDL/SDL_image.h>
    #include <GL/gl.h>
    #include <GL/glu.h>
    #include "Cal3D/cal3d.h"
    #include <cstdlib>
    #include "sdlglutils.h"
     
    void Dessiner();
    void pause();
     
    bool meshLoad() ;
    bool meshAttach( CalModel & ) ;
    void renderModel( CalModel &m_calModel ) ;
     
    CalCoreModel Personnage("mon_perso");
    int cally_calf_leftID     ;
    int cally_calf_rightID    ;
    int cally_chesID          ;
    int cally_foot_leftID     ;
    int cally_foot_rightID    ;
    int cally_hand_leftID     ;
    int cally_hand_rightID    ;
    int cally_headID          ;
    int cally_lowerarm_leftID ;
    int cally_lowerarm_rightID;
    int cally_neckID          ;
    int cally_pelvisID        ;
    int cally_ponytailID      ;
    int cally_thigh_leftID    ;
    int cally_thigh_rightID   ;
    int cally_upperarm_leftID ;
    int cally_upperarm_rightID;
     
    int m_vertexCount = 0;
    int m_faceCount = 0;
     
     
    int main(int argc, char *argv[])
    {
        /**********************************/
        /****    Initialisation SDL    ****/
        /**********************************/
        SDL_Event event;
        SDL_Init(SDL_INIT_VIDEO);
        atexit(SDL_Quit);
        SDL_WM_SetCaption("Test Cal3D", NULL);
        SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
     
     
        //---------------------------------------------------------------------------------------------------
     
        /*************************************/
        /****    Initialisation OpenGL    ****/
        /*************************************/    
     
        // clear all the buffers
        glClearColor(0.5f, 0.25f, 0.25f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
        // set the projection transformation
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0f, (double)640/480, 50, 1000.0);
     
        // set the model transformation
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
     
        // light attributes
        const GLfloat light_ambient[]  = { 0.3f, 0.3f, 0.3f, 1.0f };
        const GLfloat light_diffuse[]  = { 0.52f, 0.5f, 0.5f, 1.0f };
        const GLfloat light_specular[] = { 0.1f, 0.1f, 0.1f, 1.0f };
     
        // setup the light attributes
        glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
        glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
        glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
     
        // set the light position
        GLfloat lightPosition[] = { 0.0f, -1.0f, 1.0f, 1.0f };
        glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
     
        // set camera position
        glTranslatef(0.0f, 0.0f, -270 * 1);
        glRotatef(-70.0f, 1.0f, 0.0f, 0.0f);
        glRotatef(-45.0f, 0.0f, 0.0f, 1.0f);
        glTranslatef(0.0f, 0.0f, -90.0f * 1);
     
        //---------------------------------------------------------------------------------------------------
     
        /************************************/
        /****    Initialisation Cal3D    ****/
        /************************************/ 
     
        //On load le squelette
        std::cout << "Loading skeleton\n" ;
        if(!Personnage.loadCoreSkeleton("squelette\\cally.csf"))
        {
            CalError::printLastError();
            return false;
        }
     
        //On load les mesh
        if( meshLoad() == false )
        {
            std::cout << "Erreur lors du load des mesh !" << std::endl ;
            return false ;
        }
     
        //---------------------------------------------------------------------------------------------------
     
        Dessiner();
     
        pause();
     
        return 0;
    }
     
    void Dessiner()
    {
     
         /*-----------------------------------------------*/
         //Dessin du repere
     
         glBegin(GL_TRIANGLES);
         glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 5.0f, 0.0f);
         glVertex3f(50.0f, 0.0f, 0.0f);
         glVertex3f(0.0f, -5.0f, 0.0f);
     
         glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 5.0f);
         glVertex3f(0.0f, 50.0f, 0.0f);
         glVertex3f(0.0f, 0.0f, -5.0f);
     
         glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
         glVertex3f(5.0f, 0.0f, 0.0f);
         glVertex3f(0.0f, 0.0f, 50.0f);
         glVertex3f(-5.0f, 0.0f, 0.0f);
         glEnd();
     
         /*-----------------------------------------------*/
         //Création du modèle
     
         CalModel m_calModel(&Personnage) ;
     
         /*-----------------------------------------------*/
         //On atache les mesh
     
         meshAttach(m_calModel) ;
         //int meshId;
         //for(meshId = 0; meshId < Personnage.getCoreMeshCount(); meshId++)
         //{
          //m_calModel.attachMesh(meshId);
         //}
     
         /*-----------------------------------------------*/
     
         // draw the bone points
         float points[1024][3];
         int nrPoints;
         //nrPoints =  m_calModel.getSkeleton()->getBonePoints(&points[0][0]);
         nrPoints = m_calModel.getSkeleton()->getBonePointsStatic(&points[0][0]);
     
         /*-----------------------------------------------*/
     
        /*********************/
        /****    DEBUG    ****/
        /*********************/ 
         /*
         std::cout << nrPoints << std::endl;
     
         int i = 0 ;
         int j = 0 ;
         
         for ( i=0; i< nrPoints ; i++ )
         {
             for( j=0; j<3 ;j++ )
             {
                  std::cout << i << "," << j << " : " << points[i][j] << std::endl ;
             }
         }
         */
     
         /*-----------------------------------------------*/
     
        /*************************/
        /****    Squelette    ****/
        /*************************/ 
     
         std::cout << "Skeleton draw" << std::endl ;
         /*
         glPointSize(4.0f);
         glBegin(GL_POINTS);
         glColor3f(255.0f, 0.0f, 0.0f);
         glVertex3f(10,10,10);
         int currPoint;
         for(currPoint = 0; currPoint < nrPoints; currPoint++)
         {             
             glVertex3f(points[currPoint][0], points[currPoint][1], points[currPoint][2]);
         }
         glEnd();
         glPointSize(1.0f);
         */
         float lines[1024][2][3];
         int nrLines;
         //nrLines =  m_calModel.getSkeleton()->getBoneLines(&lines[0][0][0]);
           nrLines = m_calModel.getSkeleton()->getBoneLinesStatic(&lines[0][0][0]);
     
         glLineWidth(3.0f);
         glColor3f(1.0f, 1.0f, 1.0f);
         glBegin(GL_LINES);
         int currLine;
         for(currLine = 0; currLine < nrLines; currLine++)
         {
            glVertex3f(lines[currLine][0][0], lines[currLine][0][1], lines[currLine][0][2]);
            glVertex3f(lines[currLine][1][0], lines[currLine][1][1], lines[currLine][1][2]);
         }
         glEnd();
         glLineWidth(1.0f);
     
         /*-----------------------------------------------*/
     
         //Rendu du modele
         renderModel(m_calModel) ;
     
         /*-----------------------------------------------*/
     
         glFlush();
         SDL_GL_SwapBuffers();
    }
     
    bool meshLoad()
    {
         std::cout << "Loading mesh function\n" ;
     
        cally_calf_leftID      = Personnage.loadCoreMesh("mesh\\cally_calf_left.cmf");
        cally_calf_rightID     = Personnage.loadCoreMesh("mesh\\cally_calf_right.cmf");
        cally_chesID           = Personnage.loadCoreMesh("mesh\\cally_chest.cmf");
        cally_foot_leftID      = Personnage.loadCoreMesh("mesh\\cally_foot_left.cmf");
        cally_foot_rightID     = Personnage.loadCoreMesh("mesh\\cally_foot_right.cmf");
        cally_hand_leftID      = Personnage.loadCoreMesh("mesh\\cally_hand_left.cmf");
        cally_hand_rightID     = Personnage.loadCoreMesh("mesh\\cally_hand_right.cmf");
        cally_headID           = Personnage.loadCoreMesh("mesh\\cally_head.cmf");
        cally_lowerarm_leftID  = Personnage.loadCoreMesh("mesh\\cally_lowerarm_left.cmf");
        cally_lowerarm_rightID = Personnage.loadCoreMesh("mesh\\cally_lowerarm_right.cmf");
        cally_neckID           = Personnage.loadCoreMesh("mesh\\cally_neck.cmf");
        cally_pelvisID         = Personnage.loadCoreMesh("mesh\\cally_pelvis.cmf");
        cally_ponytailID       = Personnage.loadCoreMesh("mesh\\cally_ponytail.cmf");
        cally_thigh_leftID     = Personnage.loadCoreMesh("mesh\\cally_thigh_left.cmf");
        cally_thigh_rightID    = Personnage.loadCoreMesh("mesh\\cally_thigh_right.cmf");
        cally_upperarm_leftID  = Personnage.loadCoreMesh("mesh\\cally_upperarm_left.cmf");
        cally_upperarm_rightID = Personnage.loadCoreMesh("mesh\\cally_upperarm_right.cmf");
     
        if( ( cally_calf_leftID      == -1) || 
            ( cally_calf_rightID     == -1) ||
            ( cally_chesID           == -1) || 
            ( cally_foot_leftID      == -1) || 
            ( cally_foot_rightID     == -1) || 
            ( cally_hand_leftID      == -1) || 
            ( cally_hand_rightID     == -1) || 
            ( cally_headID           == -1) ||
            ( cally_lowerarm_leftID  == -1) ||
            ( cally_lowerarm_rightID == -1) ||
            ( cally_neckID           == -1) ||
            ( cally_pelvisID         == -1) ||
            ( cally_ponytailID       == -1) || 
            ( cally_thigh_leftID     == -1) || 
            ( cally_thigh_rightID    == -1) || 
            ( cally_upperarm_leftID  == -1) || 
            ( cally_upperarm_rightID == -1) 
          )
        {
            CalError::printLastError();
            return false;
        }
     
        return true ;
    }
     
    bool meshAttach( CalModel &m_calModel)
    {
         std::cout << "Attach mesh function\n" ;
     
         if(!m_calModel.attachMesh(cally_calf_leftID)     ||
    		!m_calModel.attachMesh(cally_calf_leftID)     ||
    		!m_calModel.attachMesh(cally_calf_rightID)    ||
    		!m_calModel.attachMesh(cally_chesID)          ||
    		!m_calModel.attachMesh(cally_foot_leftID)     ||
    		!m_calModel.attachMesh(cally_foot_rightID)    ||
    		!m_calModel.attachMesh(cally_hand_leftID)     ||
    		!m_calModel.attachMesh(cally_hand_rightID)    ||
    		!m_calModel.attachMesh(cally_headID)          ||  
    		!m_calModel.attachMesh(cally_lowerarm_leftID) ||
    		!m_calModel.attachMesh(cally_lowerarm_rightID)||
    		!m_calModel.attachMesh(cally_neckID)          ||
    		!m_calModel.attachMesh(cally_pelvisID)        ||
    		!m_calModel.attachMesh(cally_ponytailID)      ||
    		!m_calModel.attachMesh(cally_thigh_leftID)    ||
    		!m_calModel.attachMesh(cally_thigh_rightID)   ||
    		!m_calModel.attachMesh(cally_upperarm_leftID) ||
    		!m_calModel.attachMesh(cally_upperarm_rightID)	
    	   )
         {
             CalError::printLastError();
             return false;
         }
     
         return true ;
    }
     
     
    void pause()
    {
        int continuer = 1;
        SDL_Event event;
     
        while (continuer)
        {
            SDL_WaitEvent(&event);
            switch(event.type)
            {
                case SDL_QUIT:
                    continuer = 0;
            }
        }
    }
     
    void renderModel( CalModel &m_calModel )
    {
     
      std::cout << "Start model rendering" << std::endl ;
     
      // get the renderer of the model
      CalRenderer *pCalRenderer;
      pCalRenderer = m_calModel.getRenderer();
     
      // begin the rendering loop
      if(pCalRenderer->beginRendering())
      {
        // set global OpenGL states
        glEnable(GL_DEPTH_TEST);
        glShadeModel(GL_SMOOTH);
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
     
        // we will use vertex arrays, so enable them
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_NORMAL_ARRAY);
     
        // get the number of meshes
        int meshCount;
        meshCount = pCalRenderer->getMeshCount();
     
        // render all meshes of the model
        int meshId;
        for(meshId = 0; meshId < meshCount; meshId++)
        {
          // get the number of submeshes
          int submeshCount;
          submeshCount = pCalRenderer->getSubmeshCount(meshId);
     
          // render all submeshes of the mesh
          int submeshId;
          for(submeshId = 0; submeshId < submeshCount; submeshId++)
          {
            // select mesh and submesh for further data access
            if(pCalRenderer->selectMeshSubmesh(meshId, submeshId))
            {
     
              std::cout << "(M,S) : " << meshId << "," << submeshId << std::endl ;
     
              unsigned char meshColor[4];
              GLfloat materialColor[4];
     
              // set the material ambient color
              pCalRenderer->getAmbientColor(&meshColor[0]);
              materialColor[0] = meshColor[0] / 255.0f;  materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f;
              glMaterialfv(GL_FRONT, GL_AMBIENT, materialColor);
     
              // set the material diffuse color
              pCalRenderer->getDiffuseColor(&meshColor[0]);
              materialColor[0] = meshColor[0] / 255.0f;  materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f;
              glMaterialfv(GL_FRONT, GL_DIFFUSE, materialColor);
     
              // set the material specular color
              pCalRenderer->getSpecularColor(&meshColor[0]);
              materialColor[0] = meshColor[0] / 255.0f;  materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f;
              glMaterialfv(GL_FRONT, GL_SPECULAR, materialColor);
     
              // set the material shininess factor
              float shininess;
              shininess = 50.0f; //pCalRenderer->getShininess();
              glMaterialfv(GL_FRONT, GL_SHININESS, &shininess);
     
              // get the transformed vertices of the submesh
              static float meshVertices[30000][3];
              int vertexCount;
              vertexCount = pCalRenderer->getVertices(&meshVertices[0][0]);
     
              // get the transformed normals of the submesh
              static float meshNormals[30000][3];
              pCalRenderer->getNormals(&meshNormals[0][0]);
     
              // get the texture coordinates of the submesh
              static float meshTextureCoordinates[30000][2];
              int textureCoordinateCount;
              textureCoordinateCount = pCalRenderer->getTextureCoordinates(0, &meshTextureCoordinates[0][0]);
     
              // get the faces of the submesh
              static CalIndex meshFaces[50000][3];
              int faceCount;
              faceCount = pCalRenderer->getFaces(&meshFaces[0][0]);
     
              // set the vertex and normal buffers
              glVertexPointer(3, GL_FLOAT, 0, &meshVertices[0][0]);
              glNormalPointer(GL_FLOAT, 0, &meshNormals[0][0]);
     
              // set the texture coordinate buffer and state if necessary
              if((pCalRenderer->getMapCount() > 0) && (textureCoordinateCount > 0))
              {
                glEnable(GL_TEXTURE_2D);
                glEnableClientState(GL_TEXTURE_COORD_ARRAY);
                glEnable(GL_COLOR_MATERIAL);
     
                 //set the texture id we stored in the map user data
                 glBindTexture(GL_TEXTURE_2D, (GLuint)pCalRenderer->getMapUserData(0));
     
                 //set the texture coordinate buffer
                 glTexCoordPointer(2, GL_FLOAT, 0, &meshTextureCoordinates[0][0]);
                 glColor3f(1.0f, 1.0f, 1.0f);
               }
     
              std::cout << "vertexCount,faceCount : " << vertexCount << "," << faceCount << std::endl ;
     
              // draw the submesh
    		  if(sizeof(CalIndex)==2)
    			  glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_SHORT, &meshFaces[0][0]);
    		  else
    			  glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_INT, &meshFaces[0][0]);
     
              // disable the texture coordinate state if necessary
              if((pCalRenderer->getMapCount() > 0) && (textureCoordinateCount > 0))
              {
                glDisable(GL_COLOR_MATERIAL);
                glDisableClientState(GL_TEXTURE_COORD_ARRAY);
                glDisable(GL_TEXTURE_2D);
              }
     
              // adjust the vertex and face counter
              m_vertexCount += vertexCount;
              m_faceCount += faceCount;
     
    // DEBUG-CODE //////////////////////////////////////////////////////////////////
    /*
    glDisable(GL_LIGHTING);
     
    glBegin(GL_LINES);
    glColor3f(1.0f, 1.0f, 1.0f);
    int vertexId;
    for(vertexId = 0; vertexId < vertexCount; vertexId++)
    {
    const float scale = 0.3f;
      glVertex3f(meshVertices[vertexId][0], meshVertices[vertexId][1], meshVertices[vertexId][2]);
      glVertex3f(meshVertices[vertexId][0] + meshNormals[vertexId][0] * scale, meshVertices[vertexId][1] + meshNormals[vertexId][1] * scale, meshVertices[vertexId][2] + meshNormals[vertexId][2] * scale);
    }
    glEnd();
    */
    glEnable(GL_LIGHTING);
     
    ////////////////////////////////////////////////////////////////////////////////
            }
          }
        }
     
        // clear vertex array state
        glDisableClientState(GL_NORMAL_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);
     
        // clear light
        glDisable(GL_LIGHTING);
        glDisable(GL_LIGHT0);
        glDisable(GL_DEPTH_TEST);
     
        // end the rendering
        pCalRenderer->endRendering();
      }
    }
    Merci d'avance pour votre aide !

  9. #9
    Membre averti Avatar de yodaime
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2006
    Messages
    282
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2006
    Messages : 282
    Points : 340
    Points
    340
    Par défaut
    Bonjour,

    Je n'ai pas résolu mon problème mais j'ai une piste !

    Je load mes mesh et puis je les attche et tout se passe bien.

    Par contre si je load et j'attache un mesh autre que "cally_ponytail.cmf", l'instruction :
    vertexCount = pCalRenderer->getVertices(&meshVertices[0][0]);

    renvoie un vertexCount à 93 mais meshVertices est vide !

    Par contre avec cally_ponytail.cmf, meshVertices est remplie.

    Bizarre, Bizarre .....

    Aider moi svp, je cale

    Merci d'avance.

  10. #10
    Candidat au Club
    Inscrit en
    Novembre 2007
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 2
    Points : 2
    Points
    2
    Par défaut
    Salut, cherches-tu encore une solution?
    Je suis moi-même en train d'implémenter Cal3D dans ma librairie. J'ai plusieurs problèmes de rendu et je ne connais pas suffisamment OpenGL et les VBO pour les régler, mais voici ce que j'ai constaté:

    - Pour mon rendu, j'utilise quelque chose qui ressemble étrangement aux VBO du moteur Loulou en tutoriel sur ce site (sauf c'est uniquement OpenGL). Par exemple je dessine des boîtes faites avec les VBO.

    - Pour Cal3D, j'ai décidé de conserver le code du viewer fourni, comme tu as fait. Le hic provient avec ce code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
            glEnableClientState(GL_VERTEX_ARRAY);
            glEnableClientState(GL_NORMAL_ARRAY);
            glVertexPointer(3, GL_FLOAT, 0, &meshVertices[0][0]);
            glNormalPointer(GL_FLOAT, 0, &meshNormals[0][0]);
            glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_INT, &meshFaces[0][0]);
            glDisableClientState(GL_NORMAL_ARRAY);
            glDisableClientState(GL_VERTEX_ARRAY);
    En aucun cas je ne suis capable d'afficher un modèle utilisant le code ci-dessus lorsque je CRÉE des VBO dans mon code. Non seulement ça ne s'affiche pas mais le frame rate semble en prendre un coup solide également.
    Quelqu'un peut m'expliquer pourquoi?
    L'affichage direct fonctionne (par poly ou par ligne avec glBegin(GL_TRIANGLES);glVertex3f(..)...) et je vois les objets faits avec VBO mais pas avec ces tableaux du code ci-dessus.

    Moi ce que je me disais, c'était que je ne voulais pas utiliser de VBO, puisqu'un code de Cal3D, c'est de l'information animée, donc des modèles qui changent à chaque frame, qu'on ne veut donc pas copier dans le buffer de la carte vidéo. Quel est donc le moyen le plus optimisé pour conserver les VBO, mais afficher de façon optimisée un modèle animé ?

    Un moyen rapide pour voir si c'était ça ton problème, c'est de décommenter le DEBUG-CODE. Si tu vois tout plein de lignes alignées sur un point, sans polygones, c'est le même problème que j'ai.

    Un point que j'ai pas compris dans ton code, c'est que tu crées un CalModel à chaque frame. Pourquoi tu conserves pas le même? Car tu vas devoir l'initialisé et y attacher les meshes à chaque frame, sans parler de l'animation... Est-ce à cause que CalModel ne prend qu'un constructeur de CalCoreModel et que tu ne peux l'initialiser au début du projet ? Si oui, conserve un CalModel* pModel et fait un pModel = new CalModel(&tonCoreModel); à l'initialisation, toute suite après avoir tout setté ton core modèle.

    Si vous avez des explications pour les tableaux OpenGL / VBO, svp aidez-moi

  11. #11
    Membre averti Avatar de yodaime
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2006
    Messages
    282
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2006
    Messages : 282
    Points : 340
    Points
    340
    Par défaut
    Salut muffinman !

    Tu tombe à point nommé, j'était sur le point d'abandonner.

    Un point que j'ai pas compris dans ton code, c'est que tu crées un CalModel à chaque frame. Pourquoi tu conserves pas le même? Car tu vas devoir l'initialisé et y attacher les meshes à chaque frame, sans parler de l'animation... Est-ce à cause que CalModel ne prend qu'un constructeur de CalCoreModel et que tu ne peux l'initialiser au début du projet ? Si oui, conserve un CalModel* pModel et fait un pModel = new CalModel(&tonCoreModel); à l'initialisation, toute suite après avoir tout setté ton core modèle.
    Excuse moi, mais je saisi pas trop ce que tu veux dire.

    Un moyen rapide pour voir si c'était ça ton problème, c'est de décommenter le DEBUG-CODE. Si tu vois tout plein de lignes alignées sur un point, sans polygones, c'est le même problème que j'ai.
    Effectivement c'est bien le même problème . Mais étrangement il ne se produit pas pour la queue de cheval du modèle.

    Quant au VBO, je t'avoue que je sais pas très bien ce que c'est.

    Si cela ne te dérange pas, pourrais tu me montrer ton code ?

    Merci d'avance.

  12. #12
    Candidat au Club
    Inscrit en
    Novembre 2007
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 2
    Points : 2
    Points
    2
    Par défaut
    Salut!
    J'ai regardé trop rapidement ton code je crois (désolé). Je comprends pas comment tu peux renderer OpenGL de la façon dont tu as procédée.
    Tu dois afficher OpenGL à chaque frame, dans une boucle sinon tu ne verras rien du tout après avoir swapé les buffer.

    Ton application boucle dans la fonction pause() (que tu devrais renommer soit dit en passant, pour qqchose comme loop() ). Ça devrait donc être l'endroit où tu fais ton rendu. Comme ça :

    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
     
    void pause()
    {
        int continuer = 1;
        SDL_Event event;
     
        while (continuer)
        {
            Dessiner(); // <---------------------- NOUVEAU
            SDL_WaitEvent(&event);
            switch(event.type)
            {
            case SDL_QUIT:
                continuer = 0;
            }
        }
    }
    Maintenant, tout ce que tu fais dans Dessiner(), va être fait en boucle, chaque frame jusqu'à ce que tu quittes.


    Le problème c'est que dans Dessiner(), tu crées un CalModel m_calModel(&Personnage) à chaque appel.

    Je te suggère donc :

    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
     
    // Déclarations et variables globales
    void Dessiner();
    void pause();
    bool meshLoad() ;
    bool meshAttach( CalModel & ) ;
    void renderModel( CalModel &m_calModel ) ;
    void initModel(); // <------------------------- NOUVEAU 
    CalCoreModel Personnage("mon_perso");
    CalModel* mp_calModel; // <---------------------- NOUVEAU
    //...
     
    int main(int argc, char *argv[])
    {
     // ... J'épargne les détails du début
        //On load le squelette
        std::cout << "Loading skeleton\n" ;
        if(!Personnage.loadCoreSkeleton("squelette\\cally.csf"))
        {
            CalError::printLastError();
            return false;
        }
     
        //On load les mesh
        if( meshLoad() == false )
        {
            std::cout << "Erreur lors du load des mesh !" << std::endl ;
            return false ;
        }
     
        initModel(); // <---------------------- NOUVEAU
        pause();
     
        return 0;
    }
     
    void initModel()
    {
        // Dans Dessiner(), j'enlève tout ce qui a rapport à l'initialisation du modèle et tu le mets ici
        // Tu laisses l'affichage du model dans dessiner.
        mp_calModel = new CalModel(&Personnage);
     
        //On atache les mesh
        meshAttach(mp_calModel);
    }
    Donc, dans Dessiner(), enlève tout ce qui a rapport à l'initialisation du modèle et tu le mets dans initModel(). Tu laisses l'affichage du modèle dans Dessiner(). Oublie pas que Dessiner() est dans pause() maintenant.

    Mon code à moi est orienté objets et séparés en milliards de petits morceaux... je crois pas que ça l'aide mais on verra peut-être ça aiderait d'en afficher une partie simplifiée.

    Et espérons que quelqu'un d'autre va lire ces message pour nous aider à clarifiers les VBOs.

    Tiens-moi au courant! Merci.

  13. #13
    Membre averti Avatar de yodaime
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2006
    Messages
    282
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2006
    Messages : 282
    Points : 340
    Points
    340
    Par défaut
    Salut muffinman !

    J'ai modifié mon code avec tes conseils. Malheureusement cela n'a rien résolu.

    Merci quand même cela m'a aidé à rendre mon code plus propre.


    Voici donc mon nouveau code :

    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
     
    #include <stdlib.h>
    #include <stdio.h>
    #include <cstdlib>
    #include <SDL/SDL.h>
    #include <SDL/SDL_image.h>
    #include <GL/gl.h>
    #include <GL/glu.h>
    #include "Cal3D/cal3d.h"
    #include <cstdlib>
    #include "sdlglutils.h"
     
    void Dessiner();
    void pause();
     
    bool meshLoad() ;
    bool meshAttach( CalModel & ) ;
    void renderModel( CalModel &m_calModel ) ;
    void initModel();
     
    CalCoreModel Personnage("mon_perso");
    CalModel* mp_calModel;
    int cally_calf_leftID     ;
    int cally_calf_rightID    ;
    int cally_chesID          ;
    int cally_foot_leftID     ;
    int cally_foot_rightID    ;
    int cally_hand_leftID     ;
    int cally_hand_rightID    ;
    int cally_headID          ;
    int cally_lowerarm_leftID ;
    int cally_lowerarm_rightID;
    int cally_neckID          ;
    int cally_pelvisID        ;
    int cally_ponytailID      ;
    int cally_thigh_leftID    ;
    int cally_thigh_rightID   ;
    int cally_upperarm_leftID ;
    int cally_upperarm_rightID;
     
    int m_vertexCount = 0;
    int m_faceCount = 0;
     
     
    int main(int argc, char *argv[])
    {
        /**********************************/
        /****    Initialisation SDL    ****/
        /**********************************/
        SDL_Event event;
        SDL_Init(SDL_INIT_VIDEO);
        atexit(SDL_Quit);
        SDL_WM_SetCaption("Test Cal3D", NULL);
        SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
     
     
        //---------------------------------------------------------------------------------------------------
     
        /*************************************/
        /****    Initialisation OpenGL    ****/
        /*************************************/    
     
        // clear all the buffers
        glClearColor(0.5f, 0.25f, 0.25f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
        // set the projection transformation
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0f, (double)640/480, 50, 1000.0);
     
        // set the model transformation
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
     
        // light attributes
        const GLfloat light_ambient[]  = { 0.3f, 0.3f, 0.3f, 1.0f };
        const GLfloat light_diffuse[]  = { 0.52f, 0.5f, 0.5f, 1.0f };
        const GLfloat light_specular[] = { 0.1f, 0.1f, 0.1f, 1.0f };
     
        // setup the light attributes
        glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
        glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
        glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
     
        // set the light position
        GLfloat lightPosition[] = { 0.0f, -1.0f, 1.0f, 1.0f };
        glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
     
        // set camera position
        glTranslatef(0.0f, 0.0f, -270 * 1);
        glRotatef(-70.0f, 1.0f, 0.0f, 0.0f);
        glRotatef(-45.0f, 0.0f, 0.0f, 1.0f);
        glTranslatef(0.0f, 0.0f, -90.0f * 1);
     
        //---------------------------------------------------------------------------------------------------
     
        /************************************/
        /****    Initialisation Cal3D    ****/
        /************************************/ 
     
        //On load le squelette
        std::cout << "Loading skeleton\n" ;
        if(!Personnage.loadCoreSkeleton("squelette\\cally.csf"))
        {
            CalError::printLastError();
            return false;
        }
     
        //On load les mesh
        if( meshLoad() == false )
        {
            std::cout << "Erreur lors du load des mesh !" << std::endl ;
            return false ;
        }
     
        //---------------------------------------------------------------------------------------------------
     
     
        initModel();
     
        pause();
     
        return 0;
    }
     
    void initModel()
    {
        // Dans Dessiner(), j'enlève tout ce qui a rapport à l'initialisation du modèle et tu le mets ici
        // Tu laisses l'affichage du model dans dessiner.
        mp_calModel = new CalModel(&Personnage);
     
        //On atache les mesh
        meshAttach(*mp_calModel);
    }
     
    void Dessiner()
    {
     
         /*-----------------------------------------------*/
         //Dessin du repere
     
         glBegin(GL_TRIANGLES);
         glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 5.0f, 0.0f);
         glVertex3f(50.0f, 0.0f, 0.0f);
         glVertex3f(0.0f, -5.0f, 0.0f);
     
         glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 5.0f);
         glVertex3f(0.0f, 50.0f, 0.0f);
         glVertex3f(0.0f, 0.0f, -5.0f);
     
         glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
         glVertex3f(5.0f, 0.0f, 0.0f);
         glVertex3f(0.0f, 0.0f, 50.0f);
         glVertex3f(-5.0f, 0.0f, 0.0f);
         glEnd();
     
         /*-----------------------------------------------*/
     
         // draw the bone points
         float points[1024][3];
         int nrPoints;
         //nrPoints =  m_calModel.getSkeleton()->getBonePoints(&points[0][0]);
         nrPoints = mp_calModel->getSkeleton()->getBonePointsStatic(&points[0][0]);
     
         /*-----------------------------------------------*/
     
        /*********************/
        /****    DEBUG    ****/
        /*********************/ 
         /*
         std::cout << nrPoints << std::endl;
     
         int i = 0 ;
         int j = 0 ;
         
         for ( i=0; i< nrPoints ; i++ )
         {
             for( j=0; j<3 ;j++ )
             {
                  std::cout << i << "," << j << " : " << points[i][j] << std::endl ;
             }
         }
         */
     
         /*-----------------------------------------------*/
     
        /*************************/
        /****    Squelette    ****/
        /*************************/ 
     
         std::cout << "Skeleton draw" << std::endl ;
         /*
         glPointSize(4.0f);
         glBegin(GL_POINTS);
         glColor3f(255.0f, 0.0f, 0.0f);
         glVertex3f(10,10,10);
         int currPoint;
         for(currPoint = 0; currPoint < nrPoints; currPoint++)
         {             
             glVertex3f(points[currPoint][0], points[currPoint][1], points[currPoint][2]);
         }
         glEnd();
         glPointSize(1.0f);
         */
         float lines[1024][2][3];
         int nrLines;
         //nrLines =  m_calModel.getSkeleton()->getBoneLines(&lines[0][0][0]);
           nrLines = mp_calModel->getSkeleton()->getBoneLinesStatic(&lines[0][0][0]);
     
         glLineWidth(3.0f);
         glColor3f(1.0f, 1.0f, 1.0f);
         glBegin(GL_LINES);
         int currLine;
         for(currLine = 0; currLine < nrLines; currLine++)
         {
            glVertex3f(lines[currLine][0][0], lines[currLine][0][1], lines[currLine][0][2]);
            glVertex3f(lines[currLine][1][0], lines[currLine][1][1], lines[currLine][1][2]);
         }
         glEnd();
         glLineWidth(1.0f);
     
         /*-----------------------------------------------*/
     
         //Rendu du modele
         renderModel(*mp_calModel) ;
     
         /*-----------------------------------------------*/
     
         glFlush();
         SDL_GL_SwapBuffers();
    }
     
    bool meshLoad()
    {
         std::cout << "Loading mesh function\n" ;
     
        cally_calf_leftID      = Personnage.loadCoreMesh("mesh\\cally_calf_left.cmf");
        cally_calf_rightID     = Personnage.loadCoreMesh("mesh\\cally_calf_right.cmf");
        cally_chesID           = Personnage.loadCoreMesh("mesh\\cally_chest.cmf");
        cally_foot_leftID      = Personnage.loadCoreMesh("mesh\\cally_foot_left.cmf");
        cally_foot_rightID     = Personnage.loadCoreMesh("mesh\\cally_foot_right.cmf");
        cally_hand_leftID      = Personnage.loadCoreMesh("mesh\\cally_hand_left.cmf");
        cally_hand_rightID     = Personnage.loadCoreMesh("mesh\\cally_hand_right.cmf");
        cally_headID           = Personnage.loadCoreMesh("mesh\\cally_head.cmf");
        cally_lowerarm_leftID  = Personnage.loadCoreMesh("mesh\\cally_lowerarm_left.cmf");
        cally_lowerarm_rightID = Personnage.loadCoreMesh("mesh\\cally_lowerarm_right.cmf");
        cally_neckID           = Personnage.loadCoreMesh("mesh\\cally_neck.cmf");
        cally_pelvisID         = Personnage.loadCoreMesh("mesh\\cally_pelvis.cmf");
        cally_ponytailID       = Personnage.loadCoreMesh("mesh\\cally_ponytail.cmf");
        cally_thigh_leftID     = Personnage.loadCoreMesh("mesh\\cally_thigh_left.cmf");
        cally_thigh_rightID    = Personnage.loadCoreMesh("mesh\\cally_thigh_right.cmf");
        cally_upperarm_leftID  = Personnage.loadCoreMesh("mesh\\cally_upperarm_left.cmf");
        cally_upperarm_rightID = Personnage.loadCoreMesh("mesh\\cally_upperarm_right.cmf");
     
        if( ( cally_calf_leftID      == -1) || 
            ( cally_calf_rightID     == -1) ||
            ( cally_chesID           == -1) || 
            ( cally_foot_leftID      == -1) || 
            ( cally_foot_rightID     == -1) || 
            ( cally_hand_leftID      == -1) || 
            ( cally_hand_rightID     == -1) || 
            ( cally_headID           == -1) ||
            ( cally_lowerarm_leftID  == -1) ||
            ( cally_lowerarm_rightID == -1) ||
            ( cally_neckID           == -1) ||
            ( cally_pelvisID         == -1) ||
            ( cally_ponytailID       == -1) || 
            ( cally_thigh_leftID     == -1) || 
            ( cally_thigh_rightID    == -1) || 
            ( cally_upperarm_leftID  == -1) || 
            ( cally_upperarm_rightID == -1) 
          )
        {
            CalError::printLastError();
            return false;
        }
     
        return true ;
    }
     
    bool meshAttach( CalModel &m_calModel)
    {
         std::cout << "Attach mesh function\n" ;
     
         if(!m_calModel.attachMesh(cally_calf_leftID)     ||
    		!m_calModel.attachMesh(cally_calf_leftID)     ||
    		!m_calModel.attachMesh(cally_calf_rightID)    ||
    		!m_calModel.attachMesh(cally_chesID)          ||
    		!m_calModel.attachMesh(cally_foot_leftID)     ||
    		!m_calModel.attachMesh(cally_foot_rightID)    ||
    		!m_calModel.attachMesh(cally_hand_leftID)     ||
    		!m_calModel.attachMesh(cally_hand_rightID)    ||
    		!m_calModel.attachMesh(cally_headID)          ||  
    		!m_calModel.attachMesh(cally_lowerarm_leftID) ||
    		!m_calModel.attachMesh(cally_lowerarm_rightID)||
    		!m_calModel.attachMesh(cally_neckID)          ||
    		!m_calModel.attachMesh(cally_pelvisID)        ||
    		!m_calModel.attachMesh(cally_ponytailID)      ||
    		!m_calModel.attachMesh(cally_thigh_leftID)    ||
    		!m_calModel.attachMesh(cally_thigh_rightID)   ||
    		!m_calModel.attachMesh(cally_upperarm_leftID) ||
    		!m_calModel.attachMesh(cally_upperarm_rightID)	
    	   )
         {
             CalError::printLastError();
             return false;
         }
     
         return true ;
    }
     
     
    void pause()
    {
        int continuer = 1;
        SDL_Event event;
     
        while (continuer)
        {
            Dessiner();
            SDL_WaitEvent(&event);
            switch(event.type)
            {
                case SDL_QUIT:
                    continuer = 0;
            }
        }
    }
     
    void renderModel( CalModel &m_calModel )
    {
     
      std::cout << "Start model rendering" << std::endl ;
     
      // get the renderer of the model
      CalRenderer *pCalRenderer;
      pCalRenderer = m_calModel.getRenderer();
     
      // begin the rendering loop
      if(pCalRenderer->beginRendering())
      {
        // set global OpenGL states
        glEnable(GL_DEPTH_TEST);
        glShadeModel(GL_SMOOTH);
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
     
        // we will use vertex arrays, so enable them
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_NORMAL_ARRAY);
     
        // get the number of meshes
        int meshCount;
        meshCount = pCalRenderer->getMeshCount();
     
        // render all meshes of the model
        int meshId;
        for(meshId = 0; meshId < meshCount; meshId++)
        {
          // get the number of submeshes
          int submeshCount;
          submeshCount = pCalRenderer->getSubmeshCount(meshId);
     
          // render all submeshes of the mesh
          int submeshId;
          for(submeshId = 0; submeshId < submeshCount; submeshId++)
          {
            // select mesh and submesh for further data access
            if(pCalRenderer->selectMeshSubmesh(meshId, submeshId))
            {
     
              std::cout << "(M,S) : " << meshId << "," << submeshId << std::endl ;
     
              unsigned char meshColor[4];
              GLfloat materialColor[4];
     
              // set the material ambient color
              pCalRenderer->getAmbientColor(&meshColor[0]);
              materialColor[0] = meshColor[0] / 255.0f;  materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f;
              glMaterialfv(GL_FRONT, GL_AMBIENT, materialColor);
     
              // set the material diffuse color
              pCalRenderer->getDiffuseColor(&meshColor[0]);
              materialColor[0] = meshColor[0] / 255.0f;  materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f;
              glMaterialfv(GL_FRONT, GL_DIFFUSE, materialColor);
     
              // set the material specular color
              pCalRenderer->getSpecularColor(&meshColor[0]);
              materialColor[0] = meshColor[0] / 255.0f;  materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f;
              glMaterialfv(GL_FRONT, GL_SPECULAR, materialColor);
     
              // set the material shininess factor
              float shininess;
              shininess = 50.0f; //pCalRenderer->getShininess();
              glMaterialfv(GL_FRONT, GL_SHININESS, &shininess);
     
              // get the transformed vertices of the submesh
              static float meshVertices[30000][3];
              int vertexCount;
              vertexCount = pCalRenderer->getVertices(&meshVertices[0][0]);
              int i = 0 ;
              int j = 0 ;
     
              for ( i=0; i< vertexCount ; i++ )
              {
                  for( j=0; j<3 ;j++ )
                  {
                       std::cout << i << "," << j << " : " << meshVertices[i][j] << std::endl ;
                  }
              }
     
              // get the transformed normals of the submesh
              static float meshNormals[30000][3];
              pCalRenderer->getNormals(&meshNormals[0][0]);
     
              // get the texture coordinates of the submesh
              static float meshTextureCoordinates[30000][2];
              int textureCoordinateCount;
              textureCoordinateCount = pCalRenderer->getTextureCoordinates(0, &meshTextureCoordinates[0][0]);
     
              // get the faces of the submesh
              static CalIndex meshFaces[50000][3];
              int faceCount;
              faceCount = pCalRenderer->getFaces(&meshFaces[0][0]);
     
              // set the vertex and normal buffers
              glVertexPointer(3, GL_FLOAT, 0, &meshVertices[0][0]);
              glNormalPointer(GL_FLOAT, 0, &meshNormals[0][0]);
     
              // set the texture coordinate buffer and state if necessary
              if((pCalRenderer->getMapCount() > 0) && (textureCoordinateCount > 0))
              {
                glEnable(GL_TEXTURE_2D);
                glEnableClientState(GL_TEXTURE_COORD_ARRAY);
                glEnable(GL_COLOR_MATERIAL);
     
                 //set the texture id we stored in the map user data
                 glBindTexture(GL_TEXTURE_2D, (GLuint)pCalRenderer->getMapUserData(0));
     
                 //set the texture coordinate buffer
                 glTexCoordPointer(2, GL_FLOAT, 0, &meshTextureCoordinates[0][0]);
                 glColor3f(1.0f, 1.0f, 1.0f);
               }
     
              std::cout << "vertexCount,faceCount : " << vertexCount << "," << faceCount << std::endl ;
     
              // draw the submesh
    		  if(sizeof(CalIndex)==2)
    			  glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_SHORT, &meshFaces[0][0]);
    		  else
    			  glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_INT, &meshFaces[0][0]);
     
              // disable the texture coordinate state if necessary
              if((pCalRenderer->getMapCount() > 0) && (textureCoordinateCount > 0))
              {
                glDisable(GL_COLOR_MATERIAL);
                glDisableClientState(GL_TEXTURE_COORD_ARRAY);
                glDisable(GL_TEXTURE_2D);
              }
     
              // adjust the vertex and face counter
              m_vertexCount += vertexCount;
              m_faceCount += faceCount;
     
    // DEBUG-CODE //////////////////////////////////////////////////////////////////
     
    glDisable(GL_LIGHTING);
    glLineWidth(3.0f);
    glBegin(GL_LINES);
    glColor3f(1.0f, 1.0f, 1.0f);
    int vertexId;
    for(vertexId = 0; vertexId < vertexCount; vertexId++)
    {
    const float scale = 0.3f;
      glVertex3f(meshVertices[vertexId][0], meshVertices[vertexId][1], meshVertices[vertexId][2]);
      glVertex3f(meshVertices[vertexId][0] + meshNormals[vertexId][0] * scale, meshVertices[vertexId][1] + meshNormals[vertexId][1] * scale, meshVertices[vertexId][2] + meshNormals[vertexId][2] * scale);
    }
    glEnd();
     
    glEnable(GL_LIGHTING);
     
    ////////////////////////////////////////////////////////////////////////////////
            }
          }
        }
     
        // clear vertex array state
        glDisableClientState(GL_NORMAL_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);
     
        // clear light
        glDisable(GL_LIGHTING);
        glDisable(GL_LIGHT0);
        glDisable(GL_DEPTH_TEST);
     
        // end the rendering
        pCalRenderer->endRendering();
      }
    }
    J'y ai inclu des instruction de debug notamment l'affichage du contenu de meshVertices ( voir le fichier joint ). On s'aperçoit que meshvertice n'est remplie que lorsque l'on affiche la queue de cheval.

    Toujours aussi bizarre ...
    Fichiers attachés Fichiers attachés

  14. #14
    Nouveau Candidat au Club
    Inscrit en
    Avril 2010
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Avril 2010
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Solution pour le problème d'attachement de mèches
    En reprenant ton code yodaime, je viens de résoudre le problème:

    Il suffit d'ajouter la fonction: m_calModel.update(1);

    dans cette partie du code:
    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
    bool meshAttach( CalModel &m_calModel)
    {
         std::cout << "Attach mesh function\n" ;
     
         if(!m_calModel.attachMesh(skeleton_hairID)			 ||
        	!m_calModel.attachMesh(skeleton_headID)          ||
        	!m_calModel.attachMesh(skeleton_calf_leftID)     ||
    		!m_calModel.attachMesh(skeleton_calf_rightID)    ||
    		!m_calModel.attachMesh(skeleton_chesID)          ||
    		!m_calModel.attachMesh(skeleton_foot_leftID)     ||
    		!m_calModel.attachMesh(skeleton_foot_rightID)    ||
    		!m_calModel.attachMesh(skeleton_hand_leftID)     ||
    		!m_calModel.attachMesh(skeleton_hand_rightID)    ||
    		!m_calModel.attachMesh(skeleton_lowerarm_leftID) ||
    		!m_calModel.attachMesh(skeleton_lowerarm_rightID)||
    		!m_calModel.attachMesh(skeleton_neckID)          ||
    		!m_calModel.attachMesh(skeleton_pelvisID)        ||
    		!m_calModel.attachMesh(skeleton_thigh_leftID)    ||
    		!m_calModel.attachMesh(skeleton_thigh_rightID)   ||
    		!m_calModel.attachMesh(skeleton_upperarm_leftID) ||
    		!m_calModel.attachMesh(skeleton_spine_lowerID) ||
    		!m_calModel.attachMesh(skeleton_spine_upperID) ||
    		!m_calModel.attachMesh(skeleton_upperarm_rightID)
    	   )
     
     
              {
                  CalError::printLastError();
                  return false;
              }
     
     
         m_calModel.update(1);   //<----ICI!!!!!!!!!!! 
         return true ;
    }

    Des fois il ne faut pas chercher bien loin..

    P.S: Je travail en ce moment sur un projet dans le cadre de mon stage utilisant la librairie CAL3D

    Dans le code ci-dessus je manipule le personnage (skeleton)

    Je vais encore travailler sur ce projet en continu pendant deux mois, la prochaine étape maintenant pour moi étant de l'animer et de contrôler ces mouvement par un programme C++.

    Je continue sur cette voie et n'hésiterai pas à poster des messages ici quand je bloquerai quelque part..

    Bon courage,

Discussions similaires

  1. Besoin d'aide avec Regexp::Assemble
    Par mobscene dans le forum Modules
    Réponses: 5
    Dernier message: 11/04/2007, 12h39
  2. [ASA] J'ai besoin d'aide avec sybase et vb6 svp !!
    Par tibo830 dans le forum SQL Anywhere
    Réponses: 7
    Dernier message: 12/05/2006, 10h09
  3. Besoin d'aide avec TinyXML
    Par Clad3 dans le forum Bibliothèques
    Réponses: 5
    Dernier message: 15/08/2005, 18h20
  4. Réponses: 2
    Dernier message: 29/08/2003, 17h52
  5. Besoin d'aide avec postgresql sous windows NT
    Par Chihuahua dans le forum PostgreSQL
    Réponses: 3
    Dernier message: 18/07/2003, 08h29

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