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