Merge pull request #2611 from RevoluPowered/feature/prototype-for-assimp-universal-scale
Prototype unit system for assimppull/2608/head^2
commit
f119fedd55
|
@ -14,7 +14,6 @@ matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
|
|
||||||
image:
|
image:
|
||||||
- Visual Studio 2013
|
|
||||||
- Visual Studio 2015
|
- Visual Studio 2015
|
||||||
- Visual Studio 2017
|
- Visual Studio 2017
|
||||||
|
|
||||||
|
@ -27,7 +26,6 @@ configuration: Release
|
||||||
install:
|
install:
|
||||||
- set PATH=C:\Ruby24-x64\bin;%PATH%
|
- set PATH=C:\Ruby24-x64\bin;%PATH%
|
||||||
- set CMAKE_DEFINES -DASSIMP_WERROR=ON
|
- set CMAKE_DEFINES -DASSIMP_WERROR=ON
|
||||||
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2013" set CMAKE_GENERATOR_NAME=Visual Studio 12 2013
|
|
||||||
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" set CMAKE_GENERATOR_NAME=Visual Studio 14 2015
|
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" set CMAKE_GENERATOR_NAME=Visual Studio 14 2015
|
||||||
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" set CMAKE_GENERATOR_NAME=Visual Studio 15 2017
|
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" set CMAKE_GENERATOR_NAME=Visual Studio 15 2017
|
||||||
- if "%platform%"=="x64" set CMAKE_GENERATOR_NAME=%CMAKE_GENERATOR_NAME% Win64
|
- if "%platform%"=="x64" set CMAKE_GENERATOR_NAME=%CMAKE_GENERATOR_NAME% Win64
|
||||||
|
|
|
@ -189,9 +189,13 @@ void FBXImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
|
||||||
if (settings.convertToMeters) {
|
if (settings.convertToMeters) {
|
||||||
unit = FbxUnit::m;
|
unit = FbxUnit::m;
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert the FBX DOM to aiScene
|
// convert the FBX DOM to aiScene
|
||||||
ConvertToAssimpScene(pScene, doc, settings.removeEmptyBones, unit);
|
ConvertToAssimpScene(pScene, doc, settings.removeEmptyBones, unit);
|
||||||
|
|
||||||
|
// Set file scale relative to meters
|
||||||
|
SetFileScale( doc.GlobalSettings().UnitScaleFactor() );
|
||||||
|
|
||||||
std::for_each(tokens.begin(),tokens.end(),Util::delete_fun<Token>());
|
std::for_each(tokens.begin(),tokens.end(),Util::delete_fun<Token>());
|
||||||
}
|
}
|
||||||
catch(std::exception&) {
|
catch(std::exception&) {
|
||||||
|
|
|
@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
#include <assimp/postprocess.h>
|
#include <assimp/postprocess.h>
|
||||||
|
#include <assimp/BaseImporter.h>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
|
@ -69,7 +69,15 @@ bool ScaleProcess::IsActive( unsigned int pFlags ) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScaleProcess::SetupProperties( const Importer* pImp ) {
|
void ScaleProcess::SetupProperties( const Importer* pImp ) {
|
||||||
|
// User scaling
|
||||||
mScale = pImp->GetPropertyFloat( AI_CONFIG_GLOBAL_SCALE_FACTOR_KEY, 1.0f );
|
mScale = pImp->GetPropertyFloat( AI_CONFIG_GLOBAL_SCALE_FACTOR_KEY, 1.0f );
|
||||||
|
|
||||||
|
// File scaling * Application Scaling
|
||||||
|
float importerScale = pImp->GetPropertyFloat( AI_CONFIG_APP_SCALE_KEY, 1.0f );
|
||||||
|
|
||||||
|
// apply scale to the scale
|
||||||
|
// helps prevent bugs with backward compatibility for anyone using normal scaling.
|
||||||
|
mScale *= importerScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScaleProcess::Execute( aiScene* pScene ) {
|
void ScaleProcess::Execute( aiScene* pScene ) {
|
||||||
|
|
|
@ -48,8 +48,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <map>
|
||||||
#include <assimp/types.h>
|
#include <assimp/types.h>
|
||||||
#include <assimp/ProgressHandler.hpp>
|
#include <assimp/ProgressHandler.hpp>
|
||||||
|
#include <assimp/ai_assert.h>
|
||||||
|
|
||||||
struct aiScene;
|
struct aiScene;
|
||||||
struct aiImporterDesc;
|
struct aiImporterDesc;
|
||||||
|
@ -161,6 +163,60 @@ public:
|
||||||
* some loader features. Importers must provide this information. */
|
* some loader features. Importers must provide this information. */
|
||||||
virtual const aiImporterDesc* GetInfo() const = 0;
|
virtual const aiImporterDesc* GetInfo() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will be called only by scale process when scaling is requested.
|
||||||
|
*/
|
||||||
|
virtual void SetFileScale(double scale)
|
||||||
|
{
|
||||||
|
fileScale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual double GetFileScale() const
|
||||||
|
{
|
||||||
|
return fileScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ImporterUnits {
|
||||||
|
M,
|
||||||
|
MM,
|
||||||
|
CM,
|
||||||
|
INCHES,
|
||||||
|
FEET
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assimp Importer
|
||||||
|
* unit conversions available
|
||||||
|
* if you need another measurment unit add it below.
|
||||||
|
* it's currently defined in assimp that we prefer meters.
|
||||||
|
* */
|
||||||
|
std::map<ImporterUnits, double> importerUnits = {
|
||||||
|
{ImporterUnits::M, 1},
|
||||||
|
{ImporterUnits::CM, 0.01},
|
||||||
|
{ImporterUnits::MM, 0.001},
|
||||||
|
{ImporterUnits::INCHES, 0.0254},
|
||||||
|
{ImporterUnits::FEET, 0.3048}
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual void SetApplicationUnits( const ImporterUnits& unit )
|
||||||
|
{
|
||||||
|
importerScale = importerUnits[unit];
|
||||||
|
applicationUnits = unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual const ImporterUnits& GetApplicationUnits()
|
||||||
|
{
|
||||||
|
return applicationUnits;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Returns scale used by application called by ScaleProcess */
|
||||||
|
double GetImporterScale() const
|
||||||
|
{
|
||||||
|
ai_assert(importerScale != 0);
|
||||||
|
ai_assert(fileScale != 0);
|
||||||
|
return importerScale * fileScale;
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Called by #Importer::GetExtensionList for each loaded importer.
|
/** Called by #Importer::GetExtensionList for each loaded importer.
|
||||||
* Take the extension list contained in the structure returned by
|
* Take the extension list contained in the structure returned by
|
||||||
|
@ -169,6 +225,10 @@ public:
|
||||||
void GetExtensionList(std::set<std::string>& extensions);
|
void GetExtensionList(std::set<std::string>& extensions);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
ImporterUnits applicationUnits = ImporterUnits::M;
|
||||||
|
double importerScale = 1.0;
|
||||||
|
double fileScale = 1.0;
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Imports the given file into the given scene structure. The
|
/** Imports the given file into the given scene structure. The
|
||||||
|
|
|
@ -999,6 +999,13 @@ enum aiComponent
|
||||||
# define AI_CONFIG_GLOBAL_SCALE_FACTOR_DEFAULT 1.0f
|
# define AI_CONFIG_GLOBAL_SCALE_FACTOR_DEFAULT 1.0f
|
||||||
#endif // !! AI_DEBONE_THRESHOLD
|
#endif // !! AI_DEBONE_THRESHOLD
|
||||||
|
|
||||||
|
#define AI_CONFIG_APP_SCALE_KEY "APP_SCALE_FACTOR"
|
||||||
|
|
||||||
|
#if (!defined AI_CONFIG_APP_SCALE_KEY)
|
||||||
|
# define AI_CONFIG_APP_SCALE_KEY 1.0
|
||||||
|
#endif // AI_CONFIG_APP_SCALE_KEY
|
||||||
|
|
||||||
|
|
||||||
// ---------- All the Build/Compile-time defines ------------
|
// ---------- All the Build/Compile-time defines ------------
|
||||||
|
|
||||||
/** @brief Specifies if double precision is supported inside assimp
|
/** @brief Specifies if double precision is supported inside assimp
|
||||||
|
|
Loading…
Reference in New Issue