1 | |
---|
2 | #include "BBCBillboardCloudUVMapper.h" |
---|
3 | #include "BBCBillboardCloud.h" |
---|
4 | #include "BBCEntityCluster.h" |
---|
5 | #include "BBCBillboardClusterData.h" |
---|
6 | |
---|
7 | namespace BBC { |
---|
8 | |
---|
9 | void BillboardCloudUVMapper::initialize() |
---|
10 | { |
---|
11 | IMG::Box2d *box = new IMG::Box2d;
|
---|
12 | IMG::NodeBsp *node = new IMG::NodeBsp;
|
---|
13 | box->SetBoundBox(0, 0, mTextureAtlasWidth, mTextureAtlasHeight);
|
---|
14 | node->SetBound(box);
|
---|
15 | mBsp.SetRoot(node); |
---|
16 | } |
---|
17 | |
---|
18 | void BillboardCloudUVMapper::setTextureWidth(unsigned short int width) |
---|
19 | { |
---|
20 | mTextureWidth = width; |
---|
21 | } |
---|
22 | |
---|
23 | unsigned short int BillboardCloudUVMapper::getTextureWidth() |
---|
24 | { |
---|
25 | return mTextureWidth; |
---|
26 | } |
---|
27 | |
---|
28 | void BillboardCloudUVMapper::setTextureHeight(unsigned short int height) |
---|
29 | { |
---|
30 | mTextureHeight = height; |
---|
31 | } |
---|
32 | |
---|
33 | unsigned short BillboardCloudUVMapper::getTextureHeight() |
---|
34 | { |
---|
35 | return mTextureHeight; |
---|
36 | } |
---|
37 | |
---|
38 | void BillboardCloudUVMapper::setTextureAtlasWidth(unsigned short int width) |
---|
39 | { |
---|
40 | mTextureAtlasWidth = width; |
---|
41 | } |
---|
42 | |
---|
43 | unsigned short int BillboardCloudUVMapper::getTextureAtlasWidth() |
---|
44 | { |
---|
45 | return mTextureAtlasWidth; |
---|
46 | } |
---|
47 | |
---|
48 | void BillboardCloudUVMapper::setTextureAtlasHeight(unsigned short int height) |
---|
49 | { |
---|
50 | mTextureAtlasHeight = height; |
---|
51 | } |
---|
52 | |
---|
53 | unsigned short BillboardCloudUVMapper::getTextureAtlasHeight() |
---|
54 | { |
---|
55 | return mTextureAtlasHeight; |
---|
56 | } |
---|
57 | |
---|
58 | void BillboardCloudUVMapper::generateTextureAtlasTextureCoords(bool mergeBillboards) |
---|
59 | {
|
---|
60 | |
---|
61 | for (unsigned int iBillboard = 0; iBillboard < mBillboardCloud->getNumBillboards(); iBillboard++)
|
---|
62 | {
|
---|
63 | Ogre::LogManager::getSingleton().logMessage("id:" + Ogre::StringConverter::toString(iBillboard));
|
---|
64 | BillboardClusterData *billboardClusterData = mBillboardCloud->getBillboard(iBillboard)->getBillboardClusterData(); |
---|
65 | |
---|
66 | if (billboardClusterData != NULL) |
---|
67 | { |
---|
68 | Ogre::LogManager::getSingleton().logMessage("billboardData"); |
---|
69 | EntityCluster *entityCluster = billboardClusterData->getEntityCluster(); |
---|
70 | if (entityCluster->getNumEntitiesClusterData() > 0) |
---|
71 | {
|
---|
72 | Ogre::LogManager::getSingleton().logMessage("entityCluster");
|
---|
73 |
|
---|
74 | IMG::NodeBsp *nodeDest;
|
---|
75 | IMG::Cluster cluster;
|
---|
76 | Ogre::LogManager::getSingleton().logMessage("w:" + Ogre::StringConverter::toString(mTextureWidth));
|
---|
77 | Ogre::LogManager::getSingleton().logMessage("h:" + Ogre::StringConverter::toString(mTextureHeight));
|
---|
78 | nodeDest = mBsp.Insert(mTextureWidth,mTextureHeight,iBillboard);
|
---|
79 |
|
---|
80 | cluster.SetBspNodeBound(nodeDest->GetBound());
|
---|
81 | //cluster.Finish();
|
---|
82 | mClusterList.Insert(&cluster);
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | //mBsp.Print();
|
---|
88 |
|
---|
89 | unsigned int numGeneratedBillboardClouds = 0;
|
---|
90 | bool enabledTextureCoordSet = false;
|
---|
91 | unsigned int iUniqueVertex = 0;
|
---|
92 |
|
---|
93 | for (unsigned int iBillboard = 0; iBillboard < mBillboardCloud->getNumBillboards(); iBillboard++)
|
---|
94 | {
|
---|
95 | Billboard *billboard = mBillboardCloud->getBillboard(iBillboard);
|
---|
96 | EntityCluster *entityCluster = billboard->getBillboardClusterData()->getEntityCluster();
|
---|
97 |
|
---|
98 | if (entityCluster->getNumEntitiesClusterData() > 0)
|
---|
99 | {
|
---|
100 | IMG::Cluster *cluster = mClusterList.Get(numGeneratedBillboardClouds);
|
---|
101 | IMG::Box2d *box = cluster->GetBspNodeBound();
|
---|
102 | Ogre::Vector2 max = box->GetMaximum();
|
---|
103 | Ogre::Vector2 min = box->GetMinimum();
|
---|
104 | Ogre::LogManager::getSingleton().logMessage("Max:" + Ogre::StringConverter::toString(Ogre::Vector3(max[0],max[1],0)) +
|
---|
105 | "\tMin:" + Ogre::StringConverter::toString(Ogre::Vector3(min[0],min[1],0)) +
|
---|
106 | "\tSize(" + Ogre::StringConverter::toString(max[0]-min[0]) +
|
---|
107 | "," + Ogre::StringConverter::toString(max[1]-min[1]) + ")");
|
---|
108 |
|
---|
109 |
|
---|
110 | SubEntity *subEntity;
|
---|
111 |
|
---|
112 | Ogre::Vector2 texCoords01,texCoords02,texCoords03,texCoords04;
|
---|
113 | texCoords01[0] = min[0] / mTextureAtlasWidth;
|
---|
114 | texCoords01[1] = min[1] / mTextureAtlasHeight;
|
---|
115 |
|
---|
116 | texCoords02[0] = max[0] / mTextureAtlasWidth;
|
---|
117 | texCoords02[1] = min[1] / mTextureAtlasHeight;
|
---|
118 |
|
---|
119 | texCoords03[0] = max[0] / mTextureAtlasWidth;
|
---|
120 | texCoords03[1] = max[1] / mTextureAtlasHeight;
|
---|
121 |
|
---|
122 | texCoords04[0] = min[0] / mTextureAtlasWidth;
|
---|
123 | texCoords04[1] = max[1] / mTextureAtlasHeight;
|
---|
124 |
|
---|
125 | if (!mergeBillboards)
|
---|
126 | {
|
---|
127 | subEntity = mBillboardCloud->getEntity()->getSubEntity(numGeneratedBillboardClouds);
|
---|
128 | subEntity->addTextureCoordSet(2);
|
---|
129 | subEntity->enableVertexColours(true);
|
---|
130 | // Face A
|
---|
131 | //(0,0,0);
|
---|
132 | //(1,0,0);
|
---|
133 | //(1,1,0);
|
---|
134 |
|
---|
135 | subEntity->setTexCoord(0, subEntity->getNumTexCoordSets()-1, Ogre::Vector3(texCoords01[0],texCoords01[1], 0));
|
---|
136 | subEntity->setTexCoord(1, subEntity->getNumTexCoordSets()-1, Ogre::Vector3(texCoords02[0],texCoords02[1], 0));
|
---|
137 | subEntity->setTexCoord(2, subEntity->getNumTexCoordSets()-1, Ogre::Vector3(texCoords03[0],texCoords03[1], 0));
|
---|
138 |
|
---|
139 | Ogre::ColourValue subEntityColour01 = Ogre::ColourValue(0, texCoords01[0],texCoords01[1]); |
---|
140 | Ogre::ColourValue subEntityColour02 = Ogre::ColourValue(0, texCoords02[0],texCoords02[1]); |
---|
141 | Ogre::ColourValue subEntityColour03 = Ogre::ColourValue(0, texCoords03[0],texCoords03[1]); |
---|
142 | |
---|
143 | subEntity->setVertexColour(0, subEntityColour01.getAsRGBA());
|
---|
144 | subEntity->setVertexColour(1, subEntityColour02.getAsRGBA());
|
---|
145 | subEntity->setVertexColour(2, subEntityColour03.getAsRGBA());
|
---|
146 |
|
---|
147 | // Face B
|
---|
148 | //(1,1,0);
|
---|
149 | //(0,1,0);
|
---|
150 | //(0,0,0);
|
---|
151 | subEntity->setTexCoord(3, subEntity->getNumTexCoordSets()-1, Ogre::Vector3(texCoords03[0],texCoords03[1],0));
|
---|
152 | subEntity->setTexCoord(4, subEntity->getNumTexCoordSets()-1, Ogre::Vector3(texCoords04[0],texCoords04[1],0));
|
---|
153 | subEntity->setTexCoord(5, subEntity->getNumTexCoordSets()-1, Ogre::Vector3(texCoords01[0],texCoords01[1],0));
|
---|
154 |
|
---|
155 | Ogre::ColourValue subEntityColour04 = Ogre::ColourValue(0, texCoords03[0],texCoords03[1]); |
---|
156 | Ogre::ColourValue subEntityColour05 = Ogre::ColourValue(0, texCoords04[0],texCoords04[1]); |
---|
157 | Ogre::ColourValue subEntityColour06 = Ogre::ColourValue(0, texCoords01[0],texCoords01[1]); |
---|
158 | |
---|
159 | subEntity->setVertexColour(3, subEntityColour04.getAsRGBA());
|
---|
160 | subEntity->setVertexColour(4, subEntityColour05.getAsRGBA());
|
---|
161 | subEntity->setVertexColour(5, subEntityColour06.getAsRGBA());
|
---|
162 |
|
---|
163 | }
|
---|
164 | else
|
---|
165 | {
|
---|
166 | subEntity = mBillboardCloud->getEntity()->getSubEntity(0);
|
---|
167 | if (!enabledTextureCoordSet)
|
---|
168 | {
|
---|
169 | subEntity->addTextureCoordSet(2);
|
---|
170 | subEntity->enableVertexColours(true);
|
---|
171 | enabledTextureCoordSet = true;
|
---|
172 | }
|
---|
173 |
|
---|
174 | // Face A
|
---|
175 | //(0,0,0);
|
---|
176 | //(1,0,0);
|
---|
177 | //(1,1,0);
|
---|
178 |
|
---|
179 | subEntity->setTexCoord(iUniqueVertex, subEntity->getNumTexCoordSets()-1, Ogre::Vector3(texCoords01[0],texCoords01[1],0));
|
---|
180 | subEntity->setTexCoord(iUniqueVertex+1, subEntity->getNumTexCoordSets()-1, Ogre::Vector3(texCoords02[0],texCoords02[1],0));
|
---|
181 | subEntity->setTexCoord(iUniqueVertex+2, subEntity->getNumTexCoordSets()-1, Ogre::Vector3(texCoords03[0],texCoords03[1],0));
|
---|
182 |
|
---|
183 | Ogre::ColourValue subEntityColour01 = Ogre::ColourValue(0, texCoords01[0],texCoords01[1]); |
---|
184 | Ogre::ColourValue subEntityColour02 = Ogre::ColourValue(0, texCoords02[0],texCoords02[1]); |
---|
185 | Ogre::ColourValue subEntityColour03 = Ogre::ColourValue(0, texCoords03[0],texCoords03[1]); |
---|
186 | |
---|
187 | subEntity->setVertexColour(iUniqueVertex, subEntityColour01.getAsRGBA());
|
---|
188 | subEntity->setVertexColour(iUniqueVertex+1, subEntityColour02.getAsRGBA());
|
---|
189 | subEntity->setVertexColour(iUniqueVertex+2, subEntityColour03.getAsRGBA());
|
---|
190 |
|
---|
191 |
|
---|
192 | // Face B
|
---|
193 | //(1,1,0);
|
---|
194 | //(0,1,0);
|
---|
195 | //(0,0,0);
|
---|
196 | subEntity->setTexCoord(iUniqueVertex+3, subEntity->getNumTexCoordSets()-1, Ogre::Vector3(texCoords03[0],texCoords03[1],0));
|
---|
197 | subEntity->setTexCoord(iUniqueVertex+4, subEntity->getNumTexCoordSets()-1, Ogre::Vector3(texCoords04[0],texCoords04[1],0));
|
---|
198 | subEntity->setTexCoord(iUniqueVertex+5, subEntity->getNumTexCoordSets()-1, Ogre::Vector3(texCoords01[0],texCoords01[1],0));
|
---|
199 |
|
---|
200 | Ogre::ColourValue subEntityColour04 = Ogre::ColourValue(0, texCoords03[0],texCoords03[1]); |
---|
201 | Ogre::ColourValue subEntityColour05 = Ogre::ColourValue(0, texCoords04[0],texCoords04[1]); |
---|
202 | Ogre::ColourValue subEntityColour06 = Ogre::ColourValue(0, texCoords01[0],texCoords01[1]); |
---|
203 | |
---|
204 | subEntity->setVertexColour(iUniqueVertex+3, subEntityColour04.getAsRGBA());
|
---|
205 | subEntity->setVertexColour(iUniqueVertex+4, subEntityColour05.getAsRGBA());
|
---|
206 | subEntity->setVertexColour(iUniqueVertex+5, subEntityColour06.getAsRGBA());
|
---|
207 |
|
---|
208 | iUniqueVertex = iUniqueVertex + 6;
|
---|
209 | }
|
---|
210 | numGeneratedBillboardClouds++;
|
---|
211 | }
|
---|
212 | }
|
---|
213 |
|
---|
214 | } |
---|
215 | |
---|
216 | void BillboardCloudUVMapper::setBillboardCloud(BillboardCloud *billboardCloud) |
---|
217 | { |
---|
218 | mBillboardCloud = billboardCloud; |
---|
219 | } |
---|
220 | |
---|
221 | BillboardCloud * BillboardCloudUVMapper::getBillboardCloud() |
---|
222 | { |
---|
223 | return mBillboardCloud; |
---|
224 | } |
---|
225 | |
---|
226 | BillboardCloudUVMapper::BillboardCloudUVMapper() |
---|
227 | { |
---|
228 | } |
---|
229 | |
---|
230 | BillboardCloudUVMapper::~BillboardCloudUVMapper() |
---|
231 | { |
---|
232 | } |
---|
233 | |
---|
234 | } |
---|