source: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/IBRBillboardCloudTreeApplication.cpp @ 778

Revision 778, 9.7 KB checked in by igarcia, 18 years ago (diff)
Line 
1
2#include "IBRBillboardCloudTreeApplication.h"
3
4IBRBillboardCloudTreeApplication::IBRBillboardCloudTreeApplication()
5{
6}
7
8IBRBillboardCloudTreeApplication::~IBRBillboardCloudTreeApplication()
9{       
10        // Gametools -- BUG: 31/03/2006
11        //if (mLBBCManager)
12        //{
13        //      delete mLBBCManager;
14        //}
15}
16
17void IBRBillboardCloudTreeApplication::initialize()
18{
19        for (unsigned int i = 0; i < 1; i++)
20        {
21                mSampleConfigFile = new LBBC::SampleConfigFile();
22                mSampleConfigFile->load(mOpts.cfg);
23                //----------------------------------------------------------------------------
24                this->setup(false);
25                mLBBCManager = new LBBC::LBBCManager();
26                mLBBCManager->setSampleConfigFile(mSampleConfigFile);
27                //mLBBCManager->loadSampleConfigFile(mOpts.cfg);
28                mLBBCManager->initialize();
29
30                if (mSampleConfigFile->getEntityDistributionGeneration())
31                {
32                        mLBBCManager->generateEntityDistribution();
33                }
34                else
35                {
36                        mLBBCManager->loadEntityDistribution();
37                }
38                if (mSampleConfigFile->getEntitySampleMeshGeneration())
39                {
40                        mLBBCManager->saveSingleEntity();
41                }
42                if (mSampleConfigFile->getEntityClustersGeneration())
43                {
44                        mLBBCManager->generateEntityClusters();
45                }
46                if (mSampleConfigFile->getBillboardCloudGeneration())
47                {
48                        mLBBCManager->generateBillboardCloud();
49                }
50
51                mLBBCManager->shutdown();
52                delete mLBBCManager;
53                mOgreBase->shutdown();         
54                delete mOgreBase;
55                //----------------------------------------------------------------------------
56                this->setup(true);
57                mLBBCManager = new LBBC::LBBCManager();
58                mLBBCManager->setSampleConfigFile(mSampleConfigFile);   
59                //mLBBCManager->loadSampleConfigFile(mOpts.cfg);
60                mLBBCManager->initialize();
61                //mLBBCManager->loadBillboardCloudMergedXML();
62                mLBBCManager->loadBillboardCloudGroupedXML();
63                this->go();     
64                for (unsigned int iFrameListenerMode = 0; iFrameListenerMode < mFrameListener->getNumFrameListenerModes(); iFrameListenerMode++)
65                {
66                        mFrameListener->getFrameListenerMode(iFrameListenerMode)->destroyScene();
67                }
68                mLBBCManager->shutdown();
69                delete mLBBCManager;
70                mRoot->shutdown();     
71                mWindow->destroy();     
72                delete mRoot;
73                delete mSampleConfigFile;
74        }
75
76
77}
78
79int IBRBillboardCloudTreeApplication::findCommandLineOpts(int numargs, char** argv, Ogre::UnaryOptionList& unaryOptList,
80                                                Ogre::BinaryOptionList& binOptList)
81{
82    int startIndex = 1;
83    for (int i = 1; i < numargs; ++i)
84    {
85                Ogre::String tmp(argv[i]);
86                if (Ogre::StringUtil::startsWith(tmp, "-"))
87        {
88                        Ogre::UnaryOptionList::iterator ui = unaryOptList.find(argv[i]);
89            if(ui != unaryOptList.end())
90            {
91                ui->second = true;
92                ++startIndex;
93                continue;
94            }
95                        Ogre::BinaryOptionList::iterator bi = binOptList.find(argv[i]);
96            if(bi != binOptList.end())
97            {
98                bi->second = argv[i+1];
99                startIndex += 2;
100                ++i;
101                continue;
102            }
103
104            // Invalid option
105                        std::cout<<"Invalid option "<<tmp<<std::endl;
106
107        }
108    }
109    return startIndex;
110}
111
112void IBRBillboardCloudTreeApplication::help()
113{
114        std::cout<<"Please specify the parameter: -cfg sample.cfg"<<std::endl;
115}
116
117void IBRBillboardCloudTreeApplication::parseArgs(int numArgs, char **args)
118{
119        if (numArgs < 2)
120    {
121        help();
122        exit(-1);
123    }
124        else
125        {
126                Ogre::UnaryOptionList unOpt;
127                Ogre::BinaryOptionList binOpt;
128
129                binOpt["-cfg"] = "";
130           
131                int startIndex = findCommandLineOpts(numArgs, args, unOpt, binOpt);
132                Ogre::UnaryOptionList::iterator ui;
133                Ogre::BinaryOptionList::iterator bi;
134               
135                bi = binOpt.find("-cfg");
136                if (!bi->second.empty())
137                {
138                        mOpts.cfg = bi->second;
139                }       
140        }
141}
142
143void IBRBillboardCloudTreeApplication::createFrameListener(void)
144{
145        mFrameListener = new IBRBillboardCloudTreeFrameListener(mWindow);
146       
147        mSceneMgr = mFrameListener->getEnabledFrameListenerMode()->getSceneManager();   
148
149        if (mSampleConfigFile->getBillboardCloudDiffuseColorEntityTextureAtlasGeneration())
150        {
151                LBBC::EntityTextureAtlasViewMode *textureAtlasFrameListenerMode;
152                textureAtlasFrameListenerMode = new LBBC::EntityTextureAtlasViewMode(mWindow,mFrameListener->getNumFrameListenerModes());
153                textureAtlasFrameListenerMode->chooseSceneManager();
154                textureAtlasFrameListenerMode->createCamera();
155                textureAtlasFrameListenerMode->createViewports();
156                textureAtlasFrameListenerMode->setTextureAtlasSize(mSampleConfigFile->getBillboardCloudDiffuseColorEntityTextureAtlasSize());
157                textureAtlasFrameListenerMode->setTextureAtlasBitRange(mSampleConfigFile->getBillboardCloudDiffuseColorEntityTextureAtlasBitRange());
158                textureAtlasFrameListenerMode->setTextureAtlasNumSamples(mSampleConfigFile->getBillboardCloudDiffuseColorEntityTextureAtlasNumSamples());
159                textureAtlasFrameListenerMode->setTextureName(mSampleConfigFile->getBillboardCloudDiffuseColorEntityTextureName());
160                textureAtlasFrameListenerMode->setTextureAtlasName(mSampleConfigFile->getBillboardCloudDiffuseColorEntityTextureAtlasName());
161                textureAtlasFrameListenerMode->setTextureAtlasFolder(mSampleConfigFile->getBillboardCloudFolder());
162
163                mFrameListener->addFrameListenerMode(textureAtlasFrameListenerMode);
164                textureAtlasFrameListenerMode->createScene();
165        }
166
167        if (mSampleConfigFile->getBillboardCloudDiffuseColorGroupedBillboardsTextureAtlasGeneration())
168        {
169                LBBC::BillboardCloudDiffuseColorTextureViewMode *anotherFrameListenerMode;
170                anotherFrameListenerMode = new LBBC::BillboardCloudDiffuseColorTextureViewMode(mWindow,mFrameListener->getNumFrameListenerModes());
171                anotherFrameListenerMode->chooseSceneManager();
172                anotherFrameListenerMode->createCamera();
173                anotherFrameListenerMode->createViewports();
174                anotherFrameListenerMode->setTextureAtlasSize(mSampleConfigFile->getBillboardCloudDiffuseColorGroupedBillboardsTextureAtlasSize());
175                anotherFrameListenerMode->setTextureSize(mSampleConfigFile->getBillboardCloudDiffuseColorGroupedBillboardsTextureSize());
176                anotherFrameListenerMode->setTextureAtlasBitRange(mSampleConfigFile->getBillboardCloudDiffuseColorGroupedBillboardsTextureAtlasBitRange());
177                anotherFrameListenerMode->setTextureAtlasName(mSampleConfigFile->getBillboardCloudDiffuseColorGroupedBillboardsTextureAtlasName());
178                anotherFrameListenerMode->setTextureName(mSampleConfigFile->getBillboardCloudDiffuseColorEntityTextureName());
179                anotherFrameListenerMode->setTextureAtlasFolder(mSampleConfigFile->getBillboardCloudFolder());
180                anotherFrameListenerMode->setEntityClustersGroupedName(mSampleConfigFile->getEntityClustersGroupedMeshName());
181                anotherFrameListenerMode->setBillboardCloudSplittedName(mSampleConfigFile->getBillboardCloudSplittedMeshName());
182                anotherFrameListenerMode->setBillboardCloudGroupedTextureAtlasDebug(mSampleConfigFile->getBillboardCloudDiffuseColorGroupedBillboardsTextureAtlasDebug());
183                anotherFrameListenerMode->createScene();
184                mFrameListener->addFrameListenerMode(anotherFrameListenerMode);
185        }
186
187        if (mSampleConfigFile->getBillboardCloudIndirectGroupedBillboardsTextureAtlasGeneration())
188        {
189                LBBC::BillboardCloudIndirectTextureViewMode *anotherFrameListenerMode;
190                anotherFrameListenerMode = new LBBC::BillboardCloudIndirectTextureViewMode(mWindow, mFrameListener->getNumFrameListenerModes());
191                anotherFrameListenerMode->chooseSceneManager();
192                anotherFrameListenerMode->createCamera();
193                anotherFrameListenerMode->createViewports();
194                anotherFrameListenerMode->setTextureAtlasSize(mSampleConfigFile->getBillboardCloudIndirectGroupedBillboardsTextureAtlasSize());
195                anotherFrameListenerMode->setTextureSize(mSampleConfigFile->getBillboardCloudIndirectGroupedBillboardsTextureSize());
196                anotherFrameListenerMode->setTextureAtlasBitRange(mSampleConfigFile->getBillboardCloudIndirectGroupedBillboardsTextureAtlasBitRange());
197                anotherFrameListenerMode->setTextureAtlasName(mSampleConfigFile->getBillboardCloudIndirectGroupedBillboardsTextureAtlasName());
198                anotherFrameListenerMode->setTextureAtlasFolder(mSampleConfigFile->getBillboardCloudFolder());
199                anotherFrameListenerMode->setBillboardCloudPointClustersName(mSampleConfigFile->getBillboardCloudIndirectPointMeshName());
200                anotherFrameListenerMode->setBillboardCloudSplittedName(mSampleConfigFile->getBillboardCloudSplittedMeshName());
201                anotherFrameListenerMode->setEntityClustersGroupedName(mSampleConfigFile->getEntityClustersGroupedMeshName());
202                anotherFrameListenerMode->setBillboardCloudGroupedTextureAtlasDebug(mSampleConfigFile->getBillboardCloudIndirectGroupedBillboardsTextureAtlasDebug());
203                anotherFrameListenerMode->createScene();
204                mFrameListener->addFrameListenerMode(anotherFrameListenerMode);
205        }
206
207        {
208                LBBC::BillboardViewMode *anotherFrameListenerMode;
209                anotherFrameListenerMode = new LBBC::BillboardViewMode(mWindow,mFrameListener->getNumFrameListenerModes());
210                anotherFrameListenerMode->chooseSceneManager();
211                anotherFrameListenerMode->createCamera();
212                anotherFrameListenerMode->createViewports();
213                //anotherFrameListenerMode->setBillboardCloudMeshName(mSampleConfigFile->getBillboardCloudGroupedMeshName());
214                anotherFrameListenerMode->createScene();
215                mFrameListener->addFrameListenerMode(anotherFrameListenerMode);
216        }
217
218        {
219                LBBC::ClusterViewMode *anotherFrameListenerMode;
220                anotherFrameListenerMode = new LBBC::ClusterViewMode(mWindow,mFrameListener->getNumFrameListenerModes());
221                anotherFrameListenerMode->chooseSceneManager();
222                anotherFrameListenerMode->createCamera();
223                anotherFrameListenerMode->createViewports();
224                //anotherFrameListenerMode->setEntityClustersMeshName(mSampleConfigFile->getEntityClustersGroupedMeshName());
225                anotherFrameListenerMode->createScene();
226                mFrameListener->addFrameListenerMode(anotherFrameListenerMode);
227        }
228
229        mFrameListener->removeFrameListenerMode(0);
230        mFrameListener->setEnabledFrameListenerMode(0);
231
232    mRoot->addFrameListener(mFrameListener);
233}
Note: See TracBrowser for help on using the repository browser.