Skip to content

Commit 675a1ae

Browse files
committed
Import of initial work on QGIS 3D framework from wonder-sk/qgis3d
1 parent ea28c2d commit 675a1ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+8413
-1
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ IF(WITH_CORE)
5959

6060
SET (WITH_DESKTOP TRUE CACHE BOOL "Determines whether QGIS desktop should be built")
6161

62+
SET (WITH_3D FALSE CACHE BOOL "Determines whether QGIS 3D library should be built")
63+
6264
# server disabled default because it needs FastCGI (which is optional dependency)
6365
SET (WITH_SERVER FALSE CACHE BOOL "Determines whether QGIS server should be built")
6466
IF(WITH_SERVER)
@@ -276,6 +278,13 @@ IF(WITH_CORE)
276278
FIND_PACKAGE(Qt5UiTools REQUIRED)
277279
FIND_PACKAGE(Qt5Script REQUIRED)
278280
FIND_PACKAGE(Qt5Sql REQUIRED)
281+
IF (WITH_3D)
282+
FIND_PACKAGE(Qt53DCore REQUIRED)
283+
FIND_PACKAGE(Qt53DRender REQUIRED)
284+
FIND_PACKAGE(Qt53DInput REQUIRED)
285+
FIND_PACKAGE(Qt53DLogic REQUIRED)
286+
FIND_PACKAGE(Qt53DExtras REQUIRED)
287+
ENDIF (WITH_3D)
279288
INCLUDE("cmake/modules/ECMQt4To5Porting.cmake")
280289
MESSAGE(STATUS "Found Qt version: ${Qt5Core_VERSION_STRING}")
281290

scripts/prepare-commit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ for f in $MODIFIED; do
7373
(( i++ )) || true
7474

