2025-01-04 04:12:51 +00:00
|
|
|
#include "scene/OEScene.h"
|
|
|
|
|
|
|
|
#include <osg/Shape>
|
|
|
|
#include <osg/ShapeDrawable>
|
|
|
|
#include <osg/PositionAttitudeTransform>
|
|
|
|
#include <osg/Program>
|
|
|
|
#include <osg/LightSource>
|
|
|
|
#include <osgDB/ReadFile>
|
2025-03-13 00:42:41 +00:00
|
|
|
#include <osgEarthUtil/EarthManipulator>
|
|
|
|
#include <osgGA/StateSetManipulator>
|
2025-01-04 04:12:51 +00:00
|
|
|
|
|
|
|
#include <osgShadow/ShadowedScene>
|
|
|
|
#include <osgShadow/ViewDependentShadowMap>
|
|
|
|
#include <osgViewer/ViewerEventHandlers>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "common/SpdLogger.h"
|
|
|
|
#include "common/RecourceHelper.h"
|
|
|
|
#include "scene/ScopedTimer.h"
|
|
|
|
#include "viewer/OsgView.h"
|
2025-01-05 13:49:36 +00:00
|
|
|
#include "viewer/OsgCameraManipulator.h"
|
2025-01-09 00:32:05 +00:00
|
|
|
#include "scene/ScaleBarHandler.h"
|
2025-01-04 04:12:51 +00:00
|
|
|
|
2025-02-22 15:16:54 +00:00
|
|
|
#include "effects/ConeWave.h"
|
|
|
|
|
2025-01-04 04:12:51 +00:00
|
|
|
const osgEarth::SpatialReference* g_srs_{ nullptr };
|
|
|
|
|
|
|
|
OEScene::OEScene() {
|
|
|
|
osgDB::FilePathList& pathList = osgDB::Registry::instance()->getDataFilePathList();
|
|
|
|
const std::string& basePath = RecourceHelper::Get().GetBasePath().toStdString();
|
|
|
|
pathList.push_back(basePath + "/resources/earth/");
|
|
|
|
pathList.push_back(basePath + "/resources/textures/");
|
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
Init();
|
2025-01-04 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
void OEScene::AttachView(osgViewer::View* view) {
|
2025-01-21 18:42:57 +00:00
|
|
|
dyt_check(nullptr != earthRootNode_);
|
2025-03-13 00:42:41 +00:00
|
|
|
skyDome_ = osgEarth::Util::SkyNode::create(earthMapNode_);
|
2025-01-04 04:12:51 +00:00
|
|
|
if (!earthMapNode_) {
|
|
|
|
LOG_WARN("eart map node is nullptr");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
dyt_check(nullptr != earthManipulator_);
|
|
|
|
view->setCameraManipulator(earthManipulator_);
|
|
|
|
skyDome_->attach(view);
|
|
|
|
skyDome_->getSunLight()->setAmbient(osg::Vec4(0.5,0.5,0.5,1.0));
|
|
|
|
addChild(skyDome_);
|
|
|
|
|
|
|
|
view->setCameraManipulator( new osgEarth::Util::EarthManipulator() );
|
2025-01-04 04:12:51 +00:00
|
|
|
|
|
|
|
skyDome_->setDateTime(osgEarth::DateTime(2024, 12, 24, 3));
|
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
view->setSceneData(this);
|
|
|
|
curentView_ = view;
|
2025-01-04 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
void OEScene::DetachView(osgViewer::View* view) {
|
|
|
|
view->setSceneData(nullptr);
|
2025-01-04 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
bool OEScene::AddToScene(osg::Node* node) const {
|
|
|
|
dyt_check(nullptr != entityRoot_);
|
|
|
|
return entityRoot_->addChild(node);
|
|
|
|
}
|
2025-01-04 04:12:51 +00:00
|
|
|
|
2025-04-21 00:20:00 +00:00
|
|
|
void OEScene::SetHomeViewpoint(const osgEarth::Viewpoint& viewpoint, double duration_s) {
|
|
|
|
dyt_check(nullptr != earthManipulator_);
|
|
|
|
earthManipulator_->setViewpoint(viewpoint, duration_s);
|
|
|
|
earthManipulator_->setHomeViewpoint(viewpoint, duration_s);
|
|
|
|
}
|
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
//
|
|
|
|
// void OEScene::InitEventHandle(osgViewer::View* view) {
|
|
|
|
// if (nullptr == view) {
|
|
|
|
// LOG_WARN("view is nullptr");
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// //view->GetView()->addEventHandler(new osgEarth::Util::EarthManipulator());
|
|
|
|
//
|
|
|
|
// view->addEventHandler(new osgViewer::HelpHandler);
|
|
|
|
// view->addEventHandler(new osgViewer::StatsHandler);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// void OEScene::DetachView(osgViewer::View* view) {
|
|
|
|
// if (nullptr != earthRootNode_) {
|
|
|
|
// std::vector<osg::Group*> parents = earthRootNode_->getParents();
|
|
|
|
// for (const auto& parent : parents) {
|
|
|
|
// parent->removeChild(earthRootNode_);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// logarithmicDepthBuffer_->uninstall(view->getCamera());
|
|
|
|
// view->setSceneData(nullptr);
|
|
|
|
//
|
|
|
|
// }
|
2025-01-04 04:12:51 +00:00
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
OESceneUI* OEScene::GetOrCreateSceneUI() {
|
|
|
|
if (sceneUI_) {
|
|
|
|
LOG_INFO("scene ui is already attached");
|
|
|
|
return sceneUI_.get();
|
|
|
|
}
|
2025-01-04 04:12:51 +00:00
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
sceneUI_ = new OESceneUI(this);
|
|
|
|
return sceneUI_.get();
|
|
|
|
}
|
2025-01-04 04:12:51 +00:00
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
osg::Viewport* OEScene::GetViewport() const {
|
|
|
|
dyt_check(nullptr != curentView_);
|
2025-01-04 04:12:51 +00:00
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
return curentView_->getCamera()->getViewport();
|
2025-01-04 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
const osgEarth::SpatialReference* OEScene::GetSrs() {
|
|
|
|
dyt_check(nullptr != g_srs_);
|
|
|
|
return g_srs_;
|
2025-01-04 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
void OEScene::Init() {
|
|
|
|
std::string earthPath = "D:/Project/DYT/Tool/TritonSample/TritonSample/triton.earth";
|
|
|
|
// earthRootNode_ = osgDB::readNodeFile("triton.earth");
|
|
|
|
earthRootNode_ = osgDB::readNodeFile(earthPath);
|
|
|
|
dyt_check(nullptr != earthRootNode_);
|
|
|
|
addChild(earthRootNode_);
|
2025-01-04 04:12:51 +00:00
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
earthMapNode_ = osgEarth::MapNode::get(earthRootNode_);
|
|
|
|
dyt_check(nullptr != earthMapNode_);
|
|
|
|
LOG_INFO("earth map node get success: {}", earthMapNode_.valid());
|
|
|
|
g_srs_ = earthMapNode_->getMapSRS();
|
2025-01-04 04:12:51 +00:00
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
earthManipulator_ = new osgEarth::Util::EarthManipulator();
|
2025-01-12 17:35:51 +00:00
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
entityRoot_ = new osg::Group;
|
|
|
|
addChild(entityRoot_);
|
2025-01-12 17:35:51 +00:00
|
|
|
}
|