#include "LBBCDiffuseColorPointClusterGenerator.h" namespace LBBC { DiffuseColorPointClusterGenerator::DiffuseColorPointClusterGenerator() { } DiffuseColorPointClusterGenerator::~DiffuseColorPointClusterGenerator() { } void DiffuseColorPointClusterGenerator::setBillboardCloud(BBC::BillboardCloud *billboardCloud) { mBillboardCloud = billboardCloud; } BBC::BillboardCloud* DiffuseColorPointClusterGenerator::getBillboardCloud() { return mBillboardCloud; } void DiffuseColorPointClusterGenerator::setEntity(BBC::EntityPtr entity) { mEntity = entity; } BBC::EntityPtr DiffuseColorPointClusterGenerator::getEntity() { return mEntity; } void DiffuseColorPointClusterGenerator::setNumSamples(Ogre::Real numSamples) { mNumSamples = numSamples; } Ogre::Real DiffuseColorPointClusterGenerator::getNumSamples() { return mNumSamples; } void DiffuseColorPointClusterGenerator::setMaterialName(Ogre::String materialName) { mMaterialName = materialName; } Ogre::String DiffuseColorPointClusterGenerator::getMaterialName() { return mMaterialName; } void DiffuseColorPointClusterGenerator::generateDiffuseColorPointCluster() { unsigned int numSubEntities = 0; mEntity->removeSubEntity(0); for (unsigned int iBillboard = 0; iBillboard < mBillboardCloud->getNumBillboards(); iBillboard++) { BBC::BillboardPtr billboard = mBillboardCloud->getBillboard(iBillboard); BBC::EntityClusterPtr entityCluster = billboard->getBillboardClusterData()->getEntityCluster(); if (entityCluster->getNumEntitiesClusterData() > 0) { mEntity->createSubEntity(); mEntity->getSubEntity(numSubEntities)->setMaterialName(mMaterialName); mEntity->getSubEntity(numSubEntities)->enableNormals(false); mEntity->getSubEntity(numSubEntities)->enableTextureCoords(true); mEntity->getSubEntity(numSubEntities)->addTextureCoordSet(2); mEntity->getSubEntity(numSubEntities)->enableVertexColours(true); Ogre::Vector3 p1, p2, p3, p4, pa, pb; Ogre::Real height, width; height = Ogre::Vector3(billboard->getBillboardClusterData()->getQuadTopLeftCorner() - billboard->getBillboardClusterData()->getQuadBottomLeftCorner()).length(); width = Ogre::Vector3(billboard->getBillboardClusterData()->getQuadTopLeftCorner() - billboard->getBillboardClusterData()->getQuadTopRightCorner()).length(); for (unsigned int iLeaf = 0; iLeaf < entityCluster->getNumEntitiesClusterData(); iLeaf++) { BBC::UniqueVertex vertex; BBC::EntityClusterData* entityClusterData = entityCluster->getEntityClusterData(iLeaf).get(); Leaf *leaf = (Leaf*)entityClusterData->getEntity().get(); vertex.position = leaf->getPosition(); Ogre::Real numSamples = mNumSamples; Ogre::Real randomInt = Ogre::Math::Ceil(Ogre::Math::RangeRandom(0.5,numSamples)); Ogre::Vector2 topLeftCorner[16]; topLeftCorner[0] = Ogre::Vector2(0.0, 0.0); topLeftCorner[1] = Ogre::Vector2(0.25, 0.0); topLeftCorner[2] = Ogre::Vector2(0.5, 0.0); topLeftCorner[3] = Ogre::Vector2(0.75, 0.0); topLeftCorner[4] = Ogre::Vector2(0.0, 0.25); topLeftCorner[5] = Ogre::Vector2(0.25, 0.25); topLeftCorner[6] = Ogre::Vector2(0.5, 0.25); topLeftCorner[7] = Ogre::Vector2(0.75, 0.25); topLeftCorner[8] = Ogre::Vector2(0.0, 0.5); topLeftCorner[9] = Ogre::Vector2(0.25, 0.5); topLeftCorner[10] = Ogre::Vector2(0.5, 0.5); topLeftCorner[11] = Ogre::Vector2(0.75, 0.5); topLeftCorner[12] = Ogre::Vector2(0.0, 0.75); topLeftCorner[13] = Ogre::Vector2(0.25, 0.75); topLeftCorner[14] = Ogre::Vector2(0.5, 0.75); topLeftCorner[15] = Ogre::Vector2(0.75, 0.75); vertex.uv[0] = Ogre::Vector3(1.0 - topLeftCorner[(unsigned int)randomInt-1][0], 1.0 - topLeftCorner[(unsigned int)randomInt-1][1], 0.0); 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(); mEntity->getSubEntity(numSubEntities)->addUniqueVertex(vertex); } unsigned int iVertexFace = 0; Ogre::Vector3 faceVertexIndices = Ogre::Vector3::ZERO; for (unsigned int iVertex = 0; iVertex < mEntity->getSubEntity(numSubEntities)->getNumVertices(); iVertex++) { faceVertexIndices[iVertexFace] = iVertex; iVertexFace++; if ((iVertex + 1) != mEntity->getSubEntity(numSubEntities)->getNumVertices()) { if (iVertexFace == 3) { mEntity->getSubEntity(numSubEntities)->addFaceVerticesIDs(faceVertexIndices); iVertexFace = 0; faceVertexIndices = Ogre::Vector3::ZERO; } } else { mEntity->getSubEntity(numSubEntities)->addFaceVerticesIDs(faceVertexIndices); } } numSubEntities++; } } } }