Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3D View changes and fixes #11048

Merged
merged 5 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/assets/viewer_3d/open_3d_viewer.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions docs/en/qgc-dev-guide/getting_started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ To install Qt:

Then install the following components:

::: info
To see a complete list of all available components in the installer _Select Components_ dialog, you might need to check the **"Archive"** box in the right column under the **"Categories"** tab, then click on **"Filter"**.
:::

- Under _Qt _{{ $frontmatter.qt_version }}_ select:
- Depending on the OS you want to build for:
- **Windows**: _MSVC 2019 64 bit_
Expand Down
21 changes: 17 additions & 4 deletions docs/en/qgc-user-guide/viewer_3d/viewer_3d.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,24 @@ You can use it to:
![3D View](../../../assets/viewer_3d/viewer_3d_overview.jpg)

# UI Overview
The screenshot above shows the main elements of the 3D View. You can navigate through the 3D View by using the mouse as follows:
- **To move horizontally and vertically**: Press and hold mouse left click, then move the cursor.
- **To rotate**: Press and hold mouse right click, then move the cursor.
- **To zoom**: Use the mouse wheel\middle button.
The screenshot above shows the main elements of the 3D View.

To open the 3D View, when you are in the [Fly View](../fly_view/fly_view.md), from the toolbar on the left, select the 3D View icon as shown below:

![3D View](../../../assets/viewer_3d/open_3d_viewer.jpg)

Once the 3D View is opened, you can navigate through the 3D environment by using either a mouse or a touchscreen as follows:
- **Mouse:**
- **To move horizontally and vertically**: Press and hold the mouse left-click, then move the cursor.
- **To rotate**: Press and hold the mouse right-click, then move the cursor.
- **To zoom**: Use the mouse wheel\middle button.

- **Touchscreen:**
- **To move horizontally and vertically**: Use a single finger, then tap and move your finger.
- **To rotate**: Use two fingers, then tap and move your fingers while keeping them together.
- **To zoom**: Use a pinch with two fingers and move them together or apart to zoom in or out.

