add osg earth
This commit is contained in:
parent
7331f4f1fd
commit
a89e078a1a
@ -23,21 +23,10 @@ OEScene::OEScene() {
|
|||||||
osgDB::FilePathList& pathList = osgDB::Registry::instance()->getDataFilePathList();
|
osgDB::FilePathList& pathList = osgDB::Registry::instance()->getDataFilePathList();
|
||||||
const std::string& basePath = RecourceHelper::Get().GetBasePath().toStdString();
|
const std::string& basePath = RecourceHelper::Get().GetBasePath().toStdString();
|
||||||
pathList.push_back(basePath + "/resources/earth/");
|
pathList.push_back(basePath + "/resources/earth/");
|
||||||
pathList.push_back(basePath + "resources/textures/");
|
pathList.push_back(basePath + "/resources/textures/");
|
||||||
|
|
||||||
earthRootNode_ = osgDB::readNodeFile("triton.earth");
|
|
||||||
if (!earthRootNode_) {
|
|
||||||
LOG_ERROR("read earth node(triton.earth) failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
earthMapNode_ = osgEarth::MapNode::get(earthRootNode_);
|
logarithmicDepthBuffer_ = std::make_unique<osgEarth::Util::LogarithmicDepthBuffer>();
|
||||||
LOG_INFO("earth map node get success: {}", earthMapNode_.valid());
|
|
||||||
|
|
||||||
entityRoot_ = new osg::Group;
|
|
||||||
if (earthMapNode_) {
|
|
||||||
earthMapNode_->addChild(entityRoot_);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -68,19 +57,66 @@ void OEScene::AttachView(OsgView* view) {
|
|||||||
//mt->setMatrix(osg::Matrix::translate(eye)/* * osg::Matrix::scale(osg::Vec3(10, 10, 10))*/);
|
//mt->setMatrix(osg::Matrix::translate(eye)/* * osg::Matrix::scale(osg::Vec3(10, 10, 10))*/);
|
||||||
//////mt->getOrCreateStateSet()-
|
//////mt->getOrCreateStateSet()-
|
||||||
|
|
||||||
//osg::Node* node = view->GetView()->getSceneData();
|
earthRootNode_ = osgDB::readNodeFile("triton.earth");
|
||||||
//if (nullptr == node) {
|
if (!earthRootNode_) {
|
||||||
// LOG_INFO("view scene data is nullptr, root valid:{}", scene_.valid());
|
LOG_ERROR("read earth node(triton.earth) failed");
|
||||||
// view->GetView()->setSceneData(scene_);
|
return;
|
||||||
//} else {
|
}
|
||||||
// osg::Group* group = node->asGroup();
|
|
||||||
// if (nullptr != group) {
|
earthMapNode_ = osgEarth::MapNode::get(earthRootNode_);
|
||||||
// LOG_INFO("node is group");
|
LOG_INFO("earth map node get success: {}", earthMapNode_.valid());
|
||||||
// group->addChild(scene_);
|
|
||||||
// } else {
|
entityRoot_ = new osg::Group;
|
||||||
// LOG_INFO("node is not group");
|
if (earthMapNode_) {
|
||||||
// }
|
earthMapNode_->addChild(entityRoot_);
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
skyDome_ = osgEarth::SkyNode::create();
|
||||||
|
if (!earthMapNode_) {
|
||||||
|
LOG_WARN("eart map node is nullptr");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
skyDome_->addChild(earthMapNode_);
|
||||||
|
|
||||||
|
osg::Node* node = view->GetView()->getSceneData();
|
||||||
|
if (nullptr == node) {
|
||||||
|
LOG_INFO("view scene data is nullptr, root valid:{}", skyDome_.valid());
|
||||||
|
view->GetView()->setSceneData(earthRootNode_);
|
||||||
|
} else {
|
||||||
|
osg::Group* group = node->asGroup();
|
||||||
|
if (nullptr != group) {
|
||||||
|
LOG_INFO("node is group");
|
||||||
|
group->addChild(skyDome_);
|
||||||
|
} else {
|
||||||
|
LOG_INFO("node is not group");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//osg::Group* parent = earthMapNode_->getParent(0);
|
||||||
|
/*osg::Group* parent = earthMapNode_->getParent(0);
|
||||||
|
if (nullptr == parent) {
|
||||||
|
skyDome_->addChild(earthMapNode_);
|
||||||
|
parent->addChild(skyDome_);
|
||||||
|
parent->removeChild(earthMapNode_);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/* skyDome_->attach(view->GetView());
|
||||||
|
|
||||||
|
skyDome_->setAtmosphereVisible(true);
|
||||||
|
skyDome_->setSunVisible(true);
|
||||||
|
skyDome_->setMoonVisible(true);
|
||||||
|
skyDome_->setStarsVisible(true);
|
||||||
|
|
||||||
|
skyDome_->setDateTime(osgEarth::DateTime(2024, 12, 24, 12));
|
||||||
|
skyDome_->setSimulationTimeTracksDateTime(true);*/
|
||||||
|
|
||||||
|
logarithmicDepthBuffer_->install(view->GetView()->getCamera());
|
||||||
|
|
||||||
|
//view->GetView()->setRealizeOperation(new osgEarth::GL3RealizeOperation());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OEScene::DetachView(OsgView* view) {
|
void OEScene::DetachView(OsgView* view) {
|
||||||
@ -90,7 +126,9 @@ void OEScene::DetachView(OsgView* view) {
|
|||||||
parent->removeChild(earthRootNode_);
|
parent->removeChild(earthRootNode_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logarithmicDepthBuffer_->uninstall(view->GetView()->getCamera());
|
||||||
view->GetView()->setSceneData(nullptr);
|
view->GetView()->setSceneData(nullptr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define USE_CUSTOM_SHADER
|
#define USE_CUSTOM_SHADER
|
||||||
|
@ -5,8 +5,10 @@
|
|||||||
|
|
||||||
#include <osgText/Text>
|
#include <osgText/Text>
|
||||||
#include <osgEarth/ModelNode>
|
#include <osgEarth/ModelNode>
|
||||||
|
#include <osgEarth/Sky>
|
||||||
|
#include <osgEarth/LogarithmicDepthBuffer>
|
||||||
|
|
||||||
#include "scene/SkyDome.h"
|
//#include "scene/SkyDome.h"
|
||||||
|
|
||||||
class OsgView;
|
class OsgView;
|
||||||
|
|
||||||
@ -36,4 +38,6 @@ private:
|
|||||||
osg::ref_ptr<osg::Node> earthRootNode_;
|
osg::ref_ptr<osg::Node> earthRootNode_;
|
||||||
osg::ref_ptr<osgEarth::MapNode> earthMapNode_;
|
osg::ref_ptr<osgEarth::MapNode> earthMapNode_;
|
||||||
osg::ref_ptr<osg::Group> entityRoot_;
|
osg::ref_ptr<osg::Group> entityRoot_;
|
||||||
|
osg::ref_ptr<osgEarth::SkyNode> skyDome_;
|
||||||
|
std::unique_ptr<osgEarth::Util::LogarithmicDepthBuffer> logarithmicDepthBuffer_;
|
||||||
};
|
};
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <osg/BlendFunc>
|
#include <osg/BlendFunc>
|
||||||
|
#include <osgEarth/GLUtils>
|
||||||
|
|
||||||
#include "common/SpdLogger.h"
|
#include "common/SpdLogger.h"
|
||||||
#include "viewer/OsgView.h"
|
#include "viewer/OsgView.h"
|
||||||
@ -55,6 +56,7 @@ OsgView* OsgViewer::CreateView(int x, int y, int width, int height, void* winHan
|
|||||||
view->InitGraphiceWindow(x, y, width, height, reinterpret_cast<WId>(winHandle), "dytView");
|
view->InitGraphiceWindow(x, y, width, height, reinterpret_cast<WId>(winHandle), "dytView");
|
||||||
|
|
||||||
OnAddView(view, x, y, width, height);
|
OnAddView(view, x, y, width, height);
|
||||||
|
//compositeViewer_->setRealizeOperation(new osgEarth::GL3RealizeOperation());
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +83,11 @@ OsgView* OsgViewer::GetView() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool OsgViewer::Initialize(void) {
|
bool OsgViewer::Initialize(void) {
|
||||||
|
if (initalized_) {
|
||||||
|
return initalized_;
|
||||||
|
}
|
||||||
initalized_ = true;
|
initalized_ = true;
|
||||||
|
compositeViewer_->setRealizeOperation(new osgEarth::GL3RealizeOperation());
|
||||||
return initalized_;
|
return initalized_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,9 +59,9 @@ bool WorkSpace::CreateScene(const std::string& scene) {
|
|||||||
activeScene_->InitEventHandle(view_);
|
activeScene_->InitEventHandle(view_);
|
||||||
#else
|
#else
|
||||||
activeScene_ = new OEScene;
|
activeScene_ = new OEScene;
|
||||||
activeScene_->UseShadows(false);
|
//activeScene_->UseShadows(false);
|
||||||
|
|
||||||
activeScene_->ChangeScene(OsgScene::CLOUDY);
|
//activeScene_->ChangeScene(OsgScene::CLOUDY);
|
||||||
|
|
||||||
activeScene_->AttachView(view_);
|
activeScene_->AttachView(view_);
|
||||||
activeScene_->InitEventHandle(view_);
|
activeScene_->InitEventHandle(view_);
|
||||||
|
Loading…
Reference in New Issue
Block a user