Skip to content
Permalink
Browse files

Import of initial work on QGIS 3D framework from wonder-sk/qgis3d

  • Loading branch information
wonder-sk committed Jul 19, 2017
1 parent ea28c2d commit 675a1ae5bc410ed4128871bdd9c710d9cbe4cfd1
Showing with 8,413 additions and 1 deletion.
  1. +9 −0 CMakeLists.txt
  2. +1 −1 scripts/prepare-commit.sh
  3. +176 −0 src/3d/CMakeLists.txt
  4. +103 −0 src/3d/aabb.h
  5. +228 −0 src/3d/cameracontroller.cpp
  6. +112 −0 src/3d/cameracontroller.h
  7. +366 −0 src/3d/chunkedentity.cpp
  8. +109 −0 src/3d/chunkedentity.h
  9. +103 −0 src/3d/chunklist.cpp
  10. +54 −0 src/3d/chunklist.h
  11. +9 −0 src/3d/chunkloader.cpp
  12. +44 −0 src/3d/chunkloader.h
  13. +128 −0 src/3d/chunknode.cpp
  14. +70 −0 src/3d/chunknode.h
  15. +309 −0 src/3d/demterraingenerator.cpp
  16. +109 −0 src/3d/demterraingenerator.h
  17. +284 −0 src/3d/demterraintilegeometry.cpp
  18. +56 −0 src/3d/demterraintilegeometry.h
  19. +153 −0 src/3d/flatterraingenerator.cpp
  20. +45 −0 src/3d/flatterraingenerator.h
  21. +77 −0 src/3d/lineentity.cpp
  22. +19 −0 src/3d/lineentity.h
  23. +488 −0 src/3d/map3d.cpp
  24. +197 −0 src/3d/map3d.h
  25. +113 −0 src/3d/maptexturegenerator.cpp
  26. +60 −0 src/3d/maptexturegenerator.h
  27. +90 −0 src/3d/maptextureimage.cpp
  28. +38 −0 src/3d/maptextureimage.h
  29. +235 −0 src/3d/pointentity.cpp
  30. +15 −0 src/3d/pointentity.h
  31. +365 −0 src/3d/poly2tri/common/shapes.cc
  32. +323 −0 src/3d/poly2tri/common/shapes.h
  33. +127 −0 src/3d/poly2tri/common/utils.h
  34. +38 −0 src/3d/poly2tri/poly2tri.h
  35. +108 −0 src/3d/poly2tri/sweep/advancing_front.cc
  36. +118 −0 src/3d/poly2tri/sweep/advancing_front.h
  37. +71 −0 src/3d/poly2tri/sweep/cdt.cc
  38. +105 −0 src/3d/poly2tri/sweep/cdt.h
  39. +793 −0 src/3d/poly2tri/sweep/sweep.cc
  40. +285 −0 src/3d/poly2tri/sweep/sweep.h
  41. +211 −0 src/3d/poly2tri/sweep/sweep_context.cc
  42. +186 −0 src/3d/poly2tri/sweep/sweep_context.h
  43. +75 −0 src/3d/polygonentity.cpp
  44. +23 −0 src/3d/polygonentity.h
  45. +83 −0 src/3d/polygongeometry.cpp
  46. +32 −0 src/3d/polygongeometry.h
  47. +367 −0 src/3d/quantizedmeshgeometry.cpp
  48. +73 −0 src/3d/quantizedmeshgeometry.h
  49. +143 −0 src/3d/quantizedmeshterraingenerator.cpp
  50. +27 −0 src/3d/quantizedmeshterraingenerator.h
  51. +176 −0 src/3d/scene.cpp
  52. +51 −0 src/3d/scene.h
  53. +28 −0 src/3d/terrain.cpp
  54. +34 −0 src/3d/terrain.h
  55. +122 −0 src/3d/terrainboundsentity.cpp
  56. +21 −0 src/3d/terrainboundsentity.h
  57. +70 −0 src/3d/terrainchunkloader.cpp
  58. +30 −0 src/3d/terrainchunkloader.h
  59. +56 −0 src/3d/terraingenerator.cpp
  60. +75 −0 src/3d/terraingenerator.h
  61. +171 −0 src/3d/tessellator.cpp
  62. +29 −0 src/3d/tessellator.h
  63. +73 −0 src/3d/tilingscheme.cpp
  64. +37 −0 src/3d/tilingscheme.h
  65. +65 −0 src/3d/utils.cpp
  66. +18 −0 src/3d/utils.h
  67. +4 −0 src/CMakeLists.txt
