diff --git a/Source/src/CMakeLists.txt b/Source/src/CMakeLists.txt index bdb289de..17961276 100644 --- a/Source/src/CMakeLists.txt +++ b/Source/src/CMakeLists.txt @@ -105,7 +105,7 @@ INCLUDE_DIRECTORIES( if(MSVC) - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi /Od") set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF") foreach(var @@ -179,7 +179,7 @@ if(${QT_VERSION_MAJOR} LESS 6) PRIVATE Qt${QT_VERSION_MAJOR}::WinExtras ) - + endif() SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ProjectDIR}/bin) diff --git a/Source/src/config.h b/Source/src/config.h index 9ff4c34f..4af7e1ae 100644 --- a/Source/src/config.h +++ b/Source/src/config.h @@ -1,5 +1,8 @@ #pragma once +#include +#include + extern const char* CONFIG_PATH; #define Q_REGISTER_METATYPE(T) \ @@ -16,3 +19,25 @@ static struct T##MetaTypeRegister { \ #else #define FORCE_INLINE inline #endif + +#define dyt_check(condition) \ +do { \ + if (!(condition)) { \ + LOG_ERROR("Check failed: {}", #condition); \ + abort(); \ + } \ +} while (0) + + +FORCE_INLINE bool IsValid(double value) { + constexpr double epsilon = std::numeric_limits::epsilon(); + + return std::abs(value) > epsilon; +} + +FORCE_INLINE bool IsDecimalValid(double value) { + double intPart; + double fractionalPart = std::modf(value, &intPart); + + return IsValid(fractionalPart); +} diff --git a/Source/src/entities/SceneComponent.cpp b/Source/src/entities/SceneComponent.cpp index fff20282..b9113791 100644 --- a/Source/src/entities/SceneComponent.cpp +++ b/Source/src/entities/SceneComponent.cpp @@ -6,6 +6,8 @@ #include "entities/Entity.h" #include "utils/OsgUtils.h" +#include "scene/SceneContent.h" + SceneComponent::SceneComponent(SceneComponent* parent) : Component(parent) { @@ -130,15 +132,27 @@ void SceneComponent::AttachScene(Entity* entity) { return; } - /* OsgScene* scene = workspace->GetActiveScene(); +#if USE_OCEAN + OsgScene* scene = workspace->GetActiveScene(); +#else + OEScene* scene = workspace->GetActiveScene(); +#endif if (nullptr == scene) { LOG_WARN("scene is nullptr"); return; } - - UpdateLocationAndRotation(); - scene->AddToOceanScene(mt_);*/ +#if USE_OCEAN + scene->AddToScene(mt_); +#else + if (!geo_) { + geo_ = new osgEarth::GeoTransform; + geo_->addChild(mt_); + } + + scene->AddToScene(geo_); +#endif + UpdateLocationAndRotation(); } void SceneComponent::AttachParent(Entity* entity) { @@ -175,8 +189,15 @@ void SceneComponent::UpdateLocationAndRotation() { const osg::Vec3& s = transform_.GetScale(); const osg::Vec3& t = transform_.GetLocation(); osg::Quat quat = OsgUtils::HPRToQuat(r); - osg::Matrix matrix = osg::Matrix::scale(s) * osg::Matrix::rotate(quat) * osg::Matrix::translate(t); - mt_->setMatrix(matrix); + osg::Matrix matrix = osg::Matrix::scale(s) * osg::Matrix::rotate(quat); + if (!geo_.valid()) { + matrix *= osg::Matrix::translate(t); + mt_->setMatrix(matrix); + } else { + mt_->setMatrix(matrix); + osgEarth::GeoPoint pos(g_srs_, t); + geo_->setPosition(pos); + } } void SceneComponent::RemoveRender() { diff --git a/Source/src/entities/SceneComponent.h b/Source/src/entities/SceneComponent.h index 160bfaed..952347cb 100644 --- a/Source/src/entities/SceneComponent.h +++ b/Source/src/entities/SceneComponent.h @@ -5,6 +5,8 @@ #include "utils/Transform.h" +#include + #include "osg/Vec3" #include "osg/MatrixTransform" @@ -41,7 +43,7 @@ public: } osg::MatrixTransform* GetMatrixTransform() const { - return mt_.get(); + return geo_.valid() ? geo_.get() : mt_.get(); } const Transform* GetTransform() const { return &transform_; @@ -66,6 +68,10 @@ protected: std::vector children_; osg::ref_ptr mt_; +#ifndef USE_OCEAN + osg::ref_ptr geo_{nullptr}; +#endif + protected: Transform transform_; }; \ No newline at end of file diff --git a/Source/src/scene/MeshManager.cpp b/Source/src/scene/MeshManager.cpp index 34dc82d1..2dd4d561 100644 --- a/Source/src/scene/MeshManager.cpp +++ b/Source/src/scene/MeshManager.cpp @@ -2,6 +2,10 @@ #include +#ifndef USE_OCEAN +#include +#endif + #include "common/SpdLogger.h" #include "common/RecourceHelper.h" @@ -55,6 +59,9 @@ osg::MatrixTransform* MeshManager::ReadNode(const std::string& file) { return nullptr; } +#ifndef USE_OCEAN + osgEarth::Registry::shaderGenerator().run(node); +#endif nodes_[file] = node; osg::MatrixTransform* mt = new osg::MatrixTransform; diff --git a/Source/src/scene/OEScene.cpp b/Source/src/scene/OEScene.cpp index 053e7b49..16b9cf4e 100644 --- a/Source/src/scene/OEScene.cpp +++ b/Source/src/scene/OEScene.cpp @@ -13,11 +13,14 @@ #include #include +#include "config.h" #include "common/SpdLogger.h" #include "common/RecourceHelper.h" #include "scene/ScopedTimer.h" #include "viewer/OsgView.h" +const osgEarth::SpatialReference* g_srs_{ nullptr }; + OEScene::OEScene() { osgDB::FilePathList& pathList = osgDB::Registry::instance()->getDataFilePathList(); @@ -57,9 +60,10 @@ void OEScene::AttachView(OsgView* view) { entityRoot_ = new osg::Group; if (earthMapNode_) { earthMapNode_->addChild(entityRoot_); + g_srs_ = earthMapNode_->getMapSRS(); + dyt_check(nullptr != g_srs_); } - skyDome_ = osgEarth::SkyNode::create(); if (!earthMapNode_) { LOG_WARN("eart map node is nullptr"); @@ -81,16 +85,6 @@ void OEScene::AttachView(OsgView* view) { 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()); diff --git a/Source/src/scene/SceneContent.h b/Source/src/scene/SceneContent.h new file mode 100644 index 00000000..ec6cd0c9 --- /dev/null +++ b/Source/src/scene/SceneContent.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +extern const osgEarth::SpatialReference* g_srs_; diff --git a/Source/src/translations/Dyt_zh_CN.ts b/Source/src/translations/Dyt_zh_CN.ts index b6629a69..28d96a96 100644 --- a/Source/src/translations/Dyt_zh_CN.ts +++ b/Source/src/translations/Dyt_zh_CN.ts @@ -709,12 +709,12 @@ QtBoolPropertyManager - + True - + False @@ -738,22 +738,22 @@ QtColorPropertyManager - + Red - + Green - + Blue - + Alpha @@ -761,33 +761,33 @@ QtConeWaveComponentManager - - + + ConeWaveComponent - + Height - + Radius - + Color1 - + Color2 - + Color3 @@ -893,28 +893,28 @@ QtDashedLineComponentManager - - + + DashedLineComponent - + Start - + End - + Radius - + Color @@ -930,12 +930,12 @@ QtEntityPropertyManager - + Name - + Transform @@ -956,37 +956,37 @@ QtFontPropertyManager - + Family - + Point Size - + Bold - + Italic - + Underline - + Strikeout - + Kerning @@ -994,22 +994,22 @@ QtLocalePropertyManager - + <Invalid> - + %1, %2 - + Language - + Country @@ -1017,13 +1017,13 @@ QtMeshComponetManager - - + + MeshComponent - + Mesh @@ -1031,22 +1031,22 @@ QtModelBasePropertyManager - + Name - + Description - + Inflow - + InnerBottomElevation @@ -1067,13 +1067,13 @@ QtPathComponentManager - - + + PathComponent - + Path @@ -1081,17 +1081,17 @@ QtPointFPropertyManager - + (%1, %2) - + X - + Y @@ -1099,17 +1099,17 @@ QtPointPropertyManager - + (%1, %2) - + X - + Y @@ -1127,12 +1127,12 @@ - + [%1, %2, %3] - + [%1, %2, %3] [%4, %5, %6] [%7, %8, %9] @@ -1140,27 +1140,27 @@ QtRectFPropertyManager - + [(%1, %2), %3 x %4] - + X - + Y - + Width - + Height @@ -1168,27 +1168,27 @@ QtRectPropertyManager - + [(%1, %2), %3 x %4] - + X - + Y - + Width - + Height @@ -1196,17 +1196,17 @@ QtSizeFPropertyManager - + %1 x %2 - + Width - + Height @@ -1214,33 +1214,33 @@ QtSizePolicyPropertyManager - - + + <Invalid> - + [%1, %2, %3, %4] - + Horizontal Policy - + Vertical Policy - + Horizontal Stretch - + Vertical Stretch @@ -1248,17 +1248,17 @@ QtSizePropertyManager - + %1 x %2 - + Width - + Height @@ -1274,17 +1274,17 @@ QtTransfromPropertyManager - + Location - + Rotation - + Scale @@ -1305,17 +1305,17 @@ QtVec3PropertyManager - + X - + Y - + Z @@ -1323,17 +1323,17 @@ QtWorkspacePropertyManager - + Name - + Description - + Timestep diff --git a/Source/src/ui/PropertyBrowser/qtpropertymanager.cpp b/Source/src/ui/PropertyBrowser/qtpropertymanager.cpp index 79ff3875..16a9aad2 100644 --- a/Source/src/ui/PropertyBrowser/qtpropertymanager.cpp +++ b/Source/src/ui/PropertyBrowser/qtpropertymanager.cpp @@ -57,6 +57,7 @@ #include #include +#include "config.h" #include "entities/EntitiesManager.h" #include "entities/MeshComponent.h" #include "entities/PathComponent.h" @@ -941,7 +942,7 @@ public: double minVal{ -DBL_MAX }; double maxVal{ DBL_MAX }; double singleStep{ 1 }; - int decimals{ 2 }; + int decimals{ 6 }; bool isInitialed{ false }; double minimumValue() const { return minVal; } double maximumValue() const { return maxVal; } @@ -1104,7 +1105,13 @@ QString QtDoublePropertyManager::valueText(const QtProperty* property) const const QtDoublePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); - return QString::number(it.value().val, 'f', it.value().decimals); + + int decimals = it.value().decimals; + if (!IsDecimalValid(it.value().val)) { + decimals = 2; + } + + return QString::number(it.value().val, 'f', decimals); } /*! diff --git a/Source/src/workspace/WorkSpace.cpp b/Source/src/workspace/WorkSpace.cpp index 0f6af669..8306cc37 100644 --- a/Source/src/workspace/WorkSpace.cpp +++ b/Source/src/workspace/WorkSpace.cpp @@ -31,11 +31,11 @@ WorkSpace::WorkSpace(const QString& name, QObject* parent) } void WorkSpace::ViewReize(int width, int height) { - /* if (nullptr != activeScene_ && nullptr != activeScene_->GetOceanScene()) { - activeScene_->GetOceanScene()->setScreenDims(osg::Vec2s(width * 2, height * 2)); + if (nullptr != activeScene_) { + //activeScene_->GetOceanScene()->setScreenDims(osg::Vec2s(width * 2, height * 2)); } else { LOG_WARN("secen_:{} or ocean is nullptr", spdlog::fmt_lib::ptr(activeScene_.get())); - }*/ + } } bool WorkSpace::CreateScene(const std::string& scene) { @@ -91,13 +91,23 @@ void WorkSpace::RemoveEntity(Entity* entity) { } } -//OsgScene* WorkSpace::GetActiveScene() const { -// if (!activeScene_.valid()) { -// return nullptr; -// } -// -// return activeScene_.get(); -//} +#if USE_OCEAN +OsgScene* WorkSpace::GetActiveScene() const { + if (!activeScene_.valid()) { + return nullptr; + } + + return activeScene_.get(); +} +#else +OEScene* WorkSpace::GetActiveScene() const { + if (!activeScene_.valid()) { + return nullptr; + } + + return activeScene_.get(); +} +#endif bool WorkSpace::SetTimestep(Timestep* timestep) { if (!timestep) { diff --git a/Source/src/workspace/WorkSpace.h b/Source/src/workspace/WorkSpace.h index 78f99013..a82e75df 100644 --- a/Source/src/workspace/WorkSpace.h +++ b/Source/src/workspace/WorkSpace.h @@ -46,7 +46,11 @@ public: void ViewReize(int width, int height); bool CreateScene(const std::string& scene); - //OsgScene* GetActiveScene() const; +#if USE_OCEAN + OsgScene* GetActiveScene() const; +#else + OEScene* GetActiveScene() const; +#endif bool SetTimestep(class Timestep* timestep); bool SetTimestepPath(const QString& path); diff --git a/Source/workspace/default2.dyt b/Source/workspace/default2.dyt index 76b938d3..479eea30 100644 --- a/Source/workspace/default2.dyt +++ b/Source/workspace/default2.dyt @@ -9,17 +9,17 @@ - + - + - + @@ -29,7 +29,7 @@ - +