From e93cdb2797f608fadaa2e4457b20d2d683e578de Mon Sep 17 00:00:00 2001 From: fo76utils <87907510+fo76utils@users.noreply.github.com> Date: Thu, 17 Oct 2024 23:54:17 +0200 Subject: [PATCH] NifModel: new function to check for Starfield internal geometry format --- src/model/nifmodel.cpp | 24 ++++++++++++++++++++++++ src/model/nifmodel.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/src/model/nifmodel.cpp b/src/model/nifmodel.cpp index 40ed097a..92c212d5 100644 --- a/src/model/nifmodel.cpp +++ b/src/model/nifmodel.cpp @@ -1824,6 +1824,30 @@ class spMeshFileImport static bool processAllItems( NifModel * nif ); }; +bool NifModel::checkInternalGeometry( const QModelIndex & blockIndex ) +{ + if ( !blockIndex.isValid() ) { + int n = getBlockCount(); + for ( int i = 0; i < n; i++ ) { + QModelIndex b = getBlockIndex( i ); + if ( isNiBlock( b, "BSGeometry" ) && !checkInternalGeometry( b ) ) + return false; + } + return true; + } + if ( !isNiBlock( blockIndex, "BSGeometry" ) ) + return true; + if ( get( blockIndex, "Flags" ) & 0x0200 ) + return true; + if ( QMessageBox::question( parentWindow, tr( "NifSkope warning" ), + tr( "This operation can only be performed on internal geometry. Convert meshes?" ) ) + != QMessageBox::Yes ) { + return false; + } + spMeshFileImport::processAllItems( this ); + return bool( get( blockIndex, "Flags" ) & 0x0200 ); +} + bool NifModel::load( QIODevice & device, const char* fileName ) { QSettings settings; diff --git a/src/model/nifmodel.h b/src/model/nifmodel.h index a6cc0264..7e97e62b 100644 --- a/src/model/nifmodel.h +++ b/src/model/nifmodel.h @@ -97,6 +97,8 @@ class NifModel final : public BaseModel // BaseModel void clear() override final; + //! Check if a Starfield model uses internal geometry data, and optionally convert meshes. Returns true on success. + bool checkInternalGeometry( const QModelIndex & blockIndex ); bool load( QIODevice & device, const char* fileName = nullptr ) override final; bool save( QIODevice & device ) const override final;