1 | |
---|
2 | #include "LBBCBillboardCloudTextureViewMode.h" |
---|
3 | #include "LBBCLeaves.h" |
---|
4 | #include "LBBCManager.h" |
---|
5 | |
---|
6 | namespace LBBC { |
---|
7 | |
---|
8 | BillboardCloudTextureViewMode::BillboardCloudTextureViewMode(Ogre::RenderWindow* win, unsigned int ogreFrameListenerModeHandle, bool useBufferedInputKeys, bool useBufferedInputMouse) |
---|
9 | :OBA::OgreFrameListenerMode(win, ogreFrameListenerModeHandle, useBufferedInputKeys, useBufferedInputMouse) |
---|
10 | { |
---|
11 | mFrame = 0; |
---|
12 | mDebugOverlay->setScale(0.0, 0.0); |
---|
13 | } |
---|
14 | |
---|
15 | BillboardCloudTextureViewMode::~BillboardCloudTextureViewMode() |
---|
16 | { |
---|
17 | |
---|
18 | } |
---|
19 | |
---|
20 | bool BillboardCloudTextureViewMode::frameStarted(const Ogre::FrameEvent& evt, Ogre::InputReader *inputReader) |
---|
21 | { |
---|
22 | if (mFrame == 1) |
---|
23 | { |
---|
24 | for (unsigned int iSubEntity = 0; iSubEntity < mClusterizedEntities->getNumSubEntities(); iSubEntity++) |
---|
25 | { |
---|
26 | mClusterizedEntities->getSubEntity(iSubEntity)->setVisible(false); |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | if (mFrame > 1) |
---|
31 | { |
---|
32 | mClusterizedEntities->getSubEntity((mCurrentTexture-1) % mClusterizedEntities->getNumSubEntities())->setVisible(false); |
---|
33 | } |
---|
34 | |
---|
35 | if (mFrame == 1) |
---|
36 | { |
---|
37 | mTextureAtlas->update(); |
---|
38 | } |
---|
39 | |
---|
40 | if (mFrame > 1) |
---|
41 | { |
---|
42 | mClusterizedEntities->getSubEntity(mCurrentTexture % mClusterizedEntities->getNumSubEntities())->setVisible(true); |
---|
43 | mClusterTextureListener.setSubEntityVisible(mCurrentTexture% mClusterizedEntities->getNumSubEntities()); |
---|
44 | mClusterTexture->update(); |
---|
45 | |
---|
46 | //if (mCurrentTexture <= mNumTextures)
|
---|
47 | {
|
---|
48 | mClusterizedEntities->getSubEntity(mCurrentTexture)->setVisible(false);
|
---|
49 | mClusterTexture->getMaterial()->getTechnique(0)->getPass(0)->setAmbient( Ogre::Math::RangeRandom(0.0,1.0), Ogre::Math::RangeRandom(0.0,1.0), Ogre::Math::RangeRandom(0.0,1.0) );
|
---|
50 | mClusterTexture->getRectangle2D()->setVisible(true);
|
---|
51 | mTextureAtlas->getRectangle2D()->setVisible(true);
|
---|
52 | Ogre::Vector2 uvMapMax = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getBillboard(mCurrentTexture)->getBillboardClusterData()->getBillboardUVMapMax(0);
|
---|
53 | Ogre::Vector2 uvMapMin = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getBillboard(mCurrentTexture)->getBillboardClusterData()->getBillboardUVMapMin(0);
|
---|
54 | mClusterTexture->setCorners(uvMapMin[0], uvMapMax[1], uvMapMax[0], uvMapMin[1]);
|
---|
55 | mClusterTexture->getMaterial()->getTechnique(0)->getPass(0)->setAmbient(uvMapMax[0], uvMapMax[1], 0.0);
|
---|
56 | mTextureAtlas->update();
|
---|
57 | //mTextureAtlas->debug();
|
---|
58 | mClusterTexture->getRectangle2D()->setVisible(false);
|
---|
59 |
|
---|
60 | Ogre::LogManager::getSingleton().logMessage("Billboard(" + Ogre::StringConverter::toString(mCurrentTexture) + ") uvMapMin(" + Ogre::StringConverter::toString(uvMapMin[0]) + "," +
|
---|
61 | Ogre::StringConverter::toString(uvMapMin[1]) + ") uvMapMax(" + Ogre::StringConverter::toString(uvMapMax[0]) + "," +
|
---|
62 | Ogre::StringConverter::toString(uvMapMax[1]) + ")");
|
---|
63 | Ogre::LogManager::getSingleton().logMessage( |
---|
64 | "USize(" + Ogre::StringConverter::toString(Ogre::Math::Abs(uvMapMax[0]-uvMapMin[0])) + |
---|
65 | "," + Ogre::StringConverter::toString(Ogre::Math::Abs(uvMapMax[1]-uvMapMin[1])) + ")");
|
---|
66 |
|
---|
67 | mCurrentTexture++;
|
---|
68 |
|
---|
69 | if (mCurrentTexture == mNumTextures)
|
---|
70 | {
|
---|
71 | if (mBitRange == 32)
|
---|
72 | {
|
---|
73 | mDestPixelFormat = Ogre::PF_FLOAT32_RGBA;
|
---|
74 | }
|
---|
75 | else if (mBitRange == 16)
|
---|
76 | {
|
---|
77 | mDestPixelFormat = Ogre::PF_FLOAT16_RGBA;
|
---|
78 | }
|
---|
79 | else // mBitRange == 8
|
---|
80 | {
|
---|
81 | mDestPixelFormat = Ogre::PF_BYTE_RGBA;
|
---|
82 | }
|
---|
83 | mTextureAtlas->save(mTextureAtlasFolder, mTextureAtlasName, mDestPixelFormat);
|
---|
84 | }
|
---|
85 |
|
---|
86 | mCurrentTexture = mCurrentTexture % mNumTextures;
|
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | mFrame++; |
---|
91 | |
---|
92 | return OgreFrameListenerMode::frameStarted(evt, inputReader); |
---|
93 | } |
---|
94 | |
---|
95 | void BillboardCloudTextureViewMode::setTextureAtlasSize(unsigned int size) |
---|
96 | { |
---|
97 | mTextureAtlasSize = size; |
---|
98 | } |
---|
99 | |
---|
100 | void BillboardCloudTextureViewMode::setEntityName(Ogre::String entityName) |
---|
101 | { |
---|
102 | mEntityName = entityName; |
---|
103 | } |
---|
104 | |
---|
105 | void BillboardCloudTextureViewMode::setTextureAtlasBitRange(unsigned int bitRange) |
---|
106 | { |
---|
107 | mBitRange = bitRange; |
---|
108 | } |
---|
109 | |
---|
110 | void BillboardCloudTextureViewMode::setTextureSize(unsigned int size) |
---|
111 | { |
---|
112 | mTextureSize = size; |
---|
113 | } |
---|
114 | |
---|
115 | void BillboardCloudTextureViewMode::setTextureAtlasFolder(Ogre::String textureAtlasFolder) |
---|
116 | { |
---|
117 | mTextureAtlasFolder = textureAtlasFolder; |
---|
118 | } |
---|
119 |
|
---|
120 | void BillboardCloudTextureViewMode::setTextureAtlasName(Ogre::String textureAtlasName)
|
---|
121 | {
|
---|
122 | mTextureAtlasName = textureAtlasName;
|
---|
123 | } |
---|
124 | |
---|
125 | void BillboardCloudTextureViewMode::createScene() |
---|
126 | { |
---|
127 | if (mBitRange == 32)
|
---|
128 | {
|
---|
129 | mSrcPixelFormat = Ogre::PF_FLOAT32_RGBA;
|
---|
130 | }
|
---|
131 | else if (mBitRange == 16)
|
---|
132 | {
|
---|
133 | mSrcPixelFormat = Ogre::PF_FLOAT16_RGBA;
|
---|
134 | }
|
---|
135 | else // mBitRange == 8
|
---|
136 | {
|
---|
137 | mSrcPixelFormat = Ogre::PF_A8R8G8B8;
|
---|
138 | } |
---|
139 | |
---|
140 | LBBC::Leaves *mLeaves = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves(); |
---|
141 | Ogre::LogManager::getSingleton().logMessage("Num.Billboards:" + Ogre::StringConverter::toString(mLeaves->getBillboardCloud()->getNumBillboards())); |
---|
142 | Ogre::LogManager::getSingleton().logMessage("Num.BillboardGroups:" + Ogre::StringConverter::toString(mLeaves->getBillboardCloud()->getNumBillboardGroups())); |
---|
143 | Ogre::Vector2 uvMapMax = mLeaves->getBillboardCloud()->getBillboard(0)->getBillboardClusterData()->getBillboardUVMapMax(0); |
---|
144 | Ogre::Vector2 uvMapMin = mLeaves->getBillboardCloud()->getBillboard(0)->getBillboardClusterData()->getBillboardUVMapMin(0); |
---|
145 | Ogre::LogManager::getSingleton().logMessage("BillboardUVMapMax:" + Ogre::StringConverter::toString( Ogre::Vector3(uvMapMax[0], uvMapMax[1], 0.0) )); |
---|
146 | Ogre::LogManager::getSingleton().logMessage("BillboardUVMapMin:" + Ogre::StringConverter::toString( Ogre::Vector3(uvMapMin[0], uvMapMin[1], 0.0) )); |
---|
147 | |
---|
148 | mClusterizedEntitiesMergedSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
149 | Ogre::LogManager::getSingleton().logMessage("Mesh:" + mEntityName);
|
---|
150 | std::cin.get();
|
---|
151 |
|
---|
152 | mClusterizedEntities = mSceneMgr->createEntity(mEntityName, mEntityName);
|
---|
153 | //mClusterizedEntities = mSceneMgr->createEntity("mapleLeavesClusterizedEntitiesMerged.mesh", "mapleLeavesClusterizedEntitiesMerged.mesh");
|
---|
154 | mClusterizedEntitiesMergedSceneNode->attachObject(mClusterizedEntities); |
---|
155 | |
---|
156 | mTextureAtlas = IMG::TextureAtlasPtr( new IMG::TextureAtlas() );
|
---|
157 | mTextureAtlas->create("TextureAtlas", mTextureAtlasSize, mTextureAtlasSize, mSrcPixelFormat, mCamera);
|
---|
158 | mTextureAtlas->setRenderTargetListener(&mTextureAtlasListener);
|
---|
159 | mTextureAtlas->setTextureAtlasSceneNode(mClusterizedEntitiesMergedSceneNode);
|
---|
160 | Ogre::MaterialPtr materialPtr1 = Ogre::MaterialManager::getSingleton().create("textureAtlasMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
161 | materialPtr1->getTechnique(0)->getPass(0)->setDiffuse( 1.0, 1.0, 1.0, 1.0);
|
---|
162 | materialPtr1->getTechnique(0)->getPass(0)->setAlphaRejectSettings(Ogre::CMPF_GREATER_EQUAL, 10);
|
---|
163 | materialPtr1->getTechnique(0)->getPass(0)->createTextureUnitState("transparent.png"); |
---|
164 | materialPtr1->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureFiltering(Ogre::FO_NONE, Ogre::FO_NONE, Ogre::FO_NONE); |
---|
165 | materialPtr1->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
|
---|
166 | mTextureAtlas->setMaterial(materialPtr1.getPointer());
|
---|
167 | mTextureAtlas->setCorners(-1.0, 1.0, 1.0, -1.0);
|
---|
168 |
|
---|
169 | mClusterTexture = IMG::TexturePtr( new IMG::Texture() );
|
---|
170 | mClusterTexture->create("clusterTexture", mTextureSize, mTextureSize, mSrcPixelFormat, mCamera); |
---|
171 | mClusterTexture->setRenderTargetListener(&mClusterTextureListener);
|
---|
172 | Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().create("textureMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
173 | materialPtr->getTechnique(0)->getPass(0)->setAmbient( 1.0, Ogre::Math::RangeRandom(0.5,1.0), 1.0 );
|
---|
174 | materialPtr->getTechnique(0)->getPass(0)->setDiffuse( 1.0, 1.0, 1.0, 1.0 );
|
---|
175 | //materialPtr->getTechnique(0)->getPass(0)->setAlphaRejectSettings(Ogre::CMPF_GREATER_EQUAL, 10);
|
---|
176 | //materialPtr->getTechnique(0)->getPass(0)->createTextureUnitState("clusterTexture", 0);
|
---|
177 | mClusterTexture->setMaterial(materialPtr.getPointer());
|
---|
178 |
|
---|
179 | mTextureAtlas->addTexture(mClusterTexture);
|
---|
180 |
|
---|
181 | mClusterTextureListener.setNumTextures(mClusterizedEntities->getNumSubEntities());
|
---|
182 | mClusterTextureListener.setTextureAtlas(mTextureAtlas);
|
---|
183 | mClusterTextureListener.setTexture(mClusterTexture);
|
---|
184 | mClusterTextureListener.setEntity(mClusterizedEntities);
|
---|
185 |
|
---|
186 | mNumTextures = mClusterizedEntities->getNumSubEntities();
|
---|
187 | mCurrentTexture = 0;
|
---|
188 | } |
---|
189 | |
---|
190 | void BillboardCloudTextureViewMode::destroyScene() |
---|
191 | { |
---|
192 | |
---|
193 | } |
---|
194 | |
---|
195 | } |
---|