@@ -59,6 +59,8 @@ IF(WITH_CORE)

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

SET (WITH_3D FALSE CACHE BOOL "Determines whether QGIS 3D library should be built")

# server disabled default because it needs FastCGI (which is optional dependency)
SET (WITH_SERVER FALSE CACHE BOOL "Determines whether QGIS server should be built")
IF(WITH_SERVER)
@@ -276,6 +278,13 @@ IF(WITH_CORE)
FIND_PACKAGE(Qt5UiTools REQUIRED)
FIND_PACKAGE(Qt5Script REQUIRED)
FIND_PACKAGE(Qt5Sql REQUIRED)
IF (WITH_3D)
FIND_PACKAGE(Qt53DCore REQUIRED)
FIND_PACKAGE(Qt53DRender REQUIRED)
FIND_PACKAGE(Qt53DInput REQUIRED)
FIND_PACKAGE(Qt53DLogic REQUIRED)
FIND_PACKAGE(Qt53DExtras REQUIRED)
ENDIF (WITH_3D)
INCLUDE("cmake/modules/ECMQt4To5Porting.cmake")
MESSAGE(STATUS "Found Qt version: ${Qt5Core_VERSION_STRING}")

@@ -73,7 +73,7 @@ for f in $MODIFIED; do
(( i++ )) || true

