1 | |
---|
2 | #include "BBCBillboardCloud.h" |
---|
3 | |
---|
4 | namespace BBC { |
---|
5 | |
---|
6 | BillboardCloud::BillboardCloud() |
---|
7 | { |
---|
8 | //mEntity = new Entity(); |
---|
9 | mEntity = 0; |
---|
10 | } |
---|
11 | |
---|
12 | BillboardCloud::~BillboardCloud() |
---|
13 | { |
---|
14 | |
---|
15 | } |
---|
16 | |
---|
17 | void BillboardCloud::clearBillboardCloud() |
---|
18 | { |
---|
19 | Ogre::LogManager::getSingleton().logMessage("Before Num.Billboards:" + Ogre::StringConverter::toString(this->getNumBillboards())); |
---|
20 | while (this->getNumBillboardGroups() > 0) |
---|
21 | { |
---|
22 | this->removeBillboardGroup(this->getNumBillboardGroups()-1); |
---|
23 | } |
---|
24 | |
---|
25 | while (this->getNumBillboards() > 0) |
---|
26 | { |
---|
27 | this->removeBillboard(this->getNumBillboards()-1); |
---|
28 | } |
---|
29 | Ogre::LogManager::getSingleton().logMessage("After Num.Billboards:" + Ogre::StringConverter::toString(this->getNumBillboards())); |
---|
30 | } |
---|
31 | |
---|
32 | std::vector<BillboardPtr>* BillboardCloud::getBillboardList() |
---|
33 | { |
---|
34 | return &mBillboardList; |
---|
35 | } |
---|
36 | |
---|
37 | void BillboardCloud::setBillboardList(std::vector<BillboardPtr> &value) |
---|
38 | { |
---|
39 | mBillboardList = value; |
---|
40 | } |
---|
41 | |
---|
42 | unsigned int BillboardCloud::getNumBillboards() |
---|
43 | { |
---|
44 | return (unsigned int)(mBillboardList.size()); |
---|
45 | } |
---|
46 | |
---|
47 | void BillboardCloud::addBillboard(BillboardPtr value) |
---|
48 | { |
---|
49 | value->setBillboardHandle((unsigned int)(mBillboardList.size())); |
---|
50 | mBillboardList.push_back(value); |
---|
51 | } |
---|
52 | |
---|
53 | void BillboardCloud::removeBillboard(unsigned int value) |
---|
54 | { |
---|
55 | BillboardPtr billboard = mBillboardList[value]; |
---|
56 | mBillboardList.erase(mBillboardList.begin() + value); |
---|
57 | } |
---|
58 | |
---|
59 | BillboardPtr BillboardCloud::getBillboard(unsigned int value) |
---|
60 | { |
---|
61 | return mBillboardList[value]; |
---|
62 | } |
---|
63 | |
---|
64 | EntityPtr BillboardCloud::getEntity() |
---|
65 | { |
---|
66 | return mEntity; |
---|
67 | } |
---|
68 | |
---|
69 | EntityPtr BillboardCloud::getEntityGrouped() |
---|
70 | { |
---|
71 | return mEntityGrouped; |
---|
72 | } |
---|
73 | |
---|
74 | void BillboardCloud::setEntityGrouped(EntityPtr value) |
---|
75 | { |
---|
76 | mEntityGrouped = value; |
---|
77 | } |
---|
78 | |
---|
79 | void BillboardCloud::setEntity(EntityPtr value) |
---|
80 | { |
---|
81 | mEntity = value; |
---|
82 | } |
---|
83 | |
---|
84 | void BillboardCloud::generateBillboardCloud(bool mergeBillboards) |
---|
85 | { |
---|
86 | mEntity = EntityPtr(new Entity()); |
---|
87 | |
---|
88 | unsigned int numGeneratedBillboardClouds = 0; |
---|
89 | bool mergeBillboardCloudTexCoordGenerated = false; |
---|
90 | |
---|
91 | for (unsigned int iBillboard = 0; iBillboard < getNumBillboards(); iBillboard++) |
---|
92 | { |
---|
93 | BillboardPtr billboard = this->getBillboard(iBillboard); |
---|
94 | EntityClusterPtr entityCluster = billboard->getBillboardClusterData()->getEntityCluster(); |
---|
95 | |
---|
96 | if (entityCluster->getNumEntitiesClusterData() > 0) |
---|
97 | { |
---|
98 | SubEntityPtr subEntity; |
---|
99 | if (mergeBillboards) |
---|
100 | { |
---|
101 | subEntity = mEntity->getSubEntity(0); |
---|
102 | |
---|
103 | if (!mergeBillboardCloudTexCoordGenerated) |
---|
104 | { |
---|
105 | subEntity->enableVertexColours(true); |
---|
106 | |
---|
107 | mergeBillboardCloudTexCoordGenerated = true; |
---|
108 | } |
---|
109 | |
---|
110 | unsigned int offset = subEntity->getNumFaces() * 3; |
---|
111 | Ogre::Vector3 indicesA = Ogre::Vector3(offset, offset + 1, offset + 2); |
---|
112 | subEntity->addFaceVerticesIDs(indicesA); |
---|
113 | offset = subEntity->getNumFaces()*3; |
---|
114 | Ogre::Vector3 indicesB = Ogre::Vector3(offset, offset + 1, offset + 2); |
---|
115 | subEntity->addFaceVerticesIDs(indicesB); |
---|
116 | } |
---|
117 | else |
---|
118 | { |
---|
119 | // The entity has by default one subentity, if we need more |
---|
120 | // we have to create them. |
---|
121 | if (numGeneratedBillboardClouds > 0) |
---|
122 | { |
---|
123 | mEntity->createSubEntity(); |
---|
124 | } |
---|
125 | Ogre::Vector3 indices = Ogre::Vector3(0,1,2); |
---|
126 | subEntity = mEntity->getSubEntity(numGeneratedBillboardClouds); |
---|
127 | |
---|
128 | subEntity->enableVertexColours(true); |
---|
129 | |
---|
130 | //Ogre::LogManager::getSingleton().logMessage("BBC-SubEntity(" + Ogre::StringConverter::toString(numGeneratedBillboardClouds) + ") - Num.Tex.Coord.Sets:" + Ogre::StringConverter::toString(subEntity->getNumTexCoordSets())); |
---|
131 | |
---|
132 | subEntity->addFaceVerticesIDs(indices); |
---|
133 | subEntity->addFaceVerticesIDs(indices + Ogre::Vector3(3,3,3)); |
---|
134 | } |
---|
135 | |
---|
136 | UniqueVertex vFaceA1,vFaceA2,vFaceA3; |
---|
137 | // Face A of the billboard quad |
---|
138 | vFaceA1.position = billboard->getBillboardClusterData()->getQuadTopLeftCorner(); |
---|
139 | vFaceA2.position = billboard->getBillboardClusterData()->getQuadTopRightCorner(); |
---|
140 | vFaceA3.position = billboard->getBillboardClusterData()->getQuadBottomRightCorner(); |
---|
141 | |
---|
142 | vFaceA1.normal = billboard->getBillboardClusterData()->getNormal(); |
---|
143 | vFaceA2.normal = billboard->getBillboardClusterData()->getNormal(); |
---|
144 | vFaceA3.normal = billboard->getBillboardClusterData()->getNormal(); |
---|
145 | |
---|
146 | vFaceA1.colour = Ogre::ColourValue(1.0 , 0.0, 0.0, 0.0).getAsARGB(); |
---|
147 | vFaceA2.colour = Ogre::ColourValue(0.0, 0.0, 0.0, 0.0).getAsARGB(); |
---|
148 | vFaceA3.colour = Ogre::ColourValue(0.0, 1.0 ,0.0, 0.0).getAsARGB(); |
---|
149 | |
---|
150 | // Face B of the billboard quad |
---|
151 | UniqueVertex vFaceB1,vFaceB2,vFaceB3; |
---|
152 | vFaceB1.position = billboard->getBillboardClusterData()->getQuadBottomRightCorner(); |
---|
153 | vFaceB2.position = billboard->getBillboardClusterData()->getQuadBottomLeftCorner(); |
---|
154 | vFaceB3.position = billboard->getBillboardClusterData()->getQuadTopLeftCorner(); |
---|
155 | |
---|
156 | vFaceB1.normal = billboard->getBillboardClusterData()->getNormal(); |
---|
157 | vFaceB2.normal = billboard->getBillboardClusterData()->getNormal(); |
---|
158 | vFaceB3.normal = billboard->getBillboardClusterData()->getNormal(); |
---|
159 | |
---|
160 | vFaceB1.colour = Ogre::ColourValue(0.0, 1.0 ,0.0, 0.0).getAsARGB(); |
---|
161 | vFaceB2.colour = Ogre::ColourValue(1.0, 1.0, 0.0, 0.0).getAsARGB(); |
---|
162 | vFaceB3.colour = Ogre::ColourValue(1.0, 0.0, 0.0, 0.0).getAsARGB(); |
---|
163 | |
---|
164 | subEntity->addUniqueVertex(vFaceA1); |
---|
165 | subEntity->addUniqueVertex(vFaceA2); |
---|
166 | subEntity->addUniqueVertex(vFaceA3); |
---|
167 | subEntity->addUniqueVertex(vFaceB1); |
---|
168 | subEntity->addUniqueVertex(vFaceB2); |
---|
169 | subEntity->addUniqueVertex(vFaceB3); |
---|
170 | |
---|
171 | numGeneratedBillboardClouds++; |
---|
172 | } |
---|
173 | } |
---|
174 | } |
---|
175 | |
---|
176 | void BillboardCloud::initializeBillboardCloudGroups(unsigned int numberGroups) |
---|
177 | { |
---|
178 | for (unsigned int iSubEntity = 0; iSubEntity < mEntity->getNumSubEntities(); iSubEntity++) |
---|
179 | { |
---|
180 | mEntity->getSubEntity(iSubEntity)->removeTextureCoordSet(); |
---|
181 | } |
---|
182 | |
---|
183 | while (getNumBillboardGroups() > 0) |
---|
184 | { |
---|
185 | BillboardGroupPtr billboardGroup = getBillboardGroup(getNumBillboardGroups()-1); |
---|
186 | removeBillboardGroup(getNumBillboardGroups()-1); |
---|
187 | } |
---|
188 | |
---|
189 | unsigned int iBillboardGroup; |
---|
190 | for (iBillboardGroup = 0; iBillboardGroup < numberGroups; iBillboardGroup++) |
---|
191 | { |
---|
192 | BillboardGroupPtr billboardGroup = BillboardGroupPtr( new BillboardGroup() ); |
---|
193 | addBillboardGroup(billboardGroup); |
---|
194 | } |
---|
195 | |
---|
196 | unsigned int numGeneratedBillboardClouds = 0; |
---|
197 | for (unsigned int iBillboard = 0; iBillboard < getNumBillboards(); iBillboard++) |
---|
198 | { |
---|
199 | BillboardPtr billboard = this->getBillboard(iBillboard); |
---|
200 | EntityClusterPtr entityCluster = billboard->getBillboardClusterData()->getEntityCluster(); |
---|
201 | |
---|
202 | if (entityCluster->getNumEntitiesClusterData() > 0) |
---|
203 | { |
---|
204 | for (unsigned int iBillboardGroup = 0; iBillboardGroup < billboard->getBillboardClusterData()->getNumUVMapGroups(); iBillboardGroup++) |
---|
205 | { |
---|
206 | billboard->getBillboardClusterData()->removeBillboardUVMapMax(iBillboardGroup); |
---|
207 | billboard->getBillboardClusterData()->removeBillboardUVMapMin(iBillboardGroup); |
---|
208 | } |
---|
209 | numGeneratedBillboardClouds++; |
---|
210 | } |
---|
211 | } |
---|
212 | |
---|
213 | unsigned int numberBillboardsEachGroup = numGeneratedBillboardClouds / numberGroups; |
---|
214 | unsigned int numberBillboardsAddedFirstGroup = numGeneratedBillboardClouds % numberGroups; |
---|
215 | |
---|
216 | //Ogre::LogManager::getSingleton().logMessage("Num.Billboards:" + Ogre::StringConverter::toString(numGeneratedBillboardClouds)); |
---|
217 | //Ogre::LogManager::getSingleton().logMessage("Num.Billboards Each Group:" + Ogre::StringConverter::toString(numberBillboardsEachGroup)); |
---|
218 | //Ogre::LogManager::getSingleton().logMessage("Num.Billboards Added First Group:" + Ogre::StringConverter::toString(numberBillboardsAddedFirstGroup)); |
---|
219 | |
---|
220 | iBillboardGroup = 0; |
---|
221 | unsigned int iBillboardsInGroup = 0; |
---|
222 | for (unsigned int iBillboard = 0; iBillboard < getNumBillboards(); iBillboard++) |
---|
223 | { |
---|
224 | BillboardPtr billboard = this->getBillboard(iBillboard); |
---|
225 | EntityClusterPtr entityCluster = billboard->getBillboardClusterData()->getEntityCluster(); |
---|
226 | |
---|
227 | if (entityCluster->getNumEntitiesClusterData() > 0) |
---|
228 | { |
---|
229 | if ((iBillboardGroup == 0) && (iBillboardsInGroup < (numberBillboardsEachGroup + numberBillboardsAddedFirstGroup))) |
---|
230 | { |
---|
231 | getBillboardGroup(iBillboardGroup)->addBillboardHandle(billboard->getBillboardHandle()); |
---|
232 | iBillboardsInGroup++; |
---|
233 | } |
---|
234 | else |
---|
235 | { |
---|
236 | if ((iBillboardGroup > 0) && (iBillboardsInGroup < numberBillboardsEachGroup)) |
---|
237 | { |
---|
238 | getBillboardGroup(iBillboardGroup)->addBillboardHandle(billboard->getBillboardHandle()); |
---|
239 | iBillboardsInGroup++; |
---|
240 | } |
---|
241 | else |
---|
242 | { |
---|
243 | iBillboardGroup++; |
---|
244 | iBillboardsInGroup = 0; |
---|
245 | |
---|
246 | getBillboardGroup(iBillboardGroup)->addBillboardHandle(billboard->getBillboardHandle()); |
---|
247 | iBillboardsInGroup++; |
---|
248 | } |
---|
249 | } |
---|
250 | } |
---|
251 | } |
---|
252 | } |
---|
253 | |
---|
254 | void BillboardCloud::generateBillboardCloudGroups() |
---|
255 | { |
---|
256 | SubEntityPtr subEntityGroup; |
---|
257 | SubEntityPtr subEntity; |
---|
258 | EntityPtr entity = EntityPtr(new Entity()); |
---|
259 | unsigned int numGeneratedBillboardClouds = 0; |
---|
260 | |
---|
261 | for (unsigned int iBillboardGroup = 0; iBillboardGroup < this->getNumBillboardGroups(); iBillboardGroup++) |
---|
262 | { |
---|
263 | if (iBillboardGroup > 0) |
---|
264 | { |
---|
265 | entity->createSubEntity(); |
---|
266 | } |
---|
267 | |
---|
268 | subEntityGroup = entity->getSubEntity(iBillboardGroup); |
---|
269 | |
---|
270 | BillboardGroupPtr billboardGroup = this->getBillboardGroup(iBillboardGroup); |
---|
271 | |
---|
272 | for (unsigned int iBillboard = 0; iBillboard < billboardGroup->getNumBillboards(); iBillboard++) |
---|
273 | { |
---|
274 | unsigned int billboardHandle = billboardGroup->getBillboardHandle(iBillboard); |
---|
275 | BillboardPtr billboard = this->getBillboard(billboardHandle); |
---|
276 | |
---|
277 | BillboardClusterData *billboardClusterData = billboard->getBillboardClusterData().get(); |
---|
278 | |
---|
279 | if (billboardClusterData != NULL) |
---|
280 | { |
---|
281 | EntityClusterPtr entityCluster = billboardClusterData->getEntityCluster(); |
---|
282 | |
---|
283 | if (entityCluster->getNumEntitiesClusterData() > 0) |
---|
284 | { |
---|
285 | subEntity = mEntity->getSubEntity(numGeneratedBillboardClouds); |
---|
286 | |
---|
287 | while (subEntityGroup->getNumTexCoordSets() < subEntity->getNumTexCoordSets()) |
---|
288 | { |
---|
289 | subEntityGroup->addTextureCoordSet(subEntity->getTexCoordDimensions(subEntityGroup->getNumTexCoordSets())); |
---|
290 | } |
---|
291 | |
---|
292 | subEntityGroup->enableVertexColours(subEntity->hasVertexColours()); |
---|
293 | |
---|
294 | unsigned int offset = subEntityGroup->getNumFaces() * 3; |
---|
295 | Ogre::Vector3 indicesA = Ogre::Vector3(offset, offset + 1, offset + 2); |
---|
296 | subEntityGroup->addFaceVerticesIDs(indicesA); |
---|
297 | offset = subEntityGroup->getNumFaces()*3; |
---|
298 | Ogre::Vector3 indicesB = Ogre::Vector3(offset, offset + 1, offset + 2); |
---|
299 | subEntityGroup->addFaceVerticesIDs(indicesB); |
---|
300 | |
---|
301 | UniqueVertex vFaceA1,vFaceA2,vFaceA3; |
---|
302 | |
---|
303 | // Face A of the billboard quad |
---|
304 | vFaceA1.position = billboard->getBillboardClusterData()->getQuadTopLeftCorner(); |
---|
305 | vFaceA2.position = billboard->getBillboardClusterData()->getQuadTopRightCorner(); |
---|
306 | vFaceA3.position = billboard->getBillboardClusterData()->getQuadBottomRightCorner(); |
---|
307 | |
---|
308 | vFaceA1.normal = billboard->getBillboardClusterData()->getNormal(); |
---|
309 | vFaceA2.normal = billboard->getBillboardClusterData()->getNormal(); |
---|
310 | vFaceA3.normal = billboard->getBillboardClusterData()->getNormal(); |
---|
311 | |
---|
312 | if (subEntity->hasVertexColours()) |
---|
313 | { |
---|
314 | vFaceA1.colour = subEntity->getVertexColour(0); |
---|
315 | vFaceA2.colour = subEntity->getVertexColour(1); |
---|
316 | vFaceA3.colour = subEntity->getVertexColour(2); |
---|
317 | } |
---|
318 | |
---|
319 | UniqueVertex vFaceB1,vFaceB2,vFaceB3; |
---|
320 | |
---|
321 | // Face B of the billboard quad |
---|
322 | vFaceB1.position = billboard->getBillboardClusterData()->getQuadBottomRightCorner(); |
---|
323 | vFaceB2.position = billboard->getBillboardClusterData()->getQuadBottomLeftCorner(); |
---|
324 | vFaceB3.position = billboard->getBillboardClusterData()->getQuadTopLeftCorner(); |
---|
325 | |
---|
326 | vFaceB1.normal = billboard->getBillboardClusterData()->getNormal(); |
---|
327 | vFaceB2.normal = billboard->getBillboardClusterData()->getNormal(); |
---|
328 | vFaceB3.normal = billboard->getBillboardClusterData()->getNormal(); |
---|
329 | |
---|
330 | if (subEntity->hasVertexColours()) |
---|
331 | { |
---|
332 | vFaceB1.colour = subEntity->getVertexColour(3); |
---|
333 | vFaceB2.colour = subEntity->getVertexColour(4); |
---|
334 | vFaceB3.colour = subEntity->getVertexColour(5); |
---|
335 | } |
---|
336 | |
---|
337 | for (unsigned int iTexCoordSet = 0; iTexCoordSet < subEntityGroup->getNumTexCoordSets(); iTexCoordSet++) |
---|
338 | { |
---|
339 | vFaceA1.uv[iTexCoordSet] = subEntity->getUniqueVertex(0).uv[iTexCoordSet]; |
---|
340 | vFaceA2.uv[iTexCoordSet] = subEntity->getUniqueVertex(1).uv[iTexCoordSet]; |
---|
341 | vFaceA3.uv[iTexCoordSet] = subEntity->getUniqueVertex(2).uv[iTexCoordSet]; |
---|
342 | vFaceB1.uv[iTexCoordSet] = subEntity->getUniqueVertex(3).uv[iTexCoordSet]; |
---|
343 | vFaceB2.uv[iTexCoordSet] = subEntity->getUniqueVertex(4).uv[iTexCoordSet]; |
---|
344 | vFaceB3.uv[iTexCoordSet] = subEntity->getUniqueVertex(5).uv[iTexCoordSet]; |
---|
345 | } |
---|
346 | |
---|
347 | subEntityGroup->addUniqueVertex(vFaceA1); |
---|
348 | subEntityGroup->addUniqueVertex(vFaceA2); |
---|
349 | subEntityGroup->addUniqueVertex(vFaceA3); |
---|
350 | subEntityGroup->addUniqueVertex(vFaceB1); |
---|
351 | subEntityGroup->addUniqueVertex(vFaceB2); |
---|
352 | subEntityGroup->addUniqueVertex(vFaceB3); |
---|
353 | |
---|
354 | numGeneratedBillboardClouds++; |
---|
355 | } |
---|
356 | } |
---|
357 | } |
---|
358 | } |
---|
359 | |
---|
360 | mEntityGrouped = entity; |
---|
361 | } |
---|
362 | |
---|
363 | unsigned int BillboardCloud::getNumBillboardGroups() |
---|
364 | { |
---|
365 | return mBillboardGroupList.size(); |
---|
366 | } |
---|
367 | |
---|
368 | BillboardGroupPtr BillboardCloud::getBillboardGroup(unsigned int iBillboardGroup) |
---|
369 | { |
---|
370 | return mBillboardGroupList[iBillboardGroup]; |
---|
371 | } |
---|
372 | |
---|
373 | void BillboardCloud::addBillboardGroup(BillboardGroupPtr value) |
---|
374 | { |
---|
375 | mBillboardGroupList.push_back(value); |
---|
376 | } |
---|
377 | |
---|
378 | void BillboardCloud::removeBillboardGroup(unsigned int value) |
---|
379 | { |
---|
380 | BillboardGroupPtr billboardGroup = mBillboardGroupList[value]; |
---|
381 | mBillboardGroupList.erase(mBillboardGroupList.begin() + value); |
---|
382 | } |
---|
383 | |
---|
384 | } |
---|