Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/bsp_model/src/lib/graphics/importer/md3/md3_animation_cfg.cc @ 8532

Last change on this file since 8532 was 8532, checked in by patrick, 18 years ago

orxonox: addin the md3 config structures

File size: 7.4 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Patrick Boenzli
13*/
14
15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER
16
17#include "md3_animation_cfg.h"
18
19#include "tokenizer.h"
20
21#include "debug.h"
22
23using namespace std;
24
25namespace md3
26{
27
28  /**
29   * create an empty MD3AnimationCfg object
30   */
31  MD3AnimationCfg::MD3AnimationCfg()
32  {
33  }
34
35
36  /**
37   * create a new MD3 Anumation object and initialize it with the data on the given line
38   * @param line: the line to read from
39   */
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    }
47  }
48
49
50  /**
51   * deconstructor
52   */
53  MD3AnimationCfg::~MD3AnimationCfg()
54  {}
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  }
166
167
168
169  /**
170  * <p>Look up the animation data for the animation with the specified name.
171  *
172  * @param name Name of the animation.
173  * @return The animation data associated with the name or null if no data was found.
174  */
175  MD3Animation* getAnimation(std::string name)
176  {
177//     return (MD3Animation)animations.get(name);
178  }
179
180}
181
182#if 0
183      /**
184         * <p>Create an empty animation data resource. Use this when creating and
185         * managing your own animations.
186      */
187        protected AnimationCfg() {
188                animations=new TreeMap();
189}
190
191        /**
192         * <p>Constructor that loads an <i>animation.cfg</i> file into the internal
193         * data stuctures. The read information can later be consulted using the
194         * animationNames() and getAnimation() methods.
195         *
196         * @param file The file to open.
197        */
198        protected AnimationCfg(String file) throws IOException {
199                this();
200                InputStream fin=new FileInputStream(file);
201                CFGIO.loadAnimationCfg(this, fin);
202                fin.close();
203}
204
205        /**
206         * <p>Constructor that loads <i>animation.cfg</i> data coming from the specified
207         * input stream into the internal data stuctures. The read information can later
208         * be consulted using the animationNames() and getAnimation() methods.
209         *
210         * @param in The stream to read data from.
211        */
212        protected AnimationCfg(InputStream in) throws IOException {
213                this();
214                CFGIO.loadAnimationCfg(this, in);
215}
216
217        /**
218         * <p>Return an Iterator listing the names of all known animations.
219        */
220        public Iterator animationNames() {
221                return animations.keySet().iterator();
222}
223
224        /**
225         * <p>Look up the animation data for the animation with the specified name.
226         *
227         * @param name Name of the animation.
228         * @return The animation data associated with the name or null if no data was found.
229        */
230        public MD3Animation getAnimation(String name) {
231                return (MD3Animation)animations.get(name);
232}
233
234        /**
235         * <p>Add the specified animation to the list of known animations.
236        */
237        public void putAnimation(MD3Animation anim) {
238                animations.put(anim.name, anim);
239}
240#endif
241
Note: See TracBrowser for help on using the repository browser.