Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8532 in orxonox.OLD


Ignore:
Timestamp:
Jun 16, 2006, 3:10:18 PM (18 years ago)
Author:
patrick
Message:

orxonox: addin the md3 config structures

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

Legend:

Unmodified
Added
Removed
  • branches/bsp_model/src/lib/graphics/importer/Makefile.am

    r8490 r8532  
    3434                           md3/md3_model.cc \
    3535                           md3/md3_animation.cc \
     36                           md3/md3_animation_cfg.cc \
    3637                           md3/md3_bone_frame.cc \
    3738                           md3/md3_mesh.cc \
     
    7677                md3/md3_model.h \
    7778                md3/md3_animation.h \
     79                md3/md3_animation_cfg.h \
    7880                md3/md3_bone_frame.h \
    7981                md3/md3_mesh.h \
  • branches/bsp_model/src/lib/graphics/importer/md3/md3_animation_cfg.cc

    r8526 r8532  
    1717#include "md3_animation_cfg.h"
    1818
    19 
     19#include "tokenizer.h"
     20
     21#include "debug.h"
     22
     23using namespace std;
    2024
    2125namespace md3
     
    3438   * @param line: the line to read from
    3539   */
    36   MD3AnimationCfg::MD3AnimationCfg(std::string line)
    37   {
     40  MD3AnimationCfg::MD3AnimationCfg(std::string filename)
     41  {
     42    this->dataStream.open(filename.c_str());
     43
     44    if( !this->dataStream) {
     45      PRINTF(1)("Error: file could not be opened: %s\n", filename.c_str());
     46    }
    3847  }
    3948
     
    4453  MD3AnimationCfg::~MD3AnimationCfg()
    4554  {}
     55
     56
     57  /**
     58   * loads the configuration file
     59   */
     60  void MD3AnimationCfg::loadConfig()
     61  {
     62//     BufferedReader bin=new BufferedReader(new InputStreamReader(in));
     63
     64    int      i = 0;                //!< last read animation, animation order is hard coded!
     65    int      torsoOffset = -1;     //!< torso offset
     66    int      firstTorsoFrame = -1; //!< first of the TORSO animation frames
     67    bool     inHeader = true;      //!< are we still in the header of the .cfg file?
     68    char     buffer[1024];         //!< buffer to write stuff into
     69
     70
     71
     72    // parse file
     73    this->dataStream.getline(buffer, 1024, '\n');
     74    std::string line(buffer);
     75    PRINTF(0)("line = %s\n", line.c_str());
     76    while( !this->dataStream.eof()) {
     77
     78      //ignore empty lines and comments
     79      if( line != "" && line.find("//") != 0) {
     80        // find the sex section
     81        if( inHeader && line.find("sex") == 0) {
     82          //parse line: sex [m | f | ...]
     83//           StringTokenizer st=new StringTokenizer(line, " \t\n\r\f/");
     84          std::vector<std::string> tokens;
     85          Tokenizer::tokenize(line, tokens, " \t\n\r\f/");
     86
     87          while( !tokens.empty())
     88          {
     89            PRINTF(0)("tokens: %s\n", tokens.back());
     90            tokens.pop_back();
     91          }
     92          return;
     93/*
     94          st.nextToken(); //throw away first token
     95          String sexStr=st.nextToken();
     96          if (sexStr.length()!=1)
     97            //non-fatal error, don't thow exception
     98            newAnimCfg.sex='?';
     99          else
     100            newAnimCfg.sex=sexStr.charAt(0);
     101        }
     102        else if (IN_HEADER && line.startsWith("headoffset")) {
     103                                        //parse line: headoffset X Y Z
     104          StringTokenizer st=new StringTokenizer(line, " \t\n\r\f/");
     105
     106          st.nextToken(); //throw away first token
     107
     108          newAnimCfg.headOffset=
     109              new md3.util.Vec3(new Float(st.nextToken()).floatValue(),
     110                                new Float(st.nextToken()).floatValue(),
     111                                new Float(st.nextToken()).floatValue());
     112        }
     113        else if (IN_HEADER && line.startsWith("footsteps")) {
     114                                        //parse line: footsteps [normal | mech | ...]
     115          StringTokenizer st=new StringTokenizer(line, " \t\n\r\f/");
     116
     117          st.nextToken(); //throw away first token
     118          newAnimCfg.footsteps=st.nextToken().trim();
     119
     120          if (!(newAnimCfg.footsteps.toLowerCase().equals("default") ||
     121                newAnimCfg.footsteps.toLowerCase().equals("normal") ||
     122                newAnimCfg.footsteps.toLowerCase().equals("boot") ||
     123                newAnimCfg.footsteps.toLowerCase().equals("flesh") ||
     124                newAnimCfg.footsteps.toLowerCase().equals("mech") ||
     125                newAnimCfg.footsteps.toLowerCase().equals("energy")
     126               ))
     127            //don't throw an exception, non-fatal error
     128            newAnimCfg.footsteps="illegal footsteps value (" + newAnimCfg.footsteps + ")";
     129        }
     130        else {
     131                                        //assume it's an animation line
     132          IN_HEADER=false; //no longer in header
     133
     134          MD3Animation animation=MD3ModelFactory.getFactory().makeMD3Animation(line);
     135
     136          animation.name=animationNames[i];
     137          animation.type=animationTypes[i++];
     138
     139                                        //workaround for strange numbering in animation.cfg: skip TORSO frames
     140                                        //for LEGS animation lines...
     141          if (animation.type==AnimationType.LEGS) {
     142                                                //when first LEGS animation is found, calc # of TORSO frames
     143            if (TORSO_OFFSET==-1)
     144              TORSO_OFFSET=animation.first-firstTORSOFrame;
     145
     146            animation.first-=TORSO_OFFSET;
     147            animation.offset=TORSO_OFFSET;
     148          }
     149          else if (animation.type==AnimationType.TORSO)
     150            if (firstTORSOFrame==-1)
     151              firstTORSOFrame=animation.first;
     152
     153          newAnimCfg.putAnimation(animation);
     154        }
     155      }
     156
     157      line=bin.readLine();
     158    }
     159    catch (Exception e) {
     160      throw new IOException(e.getMessage());
     161    }*/
     162        }
     163      }
     164    }
     165  }
    46166
    47167
  • branches/bsp_model/src/lib/graphics/importer/md3/md3_animation_cfg.h

    r8526 r8532  
    1313#include <string>
    1414#include <map>
     15
     16#include <iostream>
     17#include <fstream>
     18
    1519
    1620
     
    3135      virtual ~MD3AnimationCfg();
    3236
     37      void loadConfig();
    3338
    3439      std::string toString() { return std::string("Name: " + this->filename); }
     
    4247      std::string             footsteps;           //!< type of the footstep sounds associated with anumations (e.g. "mech", "default")
    4348
     49      std::ifstream           dataStream;          //!< the data stream
     50
    4451      std::map<std::string, MD3Animation*>     animations;          //!< mapping of animation names to MD3Animation objects.
    4552  };
Note: See TracChangeset for help on using the changeset viewer.