mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-02 00:04:27 -04:00
Compare commits
2 Commits
b7a75a8c44
...
a04a5dd350
Author | SHA1 | Date | |
---|---|---|---|
|
a04a5dd350 | ||
|
78998ba305 |
@ -28,7 +28,6 @@
|
||||
#include "qgsraycastingutils_p.h"
|
||||
#include "qgstiledsceneboundingvolume.h"
|
||||
#include "qgstiledscenetile.h"
|
||||
#include "qgsziputils.h"
|
||||
|
||||
#include <QtConcurrentRun>
|
||||
|
||||
@ -126,7 +125,7 @@ void QgsTiledSceneChunkLoader::start()
|
||||
errors.append( QStringLiteral( "Failed to parse tile from '%1'" ).arg( uri ) );
|
||||
}
|
||||
}
|
||||
else if ( format == "cesiumtiles" )
|
||||
else if ( format == QLatin1String( "cesiumtiles" ) )
|
||||
{
|
||||
const QgsCesiumUtils::TileContents tileContent = QgsCesiumUtils::extractGltfFromTileContent( content );
|
||||
if ( tileContent.gltf.isEmpty() )
|
||||
@ -134,35 +133,14 @@ void QgsTiledSceneChunkLoader::start()
|
||||
entityTransform.tileTransform.translate( tileContent.rtcCenter );
|
||||
mEntity = QgsGltf3DUtils::gltfToEntity( tileContent.gltf, entityTransform, uri, &errors );
|
||||
}
|
||||
else if ( format == "draco" )
|
||||
else if ( format == QLatin1String( "draco" ) )
|
||||
{
|
||||
// SLPK and Extracted SLPK have the files gzipped
|
||||
QByteArray contentExtracted;
|
||||
if ( content.startsWith( QByteArray( "\x1f\x8b", 2 ) ) )
|
||||
{
|
||||
if ( !QgsZipUtils::decodeGzip( content, contentExtracted ) )
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
contentExtracted = content;
|
||||
}
|
||||
|
||||
const QVariantMap tileMetadata = tile.metadata();
|
||||
QgsCoordinateReferenceSystem sceneCrs = mFactory.mBoundsTransform.sourceCrs();
|
||||
|
||||
QgsGltfUtils::I3SNodeContext i3sContext;
|
||||
i3sContext.materialInfo = tileMetadata["material"].toMap();
|
||||
i3sContext.isGlobalMode = sceneCrs.type() == Qgis::CrsType::Geocentric;
|
||||
if ( i3sContext.isGlobalMode )
|
||||
{
|
||||
i3sContext.nodeCenterEcef = tile.boundingVolume().box().center();
|
||||
i3sContext.datasetToSceneTransform = QgsCoordinateTransform( mFactory.mLayerCrs, sceneCrs, mFactory.mRenderContext.transformContext() );
|
||||
}
|
||||
i3sContext.initFromTile( tile, mFactory.mLayerCrs, mFactory.mBoundsTransform.sourceCrs(), mFactory.mRenderContext.transformContext() );
|
||||
|
||||
QString dracoLoadError;
|
||||
tinygltf::Model model;
|
||||
if ( !QgsGltfUtils::loadDracoModel( contentExtracted, i3sContext, model, &dracoLoadError ) )
|
||||
if ( !QgsGltfUtils::loadDracoModel( content, i3sContext, model, &dracoLoadError ) )
|
||||
{
|
||||
errors.append( dracoLoadError );
|
||||
return;
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include "qgsmatrix4x4.h"
|
||||
#include "qgsconfig.h"
|
||||
#include "qgslogger.h"
|
||||
#include "qgstiledscenetile.h"
|
||||
#include "qgsziputils.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QMatrix4x4>
|
||||
@ -430,13 +432,32 @@ void dumpDracoModelInfo( draco::Mesh *dracoMesh )
|
||||
|
||||
bool QgsGltfUtils::loadDracoModel( const QByteArray &data, const I3SNodeContext &context, tinygltf::Model &model, QString *errors )
|
||||
{
|
||||
//
|
||||
// SLPK and Extracted SLPK have the files gzipped
|
||||
//
|
||||
|
||||
QByteArray dataExtracted;
|
||||
if ( data.startsWith( QByteArray( "\x1f\x8b", 2 ) ) )
|
||||
{
|
||||
if ( !QgsZipUtils::decodeGzip( data, dataExtracted ) )
|
||||
{
|
||||
if ( errors )
|
||||
*errors = "Failed to decode gzipped model";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dataExtracted = data;
|
||||
}
|
||||
|
||||
//
|
||||
// load the model in decoder and do basic sanity checks
|
||||
//
|
||||
|
||||
draco::Decoder decoder;
|
||||
draco::DecoderBuffer decoderBuffer;
|
||||
decoderBuffer.Init( data.constData(), data.size() );
|
||||
decoderBuffer.Init( dataExtracted.constData(), dataExtracted.size() );
|
||||
|
||||
draco::StatusOr<draco::EncodedGeometryType> geometryTypeStatus = decoder.GetEncodedGeometryType( &decoderBuffer );
|
||||
if ( !geometryTypeStatus.ok() )
|
||||
@ -790,4 +811,17 @@ bool QgsGltfUtils::writeGltfModel( const tinygltf::Model &model, const QString &
|
||||
return res;
|
||||
}
|
||||
|
||||
void QgsGltfUtils::I3SNodeContext::initFromTile( const QgsTiledSceneTile &tile, const QgsCoordinateReferenceSystem &layerCrs, const QgsCoordinateReferenceSystem &sceneCrs, const QgsCoordinateTransformContext &transformContext )
|
||||
{
|
||||
const QVariantMap tileMetadata = tile.metadata();
|
||||
|
||||
materialInfo = tileMetadata[QStringLiteral( "material" )].toMap();
|
||||
isGlobalMode = sceneCrs.type() == Qgis::CrsType::Geocentric;
|
||||
if ( isGlobalMode )
|
||||
{
|
||||
nodeCenterEcef = tile.boundingVolume().box().center();
|
||||
datasetToSceneTransform = QgsCoordinateTransform( layerCrs, sceneCrs, transformContext );
|
||||
}
|
||||
}
|
||||
|
||||
///@endcond
|
||||
|
@ -41,6 +41,7 @@ class QMatrix4x4;
|
||||
class QImage;
|
||||
|
||||
class QgsMatrix4x4;
|
||||
class QgsTiledSceneTile;
|
||||
class QgsVector3D;
|
||||
|
||||
namespace tinygltf
|
||||
@ -173,8 +174,13 @@ class CORE_EXPORT QgsGltfUtils
|
||||
* geometry of a I3S node.
|
||||
* \since QGIS 4.0
|
||||
*/
|
||||
struct I3SNodeContext
|
||||
struct CORE_EXPORT I3SNodeContext
|
||||
{
|
||||
//! Initialize the node content from tile's info
|
||||
void initFromTile( const QgsTiledSceneTile &tile,
|
||||
const QgsCoordinateReferenceSystem &layerCrs,
|
||||
const QgsCoordinateReferenceSystem &sceneCrs,
|
||||
const QgsCoordinateTransformContext &transformContext );
|
||||
|
||||
/**
|
||||
* Material parsed from I3S material definition of the node. See
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include "qgstextrenderer.h"
|
||||
#include "qgsruntimeprofiler.h"
|
||||
#include "qgsapplication.h"
|
||||
#include "qgsziputils.h"
|
||||
|
||||
#include <QMatrix4x4>
|
||||
#include <qglobal.h>
|
||||
@ -442,34 +441,11 @@ bool QgsTiledSceneLayerRenderer::renderTileContent( const QgsTiledSceneTile &til
|
||||
}
|
||||
else if ( format == QLatin1String( "draco" ) )
|
||||
{
|
||||
// SLPK and Extracted SLPK have the files gzipped
|
||||
QByteArray tileContentExtracted;
|
||||
if ( tileContent.startsWith( QByteArray( "\x1f\x8b", 2 ) ) )
|
||||
{
|
||||
if ( !QgsZipUtils::decodeGzip( tileContent, tileContentExtracted ) )
|
||||
{
|
||||
QgsDebugError( QStringLiteral( "Unable to decode gzipped data: %1" ).arg( contentUri ) );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tileContentExtracted = tileContent;
|
||||
}
|
||||
|
||||
const QVariantMap tileMetadata = tile.metadata();
|
||||
|
||||
QgsGltfUtils::I3SNodeContext i3sContext;
|
||||
i3sContext.materialInfo = tileMetadata["material"].toMap();
|
||||
i3sContext.isGlobalMode = mSceneCrs.type() == Qgis::CrsType::Geocentric;
|
||||
if ( i3sContext.isGlobalMode )
|
||||
{
|
||||
i3sContext.nodeCenterEcef = tile.boundingVolume().box().center();
|
||||
i3sContext.datasetToSceneTransform = QgsCoordinateTransform( mLayerCrs, mSceneCrs, context.renderContext().transformContext() );
|
||||
}
|
||||
i3sContext.initFromTile( tile, mLayerCrs, mSceneCrs, context.renderContext().transformContext() );
|
||||
|
||||
QString errors;
|
||||
if ( !QgsGltfUtils::loadDracoModel( tileContentExtracted, i3sContext, model, &errors ) )
|
||||
if ( !QgsGltfUtils::loadDracoModel( tileContent, i3sContext, model, &errors ) )
|
||||
{
|
||||
if ( !mErrors.contains( errors ) )
|
||||
mErrors.append( errors );
|
||||
|
Loading…
x
Reference in New Issue
Block a user