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 "md2Model.h" |
---|
18 | |
---|
19 | //#include <stdio.h> |
---|
20 | //#include <stdlib.h> |
---|
21 | //#include <string> |
---|
22 | #include <fstream> |
---|
23 | |
---|
24 | |
---|
25 | using namespace std; |
---|
26 | |
---|
27 | /******************************************************************************** |
---|
28 | * MD2MODEL * |
---|
29 | ********************************************************************************/ |
---|
30 | |
---|
31 | /** |
---|
32 | \brief standard constructor |
---|
33 | |
---|
34 | creates a new model |
---|
35 | */ |
---|
36 | MD2Model::MD2Model () |
---|
37 | { |
---|
38 | this->setClassName ("MD2Model"); |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | /** |
---|
43 | \brief standard deconstructor |
---|
44 | |
---|
45 | */ |
---|
46 | MD2Model::~MD2Model () |
---|
47 | { |
---|
48 | // delete what has to be deleted here |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | /******************************************************************************** |
---|
53 | * MD2LOADER * |
---|
54 | ********************************************************************************/ |
---|
55 | |
---|
56 | /** |
---|
57 | \brief standard deconstructor |
---|
58 | creates a new model loader |
---|
59 | */ |
---|
60 | MD2Loader::MD2Loader() |
---|
61 | { |
---|
62 | this->setClassName ("MD2Loader"); |
---|
63 | /* initialize all data to initial state */ |
---|
64 | memset(&this->header, 0, sizeof(tMd2Header)); |
---|
65 | this->pSkins = NULL; |
---|
66 | this->pTexCoords = NULL; |
---|
67 | this->pTriangles = NULL; |
---|
68 | this->pFrames = NULL; |
---|
69 | } |
---|
70 | |
---|
71 | /** |
---|
72 | \brief standard deconstructor |
---|
73 | */ |
---|
74 | MD2Loader::~MD2Loader() |
---|
75 | {} |
---|
76 | |
---|
77 | |
---|
78 | /** |
---|
79 | \brief this is called by the client to open the .Md2 file, read it, then clean up |
---|
80 | \param model to load in |
---|
81 | \param file name to load |
---|
82 | \param texture name to load |
---|
83 | */ |
---|
84 | bool MD2Loader::importMD2(t3DModel *pModel, char *fileName, char *textureName) |
---|
85 | { |
---|
86 | char strMessage[255] = {0}; |
---|
87 | |
---|
88 | this->pFile = fopen(fileName, "rb"); |
---|
89 | if( unlikely(!pFile)) |
---|
90 | { |
---|
91 | PRINTF(1)("Couldn't open the MD2 File for loading. Exiting.\n"); |
---|
92 | return false; |
---|
93 | } |
---|
94 | fread(&this->header, 1, sizeof(tMd2Header), pFile); |
---|
95 | /* check for the header version: make sure its a md2 file :) */ |
---|
96 | if( likely(this->header.version != 8)) |
---|
97 | { |
---|
98 | PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName); |
---|
99 | return false; |
---|
100 | } |
---|
101 | |
---|
102 | this->readMD2Data(); |
---|
103 | this->convertDataStructures(pModel); |
---|
104 | |
---|
105 | if( likely((int)textureName)) |
---|
106 | { |
---|
107 | tMaterialInfo textureInfo; |
---|
108 | strcpy(textureInfo.strFile, textureName); |
---|
109 | /* since there is only one texture for a .Md2 file, the ID is always 0 */ |
---|
110 | textureInfo.texureId = 0; |
---|
111 | textureInfo.uTile = 1; |
---|
112 | /* we only have 1 material for a model */ |
---|
113 | pModel->numOfMaterials = 1; |
---|
114 | //pModel->materialList.add(texture); |
---|
115 | } |
---|
116 | |
---|
117 | this->cleanUp(); |
---|
118 | return true; |
---|
119 | } |
---|
120 | |
---|
121 | /** |
---|
122 | \brief This function reads in all of the model's data, except the animation frames |
---|
123 | */ |
---|
124 | void MD2Loader::readMD2Data() |
---|
125 | {} |
---|
126 | |
---|
127 | /** |
---|
128 | \brief this function fills in the animation list for each animation by name and frame |
---|
129 | \param model |
---|
130 | */ |
---|
131 | void MD2Loader::parseAnimations(t3DModel *pModel) |
---|
132 | {} |
---|
133 | |
---|
134 | /** |
---|
135 | \brief this function converts the .md2 structures to our own model and object structures: decompress |
---|
136 | \param model |
---|
137 | */ |
---|
138 | void MD2Loader::convertDataStructures(t3DModel *pModel) |
---|
139 | {} |
---|
140 | |
---|
141 | |
---|
142 | /** |
---|
143 | \brief this function conputes the normals of the model |
---|
144 | \param model |
---|
145 | */ |
---|
146 | void MD2Loader::computeNormals(t3DModel *pModel) |
---|
147 | {} |
---|
148 | |
---|
149 | /** |
---|
150 | \brief This function cleans up our allocated memory and closes the file |
---|
151 | */ |
---|
152 | void MD2Loader::cleanUp() |
---|
153 | {} |
---|