To visualize the 3D map of a particular area in the 3D viewer, you have to download the .osm file of that area from the [OpenStreetMap](https://www.openstreetmap.org/#map=16/47.3964/8.5498) website and then import it through the Setting menu. More details on the Setting menu can be found in the next section.
# Setting icon ![Setting icons](../../../assets/viewer_3d/icon_3d_view.jpg)
This icon will open a pop-up window for setting up the 3D View as shown below:

Expand Down
1 change: 0 additions & 1 deletion qgcimages.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@
<file alias="Yield.svg">src/ui/toolbar/Images/Yield.svg</file>
<file alias="ZoomMinus.svg">src/FlightMap/Images/ZoomMinus.svg</file>
<file alias="ZoomPlus.svg">src/FlightMap/Images/ZoomPlus.svg</file>
<file alias="Viewer3D/GearIcon.png">src/Viewer3D/Images/gear_icon.png</file>
<file alias="Viewer3D/City3DMapIcon.svg">src/Viewer3D/Images/city_3d_map_icon.svg</file>
</qresource>
</RCC>
1 change: 0 additions & 1 deletion qgroundcontrol.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@
<file alias="VTOLLandingPatternEditor.qml">src/PlanView/VTOLLandingPatternEditor.qml</file>
<file alias="QGroundControl/Controls/MockLinkOptionsDlg.qml">src/comm/MockLinkOptionsDlg.qml</file>
<file alias="QGroundControl/FlightDisplay/FlyViewInsetViewer.qml">src/FlightDisplay/FlyViewInsetViewer.qml</file>
<file alias="Viewer3D/Viewer3DSettingMenu.qml">src/Viewer3D/Viewer3D/Viewer3DSettingMenu.qml</file>
<file alias="Viewer3D/Viewer3D.qml">src/Viewer3D/Viewer3D/Viewer3D.qml</file>
<file alias="Viewer3D/qmldir">src/Viewer3D/Viewer3D/qmldir</file>
<file alias="Viewer3D/Models3D/CameraLightModel.qml">src/Viewer3D/Viewer3D/Models3D/CameraLightModel.qml</file>
Expand Down
1 change: 1 addition & 0 deletions src/FlightDisplay/FlyView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Item {
pipMode: !_mainWindowIsMap
toolInsets: customOverlay.totalToolInsets
mapName: "FlightDisplayView"
enabled: !viewer3DWindow.isOpen
}

FlyViewVideo {
Expand Down
54 changes: 19 additions & 35 deletions src/FlightDisplay/FlyViewToolStripActionList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,41 @@ ToolStripActionList {
id: _root

signal displayPreFlightChecklist
property bool _viewer3DEnabled: QGroundControl.settingsManager.viewer3DSettings.enabled.rawValue

model: [
ToolStripAction {
text: qsTr("Plan")
iconSource: "/qmlimages/Plan.svg"
onTriggered:{
mainWindow.showPlanView()
map_icon.showFlyMap()
mapIcon.showFlyMap()
}
},
ToolStripAction {
id: map_icon
property bool _is3DViewOpen: viewer3DWindow.isOpen

id: mapIcon
visible: _viewer3DEnabled
text: qsTr("3D View")
iconSource: "/qmlimages/Viewer3D/City3DMapIcon.svg"
onTriggered:{
if(viewer3DWindow.viewer3DOpen === false)
{
show3dMap();
}
else
{
showFlyMap();
if(_is3DViewOpen === false){
viewer3DWindow.open()
}else{
viewer3DWindow.close()
}
}

function show3dMap()
{
viewer3DWindow.viewer3DOpen = true
map_icon.iconSource = "/qmlimages/PaperPlane.svg"
text= qsTr("Fly")
city_map_setting_icon.enabled = true
}

function showFlyMap()
{
viewer3DWindow.viewer3DOpen = false
iconSource = "/qmlimages/Viewer3D/City3DMapIcon.svg"
text = qsTr("3D View")
city_map_setting_icon.enabled = false
viewer3DWindow.settingMenuOpen = false
city_map_setting_icon.checked = false
}
},
ToolStripAction {
id: city_map_setting_icon
text: qsTr("Setting")
iconSource: "/qmlimages/Viewer3D/GearIcon.png"
enabled: false
visible: enabled
onTriggered:{
viewer3DWindow.settingMenuOpen = !viewer3DWindow.settingMenuOpen
on_Is3DViewOpenChanged: {
if(_is3DViewOpen === true){
mapIcon.iconSource = "/qmlimages/PaperPlane.svg"
text= qsTr("Fly")
}else{
viewer3DWindow.close()
iconSource = "/qmlimages/Viewer3D/City3DMapIcon.svg"
text = qsTr("3D View")
}
}
},
PreFlightCheckListShowAction { onTriggered: displayPreFlightChecklist() },
Expand Down
2 changes: 2 additions & 0 deletions src/Settings/SettingsManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SettingsManager::SettingsManager(QGCApplication* app, QGCToolbox* toolbox)
, _adsbVehicleManagerSettings (nullptr)
, _batteryIndicatorSettings (nullptr)
, _mapsSettings (nullptr)
, _viewer3DSettings (nullptr)
#if !defined(NO_ARDUPILOT_DIALECT)
, _apmMavlinkStreamRateSettings (nullptr)
#endif
Expand Down Expand Up @@ -58,6 +59,7 @@ void SettingsManager::setToolbox(QGCToolbox *toolbox)
_adsbVehicleManagerSettings = new ADSBVehicleManagerSettings (this);
_batteryIndicatorSettings = new BatteryIndicatorSettings (this);
_mapsSettings = new MapsSettings (this);
_viewer3DSettings = new Viewer3DSettings (this);
#if !defined(NO_ARDUPILOT_DIALECT)
_apmMavlinkStreamRateSettings = new APMMavlinkStreamRateSettings(this);
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/Settings/SettingsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "BatteryIndicatorSettings.h"
#include <QVariantList>
#include "RemoteIDSettings.h"
#include "Viewer3DSettings.h"

/// Provides access to all app settings
class SettingsManager : public QGCTool
Expand All @@ -56,6 +57,7 @@ class SettingsManager : public QGCTool
Q_PROPERTY(QObject* adsbVehicleManagerSettings READ adsbVehicleManagerSettings CONSTANT)
Q_PROPERTY(QObject* batteryIndicatorSettings READ batteryIndicatorSettings CONSTANT)
Q_PROPERTY(QObject* mapsSettings READ mapsSettings CONSTANT)
Q_PROPERTY(QObject* viewer3DSettings READ viewer3DSettings CONSTANT)
#if !defined(NO_ARDUPILOT_DIALECT)
Q_PROPERTY(QObject* apmMavlinkStreamRateSettings READ apmMavlinkStreamRateSettings CONSTANT)
#endif
Expand All @@ -78,6 +80,7 @@ class SettingsManager : public QGCTool
ADSBVehicleManagerSettings* adsbVehicleManagerSettings (void) { return _adsbVehicleManagerSettings; }
BatteryIndicatorSettings* batteryIndicatorSettings (void) { return _batteryIndicatorSettings; }
MapsSettings* mapsSettings (void) { return _mapsSettings; }
Viewer3DSettings* viewer3DSettings (void) { return _viewer3DSettings; }
#if !defined(NO_ARDUPILOT_DIALECT)
APMMavlinkStreamRateSettings* apmMavlinkStreamRateSettings(void) { return _apmMavlinkStreamRateSettings; }
#endif
Expand All @@ -98,6 +101,7 @@ class SettingsManager : public QGCTool
ADSBVehicleManagerSettings* _adsbVehicleManagerSettings;
BatteryIndicatorSettings* _batteryIndicatorSettings;
MapsSettings* _mapsSettings;
Viewer3DSettings* _viewer3DSettings;
#if !defined(NO_ARDUPILOT_DIALECT)
APMMavlinkStreamRateSettings* _apmMavlinkStreamRateSettings;
#endif
Expand Down
6 changes: 6 additions & 0 deletions src/Settings/Viewer3D.SettingsGroup.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"fileType": "FactMetaData",
"QGC.MetaData.Facts":
[
{
"name": "enabled",
"shortDesc": "Enable the 3D viewer",
"type": "bool",
"default": false
},
{
"name": "osmFilePath",
"shortDesc": "Path to the OSM file for the 3D viewer.",
Expand Down
1 change: 1 addition & 0 deletions src/Settings/Viewer3DSettings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ DECLARE_SETTINGGROUP(Viewer3D, "Viewer3D")
qmlRegisterUncreatableType<Viewer3DSettings>("QGroundControl.SettingsManager", 1, 0, "Viewer3DSettings", "Reference only");
}

DECLARE_SETTINGSFACT(Viewer3DSettings, enabled)
DECLARE_SETTINGSFACT(Viewer3DSettings, osmFilePath)
DECLARE_SETTINGSFACT(Viewer3DSettings, buildingLevelHeight)
DECLARE_SETTINGSFACT(Viewer3DSettings, altitudeBias)
Expand Down
1 change: 1 addition & 0 deletions src/Settings/Viewer3DSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Viewer3DSettings : public SettingsGroup

DEFINE_SETTING_NAME_GROUP()

DEFINE_SETTINGFACT(enabled)
DEFINE_SETTINGFACT(osmFilePath)
DEFINE_SETTINGFACT(buildingLevelHeight)
DEFINE_SETTINGFACT(altitudeBias)
Expand Down
55 changes: 38 additions & 17 deletions src/Viewer3D/CityMapGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include<QThread>

#include "QGCApplication.h"
#include "SettingsManager.h"


CityMapGeometry::CityMapGeometry()
{
Expand All @@ -10,8 +13,10 @@ CityMapGeometry::CityMapGeometry()
_vertexData.clear();
_mapLoadedFlag = 0;

connect(this, &CityMapGeometry::osmFilePathChanged, this, &CityMapGeometry::updateData);
connect(this, &CityMapGeometry::osmParserChanged, this, &CityMapGeometry::updateData);
_viewer3DSettings = qgcApp()->toolbox()->settingsManager()->viewer3DSettings();

setOsmFilePath(_viewer3DSettings->osmFilePath()->rawValue());
connect(_viewer3DSettings->osmFilePath(), &Fact::rawValueChanged, this, &CityMapGeometry::setOsmFilePath);
}

void CityMapGeometry::setModelName(QString modelName)
Expand All @@ -22,44 +27,54 @@ void CityMapGeometry::setModelName(QString modelName)
emit modelNameChanged();
}

void CityMapGeometry::setOsmFilePath(QString filePath)
void CityMapGeometry::setOsmFilePath(QVariant value)
{
if(_osmFilePath.compare(filePath) == 0){
if(_osmFilePath.compare(value.toString()) == 0){
return;
}

clearViewer();
_mapLoadedFlag = 0;
_osmFilePath = filePath;
_osmFilePath = value.toString();
emit osmFilePathChanged();

updateData();
loadOsmMap();
}

void CityMapGeometry::setOsmParser(OsmParser *newOsmParser)
{
_osmParser = newOsmParser;

if(_osmParser){
connect(_osmParser, &OsmParser::buildingLevelHeightChanged, this, &CityMapGeometry::updateData);
connect(_osmParser, &OsmParser::buildingLevelHeightChanged, this, &CityMapGeometry::updateViewer);
connect(_osmParser, &OsmParser::mapChanged, this, &CityMapGeometry::updateViewer);
}
emit osmParserChanged();
loadOsmMap();
}

//! [update data]
void CityMapGeometry::updateData()
bool CityMapGeometry::loadOsmMap()
{
clear();
if(_mapLoadedFlag){
return true;
}

if(!_osmParser){
return;
return false;
}
_mapLoadedFlag = 1;
_osmParser->parseOsmFile(_osmFilePath);
return true;
}

void CityMapGeometry::updateViewer()
{
clear();

if(_mapLoadedFlag == 0){
_osmParser->parseOsmFile(_osmFilePath);
_mapLoadedFlag = 1;
if(!_osmParser){
return;
}

if(_mapLoadedFlag){
if(loadOsmMap()){
_vertexData = _osmParser->buildingToMesh();

int stride = 3 * sizeof(float);
Expand All @@ -72,8 +87,14 @@ void CityMapGeometry::updateData()
addAttribute(QQuick3DGeometry::Attribute::PositionSemantic,
0,
QQuick3DGeometry::Attribute::F32Type);

}
update();
}
}

void CityMapGeometry::clearViewer()
{
clear();
_vertexData.clear();
update();
}
16 changes: 12 additions & 4 deletions src/Viewer3D/CityMapGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

/// @author Omid Esrafilian <[email protected]>

class Viewer3DSettings;

class CityMapGeometry : public QQuick3DGeometry
{
Q_OBJECT
Q_PROPERTY(QString modelName READ modelName WRITE setModelName NOTIFY modelNameChanged)
Q_PROPERTY(QString osmFilePath READ osmFilePath WRITE setOsmFilePath NOTIFY osmFilePathChanged)
Q_PROPERTY(OsmParser* osmParser READ osmParser WRITE setOsmParser NOTIFY osmParserChanged)

public:
Expand All @@ -24,25 +25,32 @@ class CityMapGeometry : public QQuick3DGeometry
void setModelName(QString modelName);

QString osmFilePath() const {return _osmFilePath;}
void setOsmFilePath(QString filePath);

OsmParser* osmParser(){ return _osmParser;}
void setOsmParser(OsmParser* newOsmParser);

bool loadOsmMap();

signals:
void modelNameChanged();
void osmFilePathChanged();
void gpsRefChanged();
void osmParserChanged();

private:
void updateData();
void updateViewer();
void clearViewer();

QString _modelName;
QString _osmFilePath;
QByteArray _vertexData;
OsmParser *_osmParser;
bool _mapLoadedFlag;
Viewer3DSettings* _viewer3DSettings = nullptr;

private slots:
void setOsmFilePath(QVariant value);


};

#endif // CITYMAPGEOMETRY_H
Binary file removed src/Viewer3D/Images/gear_icon.png
Binary file not shown.
Loading
Loading