Changeset 961 for GTP/trunk/Lib/Illum
- Timestamp:
- 05/15/06 18:48:34 (19 years ago)
- Location:
- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src
-
Property
svn:ignore
set to
LBBCPointClusterGenerator.cpp
-
Property
svn:ignore
set to
-
GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/IBRBillboardCloudTreeApplication.cpp
r950 r961 253 253 } 254 254 255 { 256 LBBC::SceneViewMode *anotherFrameListenerMode; 257 anotherFrameListenerMode = new LBBC::SceneViewMode(mWindow,mFrameListener->getNumFrameListenerModes()); 258 anotherFrameListenerMode->chooseSceneManager(); 259 anotherFrameListenerMode->createCamera(); 260 anotherFrameListenerMode->createViewports(); 261 anotherFrameListenerMode->createScene(); 262 //anotherFrameListenerMode->loadScene("../../media/scene/scene.OSM"); 263 ////anotherFrameListenerMode->loadScene("../../media/scene/sceneLeaves.OSM"); 264 //anotherFrameListenerMode->loadScene("../../media/scene/scenePointLeaves.OSM"); 265 mFrameListener->addFrameListenerMode(anotherFrameListenerMode); 266 } 267 255 268 mFrameListener->removeFrameListenerMode(0); 256 269 mFrameListener->setEnabledFrameListenerMode(0); -
GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/IBRBillboardCloudTreeFrameListener.cpp
r900 r961 106 106 } 107 107 108 if (mInputDevice->isKeyDown(Ogre::KC_F7)) 109 { 110 mCurrentOgreFrameListenerMode = 6; 111 this->setEnabledFrameListenerMode(mCurrentOgreFrameListenerMode); 112 mWindow->setDebugText(""); 113 114 //mTimeUntilNextToggle = 0.25; 115 } 116 108 117 // Return true to continue rendering 109 118 return true; -
GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/LBBCManager.cpp
r958 r961 11 11 mLeafDistributionGenerator = new LeafDistributionGenerator(); 12 12 mBillboardCloudGenerator = new KMeansClusterGenerator(); 13 mDiffuseColorPointClusterGenerator = new DiffuseColorPointClusterGenerator(); 13 14 mBillboardCloudUVMapper = new BBC::BillboardCloudUVMapper(); 14 15 mOgreMeshSerializer = new BBC::OgreMeshSerializer(); … … 34 35 { 35 36 delete mLeafDistributionSerializer; 37 } 38 if (mDiffuseColorPointClusterGenerator) 39 { 40 delete mDiffuseColorPointClusterGenerator; 36 41 } 37 42 if (mLeafDistributionGenerator) … … 499 504 } 500 505 501 saveBillboardCloudIndirectSplittedPointMeshName();502 } 503 504 void LBBCManager:: saveBillboardCloudIndirectSplittedPointMeshName()506 generateBillboardCloudDiffuseColorPointCluster(); 507 } 508 509 void LBBCManager::generateBillboardCloudDiffuseColorPointCluster() 505 510 { 506 511 BBC::EntityPtr entity; 507 unsigned int numSubEntities = 0;508 509 512 entity = BBC::EntityPtr(new BBC::Entity()); 510 entity->removeSubEntity(0); 511 512 for (unsigned int iBillboard = 0; iBillboard < getLeaves()->getBillboardCloud()->getNumBillboards(); iBillboard++) 513 { 514 BBC::BillboardPtr billboard = getLeaves()->getBillboardCloud()->getBillboard(iBillboard); 515 BBC::EntityClusterPtr entityCluster = billboard->getBillboardClusterData()->getEntityCluster(); 516 517 if (entityCluster->getNumEntitiesClusterData() > 0) 518 { 519 entity->createSubEntity(); 520 entity->getSubEntity(numSubEntities)->setMaterialName(mSampleConfigFile->getBillboardCloudIndirectPointMaterialName()); 521 entity->getSubEntity(numSubEntities)->enableNormals(false); 522 entity->getSubEntity(numSubEntities)->enableTextureCoords(true); 523 entity->getSubEntity(numSubEntities)->addTextureCoordSet(2); 524 entity->getSubEntity(numSubEntities)->enableVertexColours(true); 525 526 Ogre::Vector3 p1, p2, p3, p4, pa, pb; 527 Ogre::Real mua, mub; 528 Ogre::Real height, width; 529 Ogre::Real hDistance, wDistance; 530 531 height = Ogre::Vector3(billboard->getBillboardClusterData()->getQuadTopLeftCorner() - billboard->getBillboardClusterData()->getQuadBottomLeftCorner()).length(); 532 width = Ogre::Vector3(billboard->getBillboardClusterData()->getQuadTopLeftCorner() - billboard->getBillboardClusterData()->getQuadTopRightCorner()).length(); 533 534 for (unsigned int iLeaf = 0; iLeaf < entityCluster->getNumEntitiesClusterData(); iLeaf++) 535 { 536 BBC::UniqueVertex vertex; 537 538 //LeafKMeansClusterData *leafKMeansClusterData = (LeafKMeansClusterData*)entityCluster->getEntityClusterData(iLeaf).get(); 539 //Leaf *leaf = (Leaf*)leafKMeansClusterData->getEntity().get(); 540 BBC::EntityClusterData* entityClusterData = entityCluster->getEntityClusterData(iLeaf).get(); 541 Leaf *leaf = (Leaf*)entityClusterData->getEntity().get(); 542 vertex.position = leaf->getPosition(); 543 544 //hDistance = 0.0; 545 //wDistance = 0.0; 546 547 //p1 = billboard->getBillboardClusterData()->getQuadTopRightCorner(); 548 //p2 = billboard->getBillboardClusterData()->getQuadBottomRightCorner(); 549 //p3 = leaf->getPosition(); 550 //p4 = leaf->getPosition() + billboard->getBillboardClusterData()->getAxisY(); 551 552 //if (BBC::Util::lineLineIntersect(p1, p2, p3, p4, &pa, &pb, &mua, &mub)) 553 //{ 554 // hDistance = Ogre::Vector3(pa - p1).length(); 555 //} 556 //else 557 //{ 558 // Ogre::LogManager::getSingleton().logMessage("Error with intersection: no solution exists."); 559 //} 560 561 //p1 = billboard->getBillboardClusterData()->getQuadTopLeftCorner(); 562 //p2 = billboard->getBillboardClusterData()->getQuadTopRightCorner(); 563 //p3 = leaf->getPosition(); 564 //p4 = leaf->getPosition() + billboard->getBillboardClusterData()->getAxisX(); 565 566 //if (BBC::Util::lineLineIntersect(p1, p2, p3, p4, &pa, &pb, &mua, &mub)) 567 //{ 568 // wDistance = Ogre::Vector3(pa - p2).length(); 569 //} 570 //else 571 //{ 572 // Ogre::LogManager::getSingleton().logMessage("Error with intersection: no solution exists."); 573 //} 574 575 //Ogre::LogManager::getSingleton().logMessage("W:" + Ogre::StringConverter::toString(width) + " UW:" + Ogre::StringConverter::toString(wDistance)); 576 //Ogre::LogManager::getSingleton().logMessage("H:" + Ogre::StringConverter::toString(height) + " UH:" + Ogre::StringConverter::toString(hDistance)); 577 578 //vertex.uv[0] = Ogre::Vector3(wDistance / width, hDistance / height, 0.0); 579 //vertex.uv[0] = Ogre::Vector3(1.0 - (hDistance / height), 1.0 - (wDistance / width), 0.0); 580 Ogre::Real numSamples = mSampleConfigFile->getBillboardCloudDiffuseColorEntityTextureAtlasNumSamples(); 581 Ogre::Real randomInt = Ogre::Math::Ceil(Ogre::Math::RangeRandom(0.5,numSamples)); 582 583 Ogre::Vector2 topLeftCorner[16]; 584 topLeftCorner[0] = Ogre::Vector2(0.0, 0.0); 585 topLeftCorner[1] = Ogre::Vector2(0.25, 0.0); 586 topLeftCorner[2] = Ogre::Vector2(0.5, 0.0); 587 topLeftCorner[3] = Ogre::Vector2(0.75, 0.0); 588 topLeftCorner[4] = Ogre::Vector2(0.0, 0.25); 589 topLeftCorner[5] = Ogre::Vector2(0.25, 0.25); 590 topLeftCorner[6] = Ogre::Vector2(0.5, 0.25); 591 topLeftCorner[7] = Ogre::Vector2(0.75, 0.25); 592 topLeftCorner[8] = Ogre::Vector2(0.0, 0.5); 593 topLeftCorner[9] = Ogre::Vector2(0.25, 0.5); 594 topLeftCorner[10] = Ogre::Vector2(0.5, 0.5); 595 topLeftCorner[11] = Ogre::Vector2(0.75, 0.5); 596 topLeftCorner[12] = Ogre::Vector2(0.0, 0.75); 597 topLeftCorner[13] = Ogre::Vector2(0.25, 0.75); 598 topLeftCorner[14] = Ogre::Vector2(0.5, 0.75); 599 topLeftCorner[15] = Ogre::Vector2(0.75, 0.75); 600 601 //vertex.uv[0] = Ogre::Vector3(randomInt / numSamples, 0.0, 0.0); 602 603 vertex.uv[0] = Ogre::Vector3(1.0 - topLeftCorner[(unsigned int)randomInt-1][0], 1.0 - topLeftCorner[(unsigned int)randomInt-1][1], 0.0); 604 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(); 605 entity->getSubEntity(numSubEntities)->addUniqueVertex(vertex); 606 } 607 608 unsigned int iVertexFace = 0; 609 Ogre::Vector3 faceVertexIndices = Ogre::Vector3::ZERO; 610 611 for (unsigned int iVertex = 0; iVertex < entity->getSubEntity(numSubEntities)->getNumVertices(); iVertex++) 612 { 613 faceVertexIndices[iVertexFace] = iVertex; 614 iVertexFace++; 615 616 if ((iVertex + 1) != entity->getSubEntity(numSubEntities)->getNumVertices()) 617 { 618 if (iVertexFace == 3) 619 { 620 entity->getSubEntity(numSubEntities)->addFaceVerticesIDs(faceVertexIndices); 621 iVertexFace = 0; 622 faceVertexIndices = Ogre::Vector3::ZERO; 623 } 624 } 625 else 626 { 627 entity->getSubEntity(numSubEntities)->addFaceVerticesIDs(faceVertexIndices); 628 } 629 } 630 631 numSubEntities++; 632 } 633 } 634 635 mOgreMeshSerializer->setEntity(entity); 513 mDiffuseColorPointClusterGenerator->setEntity(entity); 514 mDiffuseColorPointClusterGenerator->setMaterialName(mSampleConfigFile->getBillboardCloudIndirectPointMaterialName()); 515 mDiffuseColorPointClusterGenerator->setNumSamples(mSampleConfigFile->getBillboardCloudDiffuseColorEntityTextureAtlasNumSamples()); 516 mDiffuseColorPointClusterGenerator->setBillboardCloud(getLeaves()->getBillboardCloud()); 517 mDiffuseColorPointClusterGenerator->generateDiffuseColorPointCluster(); 518 saveBillboardCloudDiffuseColorPointCluster(); 519 } 520 521 void LBBCManager::saveBillboardCloudDiffuseColorPointCluster() 522 { 523 mOgreMeshSerializer->setEntity(mDiffuseColorPointClusterGenerator->getEntity()); 636 524 mOgreMeshSerializer->exportMesh(mSampleConfigFile->getBillboardCloudFolder() + mSampleConfigFile->getBillboardCloudIndirectPointMeshName(), false, false); 637 OBA::OgreBase::getSingleton().getMeshSerializer()->exportMesh( entity->getMesh()->get(), mSampleConfigFile->getEntityDistributionFolder() + mSampleConfigFile->getBillboardCloudIndirectPointMeshName());525 OBA::OgreBase::getSingleton().getMeshSerializer()->exportMesh(mDiffuseColorPointClusterGenerator->getEntity()->getMesh()->get(), mSampleConfigFile->getEntityDistributionFolder() + mSampleConfigFile->getBillboardCloudIndirectPointMeshName()); 638 526 //OBA::OgreBase::getSingleton().getXMLMeshSerializer()->exportMesh(entity->getMesh()->get(), mSampleConfigFile->getEntityDistributionFolder() + mSampleConfigFile->getBillboardCloudIndirectPointMeshName() + ".xml"); 639 640 527 } 641 528 -
GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/OBAOgreFrameListenerMode.cpp
r900 r961 3 3 4 4 namespace OBA { 5 6 void OSceneCallback::OnCameraCreate(Ogre::Camera* pCamera, TiXmlElement* pCameraDesc) 7 { 8 // If a camera of name "FirstCamera" is loaded, it will be set as the default current 9 if(pCamera->getName() == "FirstCamera") 10 Ogre::Root::getSingleton().getAutoCreatedWindow()->getViewport(0)->setCamera(pCamera); 11 } 5 12 6 13 OgreFrameListenerMode::OgreFrameListenerMode(Ogre::RenderWindow *win, unsigned int ogreFrameListenerModeHandle, bool useBufferedInputKeys, bool useBufferedInputMouse) … … 121 128 mCamera->yaw(mRotScale); 122 129 } 130 131 // We can cycle cameras with the 'c' key 132 if (mInputDevice->isKeyDown(Ogre::KC_C) && (mTimeUntilNextToggle <= 0)) 133 { 134 135 Ogre::Camera* firstCam; 136 Ogre::Camera* currentCam = mWindow->getViewport(0)->getCamera(); 137 138 Ogre::Viewport* vp = mWindow->getViewport(0); 139 140 Ogre::SceneManager::CameraIterator it = mSceneMgr->getCameraIterator(); 141 142 if(it.hasMoreElements()) 143 { 144 firstCam = it.peekNextValue(); 145 } 146 147 while(it.hasMoreElements()) 148 { 149 Ogre::Camera* cam = it.getNext(); 150 151 if(currentCam == cam) 152 { 153 Ogre::Camera* camera = it.hasMoreElements() ? it.getNext() : firstCam; 154 vp->setCamera(camera); 155 } 156 } 157 mTimeUntilNextToggle = 0.5f; 158 } 123 159 124 160 // see if switching is on, and you want to toggle … … 303 339 } 304 340 341 static Ogre::Real currentTime = 0; 342 343 // We update all loaded animations each frame 344 Ogre::SceneManager::AnimationIterator animationIt = mSceneMgr->getAnimationIterator(); 345 346 while(animationIt.hasMoreElements()) 347 { 348 Ogre::Animation* animation = animationIt.getNext(); 349 350 const Ogre::Animation::NodeTrackList& trackList = animation->_getNodeTrackList(); 351 352 Ogre::Animation::NodeTrackList::const_iterator it = trackList.begin(); 353 Ogre::Animation::NodeTrackList::const_iterator iend = trackList.end(); 354 355 for(; it != iend; ++it) { 356 const Ogre::NodeAnimationTrack* track = it->second; 357 track->getAssociatedNode()->resetToInitialState(); 358 } 359 360 currentTime += evt.timeSinceLastFrame; 361 animation->apply(currentTime); 362 } 363 305 364 return true; 306 365 } … … 410 469 } 411 470 471 void OgreFrameListenerMode::loadScene(Ogre::String filename) 472 { 473 // Create an oE_Loader Callback object to post-process created objects 474 OSceneCallback oeCallback; 475 476 mOScene = new OSMScene(mSceneMgr, mWindow); 477 478 // Initialises with the scene to be loaded and the callback if requiered 479 mOScene->initialise(filename.c_str(), &oeCallback); 480 481 // create and setup the scene in the root node 482 mOScene->createScene(); 483 } 484 412 485 void OgreFrameListenerMode::createScene() 413 486 {
Note: See TracChangeset
for help on using the changeset viewer.