case "$f" in
src/core/gps/qextserialport/*|src/plugins/globe/osgEarthQt/*|src/plugins/globe/osgEarthUtil/*)
src/core/gps/qextserialport/*|src/plugins/globe/osgEarthQt/*|src/plugins/globe/osgEarthUtil/*|src/3d/poly2tri/*)
echo $f skipped
continue
;;
@@ -0,0 +1,176 @@
#############################################################
# sources

SET(QGIS_3D_SRCS
cameracontroller.cpp
chunkedentity.cpp
chunklist.cpp
chunkloader.cpp
chunknode.cpp
demterraingenerator.cpp
demterraintilegeometry.cpp
flatterraingenerator.cpp
lineentity.cpp
map3d.cpp
maptexturegenerator.cpp
maptextureimage.cpp
pointentity.cpp
polygonentity.cpp
polygongeometry.cpp
#quantizedmeshgeometry.cpp
#quantizedmeshterraingenerator.cpp
scene.cpp
terrain.cpp
terrainboundsentity.cpp
terrainchunkloader.cpp
terraingenerator.cpp
tessellator.cpp
tilingscheme.cpp
utils.cpp

poly2tri/common/shapes.cc
poly2tri/sweep/advancing_front.cc
poly2tri/sweep/cdt.cc
poly2tri/sweep/sweep_context.cc
poly2tri/sweep/sweep.cc
)

SET(QGIS_3D_MOC_HDRS
cameracontroller.h
chunkedentity.h
demterraingenerator.h
demterraintilegeometry.h
maptexturegenerator.h
maptextureimage.h
scene.h
terrain.h
)

QT5_WRAP_CPP(QGIS_3D_MOC_SRCS ${QGIS_3D_MOC_HDRS})

# install headers

SET(QGIS_3D_HDRS
aabb.h
cameracontroller.h
chunkedentity.h
chunklist.h
chunkloader.h
chunknode.h
demterraingenerator.h
demterraintilegeometry.h
flatterraingenerator.h
lineentity.h
map3d.h
maptexturegenerator.h
maptextureimage.h
pointentity.h
polygonentity.h
polygongeometry.h
#quantizedmeshgeometry.h
#quantizedmeshterraingenerator.h
scene.h
terrain.h
terrainboundsentity.h
terrainchunkloader.h
terraingenerator.h
tessellator.h
tilingscheme.h
utils.h
)

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/core/
${CMAKE_SOURCE_DIR}/src/core/geometry
${CMAKE_SOURCE_DIR}/src/core/raster
${CMAKE_SOURCE_DIR}/src/core/symbology-ng
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/expression
${CMAKE_BINARY_DIR}/src/core
${CMAKE_BINARY_DIR}/src/3d
)
INCLUDE_DIRECTORIES(SYSTEM
${PROJ_INCLUDE_DIR}
${GEOS_INCLUDE_DIR}
${GDAL_INCLUDE_DIR}
${SQLITE3_INCLUDE_DIR}
)

#############################################################
# qgis_3d library

ADD_LIBRARY(qgis_3d SHARED ${QGIS_3D_SRCS} ${QGIS_3D_MOC_SRCS} ${QGIS_3D_HDRS})

qt5_use_modules(qgis_3d 3DCore 3DRender 3DInput 3DLogic 3DExtras)

GENERATE_EXPORT_HEADER(
qgis_3d
BASE_NAME 3D
EXPORT_FILE_NAME qgis_3d.h
)
IF(MSVC)
SET_TARGET_PROPERTIES(qgis_3d PROPERTIES LINK_FLAGS "/FORCE:MULTIPLE")
ENDIF(MSVC)

SET(QGIS_3D_HDRS ${QGIS_3D_HDRS} ${CMAKE_CURRENT_BINARY_DIR}/qgis_3d.h)

IF(NOT APPLE)
INSTALL(FILES ${QGIS_3D_HDRS} DESTINATION ${QGIS_INCLUDE_DIR})
ELSE(NOT APPLE)
SET_TARGET_PROPERTIES(qgis_3d PROPERTIES
# no moc headers, messes up PROPERTIES syntax
CLEAN_DIRECT_OUTPUT 1
FRAMEWORK 1
FRAMEWORK_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}"
MACOSX_FRAMEWORK_INFO_PLIST "${CMAKE_SOURCE_DIR}/mac/framework.info.plist.in"
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${COMPLETE_VERSION}
MACOSX_FRAMEWORK_IDENTIFIER org.qgis.qgis3_3d
BUILD_WITH_INSTALL_RPATH TRUE
PUBLIC_HEADER "${QGIS_3D_HDRS}"
LINK_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}"
)
# generated export header does not get copied with PUBLIC_HEADER files
ADD_CUSTOM_COMMAND(TARGET qgis_3d
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy qgis_3d.h
"${QGIS_OUTPUT_DIRECTORY}/${QGIS_LIB_SUBDIR}/qgis_3d.framework/Headers"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS qgis_3d.h
)
ENDIF(NOT APPLE)

#generate unversioned libs for android
IF (NOT ANDROID)
SET_TARGET_PROPERTIES(qgis_3d PROPERTIES
VERSION ${COMPLETE_VERSION}
SOVERSION ${COMPLETE_VERSION}
)
ENDIF (NOT ANDROID)

TARGET_LINK_LIBRARIES(qgis_3d qgis_core)

# clang-tidy
IF(CLANG_TIDY_EXE)
SET_TARGET_PROPERTIES(
qgis_3d PROPERTIES
CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
)
ENDIF(CLANG_TIDY_EXE)

# install

INSTALL(TARGETS qgis_3d
RUNTIME DESTINATION ${QGIS_BIN_DIR}
LIBRARY DESTINATION ${QGIS_LIB_DIR}
ARCHIVE DESTINATION ${QGIS_LIB_DIR}
FRAMEWORK DESTINATION ${QGIS_FW_SUBDIR}
PUBLIC_HEADER DESTINATION ${QGIS_INCLUDE_DIR})

# Mac dev frameworks

IF (APPLE AND QGIS_MACAPP_INSTALL_DEV)
INSTALL(TARGETS qgis_3d FRAMEWORK DESTINATION ${QGIS_MACAPP_DEV_PREFIX})
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\")")
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\")")
ENDIF (APPLE AND QGIS_MACAPP_INSTALL_DEV)
@@ -0,0 +1,103 @@
#ifndef AABB_H
#define AABB_H

#include <math.h>
#include <QList>
#include <QVector3D>

//! axis-aligned bounding box - in world coords
class AABB
{
public:
AABB()
: xMin( 0 ), yMin( 0 ), zMin( 0 ), xMax( 0 ), yMax( 0 ), zMax( 0 )
{
}

AABB( float xMin, float yMin, float zMin, float xMax, float yMax, float zMax )
: xMin( xMin ), yMin( yMin ), zMin( zMin ), xMax( xMax ), yMax( yMax ), zMax( zMax )
{
// normalize coords
if ( this->xMax < this->xMin )
qSwap( this->xMin, this->xMax );
if ( this->yMax < this->yMin )
qSwap( this->yMin, this->yMax );
if ( this->zMax < this->zMin )
qSwap( this->zMin, this->zMax );
}

float xExtent() const { return xMax - xMin; }
float yExtent() const { return yMax - yMin; }
float zExtent() const { return zMax - zMin; }

float xCenter() const { return ( xMax + xMin ) / 2; }
float yCenter() const { return ( yMax + yMin ) / 2; }
float zCenter() const { return ( zMax + zMin ) / 2; }

QVector3D center() const { return QVector3D( xCenter(), yCenter(), zCenter() ); }

bool intersects( const AABB &other ) const
{
return xMin < other.xMax && other.xMin < xMax &&
yMin < other.yMax && other.yMin < yMax &&
zMin < other.zMax && other.zMin < zMax;
}

bool intersects( float x, float y, float z ) const
{
return xMin <= x && xMax >= x &&
yMin <= y && yMax >= y &&
zMin <= z && zMax >= z;
}

float distanceFromPoint( float x, float y, float z ) const
{
float dx = qMax( xMin - x, qMax( 0.f, x - xMax ) );
float dy = qMax( yMin - y, qMax( 0.f, y - yMax ) );
float dz = qMax( zMin - z, qMax( 0.f, z - zMax ) );
return sqrt( dx * dx + dy * dy + dz * dz );
}

float distanceFromPoint( const QVector3D &v ) const
{
return distanceFromPoint( v.x(), v.y(), v.z() );
}

QList<QVector3D> verticesForLines() const
{
QList<QVector3D> vertices;
for ( int i = 0; i < 2; ++i )
{
float x = i ? xMax : xMin;
for ( int j = 0; j < 2; ++j )
{
float y = j ? yMax : yMin;
for ( int k = 0; k < 2; ++k )
{
float z = k ? zMax : zMin;
if ( i == 0 )
{
vertices.append( QVector3D( xMin, y, z ) );
vertices.append( QVector3D( xMax, y, z ) );
}
if ( j == 0 )
{
vertices.append( QVector3D( x, yMin, z ) );
vertices.append( QVector3D( x, yMax, z ) );
}
if ( k == 0 )
{
vertices.append( QVector3D( x, y, zMin ) );
vertices.append( QVector3D( x, y, zMax ) );
}
}
}
}
return vertices;
}

float xMin, yMin, zMin;
float xMax, yMax, zMax;
};

#endif // AABB_H

0 comments on commit 675a1ae

Please sign in to comment.
You can’t perform that action at this time.