Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7801 in orxonox.OLD for branches/bsp_model/src/lib/graphics/importer


Ignore:
Timestamp:
May 24, 2006, 1:24:39 PM (18 years ago)
Author:
bottac
Message:

Support for animated textures in bsp maps started.

Location:
branches/bsp_model/src/lib/graphics/importer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/bsp_model/src/lib/graphics/importer/bsp_file.cc

    r7596 r7801  
    2525#include "vector.h"
    2626#include "util/loading/resource_manager.h"
     27#include "movie_player.h"
    2728
    2829#include <SDL/SDL_endian.h>
     
    4546  int size;
    4647  struct stat results;
    47   // name = "/root/data/Kanti175.bsp";
     48
    4849
    4950  if (stat( name , &results) == 0) {
     
    393394    this->Materials[i].mat->setSpecular(0.4,0.4,1.0);
    394395    //this->Materials[i]->setShininess(100.0);
    395     this->Materials[i].mat->setTransparency(1.0);
     396   // this->Materials[i].mat->setTransparency(1.0);
    396397    this->Materials[i].mat->setDiffuseMap("pictures/ground.tga");
    397398    this->Materials[i].mat->setAmbientMap("pictures/ground.tga");
    398399    this->Materials[i].mat->setSpecularMap("pictures/ground.tga");
    399400    this->Materials[i].alpha = false;
     401    this->Materials[i].animated = false;
    400402     continue;
    401403    }
     404   
     405      // Check for mov
     406    strcpy(fileName, &this->textures[8+ 72*i]);
     407    strcpy(ext, ".mov");
     408    strncat (fileName, ext, strlen(fileName));
     409
     410    absFileName = ResourceManager::getFullName(fileName);
     411
     412    if(ResourceManager::isFile(absFileName)) {
     413      PRINTF(0)("BSP FILE: gefunden . \n");
     414      this->Materials[i] = this->loadAVI(fileName);
     415      continue;
     416    }
    402417     
     418    // Check for avi
     419    strcpy(fileName, &this->textures[8+ 72*i]);
     420    strcpy(ext, ".avi");
     421    strncat (fileName, ext, strlen(fileName));
     422
     423    absFileName = ResourceManager::getFullName(fileName);
     424
     425    if(ResourceManager::isFile(absFileName)) {
     426      PRINTF(0)("BSP FILE: gefunden . \n");
     427      this->Materials[i] = this->loadAVI(fileName);
     428      continue;
     429    }
     430   
     431       // Check for mpg
     432    strcpy(fileName, &this->textures[8+ 72*i]);
     433    strcpy(ext, ".mpg");
     434    strncat (fileName, ext, strlen(fileName));
     435
     436    absFileName = ResourceManager::getFullName(fileName);
     437
     438    if(ResourceManager::isFile(absFileName)) {
     439      PRINTF(0)("BSP FILE: gefunden . \n");
     440      this->Materials[i] = this->loadAVI(fileName);
     441      continue;
     442    }
    403443   
    404444    // Check for tga
     
    481521    this->Materials[i].mat->setSpecular(0.4,0.4,0.4);
    482522    //this->Materials[i]->setShininess(100.0);
    483     this->Materials[i].mat->setTransparency(1.0);
    484     this->Materials[i].mat->setDiffuseMap("pictures/ground.tga");
    485     this->Materials[i].mat->setAmbientMap("pictures/ground.tga");
    486     this->Materials[i].mat->setSpecularMap("pictures/ground.tga");
    487     this->Materials[i].alpha = false;
     523    //this->Materials[i].mat->setTransparency(1.0);
     524    this->Materials[i].mat->setDiffuseMap("pictures/error_texture.png");
     525    this->Materials[i].mat->setAmbientMap("pictures/error_texture.png");
     526    this->Materials[i].mat->setSpecularMap("pictures/error_texture.png");
     527    this->Materials[i].alpha = true;
     528    this->Materials[i].animated = false;
    488529   
    489530  }
     
    503544
    504545  Material* tmp = new Material();
    505   tmp->setDiffuse(1.0,1.0,1.0);
    506   tmp->setAmbient(1.0,1.0,1.0 );
     546   tmp->setDiffuse(1.0,1.0,1.0);
     547   tmp->setAmbient(1.0,1.0,1.0 );
    507548  tmp->setSpecular(1.0,1.0,1.0);
    508549  //    tmp->setShininess(.5);
    509   //    tmp->setTransparency(1.0);
     550  //    tmp->setTransparency(0.0);
    510551
    511552  tmp->setDiffuseMap(mat);
    512553
    513554  tmpAMat.mat = tmp;
    514 
     555  tmpAMat.animated = false;
     556  return tmpAMat;
     557}
     558
     559AMat BspFile::loadAVI(char* mat)
     560{
     561  AMat tmpAMat;
     562
     563
     564  MoviePlayer * testMC = new MoviePlayer(mat);
     565  testMC->start(0);
     566
     567  //Material* tmp = new Material();
     568 // tmp->setDiffuse(1.0,1.0,1.0);
     569  //tmp->setAmbient(1.0,1.0,1.0 );
     570  //tmp->setSpecular(1.0,1.0,1.0);
     571  //    tmp->setShininess(.5);tmpAMat
     572  //    tmp->setTransparency(0.0);
     573
     574  //tmp->setDiffuseMap(mat);
     575
     576  tmpAMat.aviMat = testMC;
     577  tmpAMat.animated = true;
     578  tmpAMat.alpha = true;
    515579  return tmpAMat;
    516580}
     
    533597  scale*=255.0;
    534598  sc*=scale;
    535   if(sc <= 205)
    536     ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc + 50;
     599  if(sc <= 180)
     600    ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc + 75;
    537601  else
    538602    ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc;
     
    595659  int level = 7;
    596660  int level1 = 8;
    597   int size0 = SDL_SwapLE32(Face->size[0]);
    598   int size1 = SDL_SwapLE32(Face->size[1]);
     661  int size0 = (Face->size[0]);
     662  int size1 = (Face->size[1]);
    599663  // For each patch...
    600664  for(int i = 0; i <  ( size0 - 1)    ; i+=2) {
     
    609673      for(int k = 0; k < 3; k++) {
    610674        for(int l = 0; l < 3; l++) {
    611           controls[k +3*l]. position[0] =   SDL_SwapLE32(    BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[0]);
    612           controls[k +3*l]. position[1] =   SDL_SwapLE32(    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].position[1]);
    613           controls[k +3*l]. position[2] =   SDL_SwapLE32(    BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[2]); /*Face->n_vertexes*/
    614 
    615           controlsTmp[2-k +6-3*l]. position[0] =   SDL_SwapLE32(    BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].position[0]);
    616           controlsTmp[2-k +6-3*l]. position[1] =   SDL_SwapLE32(    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].position[1]);
    617           controlsTmp[2-k +6-3*l]. position[2] =   SDL_SwapLE32(    BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[2]); /*Face->n_vertexes*/
    618 
    619           VControls[k +3*l]. position[0] =   SDL_SwapLE32(    BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].position[0]);
    620           VControls[k +3*l]. position[1] =   SDL_SwapLE32(    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].position[1]);
    621           VControls[k +3*l]. position[2] =   SDL_SwapLE32(    BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[2]);
    622 
    623           VControls[k +3*l]. normal[0] =   SDL_SwapLE32(    BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].normal[0]);
    624           VControls[k +3*l]. normal[1] =   SDL_SwapLE32(    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].normal[1]);
    625           VControls[k +3*l]. normal[2] =   SDL_SwapLE32(    BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].normal[2]);
    626 
    627           VControls[k +3*l]. texcoord[0][0]=    SDL_SwapLE32(    BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].texcoord[0][0]);
    628           VControls[k +3*l]. texcoord[0][1] =   SDL_SwapLE32(    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].texcoord[0][1]);
    629           VControls[k +3*l]. texcoord[1][0] =   SDL_SwapLE32(    BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].texcoord[1][0]);
    630           VControls[k +3*l]. texcoord[1][1] =   SDL_SwapLE32(    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].texcoord[1][1]);
     675          controls[k +3*l]. position[0] =   (    BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[0]);
     676          controls[k +3*l]. position[1] =   (    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].position[1]);
     677          controls[k +3*l]. position[2] =   (    BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[2]); /*Face->n_vertexes*/
     678
     679          controlsTmp[2-k +6-3*l]. position[0] =   (    BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].position[0]);
     680          controlsTmp[2-k +6-3*l]. position[1] =   (    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].position[1]);
     681          controlsTmp[2-k +6-3*l]. position[2] =   (    BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[2]); /*Face->n_vertexes*/
     682
     683          VControls[k +3*l]. position[0] =   (    BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].position[0]);
     684          VControls[k +3*l]. position[1] =   (    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].position[1]);
     685          VControls[k +3*l]. position[2] =   (    BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[2]);
     686
     687          VControls[k +3*l]. normal[0] =   (    BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].normal[0]);
     688          VControls[k +3*l]. normal[1] =   (    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].normal[1]);
     689          VControls[k +3*l]. normal[2] =   (    BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].normal[2]);
     690
     691          VControls[k +3*l]. texcoord[0][0]=    (    BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].texcoord[0][0]);
     692          VControls[k +3*l]. texcoord[0][1] =   (    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].texcoord[0][1]);
     693          VControls[k +3*l]. texcoord[1][0] =   (    BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].texcoord[1][0]);
     694          VControls[k +3*l]. texcoord[1][1] =   (    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].texcoord[1][1]);
    631695
    632696
     
    911975  //Face->n_meshverts = sz;
    912976}
     977
     978void BspFile::swapAllBspCoordinates()
     979{
     980 
     981}
     982
     983void BspFile::swapCoords((int *) array)
     984{
     985 
     986}
     987
     988void BspFile::swapCoords((float *) array)
     989{
     990 
     991}
     992
  • branches/bsp_model/src/lib/graphics/importer/bsp_file.h

    r7596 r7801  
    1717class Vector;
    1818class Material;
     19class MoviePlayer;
    1920class VertexArrayModel;
     21
    2022
    2123typedef struct
     
    118120{
    119121  Material* mat;
     122  MoviePlayer* aviMat;
    120123  bool alpha;
     124  bool animated;
    121125}
    122126AMat;
     
    148152  BspTreeNode* get_root();
    149153  AMat loadMat( char* mat );
    150 
     154  AMat loadAVI(char * mat);
     155 
    151156
    152157private:
     
    197202  unsigned int whiteLightMap;
    198203  unsigned char whiteTexture[3];
     204  void swapAllBspCoordinates();
     205  void swapCoords(int * array);
     206  void swapCoords(float * array);
    199207  SDL_Surface* testSurf;
    200208
     209 
     210
    201211};
    202212
  • branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc

    r7596 r7801  
    3030#include <vector>
    3131#include <deque>
    32 
     32#include "movie_player.h"
    3333
    3434
     
    8888
    8989  this->cam = State::getCameraTargetNode()->getAbsCoor();
    90   //this->checkCollision(this->root, &this->cam);   //!< Test Collision Detection
     90 // this->checkCollision(this->root, &this->cam);   //!< Test Collision Detection
    9191  this->outputStartsOut = true;
    9292  this->outputAllSolid = false;
    9393  this->outputFraction = 1.0f;
    9494 
    95   //this->checkCollisionRay(this->root,0.0f,1.0f, &(State::getCameraTargetNode()->getLastAbsCoor()), &this->cam);
     95  this->checkCollisionRay(this->root,0.0f,1.0f, &(State::getCameraTargetNode()->getLastAbsCoor()), &this->cam);
    9696 
    9797  if(this->outputFraction != 1.0f || this->outputAllSolid ) this->drawDebugCube(&this->cam);
    9898
    99   if (false || viscluster < 0  || ((int *)(this->bspFile->header))[35] == 0 )  //!< if (sizeof(Visdata) == 0)
     99  if ( viscluster < 0  || ((int *)(this->bspFile->header))[35] == 0 )  //!< if (sizeof(Visdata) == 0)
    100100  {
    101101   
     
    112112      /** Do Frustum culling and draw 'em all **/
    113113      bool inFrustum = true;
    114       float dMins;
    115       float dMaxs;
     114
    116115      Vector dir;
    117116      dir.x = this->cam.x - State::getCameraTargetNode()->getLastAbsCoor().x;
     
    120119      float dist =  dir.x*this->cam.x +dir.y*this->cam.y +dir.z*this->cam.z;
    121120      //if(dist < 0) dist = -dist;
    122       dMins = dir.x*(float)curLeaf.mins[0] +dir.y*(float)curLeaf.mins[1] +dir.z*(float)curLeaf.mins[2] ;
    123       dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] ;
     121      const float dMins = dir.x*(float)curLeaf.mins[0] +dir.y*(float)curLeaf.mins[1] +dir.z*(float)curLeaf.mins[2] - dist ;
     122      const float dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] - dist ;
    124123     
    125       if(dMins < -100.0 && dMaxs < -100.0)
     124      if(dMins < -30.0 && dMaxs < -30.0)
    126125      {   
    127        continue;
     126       //continue;
     127      }
     128      if( (this->cam - Vector(curLeaf.mins[0],curLeaf.mins[1], curLeaf.mins[2])).len() > 3000  && (this->cam - Vector(curLeaf.maxs[0],curLeaf.maxs[1], curLeaf.maxs[2])).len() > 3000)
     129      {
     130        //continue;
    128131      }
    129132   
     
    176179        const float dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] - dist;
    177180     
    178         if(dMins < -100.0 && dMaxs < -100.0)
     181        if(dMins < -150.0 && dMaxs < -150.0)
    179182        {   
    180183        continue;
     
    208211    this->trasparent.pop_back();
    209212  }
    210 
     213  glActiveTextureARB(GL_TEXTURE1_ARB);
     214  glBindTexture(GL_TEXTURE_2D, this->bspFile->whiteLightMap);
     215  glEnable(GL_TEXTURE_2D);
    211216
    212217}//draw
     
    220225  int stride = sizeof(BspVertex);  // sizeof(Vertex)
    221226  int offset    = curFace.vertex;
    222 
     227  if (curFace.effect != -1) return;
    223228  // PRINTF(0)("BSP Manager: ");
    224229  // PRINTF(0)("BSP Manager: type: %i  \n", curFace.texture);
     
    229234    return;
    230235  }
    231   if(curFace.type == 3) return;
    232   //  if(this->bspFile->Materials[curFace.texture] != NULL)
     236  if(curFace.type != 1) return;
     237  if((char*)(this->bspFile->textures)[curFace.texture*72]== 0) return;
    233238
    234239  if(this->lastTex != curFace.texture) {
     240    if(this->bspFile->Materials[curFace.texture].animated)
     241    {
     242      glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_COLOR);
     243      glEnable(GL_BLEND);
     244      if(this->bspFile->Materials[curFace.texture].aviMat->getStatus() == 2) this->bspFile->Materials[curFace.texture].aviMat->start(0);
     245      this->bspFile->Materials[curFace.texture].aviMat->tick(0.005);
     246      int n =  this->bspFile->Materials[curFace.texture].aviMat->getTexture();
     247      glActiveTextureARB(GL_TEXTURE0_ARB);
     248      glBindTexture(GL_TEXTURE_2D, n );
     249      glDisable(GL_BLEND);
     250    }
     251    else
     252    {
    235253    this->bspFile->Materials[curFace.texture].mat->select();
    236254    this->lastTex = curFace.texture;
     255    }
    237256  }
    238257
     
    247266  }
    248267
     268  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     269 
    249270 // glColor4f(3.0,3.0,3.0,1.0);
    250271  glEnableClientState(GL_VERTEX_ARRAY );
     
    258279  glClientActiveTextureARB(GL_TEXTURE0_ARB);
    259280  glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0]));
    260   glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     281  //glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    261282
    262283  glClientActiveTextureARB(GL_TEXTURE1_ARB);
     
    273294  glDisableClientState(GL_TEXTURE1_ARB);
    274295  glDisableClientState(GL_VERTEX_ARRAY );
    275   //glDisableClientState(GL_TEXTURE_COORD_ARRAY );
     296  glDisableClientState(GL_TEXTURE_COORD_ARRAY );
    276297  glDisableClientState(GL_NORMAL_ARRAY );
    277298  // glDisableClientState(GL_COLOR_ARRAY);
     
    330351    this->lastTex = Face->texture;
    331352  }
    332 
     353  if (Face->effect != -1) return;
    333354
    334355
     
    344365  //glColor4f(3.0,3.0,3.0,1.0);
    345366
    346   //glEnable( GL_AUTO_NORMAL);
     367  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     368  glEnable( GL_AUTO_NORMAL);
    347369  glEnableClientState(GL_VERTEX_ARRAY );
    348370  glEnableClientState(GL_TEXTURE_COORD_ARRAY );
    349   for(int i = 0; i < Face->n_meshverts  ; i++) {
    350     glFrontFace(GL_CW);
     371  for(int i = Face->n_meshverts -1; i >=0   ; i--) {
     372   //glFrontFace(GL_CW);
    351373    //PRINTF(0)("BSP Manager: Face->size[0]: %i . \n", Face->size[0]);
    352374
    353375
    354     glEnableClientState(GL_NORMAL_ARRAY );
     376    //glEnableClientState(GL_NORMAL_ARRAY );
    355377
    356378    glVertexPointer(3, GL_FLOAT,44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).position[0]));
     
    358380
    359381    glClientActiveTextureARB(GL_TEXTURE0_ARB);
     382    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    360383    glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[0][0]));
    361     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     384 
    362385
    363386
     
    367390
    368391
    369     glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) );
    370 
    371 
    372 
    373 
    374     for(int row=0; row<7; ++row) {
     392  //  glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) );
     393
     394
     395
     396
     397    for(int row=6; row>=0; --row) {
    375398      glDrawElements(GL_TRIANGLE_STRIP, 2*(8), GL_UNSIGNED_INT,
    376399                     & (     (((GLuint*)  (this->bspFile->patchIndexes))[7*8*2*(Face->meshvert+i)+ row*2*8]  ))  );
    377400    }
    378401
    379     glFrontFace(GL_CCW);
     402    //glFrontFace(GL_CCW);
    380403  }
    381404  glDisableClientState(GL_TEXTURE0_ARB);
    382405  glDisableClientState(GL_TEXTURE1_ARB);
    383   //glDisable(GL_AUTO_NORMAL);
     406  glDisable(GL_AUTO_NORMAL);
    384407  glDisableClientState(GL_VERTEX_ARRAY );
    385408  glDisableClientState(GL_TEXTURE_COORD_ARRAY );
    386409
    387   glBegin(GL_QUADS);
    388 
    389   glEnd();
     410
    390411}
    391412
Note: See TracChangeset for help on using the changeset viewer.