1 | |
---|
2 | #include "LBBCManager.h" |
---|
3 | |
---|
4 | namespace LBBC { |
---|
5 | |
---|
6 | LBBCManager::LBBCManager() |
---|
7 | : BBC::BBCManager() |
---|
8 | { |
---|
9 | mBillboardCloudSerializer = new KMeansClusterSerializer(); |
---|
10 | mLeafDistributionSerializer = new LeafDistributionSerializer(); |
---|
11 | mLeafDistributionGenerator = new LeafDistributionGenerator(); |
---|
12 | mBillboardCloudGenerator = new KMeansClusterGenerator(); |
---|
13 | mDiffuseColorPointClusterGenerator = new DiffuseColorPointClusterGenerator(); |
---|
14 | mBillboardCloudUVMapper = new BBC::BillboardCloudUVMapper(); |
---|
15 | mOgreMeshSerializer = new BBC::OgreMeshSerializer(); |
---|
16 | mColladaMeshSerializer = new BBC::ColladaMeshSerializer(); |
---|
17 | } |
---|
18 | |
---|
19 | LBBCManager::~LBBCManager() |
---|
20 | { |
---|
21 | if (mColladaMeshSerializer) |
---|
22 | { |
---|
23 | delete mColladaMeshSerializer; |
---|
24 | } |
---|
25 | if (mOgreMeshSerializer) |
---|
26 | { |
---|
27 | delete mOgreMeshSerializer; |
---|
28 | } |
---|
29 | // Gametools -- BUG: 06/04/2006 |
---|
30 | //if (mSampleConfigFile) |
---|
31 | //{ |
---|
32 | // delete mSampleConfigFile; |
---|
33 | //} |
---|
34 | if (mLeafDistributionSerializer) |
---|
35 | { |
---|
36 | delete mLeafDistributionSerializer; |
---|
37 | } |
---|
38 | if (mDiffuseColorPointClusterGenerator) |
---|
39 | { |
---|
40 | delete mDiffuseColorPointClusterGenerator; |
---|
41 | } |
---|
42 | if (mLeafDistributionGenerator) |
---|
43 | { |
---|
44 | delete mLeafDistributionGenerator; |
---|
45 | } |
---|
46 | if (mBillboardCloudGenerator) |
---|
47 | { |
---|
48 | delete mBillboardCloudGenerator; |
---|
49 | } |
---|
50 | if (mBillboardCloudUVMapper) |
---|
51 | { |
---|
52 | delete mBillboardCloudUVMapper; |
---|
53 | } |
---|
54 | if (mBillboardCloudSerializer) |
---|
55 | { |
---|
56 | delete mBillboardCloudSerializer; |
---|
57 | } |
---|
58 | if (mLeaves) |
---|
59 | { |
---|
60 | delete mLeaves; |
---|
61 | } |
---|
62 | |
---|
63 | } |
---|
64 | |
---|
65 | SampleConfigFile* LBBCManager::getSampleConfigFile() |
---|
66 | { |
---|
67 | return mSampleConfigFile; |
---|
68 | } |
---|
69 | |
---|
70 | void LBBCManager::setSampleConfigFile(SampleConfigFile *sampleConfigFile) |
---|
71 | { |
---|
72 | mSampleConfigFile = sampleConfigFile; |
---|
73 | } |
---|
74 | |
---|
75 | void LBBCManager::loadSampleConfigFile(Ogre::String sampleConfigFile) |
---|
76 | { |
---|
77 | mSampleConfigFile = new SampleConfigFile(); |
---|
78 | mSampleConfigFile->load(sampleConfigFile); |
---|
79 | } |
---|
80 | |
---|
81 | void LBBCManager::initialize() |
---|
82 | { |
---|
83 | mLeaves = new Leaves(); |
---|
84 | BBC::EntityPtr entityLeaves(new BBC::Entity); |
---|
85 | BBC::MeshPtr meshLeaves(new BBC::Mesh(this->loadMesh(mSampleConfigFile->getEntitiesFolder(), mSampleConfigFile->getEntitiesMeshName())) ); |
---|
86 | entityLeaves->setMesh(meshLeaves); |
---|
87 | mLeaves->setEntity(entityLeaves); |
---|
88 | } |
---|
89 | |
---|
90 | void LBBCManager::createEntityDistribution() |
---|
91 | { |
---|
92 | mLeafDistributionGenerator->setDistribution(mLeaves->getDistribution()); |
---|
93 | mLeafDistributionGenerator->getEntity()->setMesh(mLeaves->getEntity()->getMesh()); |
---|
94 | mLeafDistributionGenerator->generate(); |
---|
95 | } |
---|
96 | |
---|
97 | void LBBCManager::saveEntityDistributionSplitted() |
---|
98 | { |
---|
99 | BBC::EntityPtr entity; |
---|
100 | entity = BBC::EntityPtr(new BBC::Entity()); |
---|
101 | |
---|
102 | if (mSampleConfigFile->getEntityDistributionSplitted() || mSampleConfigFile->getEntityDistributionMerged()) |
---|
103 | { |
---|
104 | BBC::EntityDistribution *entityDistribution; |
---|
105 | unsigned int numSerializedEntities = 0; |
---|
106 | |
---|
107 | entityDistribution = mLeaves->getDistribution(); |
---|
108 | for (unsigned int iEntity = 0; iEntity < entityDistribution->getNumEntities(); iEntity++) |
---|
109 | { |
---|
110 | BBC::SubEntityPtr subEntity = entityDistribution->getEntity(iEntity)->getSubEntity(0); |
---|
111 | |
---|
112 | if (iEntity == 0) |
---|
113 | { |
---|
114 | // delete the default constructed subentity... |
---|
115 | entity->removeSubEntity(0); |
---|
116 | |
---|
117 | // Add our first subentity... |
---|
118 | entity->addSubEntity(subEntity); |
---|
119 | } |
---|
120 | else |
---|
121 | { |
---|
122 | entity->addSubEntity(subEntity); |
---|
123 | } |
---|
124 | |
---|
125 | entity->getSubEntity(numSerializedEntities)->setMaterialName(mSampleConfigFile->getEntityDistributionMergedMaterialName()); |
---|
126 | numSerializedEntities++; |
---|
127 | } |
---|
128 | |
---|
129 | entity->setSubEntitiesDistinctVertexColours(); |
---|
130 | |
---|
131 | if (mSampleConfigFile->getEntityDistributionSplitted()) |
---|
132 | { |
---|
133 | mOgreMeshSerializer->setEntity(entity); |
---|
134 | mOgreMeshSerializer->exportMesh(mSampleConfigFile->getEntityClustersFolder() + |
---|
135 | mSampleConfigFile->getEntityClustersSplittedMeshName(), false, false); |
---|
136 | |
---|
137 | OBA::OgreBase::getSingleton().getMeshSerializer()->exportMesh(entity->getMesh()->get(), mSampleConfigFile->getEntityDistributionFolder() + mSampleConfigFile->getEntityDistributionSplittedMeshName()); |
---|
138 | //OBA::OgreBase::getSingleton().getXMLMeshSerializer()->exportMesh(entity->getMesh().get(), mSampleConfigFile->getEntityClustersFolder() + mSampleConfigFile->getEntitiesMeshPrefixName() + "Splitted.mesh" + ".xml"); |
---|
139 | } |
---|
140 | |
---|
141 | if (mSampleConfigFile->getEntityDistributionMerged()) |
---|
142 | { |
---|
143 | entity->mergeSubEntities(); |
---|
144 | entity->getSubEntity(0)->setMaterialName(mSampleConfigFile->getEntityDistributionMergedMaterialName());
|
---|
145 | |
---|
146 | mOgreMeshSerializer->setEntity(entity); |
---|
147 | mOgreMeshSerializer->exportMesh(mSampleConfigFile->getEntityClustersFolder() + |
---|
148 | mSampleConfigFile->getEntityClustersGroupedMeshName(), false, false); |
---|
149 | |
---|
150 | OBA::OgreBase::getSingleton().getMeshSerializer()->exportMesh((Ogre::Mesh*)entity->getMesh().get(), mSampleConfigFile->getEntityDistributionFolder() + mSampleConfigFile->getEntityClustersGroupedMeshName()); |
---|
151 | //OBA::OgreBase::getSingleton().getXMLMeshSerializer()->exportMesh(entity->getMesh(), mSampleConfigFile->getEntityClustersFolder() + mSampleConfigFile->getEntitiesMeshPrefixName() + "Merged.mesh" + ".xml"); |
---|
152 | } |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | void LBBCManager::saveEntityDistributionXML() |
---|
157 | { |
---|
158 | TiXmlDocument *document = mLeafDistributionSerializer->create( |
---|
159 | mSampleConfigFile->getEntityDistributionFolder() + |
---|
160 | mSampleConfigFile->getEntityDistributionXMLName()); |
---|
161 | |
---|
162 | mLeafDistributionSerializer->setLeafDistribution(mLeaves->getDistribution()); |
---|
163 | mLeafDistributionSerializer->writeLeafDistribution(document); |
---|
164 | mLeafDistributionSerializer->save(); |
---|
165 | } |
---|
166 | |
---|
167 | void LBBCManager::loadEntityDistribution() |
---|
168 | { |
---|
169 | TiXmlDocument *document = mLeafDistributionSerializer->load( |
---|
170 | mSampleConfigFile->getEntityDistributionFolder() + |
---|
171 | mSampleConfigFile->getEntityDistributionXMLName()); |
---|
172 | mLeafDistributionSerializer->setLeafDistribution(mLeaves->getDistribution()); |
---|
173 | mLeafDistributionSerializer->getEntity()->setMesh(mLeaves->getEntity()->getMesh()); |
---|
174 | mLeafDistributionSerializer->readLeafDistribution(document); |
---|
175 | |
---|
176 | BBC::EntityPtr entity; |
---|
177 | BBC::EntityDistribution *entityDistribution; |
---|
178 | |
---|
179 | BBC::MeshPtr pMeshLeavesSplitted(new BBC::Mesh(this->loadMesh(mSampleConfigFile->getEntitiesFolder(), mSampleConfigFile->getEntityDistributionSplittedMeshName()))); |
---|
180 | entity = BBC::EntityPtr(new BBC::Entity()); |
---|
181 | entity->setMesh(pMeshLeavesSplitted); |
---|
182 | |
---|
183 | entity->loadMesh(false); |
---|
184 | entityDistribution = mLeaves->getDistribution(); |
---|
185 | |
---|
186 | for (unsigned int iSubEntity = 0; iSubEntity < entity->getNumSubEntities(); iSubEntity++) |
---|
187 | { |
---|
188 | BBC::EntityPtr entitySample; |
---|
189 | BBC::SubEntityPtr subEntity; |
---|
190 | BBC::SubEntityPtr subEntitySample; |
---|
191 | |
---|
192 | subEntity = entity->getSubEntity(iSubEntity); |
---|
193 | entitySample = entityDistribution->getEntity(iSubEntity); |
---|
194 | subEntitySample = entitySample->getSubEntity(0); |
---|
195 | entitySample->removeSubEntity(0); |
---|
196 | |
---|
197 | // Add our first subentity... |
---|
198 | entitySample->addSubEntity(subEntity); |
---|
199 | } |
---|
200 | } |
---|
201 | |
---|
202 | void LBBCManager::generateEntityDistribution() |
---|
203 | { |
---|
204 | createEntityDistribution(); |
---|
205 | saveEntityDistributionXML(); |
---|
206 | saveEntityDistributionSplitted(); |
---|
207 | } |
---|
208 | |
---|
209 | void LBBCManager::saveBillboardCloudGroupedIndirectTexturing() |
---|
210 | { |
---|
211 | for (unsigned int iSubEntity = 0; iSubEntity < mLeaves->getBillboardCloud()->getEntityGrouped()->getNumSubEntities(); iSubEntity++) |
---|
212 | { |
---|
213 | BBC::SubEntityPtr subEntity = mLeaves->getBillboardCloud()->getEntityGrouped()->getSubEntity(iSubEntity); |
---|
214 | subEntity->setMaterialName(mSampleConfigFile->getBillboardCloudGroupedIndirectTexturingMaterialName() + Ogre::StringConverter::toString(iSubEntity)); |
---|
215 | } |
---|
216 | |
---|
217 | Ogre::LogManager::getSingleton().logMessage("Num.SubEntities:" + Ogre::StringConverter::toString(mLeaves->getBillboardCloud()->getEntityGrouped()->getNumSubEntities())); |
---|
218 | |
---|
219 | mOgreMeshSerializer->setEntity(mLeaves->getBillboardCloud()->getEntityGrouped()); |
---|
220 | mOgreMeshSerializer->exportMesh(mSampleConfigFile->getBillboardCloudFolder() + |
---|
221 | mSampleConfigFile->getBillboardCloudGroupedIndirectTexturingMeshName(), false, false); |
---|
222 | |
---|
223 | OBA::OgreBase::getSingleton().getMeshSerializer()->exportMesh(mLeaves->getBillboardCloud()->getEntityGrouped()->getMesh()->get(), mSampleConfigFile->getBillboardCloudFolder() + mSampleConfigFile->getBillboardCloudGroupedIndirectTexturingMeshName()); |
---|
224 | //OBA::OgreBase::getSingleton().getXMLMeshSerializer()->exportMesh(mLeaves->getBillboardCloud()->getEntityGrouped()->getMesh()->get(), mSampleConfigFile->getBillboardCloudFolder() + mSampleConfigFile->getBillboardCloudGroupedIndirectTexturingMeshName() + ".xml"); |
---|
225 | |
---|
226 | mColladaMeshSerializer->setEntity(mLeaves->getBillboardCloud()->getEntityGrouped()); |
---|
227 | mColladaMeshSerializer->exportMesh(mSampleConfigFile->getBillboardCloudFolder() + |
---|
228 | mSampleConfigFile->getBillboardCloudGroupedIndirectTexturingMeshName(), false, false); |
---|
229 | } |
---|
230 | |
---|
231 | |
---|
232 | void LBBCManager::saveBillboardCloudSplitted() |
---|
233 | { |
---|
234 | for (unsigned int iSubEntity = 0; iSubEntity < mLeaves->getBillboardCloud()->getEntity()->getNumSubEntities(); iSubEntity++) |
---|
235 | { |
---|
236 | BBC::SubEntityPtr subEntity = mLeaves->getBillboardCloud()->getEntity()->getSubEntity(iSubEntity); |
---|
237 | subEntity->setMaterialName(mSampleConfigFile->getBillboardCloudSplittedMaterialName()); |
---|
238 | } |
---|
239 | |
---|
240 | Ogre::LogManager::getSingleton().logMessage("Num.SubEntities:" + Ogre::StringConverter::toString(mLeaves->getBillboardCloud()->getEntity()->getNumSubEntities())); |
---|
241 | |
---|
242 | mOgreMeshSerializer->setEntity(mLeaves->getBillboardCloud()->getEntity()); |
---|
243 | mOgreMeshSerializer->exportMesh(mSampleConfigFile->getBillboardCloudFolder() + |
---|
244 | mSampleConfigFile->getBillboardCloudSplittedMeshName(),false, false); |
---|
245 | |
---|
246 | OBA::OgreBase::getSingleton().getMeshSerializer()->exportMesh(mLeaves->getBillboardCloud()->getEntity()->getMesh()->get(), mSampleConfigFile->getBillboardCloudFolder() + mSampleConfigFile->getBillboardCloudSplittedMeshName()); |
---|
247 | //OBA::OgreBase::getSingleton().getXMLMeshSerializer()->exportMesh(mLeaves->getBillboardCloud()->getEntity()->getMesh()->get(), mSampleConfigFile->getBillboardCloudFolder() + mSampleConfigFile->getBillboardCloudSplittedMeshName() + ".xml"); |
---|
248 | |
---|
249 | mColladaMeshSerializer->setEntity(mLeaves->getBillboardCloud()->getEntity()); |
---|
250 | mColladaMeshSerializer->exportMesh(mSampleConfigFile->getBillboardCloudFolder() + |
---|
251 | mSampleConfigFile->getBillboardCloudSplittedMeshName(),false, false); |
---|
252 | } |
---|
253 | |
---|
254 | void LBBCManager::saveBillboardCloudGroupedDiffuseColor() |
---|
255 | { |
---|
256 | for (unsigned int iSubEntity = 0; iSubEntity < mLeaves->getBillboardCloud()->getEntityGrouped()->getNumSubEntities(); iSubEntity++) |
---|
257 | { |
---|
258 | BBC::SubEntityPtr subEntity = mLeaves->getBillboardCloud()->getEntityGrouped()->getSubEntity(iSubEntity); |
---|
259 | subEntity->setMaterialName(mSampleConfigFile->getBillboardCloudGroupedDiffuseColorMaterialName() + Ogre::StringConverter::toString(iSubEntity)); |
---|
260 | } |
---|
261 | |
---|
262 | Ogre::LogManager::getSingleton().logMessage("Num.SubEntities:" + Ogre::StringConverter::toString(mLeaves->getBillboardCloud()->getEntityGrouped()->getNumSubEntities())); |
---|
263 | |
---|
264 | mOgreMeshSerializer->setEntity(mLeaves->getBillboardCloud()->getEntityGrouped()); |
---|
265 | mOgreMeshSerializer->exportMesh(mSampleConfigFile->getBillboardCloudFolder() + |
---|
266 | mSampleConfigFile->getBillboardCloudGroupedDiffuseColorMeshName(),false, false); |
---|
267 | |
---|
268 | OBA::OgreBase::getSingleton().getMeshSerializer()->exportMesh(mLeaves->getBillboardCloud()->getEntityGrouped()->getMesh()->get(), mSampleConfigFile->getBillboardCloudFolder() + mSampleConfigFile->getBillboardCloudGroupedDiffuseColorMeshName()); |
---|
269 | //OBA::OgreBase::getSingleton().getXMLMeshSerializer()->exportMesh(mLeaves->getBillboardCloud()->getEntityGrouped()->getMesh()->get(), mSampleConfigFile->getBillboardCloudFolder() + mSampleConfigFile->getBillboardCloudGroupedDiffuseColorMeshName() + ".xml"); |
---|
270 | |
---|
271 | mColladaMeshSerializer->setEntity(mLeaves->getBillboardCloud()->getEntityGrouped()); |
---|
272 | mColladaMeshSerializer->exportMesh(mSampleConfigFile->getBillboardCloudFolder() + |
---|
273 | mSampleConfigFile->getBillboardCloudGroupedDiffuseColorMeshName(),false, false); |
---|
274 | } |
---|
275 | |
---|
276 | void LBBCManager::saveBillboardCloudSplittedXML() |
---|
277 | { |
---|
278 | TiXmlDocument *document2 = mBillboardCloudSerializer->create( |
---|
279 | mSampleConfigFile->getBillboardCloudFolder() + |
---|
280 | mSampleConfigFile->getBillboardCloudSplittedXMLName()); |
---|
281 | mBillboardCloudSerializer->setBillboardCloud(mLeaves->getBillboardCloud()); |
---|
282 | mBillboardCloudSerializer->writeBillboardCloud(document2, false); |
---|
283 | mBillboardCloudSerializer->save(); |
---|
284 | } |
---|
285 | |
---|
286 | void LBBCManager::saveBillboardCloudGroupedIndirectTexturingXML() |
---|
287 | { |
---|
288 | TiXmlDocument *document2 = mBillboardCloudSerializer->create( |
---|
289 | mSampleConfigFile->getBillboardCloudFolder() + |
---|
290 | mSampleConfigFile->getBillboardCloudGroupedIndirectTexturingXMLName()); |
---|
291 | mBillboardCloudSerializer->setBillboardCloud(mLeaves->getBillboardCloud()); |
---|
292 | mBillboardCloudSerializer->writeBillboardCloud(document2, true); |
---|
293 | mBillboardCloudSerializer->save(); |
---|
294 | } |
---|
295 | |
---|
296 | void LBBCManager::saveBillboardCloudGroupedDiffuseColorXML() |
---|
297 | { |
---|
298 | TiXmlDocument *document2 = mBillboardCloudSerializer->create( |
---|
299 | mSampleConfigFile->getBillboardCloudFolder() + |
---|
300 | mSampleConfigFile->getBillboardCloudGroupedDiffuseColorXMLName()); |
---|
301 | mBillboardCloudSerializer->setBillboardCloud(mLeaves->getBillboardCloud()); |
---|
302 | mBillboardCloudSerializer->writeBillboardCloud(document2, true); |
---|
303 | mBillboardCloudSerializer->save(); |
---|
304 | } |
---|
305 | |
---|
306 | void LBBCManager::loadBillboardCloudSplittedXML() |
---|
307 | { |
---|
308 | TiXmlDocument *document = mBillboardCloudSerializer->load( |
---|
309 | mSampleConfigFile->getBillboardCloudFolder() + |
---|
310 | mSampleConfigFile->getBillboardCloudSplittedXMLName()); |
---|
311 |
|
---|
312 | mBillboardCloudSerializer->setBillboardCloud(mLeaves->getBillboardCloud());
|
---|
313 | mBillboardCloudSerializer->readBillboardCloud(document, false); |
---|
314 | } |
---|
315 | |
---|
316 | void LBBCManager::loadBillboardCloudGroupedIndirectTexturingXML() |
---|
317 | { |
---|
318 | TiXmlDocument *document = mBillboardCloudSerializer->load( |
---|
319 | mSampleConfigFile->getBillboardCloudFolder() + |
---|
320 | mSampleConfigFile->getBillboardCloudGroupedIndirectTexturingXMLName()); |
---|
321 |
|
---|
322 | mLeaves->getBillboardCloud()->clearBillboardCloud();
|
---|
323 | mBillboardCloudSerializer->setBillboardCloud(mLeaves->getBillboardCloud());
|
---|
324 | mBillboardCloudSerializer->readBillboardCloud(document, true); |
---|
325 | } |
---|
326 | |
---|
327 | void LBBCManager::loadBillboardCloudGroupedDiffuseColorXML() |
---|
328 | { |
---|
329 | TiXmlDocument *document = mBillboardCloudSerializer->load( |
---|
330 | mSampleConfigFile->getBillboardCloudFolder() + |
---|
331 | mSampleConfigFile->getBillboardCloudGroupedDiffuseColorXMLName()); |
---|
332 | |
---|
333 | mLeaves->getBillboardCloud()->clearBillboardCloud(); |
---|
334 | mBillboardCloudSerializer->setBillboardCloud(mLeaves->getBillboardCloud());
|
---|
335 | mBillboardCloudSerializer->readBillboardCloud(document, true); |
---|
336 | } |
---|
337 | |
---|
338 | |
---|
339 | |
---|
340 | void LBBCManager::saveEntityClusters() |
---|
341 | { |
---|
342 | BBC::BillboardClusterDataPtr billboardClusterData; |
---|
343 | BBC::EntityClusterPtr entityCluster; |
---|
344 | unsigned int numSerializedBillboards = 0; |
---|
345 | |
---|
346 | if (mSampleConfigFile->getEntityClustersSplittedClusters()) |
---|
347 | { |
---|
348 | |
---|
349 | for (unsigned int iBillboard = 0; iBillboard < mLeaves->getBillboardCloud()->getNumBillboards(); iBillboard++) |
---|
350 | { |
---|
351 | billboardClusterData = mLeaves->getBillboardCloud()->getBillboard(iBillboard)->getBillboardClusterData(); |
---|
352 | entityCluster = billboardClusterData->getEntityCluster(); |
---|
353 | Ogre::LogManager::getSingleton().logMessage("iBillboard: " + Ogre::StringConverter::toString(iBillboard)); |
---|
354 | if (entityCluster->getNumEntitiesClusterData() > 0) |
---|
355 | { |
---|
356 | BBC::EntityPtr entityClusterized = entityCluster->getEntity(); |
---|
357 | entityClusterized->getSubEntity(0)->setMaterialName(mSampleConfigFile->getEntityClustersSplittedMaterialName()); |
---|
358 | |
---|
359 | mOgreMeshSerializer->setEntity(entityClusterized); |
---|
360 | mOgreMeshSerializer->exportMesh(mSampleConfigFile->getEntityDistributionFolder() + |
---|
361 | mSampleConfigFile->getEntityClustersSplittedMeshName() + |
---|
362 | Ogre::StringConverter::toString(numSerializedBillboards) + ".mesh", !(mSampleConfigFile->getEntityClustersSplittedClusters()), false); |
---|
363 | |
---|
364 | OBA::OgreBase::getSingleton().getMeshSerializer()->exportMesh(entityClusterized->getMesh()->get(), |
---|
365 | mSampleConfigFile->getEntityClustersFolder() + |
---|
366 | mSampleConfigFile->getEntityClustersSplittedMeshName() + |
---|
367 | Ogre::StringConverter::toString(numSerializedBillboards) + ".mesh"); |
---|
368 | //OBA::OgreBase::getSingleton().getXMLMeshSerializer()->exportMesh(entityClusterized->getMesh(), entityClusterized->getMesh()->getName() + ".xml"); |
---|
369 | |
---|
370 | //mColladaMeshSerializer->setEntity(entityClusterized); |
---|
371 | //mColladaMeshSerializer->exportMesh(mSampleConfigFile->getEntityDistributionFolder() + |
---|
372 | // mSampleConfigFile->getEntityClustersSplittedMeshName() + |
---|
373 | // Ogre::StringConverter::toString(numSerializedBillboards) + ".mesh", !(mSampleConfigFile->getEntityClustersSplittedClusters()), false); |
---|
374 | |
---|
375 | numSerializedBillboards++; |
---|
376 | } |
---|
377 | } |
---|
378 | } |
---|
379 | numSerializedBillboards = 0; |
---|
380 | |
---|
381 | if (mSampleConfigFile->getEntityClustersGroupedClusters()) |
---|
382 | { |
---|
383 | BBC::EntityPtr entity; |
---|
384 | entity = BBC::EntityPtr(new BBC::Entity()); |
---|
385 | |
---|
386 | for (unsigned int iBillboard = 0; iBillboard < mLeaves->getBillboardCloud()->getNumBillboards(); iBillboard++) |
---|
387 | { |
---|
388 | billboardClusterData = mLeaves->getBillboardCloud()->getBillboard(iBillboard)->getBillboardClusterData(); |
---|
389 | entityCluster = billboardClusterData->getEntityCluster(); |
---|
390 | |
---|
391 | if (entityCluster->getNumEntitiesClusterData() > 0) |
---|
392 | { |
---|
393 | BBC::EntityPtr entityClusterized = entityCluster->getEntity(); |
---|
394 | entityClusterized->getSubEntity(0)->setMaterialName(mSampleConfigFile->getEntityClustersGroupedMaterialName()); |
---|
395 | BBC::SubEntityPtr subEntity = entityClusterized->getSubEntity(0); |
---|
396 | |
---|
397 | if (numSerializedBillboards == 0) |
---|
398 | { |
---|
399 | // delete the default constructed subentity... |
---|
400 | entity->removeSubEntity(0); |
---|
401 | |
---|
402 | // Add our first subentity... |
---|
403 | entity->addSubEntity(subEntity); |
---|
404 | } |
---|
405 | else |
---|
406 | { |
---|
407 | entity->addSubEntity(subEntity); |
---|
408 | } |
---|
409 | |
---|
410 | numSerializedBillboards++; |
---|
411 | } |
---|
412 | } |
---|
413 | |
---|
414 | Ogre::LogManager::getSingleton().logMessage(" Mesh Generation --" + Ogre::StringConverter::toString(numSerializedBillboards)); |
---|
415 | |
---|
416 | mOgreMeshSerializer->setEntity(entity); |
---|
417 | mOgreMeshSerializer->exportMesh(mSampleConfigFile->getEntityClustersFolder() + |
---|
418 | mSampleConfigFile->getEntityClustersGroupedMeshName(), false, false); |
---|
419 | |
---|
420 | OBA::OgreBase::getSingleton().getMeshSerializer()->exportMesh(entity->getMesh()->get(), mSampleConfigFile->getEntityClustersFolder() + mSampleConfigFile->getEntityClustersGroupedMeshName()); |
---|
421 | //OBA::OgreBase::getSingleton().getXMLMeshSerializer()->exportMesh(entity->getMesh(), mSampleConfigFile->getEntityClustersFolder() + mSampleConfigFile->getEntityClustersMeshPrefixName() + "Merged.mesh" + ".xml"); |
---|
422 | |
---|
423 | //mColladaMeshSerializer->setEntity(entity); |
---|
424 | //mColladaMeshSerializer->exportMesh(mSampleConfigFile->getEntityClustersFolder() + |
---|
425 | // mSampleConfigFile->getEntityClustersGroupedMeshName(), false, false); |
---|
426 | } |
---|
427 | } |
---|
428 | |
---|
429 | void LBBCManager::createEntityClusters() |
---|
430 | { |
---|
431 | mBillboardCloudGenerator->setDistribution(mLeaves->getDistribution()); |
---|
432 | mBillboardCloudGenerator->setBillboardCloud(mLeaves->getBillboardCloud()); |
---|
433 | mBillboardCloudGenerator->setMaxNumBillboards(mSampleConfigFile->getEntityClustersMaxClusters()); |
---|
434 | ((KMeansClusterGenerator*)mBillboardCloudGenerator)->setAlpha(mSampleConfigFile->getEntityClustersAlpha()); |
---|
435 | ((KMeansClusterGenerator*)mBillboardCloudGenerator)->setNumIterations(mSampleConfigFile->getEntityClustersNumIterations()); |
---|
436 | ((KMeansClusterGenerator*)mBillboardCloudGenerator)->generate(); |
---|
437 | } |
---|
438 | |
---|
439 | void LBBCManager::saveSingleEntity() |
---|
440 | { |
---|
441 | BBC::EntityPtr entityLeaf = mLeaves->getDistribution()->getEntity(2); |
---|
442 | entityLeaf->getSubEntity(0)->setMaterialName(mSampleConfigFile->getEntitySampleMaterialName()); |
---|
443 | |
---|
444 | mOgreMeshSerializer->setEntity(entityLeaf); |
---|
445 | mOgreMeshSerializer->exportMesh(mSampleConfigFile->getEntityDistributionFolder() + |
---|
446 | mSampleConfigFile->getEntitySampleMeshName(), false, false); |
---|
447 | |
---|
448 | OBA::OgreBase::getSingleton().getMeshSerializer()->exportMesh(entityLeaf->getMesh()->get(), mSampleConfigFile->getEntityDistributionFolder() + mSampleConfigFile->getEntitySampleMeshName()); |
---|
449 | //OBA::OgreBase::getSingleton().getXMLMeshSerializer()->exportMesh(entityLeaf->getMesh()->get(), mSampleConfigFile->getEntityDistributionFolder() + mSampleConfigFile->getEntitySampleMeshName() + ".xml"); |
---|
450 | |
---|
451 | mColladaMeshSerializer->setEntity(entityLeaf); |
---|
452 | mColladaMeshSerializer->exportMesh(mSampleConfigFile->getEntityDistributionFolder() + |
---|
453 | mSampleConfigFile->getEntitySampleMeshName(), false, false); |
---|
454 | } |
---|
455 | |
---|
456 | void LBBCManager::generateEntityClusters() |
---|
457 | { |
---|
458 | createEntityClusters(); |
---|
459 | saveEntityClusters(); |
---|
460 | } |
---|
461 | |
---|
462 | void LBBCManager::generateBillboardCloud() |
---|
463 | { |
---|
464 | mLeaves->getBillboardCloud()->generateBillboardCloud(false); |
---|
465 | if (mSampleConfigFile->getBillboardCloudGroupedDiffuseColorBillboards()) |
---|
466 | { |
---|
467 | mLeaves->getBillboardCloud()->initializeBillboardCloudGroups(mSampleConfigFile->getBillboardCloudGroupedDiffuseColorGroups()); |
---|
468 | |
---|
469 | mBillboardCloudUVMapper->shutdown(); |
---|
470 | mBillboardCloudUVMapper->setBillboardCloud(mLeaves->getBillboardCloud()); |
---|
471 | mBillboardCloudUVMapper->setTextureWidth(mSampleConfigFile->getBillboardCloudDiffuseColorGroupedBillboardsTextureSize()); |
---|
472 | mBillboardCloudUVMapper->setTextureHeight(mSampleConfigFile->getBillboardCloudDiffuseColorGroupedBillboardsTextureSize()); |
---|
473 | mBillboardCloudUVMapper->setTextureAtlasWidth(mSampleConfigFile->getBillboardCloudDiffuseColorGroupedBillboardsTextureAtlasSize()); |
---|
474 | mBillboardCloudUVMapper->setTextureAtlasHeight(mSampleConfigFile->getBillboardCloudDiffuseColorGroupedBillboardsTextureAtlasSize()); |
---|
475 | mBillboardCloudUVMapper->generateTextureAtlasTextureCoords(false, mSampleConfigFile->getBillboardCloudGroupedDiffuseColorBillboards(), mSampleConfigFile->getBillboardCloudGroupedDiffuseColorGroups()); |
---|
476 | |
---|
477 | mLeaves->getBillboardCloud()->generateBillboardCloudGroups(); |
---|
478 | saveBillboardCloudGroupedDiffuseColor(); |
---|
479 | saveBillboardCloudGroupedDiffuseColorXML(); |
---|
480 | } |
---|
481 | |
---|
482 | if (mSampleConfigFile->getBillboardCloudGroupedIndirectTexturingBillboards()) |
---|
483 | { |
---|
484 | mLeaves->getBillboardCloud()->initializeBillboardCloudGroups(mSampleConfigFile->getBillboardCloudGroupedIndirectTexturingGroups()); |
---|
485 | |
---|
486 | mBillboardCloudUVMapper->shutdown(); |
---|
487 | mBillboardCloudUVMapper->setBillboardCloud(mLeaves->getBillboardCloud()); |
---|
488 | mBillboardCloudUVMapper->setTextureWidth(mSampleConfigFile->getBillboardCloudIndirectGroupedBillboardsTextureSize()); |
---|
489 | mBillboardCloudUVMapper->setTextureHeight(mSampleConfigFile->getBillboardCloudIndirectGroupedBillboardsTextureSize()); |
---|
490 | mBillboardCloudUVMapper->setTextureAtlasWidth(mSampleConfigFile->getBillboardCloudIndirectGroupedBillboardsTextureAtlasSize()); |
---|
491 | mBillboardCloudUVMapper->setTextureAtlasHeight(mSampleConfigFile->getBillboardCloudIndirectGroupedBillboardsTextureAtlasSize()); |
---|
492 | mBillboardCloudUVMapper->generateTextureAtlasTextureCoords(false, mSampleConfigFile->getBillboardCloudGroupedIndirectTexturingBillboards(), mSampleConfigFile->getBillboardCloudGroupedIndirectTexturingGroups()); |
---|
493 | |
---|
494 | mLeaves->getBillboardCloud()->generateBillboardCloudGroups(); |
---|
495 | saveBillboardCloudGroupedIndirectTexturing(); |
---|
496 | saveBillboardCloudGroupedIndirectTexturingXML(); |
---|
497 | } |
---|
498 | |
---|
499 | if (mSampleConfigFile->getBillboardCloudSplittedBillboards()) |
---|
500 | { |
---|
501 | mLeaves->getBillboardCloud()->generateBillboardCloud(false); |
---|
502 | saveBillboardCloudSplitted(); |
---|
503 | saveBillboardCloudSplittedXML(); |
---|
504 | } |
---|
505 | |
---|
506 | generateBillboardCloudDiffuseColorPointCluster(); |
---|
507 | } |
---|
508 | |
---|
509 | void LBBCManager::generateBillboardCloudDiffuseColorPointCluster() |
---|
510 | { |
---|
511 | BBC::EntityPtr entity; |
---|
512 | entity = BBC::EntityPtr(new BBC::Entity()); |
---|
513 | mDiffuseColorPointClusterGenerator->setEntity(entity); |
---|
514 | mDiffuseColorPointClusterGenerator->setMaterialName(mSampleConfigFile->getBillboardCloudDiffuseColorPointClustersMaterialName()); |
---|
515 | mDiffuseColorPointClusterGenerator->setNumSamples(mSampleConfigFile->getBillboardCloudDiffuseColorEntityTextureAtlasNumSamples()); |
---|
516 | mDiffuseColorPointClusterGenerator->setBillboardCloud(getLeaves()->getBillboardCloud()); |
---|
517 | mDiffuseColorPointClusterGenerator->generateDiffuseColorPointCluster(); |
---|
518 | saveBillboardCloudDiffuseColorPointCluster(); |
---|
519 | } |
---|
520 | |
---|
521 | void LBBCManager::saveBillboardCloudDiffuseColorPointCluster() |
---|
522 | { |
---|
523 | mOgreMeshSerializer->setEntity(mDiffuseColorPointClusterGenerator->getEntity()); |
---|
524 | mOgreMeshSerializer->exportMesh(mSampleConfigFile->getBillboardCloudFolder() + mSampleConfigFile->getBillboardCloudDiffuseColorPointClustersMeshName(), false, false); |
---|
525 | OBA::OgreBase::getSingleton().getMeshSerializer()->exportMesh(mDiffuseColorPointClusterGenerator->getEntity()->getMesh()->get(), mSampleConfigFile->getEntityDistributionFolder() + mSampleConfigFile->getBillboardCloudDiffuseColorPointClustersMeshName()); |
---|
526 | //OBA::OgreBase::getSingleton().getXMLMeshSerializer()->exportMesh(entity->getMesh()->get(), mSampleConfigFile->getEntityDistributionFolder() + mSampleConfigFile->getBillboardCloudIndirectPointMeshName() + ".xml"); |
---|
527 | } |
---|
528 | |
---|
529 | Leaves* LBBCManager::getLeaves() |
---|
530 | { |
---|
531 | return mLeaves; |
---|
532 | } |
---|
533 | |
---|
534 | } |
---|