7575
case "$f" in
76-
src/core/gps/qextserialport/*|src/plugins/globe/osgEarthQt/*|src/plugins/globe/osgEarthUtil/*)
76+
src/core/gps/qextserialport/*|src/plugins/globe/osgEarthQt/*|src/plugins/globe/osgEarthUtil/*|src/3d/poly2tri/*)
7777
echo $f skipped
7878
continue
7979
;;

src/3d/CMakeLists.txt

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
#############################################################
2+
# sources
3+
4+
SET(QGIS_3D_SRCS
5+
cameracontroller.cpp
6+
chunkedentity.cpp
7+
chunklist.cpp
8+
chunkloader.cpp
9+
chunknode.cpp
10+
demterraingenerator.cpp
11+
demterraintilegeometry.cpp
12+
flatterraingenerator.cpp
13+
lineentity.cpp
14+
map3d.cpp
15+
maptexturegenerator.cpp
16+
maptextureimage.cpp
17+
pointentity.cpp
18+
polygonentity.cpp
19+
polygongeometry.cpp
20+
#quantizedmeshgeometry.cpp
21+
#quantizedmeshterraingenerator.cpp
22+
scene.cpp
23+
terrain.cpp
24+
terrainboundsentity.cpp
25+
terrainchunkloader.cpp
26+
terraingenerator.cpp
27+
tessellator.cpp
28+
tilingscheme.cpp
29+
utils.cpp
30+
31+
poly2tri/common/shapes.cc
32+
poly2tri/sweep/advancing_front.cc
33+
poly2tri/sweep/cdt.cc
34+
poly2tri/sweep/sweep_context.cc
35+
poly2tri/sweep/sweep.cc
36+
)
37+
38+
SET(QGIS_3D_MOC_HDRS
39+
cameracontroller.h
40+
chunkedentity.h
41+
demterraingenerator.h
42+
demterraintilegeometry.h
43+
maptexturegenerator.h
44+
maptextureimage.h
45+
scene.h
46+
terrain.h
47+
)
48+
49+
QT5_WRAP_CPP(QGIS_3D_MOC_SRCS ${QGIS_3D_MOC_HDRS})
50+
51+
# install headers
52+
53+
SET(QGIS_3D_HDRS
54+
aabb.h
55+
cameracontroller.h
56+
chunkedentity.h
57+
chunklist.h
58+
chunkloader.h
59+
chunknode.h
60+
demterraingenerator.h
61+
demterraintilegeometry.h
62+
flatterraingenerator.h
63+
lineentity.h
64+
map3d.h
65+
maptexturegenerator.h
66+
maptextureimage.h
67+
pointentity.h
68+
polygonentity.h
69+
polygongeometry.h
70+
#quantizedmeshgeometry.h
71+
#quantizedmeshterraingenerator.h
72+
scene.h
73+
terrain.h
74+
terrainboundsentity.h
75+
terrainchunkloader.h
76+
terraingenerator.h
77+
tessellator.h
78+
tilingscheme.h
79+
utils.h
80+
)
81+
82+
INCLUDE_DIRECTORIES(
83+
${CMAKE_CURRENT_SOURCE_DIR}
84+
${CMAKE_SOURCE_DIR}/src/core/
85+
${CMAKE_SOURCE_DIR}/src/core/geometry
86+
${CMAKE_SOURCE_DIR}/src/core/raster
87+
${CMAKE_SOURCE_DIR}/src/core/symbology-ng
88+
${CMAKE_SOURCE_DIR}/src/core/metadata
89+
${CMAKE_SOURCE_DIR}/src/core/expression
90+
${CMAKE_BINARY_DIR}/src/core
91+
${CMAKE_BINARY_DIR}/src/3d
92+
)
93+
INCLUDE_DIRECTORIES(SYSTEM
94+
${PROJ_INCLUDE_DIR}
95+
${GEOS_INCLUDE_DIR}
96+
${GDAL_INCLUDE_DIR}
97+
${SQLITE3_INCLUDE_DIR}
98+
)
99+
100+
#############################################################
101+
# qgis_3d library
102+
103+
ADD_LIBRARY(qgis_3d SHARED ${QGIS_3D_SRCS} ${QGIS_3D_MOC_SRCS} ${QGIS_3D_HDRS})
104+
105+
qt5_use_modules(qgis_3d 3DCore 3DRender 3DInput 3DLogic 3DExtras)
106+
107+
GENERATE_EXPORT_HEADER(
108+
qgis_3d
109+
BASE_NAME 3D
110+
EXPORT_FILE_NAME qgis_3d.h
111+
)
112+
IF(MSVC)
113+
SET_TARGET_PROPERTIES(qgis_3d PROPERTIES LINK_FLAGS "/FORCE:MULTIPLE")
114+
ENDIF(MSVC)
115+
116+
SET(QGIS_3D_HDRS ${QGIS_3D_HDRS} ${CMAKE_CURRENT_BINARY_DIR}/qgis_3d.h)
117+
118+
IF(NOT APPLE)
119+
INSTALL(FILES ${QGIS_3D_HDRS} DESTINATION ${QGIS_INCLUDE_DIR})
120+
ELSE(NOT APPLE)
121+
SET_TARGET_PROPERTIES(qgis_3d PROPERTIES
122+
# no moc headers, messes up PROPERTIES syntax
123+
CLEAN_DIRECT_OUTPUT 1
124+
FRAMEWORK 1
125+
FRAMEWORK_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}"
126+
MACOSX_FRAMEWORK_INFO_PLIST "${CMAKE_SOURCE_DIR}/mac/framework.info.plist.in"
127+
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${COMPLETE_VERSION}
128+
MACOSX_FRAMEWORK_IDENTIFIER org.qgis.qgis3_3d
129+
BUILD_WITH_INSTALL_RPATH TRUE
130+
PUBLIC_HEADER "${QGIS_3D_HDRS}"
131+
LINK_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}"
132+
)
133+
# generated export header does not get copied with PUBLIC_HEADER files
134+
ADD_CUSTOM_COMMAND(TARGET qgis_3d
135+
POST_BUILD
136+
COMMAND ${CMAKE_COMMAND} -E copy qgis_3d.h
137+
"${QGIS_OUTPUT_DIRECTORY}/${QGIS_LIB_SUBDIR}/qgis_3d.framework/Headers"
138+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
139+
DEPENDS qgis_3d.h
140+
)
141+
ENDIF(NOT APPLE)
142+
143+
#generate unversioned libs for android
144+
IF (NOT ANDROID)
145+
SET_TARGET_PROPERTIES(qgis_3d PROPERTIES
146+
VERSION ${COMPLETE_VERSION}
147+
SOVERSION ${COMPLETE_VERSION}
148+
)
149+
ENDIF (NOT ANDROID)
150+
151+
TARGET_LINK_LIBRARIES(qgis_3d qgis_core)
152+
153+
# clang-tidy
154+
IF(CLANG_TIDY_EXE)
155+
SET_TARGET_PROPERTIES(
156+
qgis_3d PROPERTIES
157+
CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
158+
)
159+
ENDIF(CLANG_TIDY_EXE)
160+
161+
# install
162+
163+
INSTALL(TARGETS qgis_3d
164+
RUNTIME DESTINATION ${QGIS_BIN_DIR}
165+
LIBRARY DESTINATION ${QGIS_LIB_DIR}
166+
ARCHIVE DESTINATION ${QGIS_LIB_DIR}
167+
FRAMEWORK DESTINATION ${QGIS_FW_SUBDIR}
168+
PUBLIC_HEADER DESTINATION ${QGIS_INCLUDE_DIR})
169+
170+
# Mac dev frameworks
171+
172+
IF (APPLE AND QGIS_MACAPP_INSTALL_DEV)
173+
INSTALL(TARGETS qgis_3d FRAMEWORK DESTINATION ${QGIS_MACAPP_DEV_PREFIX})
174+
INSTALL(CODE "EXECUTE_PROCESS(COMMAND install_name_tool -id \"${QGIS_MACAPP_DEV_PREFIX}/qgis_3d.framework/Versions/${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}/qgis_3d\" \"$ENV{DESTDIR}${QGIS_MACAPP_DEV_PREFIX}/qgis_3d.framework/qgis_3d\")")
175+
INSTALL(CODE "EXECUTE_PROCESS(COMMAND install_name_tool -change \"${CMAKE_INSTALL_NAME_DIR}/qgis_core.framework/Versions/${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}/qgis_core\" \"${QGIS_MACAPP_DEV_PREFIX}/qgis_core.framework/Versions/${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}/qgis_core\" \"$ENV{DESTDIR}${QGIS_MACAPP_DEV_PREFIX}/qgis_3d.framework/qgis_3d\")")
176+
ENDIF (APPLE AND QGIS_MACAPP_INSTALL_DEV)

src/3d/aabb.h

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#ifndef AABB_H
2+
#define AABB_H
3+
4+
#include <math.h>
5+
#include <QList>
6+
#include <QVector3D>
7+
8+
//! axis-aligned bounding box - in world coords
9+
class AABB
10+
{
11+
public:
12+
AABB()
13+
: xMin( 0 ), yMin( 0 ), zMin( 0 ), xMax( 0 ), yMax( 0 ), zMax( 0 )
14+
{
15+
}
16+
17+
AABB( float xMin, float yMin, float zMin, float xMax, float yMax, float zMax )
18+
: xMin( xMin ), yMin( yMin ), zMin( zMin ), xMax( xMax ), yMax( yMax ), zMax( zMax )
19+
{
20+
// normalize coords
21+
if ( this->xMax < this->xMin )
22+
qSwap( this->xMin, this->xMax );
23+
if ( this->yMax < this->yMin )
24+
qSwap( this->yMin, this->yMax );
25+
if ( this->zMax < this->zMin )
26+
qSwap( this->zMin, this->zMax );
27+
}
28+
29+
float xExtent() const { return xMax - xMin; }
30+
float yExtent() const { return yMax - yMin; }
31+
float zExtent() const { return zMax - zMin; }
32+
33+
float xCenter() const { return ( xMax + xMin ) / 2; }
34+
float yCenter() const { return ( yMax + yMin ) / 2; }
35+
float zCenter() const { return ( zMax + zMin ) / 2; }
36+
37+
QVector3D center() const { return QVector3D( xCenter(), yCenter(), zCenter() ); }
38+
39+
bool intersects( const AABB &other ) const
40+
{
41+
return xMin < other.xMax && other.xMin < xMax &&
42+
yMin < other.yMax && other.yMin < yMax &&
43+
zMin < other.zMax && other.zMin < zMax;
44+
}
45+
46+
bool intersects( float x, float y, float z ) const
47+
{
48+
return xMin <= x && xMax >= x &&
49+
yMin <= y && yMax >= y &&
50+
zMin <= z && zMax >= z;
51+
}
52+
53+
float distanceFromPoint( float x, float y, float z ) const
54+
{
55+
float dx = qMax( xMin - x, qMax( 0.f, x - xMax ) );
56+
float dy = qMax( yMin - y, qMax( 0.f, y - yMax ) );
57+
float dz = qMax( zMin - z, qMax( 0.f, z - zMax ) );
58+
return sqrt( dx * dx + dy * dy + dz * dz );
59+
}
60+
61+
float distanceFromPoint( const QVector3D &v ) const
62+
{
63+
return distanceFromPoint( v.x(), v.y(), v.z() );
64+
}
65+
66+
QList<QVector3D> verticesForLines() const
67+
{
68+
QList<QVector3D> vertices;
69+
for ( int i = 0; i < 2; ++i )
70+
{
71+
float x = i ? xMax : xMin;
72+
for ( int j = 0; j < 2; ++j )
73+
{
74+
float y = j ? yMax : yMin;
75+
for ( int k = 0; k < 2; ++k )
76+
{
77+
float z = k ? zMax : zMin;
78+
if ( i == 0 )
79+
{
80+
vertices.append( QVector3D( xMin, y, z ) );
81+
vertices.append( QVector3D( xMax, y, z ) );
82+
}
83+
if ( j == 0 )
84+
{
85+
vertices.append( QVector3D( x, yMin, z ) );
86+
vertices.append( QVector3D( x, yMax, z ) );
87+
}
88+
if ( k == 0 )
89+
{
90+
vertices.append( QVector3D( x, y, zMin ) );
91+
vertices.append( QVector3D( x, y, zMax ) );
92+
}
93+
}
94+
}
95+
}
96+
return vertices;
97+
}
98+
99+
float xMin, yMin, zMin;
100+
float xMax, yMax, zMax;
101+
};
102+
103+
#endif // AABB_H

0 commit comments

Comments
 (0)