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