source: GTP/trunk/Lib/Vis/OnlineCullingCHC/IVReader/src/ivreader.cpp @ 868

Revision 868, 21.7 KB checked in by mattausch, 18 years ago (diff)

fitting objects to bb, debug

Line 
1#include "IVReader.h"
2#include <string>
3#include <stdlib.h>
4#include <sstream>
5
6IVMeshListNode *IVReader::meshList = NULL;
7int IVReader::instanceCnt = 0;
8Ogre::Log *IVReader::IVLog = NULL;
9
10
11
12IVMeshListNode::IVMeshListNode(std::string name, IVManualMeshLoader *loader)
13{
14        this->name = name;
15        this->loader = loader;
16        next = NULL;
17}
18
19IVMeshListNode::~IVMeshListNode()
20{
21        if (loader != NULL) delete loader;
22}
23
24void IVMeshListNode::attachNewNode(std::string name, IVManualMeshLoader *loader)
25{
26        IVMeshListNode *help = this;
27
28        while (help->next != NULL) help = help->next;
29        help->next = new IVMeshListNode(name, loader);
30}
31
32IVManualMeshLoader *IVMeshListNode::getManualMeshLoader(std::string name)
33{
34        IVMeshListNode *help = this;
35        if (help->name == name) return help->loader;
36        while (help->next != NULL)
37        {
38                help = help->next;
39                if (help->name == name) return help->loader;
40        }
41        return NULL;
42}
43
44IVDefListNode::IVDefListNode(std::string name, IVNode *node)
45{
46        this->name = name;
47        this->node = node;
48        next = NULL;
49}
50
51IVDefListNode::~IVDefListNode()
52{
53}
54
55void IVDefListNode::attachNewNode(std::string name, IVNode *node)
56{
57        IVDefListNode *help = this;
58
59        while (help->next != NULL) help = help->next;
60        help->next = new IVDefListNode(name, node);
61}
62
63IVNode *IVDefListNode::getDef(std::string name)
64{
65        IVDefListNode *help = this;
66        if (help->name == name) return help->node;
67        while (help->next != NULL)
68        {
69                help = help->next;
70                if (help->name == name) return help->node;
71        }
72        return NULL;
73}
74
75IVReader::IVReader()
76{       
77        root = NULL; meshList = NULL; defList = NULL; fileName = NULL;
78        instanceCnt++;
79        IVLog = NULL;
80}
81
82IVReader::~IVReader()
83{
84        collapse();
85
86        instanceCnt--;
87        if (instanceCnt == 0) if (meshList != NULL)
88        {       
89                IVMeshListNode *help = meshList, *delme = NULL;
90                while (help->next != NULL)
91                {
92                        delme = help; help = help->next; delete delme;
93                }
94                delete help;
95        }
96}
97
98void IVReader::collapse()
99{
100        if (root != NULL) {     delete root; root = NULL; }
101        if (defList != NULL)
102        {       
103                IVDefListNode *help = defList, *delme = NULL;
104                while (help->next != NULL)
105                {
106                        delme = help; help = help->next; delete delme;
107                }
108                delete help;
109                defList = NULL;
110        }
111        if (this->fileName != NULL) { delete [] this->fileName; this->fileName = NULL; }
112
113}
114
115void IVReader::setLog(Ogre::Log *IVLog)
116{
117        this->IVLog = IVLog;
118}
119
120std::string IVReader::intToStr(int num)
121{
122        std::ostringstream myStream;
123        myStream << num;
124        myStream.flush();
125       
126        return(myStream.str());
127}
128
129std::string IVReader::realToStr(Ogre::Real num)
130{
131        std::ostringstream myStream;
132        myStream << num;
133        myStream.flush();
134       
135        return(myStream.str());
136}
137
138bool IVReader::loadFile(const char* fileName)
139{
140        std::string message = "trying to load "; message = message + fileName + "...";
141       
142        if (IVLog != NULL)
143                IVLog->logMessage(message);
144       
145        collapse();
146        this->fileName = new char[strlen(fileName)+1]; strcpy(this->fileName, fileName);
147        treeCnt = 0;
148
149    infile = fopen(fileName, "r"); root = NULL;
150
151        if (infile == NULL)
152        {
153                message = "! Error loading File "; message = message + fileName + " !";
154                if (IVLog != NULL) IVLog->logMessage(message);
155                return false;
156        }
157
158        if ((fgets(buf, BUFFERSIZE, infile) == NULL) && !feof(infile))
159        {
160                message = "! Error loading File "; message = message + fileName + " !";
161                if (IVLog != NULL) IVLog->logMessage(message);
162                fclose(infile);
163                return false;
164        }
165
166        if (!checkHeader(buf))
167        {
168                message = "! Invalid Header !";
169                if (IVLog != NULL) IVLog->logMessage(message);
170                fclose(infile);
171                return false;
172        }
173
174        IVTokenType tmptyp = IV_TOKEN_INVALID;
175        eof = false;   
176
177        bufOffset = 0;
178        char token[BUFFERSIZE] = "\0", oldtoken[BUFFERSIZE] = "\0", fieldtoken[BUFFERSIZE] = "\0";
179        int level = 0;
180
181        while (getNextElement(token, &tmptyp))
182        {
183                if (tmptyp == IV_TOKEN_BRACEOPEN)
184                {
185                        root = new IVNode(oldtoken);
186                        level++;
187                        break;
188                }
189
190                strcpy(oldtoken, token);
191        }
192
193        IVNode *actualNode = root, *parent = root, *fieldNode = root, *newNode = NULL;
194        IVTokenType oldtmptyp = tmptyp;
195        bool textfield = false, realfield = false; IVType fieldtyp = IV_INVALID;
196        bool def = false; std::string defLabel;
197        Ogre::Real rblock[BLOCKSIZE];
198        float *rvalues;
199        int cnt = 0; int blockcnt = 0;
200        while (getNextElement(token, &tmptyp))
201        {
202                if ((tmptyp == IV_TOKEN_BRACKETOPEN))
203                        if (!getNextElement(token, &tmptyp)) break;
204                if ((tmptyp == IV_TOKEN_INVALID))
205                        if (!getNextElement(token, &tmptyp)) break;
206                if (tmptyp == IV_TOKEN_BRACEOPEN)
207                {
208                        actualNode = new IVNode(oldtoken);
209                        if (parent == NULL)
210                        {
211                                message = "Error loading file "; message = message + fileName + "! Invalid tree structure.";
212                                if (IVLog != NULL) IVLog->logMessage(message);
213                                fclose(infile);
214                                return false;
215                        }
216                        parent->attachNode(actualNode);
217                        parent = actualNode;
218                        level++;
219
220                        if (def)
221                        {
222                                addDefToList(defLabel, actualNode);
223                                def = false;
224                        }
225
226                } else
227                if (tmptyp == IV_TOKEN_BRACECLOSE)
228                {
229                        if (realfield)
230                        {
231                                if (blockcnt == 0) rvalues = (Ogre::Real *)malloc((cnt)*sizeof(Ogre::Real));
232                                else rvalues = (Ogre::Real *)realloc(rvalues, (BLOCKSIZE*(blockcnt) + cnt)*sizeof(Ogre::Real));                                         
233                                memcpy((void *)&rvalues[BLOCKSIZE*blockcnt], rblock, cnt*sizeof(Ogre::Real));
234                                fieldNode->addField(fieldtoken, rvalues, BLOCKSIZE*blockcnt+cnt, fieldtyp);
235                                realfield = false;
236//                              free(rvalues);
237                        }
238
239                        if (level > 0)
240                        {
241                                actualNode = parent = actualNode->getParent();
242                                level--;
243                        }
244                } else
245                {
246                        if (oldtmptyp == IV_TOKEN_DEF)
247                        {
248                                def = true; defLabel = ""; defLabel = defLabel + token;
249                        } else
250                        if (oldtmptyp == IV_TOKEN_USE)
251                        {
252                                        newNode = new IVNode("USE");
253                                        if (parent == NULL)
254                                        {
255                                                message = "Error loading file "; message = message + fileName + "! Invalid tree structure.";
256                                                if (IVLog != NULL) IVLog->logMessage(message);
257                                                fclose(infile);
258                                                return false;
259                                        }
260                                        char *s = (char *)malloc(sizeof(char)*(strlen(token)+1));
261                                        memcpy(s, token, strlen(token));
262                                        s[strlen(token)] = '\0';
263                                        newNode->addField("label", s);
264                                        actualNode->attachNode(newNode);
265                        } else
266                        if (!def)
267                        if (oldtmptyp == IV_TOKEN_STRING)
268                        {
269                                if (!textfield)
270                                {
271                                        if (tmptyp == IV_TOKEN_STRING)
272                                        {
273/*                                              char *s = new char[strlen(token)+1];
274                                                strcpy(s, token);
275*/                                             
276                                                char *s = (char *)malloc(sizeof(char)*(strlen(token)+1));
277                                                memcpy(s, token, strlen(token));
278                                                s[strlen(token)] = '\0';
279                                                actualNode->addField(oldtoken, s);
280//                                              delete [] s;
281                                        }
282                                }
283                                if (!realfield)
284                                {
285                                        if ((tmptyp == IV_TOKEN_REAL) || (tmptyp == IV_TOKEN_INT))
286                                        {       
287                                                cnt = 0; blockcnt = 0;
288                                                char *stopstring;                                               
289                                                rblock[0] = strtod(token, &stopstring);
290                                                cnt++;
291                                                strcpy(fieldtoken, oldtoken);
292                                                fieldNode = actualNode;
293                                            if (tmptyp == IV_TOKEN_REAL) fieldtyp = IV_REAL;
294                                                if (tmptyp == IV_TOKEN_INT)     fieldtyp = IV_INT;
295                                                realfield = true;
296                                        }
297                                }
298                                textfield = !textfield;
299                        }
300                        else
301                        {
302                                if (realfield) 
303                                {
304                                        if ((tmptyp == IV_TOKEN_REAL) || (tmptyp == IV_TOKEN_INT))
305                                        {               
306                                                char *stopstring;
307                                                if (cnt >= BLOCKSIZE)
308                                                {
309                                                        if (blockcnt == 0) rvalues = (Ogre::Real *)malloc((BLOCKSIZE)*sizeof(Ogre::Real));
310                                                        else rvalues = (Ogre::Real *)realloc(rvalues, (BLOCKSIZE*(blockcnt+1))*sizeof(Ogre::Real));
311                                                        memcpy((void *)&rvalues[BLOCKSIZE*blockcnt], rblock, BLOCKSIZE*sizeof(Ogre::Real));
312                                                        cnt = 0;
313                                                        blockcnt++;
314                                                       
315                                                }
316                                                rblock[cnt] = strtod(token, &stopstring);
317                                                cnt++;
318                                            if (tmptyp == IV_TOKEN_REAL) fieldtyp = IV_REAL;
319                                        }
320                                        else
321                                        {
322                                                if (blockcnt == 0) rvalues = (Ogre::Real *)malloc((cnt)*sizeof(Ogre::Real));
323                                                else rvalues = (Ogre::Real *)realloc(rvalues, (BLOCKSIZE*(blockcnt) + cnt)*sizeof(Ogre::Real));                                         
324                                                memcpy((void *)&rvalues[BLOCKSIZE*blockcnt], rblock, cnt*sizeof(Ogre::Real));
325                                                fieldNode->addField(fieldtoken, rvalues, BLOCKSIZE*blockcnt+cnt, fieldtyp);
326                                                realfield = false;
327//                                              free(rvalues);
328                                        }
329                                }
330                               
331                                textfield = false;
332                        }
333                }
334
335
336                strcpy(oldtoken, token);
337                oldtmptyp = tmptyp;
338        }
339        message = ""; ; message = message + fileName + " loaded.";
340        if (IVLog != NULL) IVLog->logMessage(message);
341        fclose(infile);
342
343        return true;
344}
345
346void IVReader::print()
347{
348        if (root != NULL) root->print();
349}
350
351bool IVReader::checkHeader(const char *string)
352{
353        for (int i=0; i < validIVHeaderCnt; i++)
354                if (strcmp(validIVHeader[i], string) == 0) return true;
355        return false;
356}
357bool IVReader::isSpace(char c)
358{
359        if ((c==' ') || (c=='\t')) return true;
360        return false;
361}
362bool IVReader::isNewline(char c)
363{
364        if (c=='\n') return true;
365        return false;
366}
367bool IVReader::isDigit(char c)
368{
369        if ((c>=48) && (c<=57)) return true;
370        return false;
371}
372bool IVReader::isHexDigit(char c)
373{
374        if ( ((c>=48) && (c<=57)) || ((c>=65) && (c<=70)) || ((c>=97) && (c<=102)) ) return true;
375        return false;
376}
377
378
379bool IVReader::getNextElement(char *token, IVTokenType *type)
380{
381        if (eof) return false;
382        bool quoted = false;
383        while (isSpace(buf[bufOffset])) bufOffset++;
384        int i=0;
385        while ((!isSpace(buf[bufOffset])) || (quoted))
386        {
387                if (!quoted)
388                {
389                        if (isNewline(buf[bufOffset]) || (buf[bufOffset] == COMMENTCHAR))
390                        {
391                                token[i] = '\0';
392                                classify(token, type);
393                                bufOffset = 0;
394                                if (fgets(buf, BUFFERSIZE, infile) == NULL)
395                                {                       
396                                        eof = true;
397                                }
398                                if (i==0) return getNextElement(token, type);
399                                return true;
400                        }
401                        if ((buf[bufOffset] == ',') || (buf[bufOffset] == ']'))
402                        {
403                                token[i] = '\0';
404                                bufOffset++;
405                                classify(token, type);
406                                return true;
407                        }
408               
409                       
410
411                } else if (isNewline(buf[bufOffset])) { eof = true;     }
412
413               
414                token[i] = buf[bufOffset];
415                i++;
416                if (buf[bufOffset] == '"')
417                {
418                        quoted = !quoted; i--;
419                }
420                bufOffset++;
421
422               
423        }
424        token[i] = '\0';
425        classify(token, type);
426        return true;
427}
428
429void IVReader::classify(char *token, IVTokenType *type)
430{
431        bool isInt = true, isReal = true;
432        if (!isDigit(token[0]) && (token[0] != '-') && (token[0] != '+'))
433        {
434                isInt = false;
435                if (token[0] != '.') isReal = false;
436        }
437        int i = 1;
438        while ((token[i] != '\0') && isReal)
439        {
440                if (isInt && (i!=2) && !isHexDigit(token[i]))
441                {
442                        isInt = false;
443                }
444                if (isInt && (i==2) && !isHexDigit(token[i]) && (token[i] != 'x') && (token[i] != 'X')) isInt = false;
445                if (isReal && (!isDigit(token[i])) && (token[i] != '.') && (token[i] != 'e') && (token[i] != 'E') && (token[i] != 'd') && (token[i] != 'D') && (token[i] != '-') && (token[i] != '+')) isReal = false;
446                i++;
447        }
448        if (isInt) *type = IV_TOKEN_INT;
449        else if (isReal) *type = IV_TOKEN_REAL;
450        else *type = IV_TOKEN_STRING;
451
452        if (strcmp(token, "DEF") == 0) *type = IV_TOKEN_DEF;
453        if (strcmp(token, "USE") == 0) *type = IV_TOKEN_USE;
454
455        if (token[1] == '\0')
456        {
457                if (token[0] == '{') *type = IV_TOKEN_BRACEOPEN;
458                if (token[0] == '}') *type = IV_TOKEN_BRACECLOSE;
459                if (token[0] == '[') *type = IV_TOKEN_BRACKETOPEN;
460                if (token[0] == ']') *type = IV_TOKEN_BRACKETCLOSE;
461                if (token[0] == '(') *type = IV_TOKEN_PARENTHESISOPEN;
462                if (token[0] == ')') *type = IV_TOKEN_PARENTHESISCLOSE;
463        }
464        if (token[0] == '\0')
465        {
466                *type = IV_TOKEN_INVALID;
467        }
468
469}
470
471/*
472IVNode *IVReader::getNode(const char* name)
473{
474        return root->getNodeRecursive(name);
475}
476*/
477void IVReader::addMeshToList(std::string name, IVManualMeshLoader *loader)
478{       
479        if (meshList == NULL)
480        {
481                meshList = new IVMeshListNode(name, loader);
482        }
483        else
484        {
485                meshList->attachNewNode(name, loader);
486        }
487}
488
489void IVReader::addDefToList(std::string name, IVNode *node)
490{       
491        if (defList == NULL)
492        {
493                defList = new IVDefListNode(name, node);
494        }
495        else
496        {
497                defList->attachNewNode(name, node);
498        }
499}
500
501Ogre::Entity *IVReader::createEntity(Ogre::SceneManager* sceneMgr, std::string name, IVMeshData *mData, Ogre::Vector3 *translation)
502{
503        using namespace Ogre;
504
505        std::string meshName = name.substr(name.find('/',0), name.length()) + "/Mesh";
506        std::string entityName = name + "/Entity";
507
508        Mesh* pMesh = NULL;
509        if ((pMesh = (Mesh *) MeshManager::getSingleton().getByName(meshName).getPointer()) == NULL)
510        {
511
512                IVMeshData *data = mData->expand();
513
514                IVManualMeshLoader *loader      = new IVManualMeshLoader(data);
515
516                if (translation != NULL) *translation = data->boundingBox->getCenter();
517
518//              data->collapse();
519//              delete data;
520
521
522                addMeshToList(meshName, loader);
523
524                Mesh* pMesh = MeshManager::getSingleton().createManual(meshName, "IVGroup", loader).getPointer();
525
526                pMesh->load();
527                pMesh->touch();
528        }
529        else
530        {
531                if (translation != NULL)
532                {
533                        *translation = meshList->getManualMeshLoader(meshName)->getBoundingBox()->getCenter();
534                }
535        }
536
537        Entity *pEntity = sceneMgr->createEntity(entityName, meshName);
538
539
540        return pEntity;
541}
542
543
544
545void IVReader::buildTree(Ogre::SceneManager* sceneMgr,  Ogre::SceneNode *sceneNodeRoot)
546{
547        using namespace Ogre;
548        if (root == NULL) return;
549
550        std::string s = intToStr(treeCnt) + "/" + fileName + "/Root";
551        SceneNode *actualSceneNode = sceneNodeRoot->createChildSceneNode(s);
552        s = "/"; s = s + fileName + "/RootMaterial";
553       
554        Material* pMaterial = NULL;
555        if ((pMaterial = (Material *) MaterialManager::getSingleton().getByName(s).getPointer()) == NULL)
556        {
557                pMaterial = (Material *)MaterialManager::getSingleton().create(s, "General").getPointer();
558        }
559        pMaterial->load();
560
561        nodeCnt = 1; matCnt = 1;
562       
563
564        buildTree(sceneMgr, actualSceneNode, root, NULL, pMaterial);   
565        treeCnt++;
566
567
568        std::string message = "Tree of "; message = message + fileName + " built (" + intToStr(nodeCnt) + " Nodes)";
569        if (IVLog != NULL) IVLog->logMessage(message);
570
571}
572
573void IVReader::buildTree(Ogre::SceneManager* sceneMgr, 
574                                                 Ogre::SceneNode *sceneNodeRoot,
575                                                 IVNode *IVReaderoot, IVMeshData *mData,
576                                                 Ogre::Material *material)
577{
578        using namespace Ogre;
579
580        Material *newMaterial = NULL;
581
582        bool meshDataCreated = false;
583        if (mData == NULL)
584        {
585                mData = new IVMeshData();
586                meshDataCreated = true;
587        }
588
589        IVType t; int i;
590       
591        IVNode *help = IVReaderoot->getNextChildNode(true);
592        while (help != NULL)
593        {       
594                if (strcmp(help->getName(), "USE") == 0)
595                {
596                        char *defLabel = (char *) help->getField("label", &t, &i);
597                        if (t == IV_STRING)
598                        {
599                                help = defList->getDef(defLabel);
600                        }
601                }
602                if ((strcmp(help->getName(), "Separator") == 0) || (strcmp(help->getName(), "TransformSeparator") == 0))
603                {
604/*                      std::string s = sceneNodeRoot->getName() + "/Sep" + intToStr(nodeCnt);
605                        nodeCnt++;
606                        SceneNode *actualSceneNode = sceneNodeRoot->createChildSceneNode(s);
607                        buildTree(sceneMgr, actualSceneNode, help, mData, actualMaterial);
608*/
609                        if (newMaterial == NULL) newMaterial = material;
610                        buildTree(sceneMgr, sceneNodeRoot, help, mData, newMaterial);
611                }
612
613                if (strcmp(help->getName(), "Texture2") == 0)
614                {
615                        char *textureFileName = (char *) help->getField("filename", &t, &i);
616                        if (t == IV_STRING)
617                        { 
618                                std::string s = sceneNodeRoot->getName().substr(sceneNodeRoot->getName().find('/',0), sceneNodeRoot->getName().length()) + "/Material" + intToStr(matCnt);
619                                matCnt++;
620                                if ((newMaterial = (Material *) MaterialManager::getSingleton().getByName(s).getPointer()) == NULL)
621                                {
622                                        newMaterial = (Material *)MaterialManager::getSingleton().create(s, "General").getPointer();
623                                        newMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(textureFileName);
624                                }
625                                newMaterial->load();
626                                newMaterial->reload();
627                        }
628                }
629// can be included
630                if (strcmp(help->getName(), "Material") == 0)
631                {
632                        Real *ambientColor = (Real *) help->getField("ambientColor", &t, &i);
633                        if ((i != 3) || (t != IV_REAL)) ambientColor = NULL;
634                        Real *diffuseColor = (Real *) help->getField("diffuseColor", &t, &i);
635                        if ((i != 3) || (t != IV_REAL)) diffuseColor = NULL;
636                        Real *specularColor = (Real *) help->getField("specularColor", &t, &i);
637                        if ((i != 3) || (t != IV_REAL)) specularColor = NULL;
638                        Real *emissiveColor = (Real *) help->getField("emissiveColor", &t, &i);
639                        if ((i != 3) || (t != IV_REAL)) emissiveColor = NULL;
640                        Real *shininess = (Real *) help->getField("shininess", &t, &i);
641                        if ((i != 1) || (t != IV_REAL)) shininess = NULL;
642                        Real *transparency = (Real *) help->getField("transparency", &t, &i);
643                        if ((i != 1) || (t != IV_REAL)) transparency = NULL;
644
645                        if (newMaterial == NULL)
646                        {
647                                std::string s = sceneNodeRoot->getName().substr(sceneNodeRoot->getName().find('/',0), sceneNodeRoot->getName().length()) + "/Material" + intToStr(matCnt);
648                                matCnt++;
649                                if ((newMaterial = (Material *) MaterialManager::getSingleton().getByName(s).getPointer()) == NULL)
650                                {
651                                        if (material == NULL) newMaterial = (Material *)MaterialManager::getSingleton().create(s, "General").getPointer();
652                                        else newMaterial = material->clone(s).getPointer();
653
654                                        Real alpha = 1.f;
655                                        if (transparency != NULL) alpha = 1.f - transparency[0];
656                                        if (ambientColor != NULL) newMaterial->setAmbient(ambientColor[0], ambientColor[1], ambientColor[2]);
657                                        if (diffuseColor != NULL) newMaterial->setDiffuse(diffuseColor[0], diffuseColor[1], diffuseColor[2], alpha);
658                                        if (specularColor != NULL) newMaterial->setSpecular(specularColor[0], specularColor[1], specularColor[2], alpha);
659                                        if (emissiveColor != NULL) newMaterial->setSelfIllumination(emissiveColor[0], emissiveColor[1], emissiveColor[2]);
660                                        if (shininess != NULL) newMaterial->setShininess(shininess[0]);
661                                       
662//                                      if (material->getTechnique(0)->getPass(0)->getNumTextureUnitStates() > 0)                                                       
663//                                      {
664//                                              newMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(material->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName());
665//                                      }
666                                }
667                                newMaterial->load();
668                                newMaterial->reload();
669                        }
670                        else
671                        {
672                                Real alpha = 1.f;
673                                if (transparency != NULL) alpha = 1.f - transparency[0];
674                                if (ambientColor != NULL) newMaterial->setAmbient(ambientColor[0], ambientColor[1], ambientColor[2]);
675                                if (diffuseColor != NULL) newMaterial->setDiffuse(diffuseColor[0], diffuseColor[1], diffuseColor[2], alpha);
676                                if (specularColor != NULL) newMaterial->setSpecular(specularColor[0], specularColor[1], specularColor[2], alpha);
677                                if (emissiveColor != NULL) newMaterial->setSelfIllumination(emissiveColor[0], emissiveColor[1], emissiveColor[2]);
678                                if (shininess != NULL) newMaterial->setShininess(shininess[0]);
679                                newMaterial->load();
680                        }
681                }
682
683                if (strcmp(help->getName(), "Coordinate3") == 0)
684                {
685                        mData->vertices = (Real *) help->getField("point", &t, &mData->vcnt);
686                        if ((t != IV_REAL) && (t != IV_INT)) mData->vertices = NULL;
687                }
688                if (strcmp(help->getName(), "Normal") == 0)
689                {
690                        mData->normals = (Real *) help->getField("vector", &t, &mData->ncnt);
691                        if ((t != IV_REAL) && (t != IV_INT)) mData->normals = NULL;
692                }
693                if (strcmp(help->getName(), "TextureCoordinate2") == 0)
694                {
695                        mData->texCoords = (Real *) help->getField("point", &t, &mData->tcnt);
696                        if ((t != IV_REAL) && (t != IV_INT)) mData->texCoords = NULL;
697                }
698
699                if (strcmp(help->getName(), "IndexedFaceSet") == 0)
700                {
701                        std::string s = sceneNodeRoot->getName() + "/IFS" + intToStr(nodeCnt);
702                        nodeCnt++;
703                        SceneNode *triangleStripSceneNode = sceneNodeRoot->createChildSceneNode(s);
704
705                        mData->indices = (Real *) help->getField("coordIndex", &t, &mData->icnt);
706                        if (t != IV_INT) mData->indices = NULL;
707
708                        mData->normalIndices = (Real *) help->getField("normalIndex", &t, &mData->nicnt);
709                        if (t != IV_INT) mData->normalIndices = NULL;
710               
711                        mData->texCoordIndices = (Real *) help->getField("textureCoordIndex", &t, &mData->ticnt);
712                        if (t != IV_INT) mData->texCoordIndices = NULL;
713               
714
715                        mData->roType = IV_ROT_FACE_SET;               
716       
717                        Vector3 translation = Vector3(0,0,0);
718                        Entity *pEntity = createEntity(sceneMgr, s, mData, &translation);
719                        if (newMaterial == NULL) newMaterial = material;
720                        if (newMaterial != NULL) pEntity->setMaterialName(newMaterial->getName());
721                               
722                        triangleStripSceneNode->attachObject(pEntity);
723                        triangleStripSceneNode->translate(translation);         
724
725                }
726
727
728                if (strcmp(help->getName(), "IndexedTriangleStripSet") == 0)
729                {
730                        std::string s = sceneNodeRoot->getName() + "/ITS" + intToStr(nodeCnt);
731                        nodeCnt++;
732                        SceneNode *triangleStripSceneNode = sceneNodeRoot->createChildSceneNode(s);
733               
734                        mData->indices = (Real *) help->getField("coordIndex", &t, &mData->icnt);
735                        if (t != IV_INT) mData->indices = NULL;
736
737                        mData->normalIndices = (Real *) help->getField("normalIndex", &t, &mData->nicnt);
738                        if (t != IV_INT) mData->normalIndices = NULL;
739
740                        mData->texCoordIndices = (Real *) help->getField("textureCoordIndex", &t, &mData->ticnt);
741                        if (t != IV_INT) mData->texCoordIndices = NULL;
742
743                        IVNode *n = help->getNextChildNode(true);
744                        while ((n != NULL) && (strcmp(help->getName(), "VertexProperty") == 0))
745                        {
746                                n = help->getNextChildNode();
747                        }
748                        if (n != NULL)
749                        {
750                                mData->vertices = (Real *) n->getField("vertex", &t, &mData->vcnt);
751                                if ((t != IV_REAL) && (t != IV_INT)) mData->vertices = NULL;
752
753                                mData->normals = (Real *) n->getField("normal", &t, &mData->ncnt);
754                                if ((t != IV_REAL) && (t != IV_INT)) mData->normals = NULL;
755                                mData->texCoords = (Real *) n->getField("texCoord", &t, &mData->tcnt);
756                                if ((t != IV_REAL) && (t != IV_INT)) mData->texCoords = NULL;
757                        }
758
759                        mData->roType = IV_ROT_TRIANGLE_STRIP;         
760
761                        Vector3 translation = Vector3(0,0,0);
762                        Entity *pEntity = createEntity(sceneMgr, s, mData, &translation);
763                        if (newMaterial == NULL) newMaterial = material;
764                        if (newMaterial != NULL) pEntity->setMaterialName(newMaterial->getName());
765                               
766                        triangleStripSceneNode->attachObject(pEntity);
767                        triangleStripSceneNode->translate(translation);         
768
769                }
770
771                help = IVReaderoot->getNextChildNode();
772        }
773        if (meshDataCreated) if (mData != NULL) delete mData;
774}
775
Note: See TracBrowser for help on using the repository browser.