From 9aae110161a0100e9a8a00a65bf681d7b2d1832c Mon Sep 17 00:00:00 2001 From: Charlie Gettys Date: Wed, 10 Apr 2019 09:29:21 -0400 Subject: [PATCH 01/47] * Remove old non-maintained mingw makefile to prevent confusion * Add notes on building with MinGW to Build.md --- Build.md | 13 +++++- code/makefile.mingw | 105 -------------------------------------------- 2 files changed, 12 insertions(+), 106 deletions(-) delete mode 100644 code/makefile.mingw diff --git a/Build.md b/Build.md index d5b443a79..04bec04f0 100644 --- a/Build.md +++ b/Build.md @@ -23,7 +23,7 @@ This will generate the project files for the visual studio. All dependencies use See https://stackoverflow.com/questions/40803170/cmake-uwp-using-cmake-to-build-universal-windows-app -# Build instrcutions for Linux / Unix +# Build instructions for Linux / Unix Open a terminal and got to your repository. You can generate the makefiles and build the library via: ``` @@ -34,6 +34,17 @@ The option -j descripes the number of parallel processes for the build. In this If you want to use a IDE for linux you can try QTCreator for instance. +# Build instructions for MinGW + +Please see [CMake Cross Compiling](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling) for general information on CMake Toolchains. + +Some users have had success building assimp using MinGW on Linux using the following toolchain, which is not maintained by assimp. [linux-mingw-w64-gnuxx11.cmake](https://github.com/ruslo/polly/blob/master/linux-mingw-w64-gnuxx11.cmake) + +The following toolchain may or may not be helpful for building assimp using MinGW on Windows (untested): + [mingw-cxx17.cmake](https://github.com/ruslo/polly/blob/master/mingw-cxx17.cmake) + +Besides the toolchain, compilation should be the same as for Linux / Unix + # CMake build options The cmake-build-environment provides options to configure the build. The following options can be used: - **BUILD_SHARED_LIBS ( default ON )**: Generation of shared libs ( dll for windows, so for Linux ). Set this to OFF to get a static lib. diff --git a/code/makefile.mingw b/code/makefile.mingw deleted file mode 100644 index 711d57f57..000000000 --- a/code/makefile.mingw +++ /dev/null @@ -1,105 +0,0 @@ -### USE OF THIS MAKEFILE IS NOT RECOMMENDED. -### It is no longer maintained. Use CMAKE instead. - -# --------------------------------------------------------------------------- -# Makefile for Open Asset Import Library (MinGW32-make) -# aramis_acg@users.sourceforge.net -# - just a quick'n'dirty one, could be buggy ... -# -# Usage: mingw32-make -f makefile.mingw - -# TARGETS: -# all Build a shared so from the whole library -# clean Cleanup object files, prepare for rebuild -# static Build a static library (*.a) - -# MACROS: (make clean before you change one) -# NOBOOST=1 Build against boost workaround -# SINGLETHREADED=1 Build single-threaded library -# DEBUG=1 Build debug build of library -# -# --------------------------------------------------------------------------- - -# C++ object files -OBJECTS := $(patsubst %.cpp,%.o, $(wildcard *.cpp)) -OBJECTS += $(patsubst %.cpp,%.o, $(wildcard extra/*.cpp)) -OBJECTS += $(patsubst %.cpp,%.o, $(wildcard ./../contrib/irrXML/*.cpp)) - -# C object files -OBJECTSC := $(patsubst %.c,%.oc, $(wildcard ./../contrib/zlib/*.c)) -OBJECTSC += $(patsubst %.c,%.oc, $(wildcard ./../contrib/ConvertUTF/*.c)) -OBJECTSC += $(patsubst %.c,%.oc, $(wildcard ./../contrib/unzip/*.c)) - -# Include flags for gcc -INCLUDEFLAGS = - -# Preprocessor defines for gcc -DEFINEFLAGS = - -# Suffix for the output binary, represents build type -NAMESUFFIX = - -# Output path for binaries -BINPATH = ../bin/mingw/ - -# GCC compiler flags -CPPFLAGS=-Wall - -# Setup environment for noboost build -ifeq ($(NOBOOST),1) - SINGLETHREADED = 1 - INCLUDEFLAGS += -I./BoostWorkaround/ - DEFINEFLAGS += -DASSIMP_BUILD_BOOST_WORKAROUND -# NAMESUFFIX += -noboost -else - # adjust this manually if your boost is stored elsewhere - INCLUDEFLAGS += -I"C:/Program Files/boost/boost_1_38" - #INCLUDEFLAGS += -I"$(BOOST_DIR)" - -endif - -# Setup environment for st build -ifeq ($(SINGLETHREADED),1) - DEFINEFLAGS += -DASSIMP_BUILD_SINGLETHREADED -# NAMESUFFIX += -st -endif - -# Setup environment for debug build -ifeq ($(DEBUG),1) - DEFINEFLAGS += -D_DEBUG -DDEBUG - CPPFLAGS += -g -# NAMESUFFIX += -debug -else - CPPFLAGS += -O2 -s - DEFINEFLAGS += -DNDEBUG -D_NDEBUG -endif - -# Output name of shared library -SHARED_TARGET = $(BINPATH)/libassimp$(NAMESUFFIX).so - -# Output name of static library -STATIC = $(BINPATH)/libassimp$(NAMESUFFIX).a - -# target: all -# usage : build a shared library (*.so) -all: $(SHARED_TARGET) - -$(SHARED_TARGET): $(OBJECTS) $(OBJECTSC) - gcc -o $@ $(OBJECTS) $(OBJECTSC) -shared -lstdc++ -%.o:%.cpp - $(CXX) -c $(CPPFLAGS) $? -o $@ $(INCLUDEFLAGS) $(DEFINEFLAGS) -%.oc:%.c - $(CXX) -x c -c -ansi $(CPPFLAGS) $? -o $@ - -# target: clean -# usage : cleanup all object files, prepare for a rebuild -.PHONY: clean -clean: - -del *.o .\..\contrib\irrXML\*.o .\..\contrib\zlib\*.oc .\..\contrib\unzip\*.oc .\..\contrib\ConvertUTF\*.oc - -# target: static -# usage : build a static library (*.a) -static: $(STATIC) -$(STATIC): $(OBJECTS) $(OBJECTSC) - ar rcs $@ $(OBJECTS) $(OBJECTSC) - From f7384dec95832c6e91f5b7896749a195c8daab52 Mon Sep 17 00:00:00 2001 From: Charlie Gettys Date: Wed, 10 Apr 2019 09:45:31 -0400 Subject: [PATCH 02/47] Possible fix for #2406. Shouldn't affect other compiled files, but have not verified this. Also, if anyone tries to debug StepFileGen1.cpp on MinGW, the debug info may not be there, but I think this is the best we can do. --- code/CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index a265a01dc..be70ba88c 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -800,6 +800,18 @@ ADD_ASSIMP_IMPORTER( MMD MMDVmdParser.h ) +# Workaround for issue #2406 - force problematic large file to be optimized to prevent string table overflow error +# Used -Os instead of -O2 as previous issues had mentioned, since -Os is roughly speaking -O2, excluding any +# optimizations that take up extra space. Given that the issue is a string table overflowing, -Os seemed appropriate +# Also, I'm not positive if both link & compile flags are needed, but this hopefully ensures that the issue should not +# recur for edge cases such as static builds. +if ((CMAKE_COMPILER_IS_MINGW) AND (CMAKE_BUILD_TYPE MATCHES Debug)) + message("-- Applying MinGW StepFileGen1.cpp Debug Workaround") + SET_SOURCE_FILES_PROPERTIES(Importer/StepFile/StepFileGen1.cpp PROPERTIES COMPILE_FLAGS -Os ) + SET_SOURCE_FILES_PROPERTIES(Importer/StepFile/StepFileGen1.cpp PROPERTIES LINK_FLAGS -Os ) + SET_SOURCE_FILES_PROPERTIES(Importer/StepFile/StepFileGen1.cpp PROPERTIES STATIC_LIBRARY_FLAGS -Os ) +endif() + ADD_ASSIMP_IMPORTER( STEP STEPFile.h Importer/StepFile/StepFileImporter.h From 6a373d55c7c78cf8aabc2c829abc62d9b9a5d47f Mon Sep 17 00:00:00 2001 From: Charlie Gettys Date: Wed, 10 Apr 2019 10:07:24 -0400 Subject: [PATCH 03/47] * Add notes on MinGW compiler version requirements * Add check on MinGW compiler version to force compliance. * Closes #2315 ? --- Build.md | 5 ++++- CMakeLists.txt | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Build.md b/Build.md index 04bec04f0..2e47c8cab 100644 --- a/Build.md +++ b/Build.md @@ -35,6 +35,9 @@ The option -j descripes the number of parallel processes for the build. In this If you want to use a IDE for linux you can try QTCreator for instance. # Build instructions for MinGW + Older versions of MinGW's compiler (e.g. 5.1.0) do not support the -mbig_obj flag +required to compile some of assimp's files, especially for debug builds. +Version 7.3.0 of g++-mingw-w64 & gcc-mingw-w64 appears to work. Please see [CMake Cross Compiling](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling) for general information on CMake Toolchains. @@ -43,7 +46,7 @@ Some users have had success building assimp using MinGW on Linux using the follo The following toolchain may or may not be helpful for building assimp using MinGW on Windows (untested): [mingw-cxx17.cmake](https://github.com/ruslo/polly/blob/master/mingw-cxx17.cmake) -Besides the toolchain, compilation should be the same as for Linux / Unix +Besides the toolchain, compilation should be the same as for Linux / Unix. # CMake build options The cmake-build-environment provides options to configure the build. The following options can be used: diff --git a/CMakeLists.txt b/CMakeLists.txt index 13a054de2..755bef89a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -234,7 +234,12 @@ ELSEIF ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) SET(CMAKE_CXX_FLAGS "-g -fvisibility=hidden -fPIC -fno-strict-aliasing -Wall -Wno-long-long -std=c++11 ${CMAKE_CXX_FLAGS}" ) SET(CMAKE_C_FLAGS "-fPIC -fno-strict-aliasing ${CMAKE_C_FLAGS}") ELSEIF( CMAKE_COMPILER_IS_MINGW ) - SET( CMAKE_CXX_FLAGS "-fvisibility=hidden -fno-strict-aliasing -Wall -Wno-long-long -std=c++11 -Wa,-mbig-obj ${CMAKE_CXX_FLAGS}" ) + IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0) + message(FATAL_ERROR "MinGW is too old") + ELSEIF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3) + message(WARNING "MinGW is old, if you experience errors, update MinGW") + ENDIF() + SET( CMAKE_CXX_FLAGS "-fvisibility=hidden -fPIC -fno-strict-aliasing -Wall -Wno-long-long -std=c++11 -Wa,-mbig-obj ${CMAKE_CXX_FLAGS}" ) SET(CMAKE_C_FLAGS "-fPIC -fno-strict-aliasing ${CMAKE_C_FLAGS} ") ADD_DEFINITIONS( -U__STRICT_ANSI__ ) ENDIF() From 567a645c4fa3fdad65c1004ac92e62384ff7bff5 Mon Sep 17 00:00:00 2001 From: Charlie Gettys Date: Wed, 10 Apr 2019 10:31:57 -0400 Subject: [PATCH 04/47] * Improve error message for new check on MinGW compiler version --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 755bef89a..2250e8006 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -235,11 +235,11 @@ ELSEIF ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) SET(CMAKE_C_FLAGS "-fPIC -fno-strict-aliasing ${CMAKE_C_FLAGS}") ELSEIF( CMAKE_COMPILER_IS_MINGW ) IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0) - message(FATAL_ERROR "MinGW is too old") + message(FATAL_ERROR "MinGW is too old to be supported. Please update MinGW and try again.") ELSEIF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3) - message(WARNING "MinGW is old, if you experience errors, update MinGW") + message(WARNING "MinGW is old, if you experience errors, update MinGW.") ENDIF() - SET( CMAKE_CXX_FLAGS "-fvisibility=hidden -fPIC -fno-strict-aliasing -Wall -Wno-long-long -std=c++11 -Wa,-mbig-obj ${CMAKE_CXX_FLAGS}" ) + SET( CMAKE_CXX_FLAGS "-fvisibility=hidden -fno-strict-aliasing -Wall -Wno-long-long -std=c++11 -Wa,-mbig-obj ${CMAKE_CXX_FLAGS}" ) SET(CMAKE_C_FLAGS "-fPIC -fno-strict-aliasing ${CMAKE_C_FLAGS} ") ADD_DEFINITIONS( -U__STRICT_ANSI__ ) ENDIF() From 24a0aaeb779d0b30e4e1640afebab8159e596d6c Mon Sep 17 00:00:00 2001 From: Charlie Gettys Date: Wed, 10 Apr 2019 11:02:36 -0400 Subject: [PATCH 05/47] Fix Codacy Warning --- Build.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Build.md b/Build.md index 2e47c8cab..afee8caf7 100644 --- a/Build.md +++ b/Build.md @@ -1,16 +1,17 @@ -# Install CMake +# Build Instructions +## Install CMake Asset-Importer-Lib can be build for a lot of different platforms. We are using cmake to generate the build environment for these via cmake. So you have to make sure that you have a working cmake-installation on your system. You can download it at https://cmake.org/ or for linux install it via ``` sudo apt-get install cmake ``` -# Get the source +## Get the source Make sure you have a working git-installation. Open a command prompt and clone the Asset-Importer-Lib via: ``` git clone https://github.com/assimp/assimp.git ``` -# Build instructions for Windows with Visual-Studio +## Build instructions for Windows with Visual-Studio First you have to install Visual-Studio on your windows-system. You can get the Community-Version for free here: https://visualstudio.microsoft.com/de/downloads/ To generate the build environment for your IDE open a command prompt, navigate to your repo and type: @@ -19,11 +20,11 @@ To generate the build environment for your IDE open a command prompt, navigate t ``` This will generate the project files for the visual studio. All dependencies used to build Asset-IMporter-Lib shall be part of the repo. If you want to use you own zlib.installation this is possible as well. Check the options for it. -# Build instructions for Windows with UWP +## Build instructions for Windows with UWP See https://stackoverflow.com/questions/40803170/cmake-uwp-using-cmake-to-build-universal-windows-app -# Build instructions for Linux / Unix +## Build instructions for Linux / Unix Open a terminal and got to your repository. You can generate the makefiles and build the library via: ``` @@ -34,7 +35,7 @@ The option -j descripes the number of parallel processes for the build. In this If you want to use a IDE for linux you can try QTCreator for instance. -# Build instructions for MinGW +## Build instructions for MinGW Older versions of MinGW's compiler (e.g. 5.1.0) do not support the -mbig_obj flag required to compile some of assimp's files, especially for debug builds. Version 7.3.0 of g++-mingw-w64 & gcc-mingw-w64 appears to work. @@ -48,7 +49,7 @@ The following toolchain may or may not be helpful for building assimp using MinG Besides the toolchain, compilation should be the same as for Linux / Unix. -# CMake build options +## CMake build options The cmake-build-environment provides options to configure the build. The following options can be used: - **BUILD_SHARED_LIBS ( default ON )**: Generation of shared libs ( dll for windows, so for Linux ). Set this to OFF to get a static lib. - **BUILD_FRAMEWORK ( default OFF, MacOnly)**: Build package as Mac OS X Framework bundle From c1f3624f5b18f7207a6dff5674bbf1c3e7c70c13 Mon Sep 17 00:00:00 2001 From: Charlie Gettys Date: Wed, 10 Apr 2019 11:06:00 -0400 Subject: [PATCH 06/47] Fix more codacy warnings --- Build.md | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/Build.md b/Build.md index afee8caf7..dc81fe0d7 100644 --- a/Build.md +++ b/Build.md @@ -1,13 +1,13 @@ # Build Instructions ## Install CMake Asset-Importer-Lib can be build for a lot of different platforms. We are using cmake to generate the build environment for these via cmake. So you have to make sure that you have a working cmake-installation on your system. You can download it at https://cmake.org/ or for linux install it via -``` +```bash sudo apt-get install cmake ``` ## Get the source Make sure you have a working git-installation. Open a command prompt and clone the Asset-Importer-Lib via: -``` +```bash git clone https://github.com/assimp/assimp.git ``` @@ -15,19 +15,18 @@ git clone https://github.com/assimp/assimp.git First you have to install Visual-Studio on your windows-system. You can get the Community-Version for free here: https://visualstudio.microsoft.com/de/downloads/ To generate the build environment for your IDE open a command prompt, navigate to your repo and type: -``` -> cmake CMakeLists.txt +```bash +cmake CMakeLists.txt ``` This will generate the project files for the visual studio. All dependencies used to build Asset-IMporter-Lib shall be part of the repo. If you want to use you own zlib.installation this is possible as well. Check the options for it. ## Build instructions for Windows with UWP See https://stackoverflow.com/questions/40803170/cmake-uwp-using-cmake-to-build-universal-windows-app - ## Build instructions for Linux / Unix Open a terminal and got to your repository. You can generate the makefiles and build the library via: -``` +```bash cmake CMakeLists.txt make -j4 ``` @@ -51,23 +50,23 @@ Besides the toolchain, compilation should be the same as for Linux / Unix. ## CMake build options The cmake-build-environment provides options to configure the build. The following options can be used: -- **BUILD_SHARED_LIBS ( default ON )**: Generation of shared libs ( dll for windows, so for Linux ). Set this to OFF to get a static lib. -- **BUILD_FRAMEWORK ( default OFF, MacOnly)**: Build package as Mac OS X Framework bundle -- **ASSIMP_DOUBLE_PRECISION( default OFF )**: All data will be stored as double values. -- **ASSIMP_OPT_BUILD_PACKAGES ( default OFF)**: Set to ON to generate CPack configuration files and packaging targets -- **ASSIMP_ANDROID_JNIIOSYSTEM ( default OFF )**: Android JNI IOSystem support is active -- **ASSIMP_NO_EXPORT ( default OFF )**: Disable Assimp's export functionality -- **ASSIMP_BUILD_ZLIB ( default OFF )**: Build your own zlib -- **ASSIMP_BUILD_ASSIMP_TOOLS ( default ON )**: If the supplementary tools for Assimp are built in addition to the library. -- **ASSIMP_BUILD_SAMPLES ( default OFF )**: If the official samples are built as well (needs Glut). -- **ASSIMP_BUILD_TESTS ( default ON )**: If the test suite for Assimp is built in addition to the library. -- **ASSIMP_COVERALLS ( default OFF )**: Enable this to measure test coverage. -- **ASSIMP_WERROR( default OFF )**: Treat warnings as errors. -- **ASSIMP_ASAN ( default OFF )**: Enable AddressSanitizer. -- **ASSIMP_UBSAN ( default OFF )**: Enable Undefined Behavior sanitizer. -- **SYSTEM_IRRXML ( default OFF )**: Use system installed Irrlicht/IrrXML library. -- **BUILD_DOCS ( default OFF )**: Build documentation using Doxygen. -- **INJECT_DEBUG_POSTFIX( default ON )**: Inject debug postfix in .a/.so lib names -- **IGNORE_GIT_HASH ( default OFF )**: Don't call git to get the hash. -- **ASSIMP_INSTALL_PDB ( default ON )**: Install MSVC debug files. + - **BUILD_SHARED_LIBS ( default ON )**: Generation of shared libs ( dll for windows, so for Linux ). Set this to OFF to get a static lib. + - **BUILD_FRAMEWORK ( default OFF, MacOnly)**: Build package as Mac OS X Framework bundle + - **ASSIMP_DOUBLE_PRECISION( default OFF )**: All data will be stored as double values. + - **ASSIMP_OPT_BUILD_PACKAGES ( default OFF)**: Set to ON to generate CPack configuration files and packaging targets + - **ASSIMP_ANDROID_JNIIOSYSTEM ( default OFF )**: Android JNI IOSystem support is active + - **ASSIMP_NO_EXPORT ( default OFF )**: Disable Assimp's export functionality + - **ASSIMP_BUILD_ZLIB ( default OFF )**: Build your own zlib + - **ASSIMP_BUILD_ASSIMP_TOOLS ( default ON )**: If the supplementary tools for Assimp are built in addition to the library. + - **ASSIMP_BUILD_SAMPLES ( default OFF )**: If the official samples are built as well (needs Glut). + - **ASSIMP_BUILD_TESTS ( default ON )**: If the test suite for Assimp is built in addition to the library. + - **ASSIMP_COVERALLS ( default OFF )**: Enable this to measure test coverage. + - **ASSIMP_WERROR( default OFF )**: Treat warnings as errors. + - **ASSIMP_ASAN ( default OFF )**: Enable AddressSanitizer. + - **ASSIMP_UBSAN ( default OFF )**: Enable Undefined Behavior sanitizer. + - **SYSTEM_IRRXML ( default OFF )**: Use system installed Irrlicht/IrrXML library. + - **BUILD_DOCS ( default OFF )**: Build documentation using Doxygen. + - **INJECT_DEBUG_POSTFIX( default ON )**: Inject debug postfix in .a/.so lib names + - **IGNORE_GIT_HASH ( default OFF )**: Don't call git to get the hash. + - **ASSIMP_INSTALL_PDB ( default ON )**: Install MSVC debug files. From 1b0c1139ebe306beaa55f3f5911d707b0d578a6f Mon Sep 17 00:00:00 2001 From: Charlie Gettys Date: Wed, 10 Apr 2019 11:45:30 -0400 Subject: [PATCH 07/47] Fix more codacy warnings! --- Build.md | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/Build.md b/Build.md index dc81fe0d7..1e28c648f 100644 --- a/Build.md +++ b/Build.md @@ -21,7 +21,7 @@ cmake CMakeLists.txt This will generate the project files for the visual studio. All dependencies used to build Asset-IMporter-Lib shall be part of the repo. If you want to use you own zlib.installation this is possible as well. Check the options for it. ## Build instructions for Windows with UWP -See https://stackoverflow.com/questions/40803170/cmake-uwp-using-cmake-to-build-universal-windows-app +See ## Build instructions for Linux / Unix Open a terminal and got to your repository. You can generate the makefiles and build the library via: @@ -50,23 +50,22 @@ Besides the toolchain, compilation should be the same as for Linux / Unix. ## CMake build options The cmake-build-environment provides options to configure the build. The following options can be used: - - **BUILD_SHARED_LIBS ( default ON )**: Generation of shared libs ( dll for windows, so for Linux ). Set this to OFF to get a static lib. - - **BUILD_FRAMEWORK ( default OFF, MacOnly)**: Build package as Mac OS X Framework bundle - - **ASSIMP_DOUBLE_PRECISION( default OFF )**: All data will be stored as double values. - - **ASSIMP_OPT_BUILD_PACKAGES ( default OFF)**: Set to ON to generate CPack configuration files and packaging targets - - **ASSIMP_ANDROID_JNIIOSYSTEM ( default OFF )**: Android JNI IOSystem support is active - - **ASSIMP_NO_EXPORT ( default OFF )**: Disable Assimp's export functionality - - **ASSIMP_BUILD_ZLIB ( default OFF )**: Build your own zlib - - **ASSIMP_BUILD_ASSIMP_TOOLS ( default ON )**: If the supplementary tools for Assimp are built in addition to the library. - - **ASSIMP_BUILD_SAMPLES ( default OFF )**: If the official samples are built as well (needs Glut). - - **ASSIMP_BUILD_TESTS ( default ON )**: If the test suite for Assimp is built in addition to the library. - - **ASSIMP_COVERALLS ( default OFF )**: Enable this to measure test coverage. - - **ASSIMP_WERROR( default OFF )**: Treat warnings as errors. - - **ASSIMP_ASAN ( default OFF )**: Enable AddressSanitizer. - - **ASSIMP_UBSAN ( default OFF )**: Enable Undefined Behavior sanitizer. - - **SYSTEM_IRRXML ( default OFF )**: Use system installed Irrlicht/IrrXML library. - - **BUILD_DOCS ( default OFF )**: Build documentation using Doxygen. - - **INJECT_DEBUG_POSTFIX( default ON )**: Inject debug postfix in .a/.so lib names - - **IGNORE_GIT_HASH ( default OFF )**: Don't call git to get the hash. - - **ASSIMP_INSTALL_PDB ( default ON )**: Install MSVC debug files. - +- **BUILD_SHARED_LIBS ( default ON )**: Generation of shared libs ( dll for windows, so for Linux ). Set this to OFF to get a static lib. +- **BUILD_FRAMEWORK ( default OFF, MacOnly)**: Build package as Mac OS X Framework bundle +- **ASSIMP_DOUBLE_PRECISION( default OFF )**: All data will be stored as double values. +- **ASSIMP_OPT_BUILD_PACKAGES ( default OFF)**: Set to ON to generate CPack configuration files and packaging targets +- **ASSIMP_ANDROID_JNIIOSYSTEM ( default OFF )**: Android JNI IOSystem support is active +- **ASSIMP_NO_EXPORT ( default OFF )**: Disable Assimp's export functionality +- **ASSIMP_BUILD_ZLIB ( default OFF )**: Build your own zlib +- **ASSIMP_BUILD_ASSIMP_TOOLS ( default ON )**: If the supplementary tools for Assimp are built in addition to the library. +- **ASSIMP_BUILD_SAMPLES ( default OFF )**: If the official samples are built as well (needs Glut). +- **ASSIMP_BUILD_TESTS ( default ON )**: If the test suite for Assimp is built in addition to the library. +- **ASSIMP_COVERALLS ( default OFF )**: Enable this to measure test coverage. +- **ASSIMP_WERROR( default OFF )**: Treat warnings as errors. +- **ASSIMP_ASAN ( default OFF )**: Enable AddressSanitizer. +- **ASSIMP_UBSAN ( default OFF )**: Enable Undefined Behavior sanitizer. +- **SYSTEM_IRRXML ( default OFF )**: Use system installed Irrlicht/IrrXML library. +- **BUILD_DOCS ( default OFF )**: Build documentation using Doxygen. +- **INJECT_DEBUG_POSTFIX( default ON )**: Inject debug postfix in .a/.so lib names +- **IGNORE_GIT_HASH ( default OFF )**: Don't call git to get the hash. +- **ASSIMP_INSTALL_PDB ( default ON )**: Install MSVC debug files. From 2f6f71651226874ac57538ff8e772d0821dead28 Mon Sep 17 00:00:00 2001 From: Charlie Gettys Date: Wed, 10 Apr 2019 12:42:19 -0400 Subject: [PATCH 08/47] Clarify build instructions --- Build.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Build.md b/Build.md index 1e28c648f..7c908606d 100644 --- a/Build.md +++ b/Build.md @@ -41,7 +41,9 @@ Version 7.3.0 of g++-mingw-w64 & gcc-mingw-w64 appears to work. Please see [CMake Cross Compiling](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling) for general information on CMake Toolchains. -Some users have had success building assimp using MinGW on Linux using the following toolchain, which is not maintained by assimp. [linux-mingw-w64-gnuxx11.cmake](https://github.com/ruslo/polly/blob/master/linux-mingw-w64-gnuxx11.cmake) +Some users have had success building assimp using MinGW on Linux using [polly](https://github.com/ruslo/polly/). + +The following toolchain, which is not maintained by assimp, seems to work on Linux: [linux-mingw-w64-gnuxx11.cmake](https://github.com/ruslo/polly/blob/master/linux-mingw-w64-gnuxx11.cmake) The following toolchain may or may not be helpful for building assimp using MinGW on Windows (untested): [mingw-cxx17.cmake](https://github.com/ruslo/polly/blob/master/mingw-cxx17.cmake) From 9b9b2c83393624e6a152556e6d35cd3169e12934 Mon Sep 17 00:00:00 2001 From: Simon Puente Date: Sun, 14 Apr 2019 10:13:32 -0700 Subject: [PATCH 09/47] Fix typo on README.md changing "fascade" to "facade" --- port/AndroidJNI/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/port/AndroidJNI/README.md b/port/AndroidJNI/README.md index 7998fa3ef..0b95efd04 100644 --- a/port/AndroidJNI/README.md +++ b/port/AndroidJNI/README.md @@ -1,6 +1,6 @@ Build Asset Importer Lib for Android ==================================== -This module provides a fascade for the io-stream-access to files behind the android-asset-management within +This module provides a facade for the io-stream-access to files behind the android-asset-management within an Android-native application. - It is built as a static library - It requires Android NDK with android API > 9 support. From b6d3cbcb61f4cc4c42678d5f183351f95c97c8d4 Mon Sep 17 00:00:00 2001 From: Huarong Chen Date: Wed, 17 Apr 2019 14:19:00 +0800 Subject: [PATCH 10/47] Fix "bytes aketrans" issues in Python>=3.1 Issue https://github.com/assimp/assimp/issues/2339 --- port/PyAssimp/pyassimp/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/port/PyAssimp/pyassimp/core.py b/port/PyAssimp/pyassimp/core.py index ca6d8629a..44163a434 100644 --- a/port/PyAssimp/pyassimp/core.py +++ b/port/PyAssimp/pyassimp/core.py @@ -93,7 +93,7 @@ def _is_init_type(obj): return False tname = obj.__class__.__name__ return not (tname[:2] == 'c_' or tname == 'Structure' \ - or tname == 'POINTER') and not isinstance(obj,int) + or tname == 'POINTER') and not isinstance(obj, (int, str, bytes)) def _init(self, target = None, parent = None): """ From e8bcf162ddc5daeffbe2dfd408b33c3cde153e46 Mon Sep 17 00:00:00 2001 From: RichardTea <31507749+RichardTea@users.noreply.github.com> Date: Wed, 17 Apr 2019 13:55:08 +0100 Subject: [PATCH 11/47] OBJ coerce invalid nan or inf texture coords to 0 Some exporters (eg Vectorworks 2019) may export texture coordinate components as "nan". While this is invalid, it's better to coerce these values to 0 rather than reject the entire file. --- code/ObjFileParser.cpp | 28 +++++++++++++++++++++++++--- code/ObjFileParser.h | 2 +- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index a8509b583..f9dd17bed 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -151,7 +151,7 @@ void ObjFileParser::parseFile( IOStreamBuffer &streamBuffer ) { } else if (*m_DataIt == 't') { // read in texture coordinate ( 2D or 3D ) ++m_DataIt; - size_t dim = getVector(m_pModel->m_TextureCoord); + size_t dim = getTexCoordVector(m_pModel->m_TextureCoord); m_pModel->m_TextureCoordDim = std::max(m_pModel->m_TextureCoordDim, (unsigned int)dim); } else if (*m_DataIt == 'n') { // Read in normal vector definition @@ -272,6 +272,17 @@ static bool isDataDefinitionEnd( const char *tmp ) { return false; } +static bool isNanOrInf(const char * in) { + // Look for "nan" or "inf", case insensitive + if ((in[0] == 'N' || in[0] == 'n') && ASSIMP_strincmp(in, "nan", 3) == 0) { + return true; + } + else if ((in[0] == 'I' || in[0] == 'i') && ASSIMP_strincmp(in, "inf", 3) == 0) { + return true; + } + return false; +} + size_t ObjFileParser::getNumComponentsInDataDefinition() { size_t numComponents( 0 ); const char* tmp( &m_DataIt[0] ); @@ -285,7 +296,7 @@ size_t ObjFileParser::getNumComponentsInDataDefinition() { if ( !SkipSpaces( &tmp ) ) { break; } - const bool isNum( IsNumeric( *tmp ) ); + const bool isNum( IsNumeric( *tmp ) || isNanOrInf(tmp)); SkipToken( tmp ); if ( isNum ) { ++numComponents; @@ -297,7 +308,7 @@ size_t ObjFileParser::getNumComponentsInDataDefinition() { return numComponents; } -size_t ObjFileParser::getVector( std::vector &point3d_array ) { +size_t ObjFileParser::getTexCoordVector( std::vector &point3d_array ) { size_t numComponents = getNumComponentsInDataDefinition(); ai_real x, y, z; if( 2 == numComponents ) { @@ -319,6 +330,17 @@ size_t ObjFileParser::getVector( std::vector &point3d_array ) { } else { throw DeadlyImportError( "OBJ: Invalid number of components" ); } + + // Coerce nan and inf to 0 as is the OBJ default value + if (!isfinite(x)) + x = 0; + + if (!isfinite(y)) + y = 0; + + if (!isfinite(z)) + z = 0; + point3d_array.push_back( aiVector3D( x, y, z ) ); m_DataIt = skipLine( m_DataIt, m_DataItEnd, m_uiLine ); return numComponents; diff --git a/code/ObjFileParser.h b/code/ObjFileParser.h index a8961452d..7d1b806ce 100644 --- a/code/ObjFileParser.h +++ b/code/ObjFileParser.h @@ -96,7 +96,7 @@ protected: /// Get the number of components in a line. size_t getNumComponentsInDataDefinition(); /// Stores the vector - size_t getVector( std::vector &point3d_array ); + size_t getTexCoordVector( std::vector &point3d_array ); /// Stores the following 3d vector. void getVector3( std::vector &point3d_array ); /// Stores the following homogeneous vector as a 3D vector From c34327b35575b1dd9ca123fa0c4b440241b25d85 Mon Sep 17 00:00:00 2001 From: RichardTea <31507749+RichardTea@users.noreply.github.com> Date: Wed, 17 Apr 2019 14:30:40 +0100 Subject: [PATCH 12/47] use std::isfinite() GCC is more standards compliant than MSVC --- code/ObjFileParser.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index f9dd17bed..2265e0c35 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -332,13 +332,13 @@ size_t ObjFileParser::getTexCoordVector( std::vector &point3d_array } // Coerce nan and inf to 0 as is the OBJ default value - if (!isfinite(x)) + if (!std::isfinite(x)) x = 0; - if (!isfinite(y)) + if (!std::isfinite(y)) y = 0; - if (!isfinite(z)) + if (!std::isfinite(z)) z = 0; point3d_array.push_back( aiVector3D( x, y, z ) ); From 5713be615c6939535d8e467b0449f3de19aab500 Mon Sep 17 00:00:00 2001 From: Hugo Pereira Date: Thu, 18 Apr 2019 16:52:47 +0100 Subject: [PATCH 13/47] [FBX export] fixed ordering of skin indices and weights, to be consistent between systems --- code/FBXExporter.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/code/FBXExporter.cpp b/code/FBXExporter.cpp index acb122714..6b1ac0e5e 100644 --- a/code/FBXExporter.cpp +++ b/code/FBXExporter.cpp @@ -1575,11 +1575,22 @@ void FBXExporter::WriteObjects () // one sticky point is that the number of vertices may not match, // because assimp splits vertices by normal, uv, etc. + // functor for aiNode sorting + struct SortNodeByName + { + bool operator()(const aiNode *lhs, const aiNode *rhs) const + { + return strcmp(lhs->mName.C_Str(), rhs->mName.C_Str()) < 0; + } + }; + // first we should mark the skeleton for each mesh. // the skeleton must include not only the aiBones, // but also all their parent nodes. // anything that affects the position of any bone node must be included. - std::vector> skeleton_by_mesh(mScene->mNumMeshes); + // Use SorNodeByName to make sure the exported result will be the same across all systems + // Otherwise the aiNodes of the skeleton would be sorted based on the pointer address, which isn't consistent + std::vector> skeleton_by_mesh(mScene->mNumMeshes); // at the same time we can build a list of all the skeleton nodes, // which will be used later to mark them as type "limbNode". std::unordered_set limbnodes; @@ -1587,7 +1598,7 @@ void FBXExporter::WriteObjects () std::map node_by_bone; for (size_t mi = 0; mi < mScene->mNumMeshes; ++mi) { const aiMesh* m = mScene->mMeshes[mi]; - std::set skeleton; + std::set skeleton; for (size_t bi =0; bi < m->mNumBones; ++bi) { const aiBone* b = m->mBones[bi]; const std::string name(b->mName.C_Str()); @@ -1728,7 +1739,7 @@ void FBXExporter::WriteObjects () aiMatrix4x4 mesh_xform = get_world_transform(mesh_node, mScene); // now make a subdeformer for each bone in the skeleton - const std::set &skeleton = skeleton_by_mesh[mi]; + const std::set skeleton= skeleton_by_mesh[mi]; for (const aiNode* bone_node : skeleton) { // if there's a bone for this node, find it const aiBone* b = nullptr; From 0b42d55f737369ff9cc80686bbc5b1cecd97d7b9 Mon Sep 17 00:00:00 2001 From: Heorhii Shakula Date: Wed, 24 Apr 2019 16:58:35 +0300 Subject: [PATCH 14/47] Fix inconsistency between animation and node name in glTF2 Importer --- code/glTF2Importer.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/code/glTF2Importer.cpp b/code/glTF2Importer.cpp index 4228db23f..bb0f7ad8d 100755 --- a/code/glTF2Importer.cpp +++ b/code/glTF2Importer.cpp @@ -789,13 +789,16 @@ static void BuildVertexWeightMapping(Mesh::Primitive& primitive, std::vector& meshOffsets, glTF2::Ref& ptr) { Node& node = *ptr; - std::string nameOrId = node.name.empty() ? node.id : node.name; - - aiNode* ainode = new aiNode(nameOrId); + aiNode* ainode = new aiNode(GetNodeName(node)); if (!node.children.empty()) { ainode->mNumChildren = unsigned(node.children.size()); @@ -921,7 +924,7 @@ struct AnimationSamplers { aiNodeAnim* CreateNodeAnim(glTF2::Asset& r, Node& node, AnimationSamplers& samplers) { aiNodeAnim* anim = new aiNodeAnim(); - anim->mNodeName = node.name; + anim->mNodeName = GetNodeName(node); static const float kMillisecondsFromSeconds = 1000.f; From 42202c22043923946b87481ff01669d4bf633fc4 Mon Sep 17 00:00:00 2001 From: Vitaly Ovchinnikov Date: Fri, 26 Apr 2019 22:13:29 +1200 Subject: [PATCH 15/47] a test for bad OBJ file format and code fix that handles it --- code/ObjFileParser.cpp | 10 +++------- test/unit/utObjImportExport.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index a8509b583..17c83ee8f 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -429,13 +429,6 @@ void ObjFileParser::getFace( aiPrimitiveType type ) { if (type == aiPrimitiveType_POINT) { ASSIMP_LOG_ERROR("Obj: Separator unexpected in point statement"); } - if (iPos == 0) { - //if there are no texture coordinates in the file, but normals - if (!vt && vn) { - iPos = 1; - iStep++; - } - } iPos++; } else if( IsSpaceOrNewLine( *m_DataIt ) ) { iPos = 0; @@ -452,6 +445,9 @@ void ObjFileParser::getFace( aiPrimitiveType type ) { ++iStep; } + if (iPos == 1 && !vt && vn) + iPos = 2; // skip texture coords for normals if there are no tex coords + if ( iVal > 0 ) { // Store parsed index if ( 0 == iPos ) { diff --git a/test/unit/utObjImportExport.cpp b/test/unit/utObjImportExport.cpp index 2d1933094..bb0d36b13 100644 --- a/test/unit/utObjImportExport.cpp +++ b/test/unit/utObjImportExport.cpp @@ -391,6 +391,39 @@ TEST_F(utObjImportExport, invalid_normals_uvs) { EXPECT_NE(nullptr, scene); } +TEST_F(utObjImportExport, no_vt_just_vns) { + static const char *ObjModel = + "v 0 0 0\n" + "v 0 0 0\n" + "v 0 0 0\n" + "v 0 0 0\n" + "v 0 0 0\n" + "v 0 0 0\n" + "v 0 0 0\n" + "v 0 0 0\n" + "v 0 0 0\n" + "v 0 0 0\n" + "v 10 0 0\n" + "v 0 10 0\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "f 10/10 11/11 12/12\n"; + + Assimp::Importer myImporter; + const aiScene *scene = myImporter.ReadFileFromMemory(ObjModel, strlen(ObjModel), 0); + EXPECT_NE(nullptr, scene); +} + TEST_F( utObjImportExport, mtllib_after_g ) { ::Assimp::Importer importer; const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/OBJ/cube_mtllib_after_g.obj", aiProcess_ValidateDataStructure ); From 58b1440fc810a207bf86fa435a88d3300f75d5db Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 26 Apr 2019 13:01:22 +0200 Subject: [PATCH 16/47] Update appveyor.yml Remove cache to fix access to not cached data. --- appveyor.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 78ef4da75..e189a71f8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -36,14 +36,14 @@ install: - ps: Invoke-WebRequest -Uri https://download.microsoft.com/download/5/7/b/57b2947c-7221-4f33-b35e-2fc78cb10df4/vc_redist.x64.exe -OutFile .\packaging\windows-innosetup\vc_redist.x64.exe - ps: Invoke-WebRequest -Uri https://download.microsoft.com/download/1/d/8/1d8137db-b5bb-4925-8c5d-927424a2e4de/vc_redist.x86.exe -OutFile .\packaging\windows-innosetup\vc_redist.x86.exe -cache: - - code\assimp.dir\%CONFIGURATION% - - contrib\zlib\zlibstatic.dir\%CONFIGURATION% - - contrib\zlib\zlib.dir\%CONFIGURATION% - - tools\assimp_cmd\assimp_cmd.dir\%CONFIGURATION% - - tools\assimp_view\assimp_viewer.dir\%CONFIGURATION% - - test\unit.dir\%CONFIGURATION% - - bin\.mtime_cache +#cache: +# - code\assimp.dir\%CONFIGURATION% +# - contrib\zlib\zlibstatic.dir\%CONFIGURATION% +# - contrib\zlib\zlib.dir\%CONFIGURATION% +# - tools\assimp_cmd\assimp_cmd.dir\%CONFIGURATION% +# - tools\assimp_view\assimp_viewer.dir\%CONFIGURATION% +# - test\unit.dir\%CONFIGURATION% +# - bin\.mtime_cache before_build: - ruby scripts\AppVeyor\mtime_cache -g scripts\AppVeyor\cacheglobs.txt -c bin\.mtime_cache\cache.json From 09905c2de39a17d8a06547779a3ff851f3d6fc60 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 26 Apr 2019 19:11:22 +0200 Subject: [PATCH 17/47] Update appveyor.yml disable vs2015 --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index e189a71f8..4b38c9cc6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,7 +15,7 @@ matrix: image: - Visual Studio 2013 - - Previous Visual Studio 2015 + #- Previous Visual Studio 2015 - Previous Visual Studio 2017 platform: From 4c3e34ba6c685b956ae2d94d288dc699b58be9ac Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 26 Apr 2019 19:28:19 +0200 Subject: [PATCH 18/47] Update Readme.md Add link to read the docs. --- Readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Readme.md b/Readme.md index 8cd3c7cb3..19e43a3cb 100644 --- a/Readme.md +++ b/Readme.md @@ -17,6 +17,8 @@ A library to import and export various 3d-model-formats including scene-post-pro APIs are provided for C and C++. There are various bindings to other languages (C#, Java, Python, Delphi, D). Assimp also runs on Android and iOS. +[Check the latest doc](https://assimp-docs.readthedocs.io/en/latest/). + Additionally, assimp features various __mesh post processing tools__: normals and tangent space generation, triangulation, vertex cache locality optimization, removal of degenerate primitives and duplicate vertices, sorting by primitive type, merging of redundant materials and many more. This is the development repo containing the latest features and bugfixes. For productive use though, we recommend one of the stable releases available from [Github Assimp Releases](https://github.com/assimp/assimp/releases). From 6d241cc2f05345a66c59a73e7d678f857a008bfa Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 26 Apr 2019 21:11:23 +0200 Subject: [PATCH 19/47] Update appveyor.yml Go back to normal --- appveyor.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 4b38c9cc6..2b5f212f9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,8 +15,8 @@ matrix: image: - Visual Studio 2013 - #- Previous Visual Studio 2015 - - Previous Visual Studio 2017 + - Visual Studio 2015 + - Visual Studio 2017 platform: - Win32 @@ -28,22 +28,22 @@ install: - set PATH=C:\Ruby24-x64\bin;%PATH% - 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%"=="Previous Visual Studio 2015" set CMAKE_GENERATOR_NAME=Visual Studio 14 2015 - - if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Previous Visual Studio 2017" set CMAKE_GENERATOR_NAME=Visual Studio 15 2017 + - 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 "%platform%"=="x64" set CMAKE_GENERATOR_NAME=%CMAKE_GENERATOR_NAME% Win64 - cmake %CMAKE_DEFINES% -G "%CMAKE_GENERATOR_NAME%" - set PATH=%PATH%;"C:\\Program Files (x86)\\Inno Setup 5" - ps: Invoke-WebRequest -Uri https://download.microsoft.com/download/5/7/b/57b2947c-7221-4f33-b35e-2fc78cb10df4/vc_redist.x64.exe -OutFile .\packaging\windows-innosetup\vc_redist.x64.exe - ps: Invoke-WebRequest -Uri https://download.microsoft.com/download/1/d/8/1d8137db-b5bb-4925-8c5d-927424a2e4de/vc_redist.x86.exe -OutFile .\packaging\windows-innosetup\vc_redist.x86.exe -#cache: -# - code\assimp.dir\%CONFIGURATION% -# - contrib\zlib\zlibstatic.dir\%CONFIGURATION% -# - contrib\zlib\zlib.dir\%CONFIGURATION% -# - tools\assimp_cmd\assimp_cmd.dir\%CONFIGURATION% -# - tools\assimp_view\assimp_viewer.dir\%CONFIGURATION% -# - test\unit.dir\%CONFIGURATION% -# - bin\.mtime_cache +cache: + - code\assimp.dir\%CONFIGURATION% + - contrib\zlib\zlibstatic.dir\%CONFIGURATION% + - contrib\zlib\zlib.dir\%CONFIGURATION% + - tools\assimp_cmd\assimp_cmd.dir\%CONFIGURATION% + - tools\assimp_view\assimp_viewer.dir\%CONFIGURATION% + - test\unit.dir\%CONFIGURATION% + - bin\.mtime_cache before_build: - ruby scripts\AppVeyor\mtime_cache -g scripts\AppVeyor\cacheglobs.txt -c bin\.mtime_cache\cache.json From 085362392418e7643a96a69efcbed103fa841c3d Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 27 Apr 2019 08:38:01 +0200 Subject: [PATCH 20/47] Update appveyor.yml Try this solution https://gitlab.kitware.com/cmake/cmake/commit/27eb7c5bdb5bb8deefe1772675dc4819592bf036 --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 2b5f212f9..39ef36179 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -31,7 +31,7 @@ install: - 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 "%platform%"=="x64" set CMAKE_GENERATOR_NAME=%CMAKE_GENERATOR_NAME% Win64 - - cmake %CMAKE_DEFINES% -G "%CMAKE_GENERATOR_NAME%" + - cmake %CMAKE_DEFINES% -G "%CMAKE_GENERATOR_NAME%" . - set PATH=%PATH%;"C:\\Program Files (x86)\\Inno Setup 5" - ps: Invoke-WebRequest -Uri https://download.microsoft.com/download/5/7/b/57b2947c-7221-4f33-b35e-2fc78cb10df4/vc_redist.x64.exe -OutFile .\packaging\windows-innosetup\vc_redist.x64.exe - ps: Invoke-WebRequest -Uri https://download.microsoft.com/download/1/d/8/1d8137db-b5bb-4925-8c5d-927424a2e4de/vc_redist.x86.exe -OutFile .\packaging\windows-innosetup\vc_redist.x86.exe From bc4e4112848c007122b7ad4d523705a35051c18e Mon Sep 17 00:00:00 2001 From: b1skit Date: Sat, 27 Apr 2019 17:20:27 -0700 Subject: [PATCH 21/47] Updated the FBXConverter to correctly set the material shading mode when a Phong shader is detected --- code/FBXConverter.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index 0abfdafdc..c76d3ccad 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -67,6 +67,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include + + + + // MY DEBUG STUFF: + +#include +using std::cout; + +// END MY DEBUG STUF + + + + namespace Assimp { namespace FBX { @@ -1596,6 +1609,13 @@ namespace Assimp { out_mat->AddProperty(&str, AI_MATKEY_NAME); } + // Set the shading mode as best we can: The FBX specification only mentions Lambert and Phong, and only Phong is mentioned in Assimp's aiShadingMode enum. + if (material.GetShadingModel() == "phong") + { + aiShadingMode shadingMode = aiShadingMode_Phong; + out_mat->AddProperty(&shadingMode, 1, AI_MATKEY_SHADING_MODEL); + } + // shading stuff and colors SetShadingPropertiesCommon(out_mat, props); SetShadingPropertiesRaw( out_mat, props, material.Textures(), mesh ); From 243b2618a9209eb5a2c10d2fcec13dc2aa29af43 Mon Sep 17 00:00:00 2001 From: b1skit Date: Sat, 27 Apr 2019 17:37:23 -0700 Subject: [PATCH 22/47] Updated the FBXConverter to correctly set the material shading mode when a Phong shader is detected --- code/FBXConverter.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index c76d3ccad..4780188ac 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -68,18 +68,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include - - - // MY DEBUG STUFF: - -#include -using std::cout; - -// END MY DEBUG STUF - - - - namespace Assimp { namespace FBX { From bcd17481e5970dba3cd68e64a32e1f8fafabf355 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Sun, 28 Apr 2019 22:16:20 -0700 Subject: [PATCH 23/47] Fix element access operator of aiColor4D --- include/assimp/color4.inl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/assimp/color4.inl b/include/assimp/color4.inl index 3192d55f3..afa53dcb5 100644 --- a/include/assimp/color4.inl +++ b/include/assimp/color4.inl @@ -85,6 +85,8 @@ AI_FORCE_INLINE TReal aiColor4t::operator[](unsigned int i) const { return g; case 2: return b; + case 3: + return a; default: break; } @@ -100,6 +102,8 @@ AI_FORCE_INLINE TReal& aiColor4t::operator[](unsigned int i) { return g; case 2: return b; + case 3: + return a; default: break; } From c821c6f30161783da1fd0a8827c118c36dcdcd33 Mon Sep 17 00:00:00 2001 From: kimkulling Date: Tue, 30 Apr 2019 15:33:31 +0200 Subject: [PATCH 24/47] Fix names of dlls. --- appveyor.yml | 9 ++- .../{script.iss => script_x64.iss} | 36 +--------- packaging/windows-innosetup/script_x86.iss | 72 +++++++++++++++++++ 3 files changed, 82 insertions(+), 35 deletions(-) rename packaging/windows-innosetup/{script.iss => script_x64.iss} (56%) create mode 100644 packaging/windows-innosetup/script_x86.iss diff --git a/appveyor.yml b/appveyor.yml index 39ef36179..c8a5a27b9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -53,7 +53,14 @@ build: project: Assimp.sln after_build: - - if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" iscc packaging\windows-innosetup\script.iss + - if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" ( + if "%platform%"=="x64" ( + iscc packaging\windows-innosetup\script_x64.iss + ) + if "%platform%"!="x64" ( + iscc packaging\windows-innosetup\script_x86.iss + ) + ) - 7z a assimp.7z bin\%CONFIGURATION%\* lib\%CONFIGURATION%\* test_script: diff --git a/packaging/windows-innosetup/script.iss b/packaging/windows-innosetup/script_x64.iss similarity index 56% rename from packaging/windows-innosetup/script.iss rename to packaging/windows-innosetup/script_x64.iss index 695740679..1738fd4b1 100644 --- a/packaging/windows-innosetup/script.iss +++ b/packaging/windows-innosetup/script_x64.iss @@ -24,25 +24,20 @@ Name: "compact"; Description: "Compact installation, no test models or language Name: "custom"; Description: "Custom installation"; Flags: iscustom [Components] -Name: "main"; Description: "Main Files (32 and 64 Bit)"; Types: full compact custom; Flags: fixed +Name: "main"; Description: "Main Files ( 64 Bit )"; Types: full compact custom; Flags: fixed Name: "tools"; Description: "Asset Viewer & Command Line Tools (32 and 64 Bit)"; Types: full compact Name: "help"; Description: "Help Files"; Types: full compact Name: "samples"; Description: "Samples"; Types: full Name: "test"; Description: "Test Models (BSD-licensed)"; Types: full Name: "test_nonbsd"; Description: "Test Models (other (free) licenses)"; Types: full -;Name: "pyassimp"; Description: "Python Bindings"; Types: full -;Name: "dassimp"; Description: "D Bindings"; Types: full -;Name: "assimp_net"; Description: "C#/.NET Bindings"; Types: full [Run] -;Filename: "{app}\stub\vc_redist.x86.exe"; Parameters: "/qb"; StatusMsg: "Installing VS2017 redistributable package (32 Bit)"; Check: not IsWin64 Filename: "{app}\stub\vc_redist.x64.exe"; Parameters: "/qb"; StatusMsg: "Installing VS2017 redistributable package (64 Bit)"; Check: IsWin64 [Files] Source: "readme_installer.txt"; DestDir: "{app}"; Flags: isreadme ; Installer stub -;Source: "vc_redist.x86.exe"; DestDir: "{app}\stub\"; Check: not IsWin64 Source: "vc_redist.x64.exe"; DestDir: "{app}\stub\"; Check: IsWin64 ; Common stuff @@ -53,27 +48,14 @@ Source: "WEB"; DestDir: "{app}" Source: "..\..\scripts\*"; DestDir: "{app}\scripts"; Flags: recursesubdirs -; x86 binaries -;Source: "..\..\bin\release\x86\assimp-vc140-mt.dll"; DestDir: "{app}\bin\x86" -;Source: "..\..\bin\release\x86\assimp_viewer.exe"; DestDir: "{app}\bin\x86"; Components: tools -;Source: "C:\Windows\SysWOW64\D3DCompiler_42.dll"; DestDir: "{app}\bin\x86"; Components: tools -;Source: "C:\Windows\SysWOW64\D3DX9_42.dll"; DestDir: "{app}\bin\x86"; Components: tools -;Source: "..\..\bin\release\x86\assimp.exe"; DestDir: "{app}\bin\x86"; Components: tools - ; x64 binaries -Source: "..\..\bin\release\assimp-vc140-mt.dll"; DestDir: "{app}\bin\x64" +Source: "..\..\bin\release\assimp-vc141-mt.dll"; DestDir: "{app}\bin\x64" Source: "..\..\bin\release\assimp_viewer.exe"; DestDir: "{app}\bin\x64"; Components: tools Source: "C:\Windows\SysWOW64\D3DCompiler_42.dll"; DestDir: "{app}\bin\x64"; DestName: "D3DCompiler_42.dll"; Components: tools Source: "C:\Windows\SysWOW64\D3DX9_42.dll"; DestDir: "{app}\bin\x64"; DestName: "D3DX9_42.dll"; Components: tools Source: "..\..\bin\release\assimp.exe"; DestDir: "{app}\bin\x64"; Components: tools -; Documentation -;Source: "..\..\doc\AssimpDoc_Html\AssimpDoc.chm"; DestDir: "{app}\doc"; Components: help -;Source: "..\..\doc\AssimpCmdDoc_Html\AssimpCmdDoc.chm"; DestDir: "{app}\doc"; Components: help -;Source: "..\..\doc\datastructure.xml"; DestDir: "{app}\doc"; Components: help - ; Import libraries -;Source: "..\..\lib\release\x86\assimp.lib"; DestDir: "{app}\lib\x86" Source: "..\..\lib\release\assimp-vc140-mt.lib"; DestDir: "{app}\lib\x64" ; Samples @@ -82,20 +64,6 @@ Source: "..\..\samples\*"; DestDir: "{app}\samples"; Flags: recursesubdirs; Comp ; Include files Source: "..\..\include\*"; DestDir: "{app}\include"; Flags: recursesubdirs -; dAssimp -;Source: "..\..\port\dAssimp\*"; DestDir: "{app}\port\D"; Flags: recursesubdirs; Components: dassimp - -; Assimp.NET -;Source: "..\..\port\Assimp.NET\*"; DestDir: "{app}\port\C#"; Flags: recursesubdirs; Components: assimp_net - -; PyAssimp -;Source: "..\..\port\PyAssimp\*"; DestDir: "{app}\port\Python"; Excludes: "*.pyc,*.dll"; Flags: recursesubdirs; Components: pyassimp - -; Test repository -;Source: "..\..\test\models\*"; DestDir: "{app}\test\models"; Flags: recursesubdirs; Components: test -;Source: "..\..\test\regression\*"; DestDir: "{app}\test\regression"; Flags: recursesubdirs; Components: test -;Source: "..\..\test\models-nonbsd\*"; DestDir: "{app}\test\models-nonbsd"; Flags: recursesubdirs; Components: test_nonbsd - [Icons] Name: "{group}\Assimp Manual"; Filename: "{app}\doc\AssimpDoc.chm" ; Components: help Name: "{group}\Assimp Command Line Manual"; Filename: "{app}\doc\AssimpCmdDoc.chm"; Components: help diff --git a/packaging/windows-innosetup/script_x86.iss b/packaging/windows-innosetup/script_x86.iss new file mode 100644 index 000000000..cf2660235 --- /dev/null +++ b/packaging/windows-innosetup/script_x86.iss @@ -0,0 +1,72 @@ +; Setup script for use with Inno Setup. + +[Setup] +AppName=Open Asset Import Library - SDK +AppVerName=Open Asset Import Library - SDK (v4.1.0) +DefaultDirName={pf}\Assimp +DefaultGroupName=Assimp +UninstallDisplayIcon={app}\bin\x86\assimp.exe +OutputDir=out +AppCopyright=Assimp Development Team +SetupIconFile=..\..\tools\shared\assimp_tools_icon.ico +WizardImageFile=compiler:WizModernImage-IS.BMP +WizardSmallImageFile=compiler:WizModernSmallImage-IS.BMP +LicenseFile=License.rtf +OutputBaseFileName=assimp-sdk-4.1.0-setup +VersionInfoVersion=4.1.0.0 +VersionInfoTextVersion=4.1.0 +VersionInfoCompany=Assimp Development Team +ArchitecturesInstallIn64BitMode=x64 + +[Types] +Name: "full"; Description: "Full installation" +Name: "compact"; Description: "Compact installation, no test models or language bindings" +Name: "custom"; Description: "Custom installation"; Flags: iscustom + +[Components] +Name: "main"; Description: "Main Files (32 and 64 Bit)"; Types: full compact custom; Flags: fixed +Name: "tools"; Description: "Asset Viewer & Command Line Tools (32 and 64 Bit)"; Types: full compact +Name: "help"; Description: "Help Files"; Types: full compact +Name: "samples"; Description: "Samples"; Types: full +Name: "test"; Description: "Test Models (BSD-licensed)"; Types: full +Name: "test_nonbsd"; Description: "Test Models (other (free) licenses)"; Types: full + +[Run] +Filename: "{app}\stub\vc_redist.x86.exe"; Parameters: "/qb"; StatusMsg: "Installing VS2017 redistributable package (32 Bit)"; Check: not IsWin64 + +[Files] +Source: "readme_installer.txt"; DestDir: "{app}"; Flags: isreadme + +; Installer stub +Source: "vc_redist.x86.exe"; DestDir: "{app}\stub\"; Check: not IsWin64 + +; Common stuff +Source: "..\..\CREDITS"; DestDir: "{app}" +Source: "..\..\LICENSE"; DestDir: "{app}" +Source: "..\..\README"; DestDir: "{app}" +Source: "WEB"; DestDir: "{app}" + +Source: "..\..\scripts\*"; DestDir: "{app}\scripts"; Flags: recursesubdirs + +; x86 binaries +Source: "..\..\bin\release\x86\assimp-vc141-mt.dll"; DestDir: "{app}\bin\x86" +Source: "..\..\bin\release\x86\assimp_viewer.exe"; DestDir: "{app}\bin\x86"; Components: tools +Source: "C:\Windows\SysWOW64\D3DCompiler_42.dll"; DestDir: "{app}\bin\x86"; Components: tools +Source: "C:\Windows\SysWOW64\D3DX9_42.dll"; DestDir: "{app}\bin\x86"; Components: tools +Source: "..\..\bin\release\x86\assimp.exe"; DestDir: "{app}\bin\x86"; Components: tools + + +; Import libraries +Source: "..\..\lib\release\x86\assimp.lib"; DestDir: "{app}\lib\x86" + +; Samples +Source: "..\..\samples\*"; DestDir: "{app}\samples"; Flags: recursesubdirs; Components: samples + +; Include files +Source: "..\..\include\*"; DestDir: "{app}\include"; Flags: recursesubdirs + +[Icons] +Name: "{group}\Assimp Manual"; Filename: "{app}\doc\AssimpDoc.chm" ; Components: help +Name: "{group}\Assimp Command Line Manual"; Filename: "{app}\doc\AssimpCmdDoc.chm"; Components: help +Name: "{group}\AssimpView"; Filename: "{app}\bin\x64\assimp_view.exe"; Components: tools; Check: IsWin64 +Name: "{group}\AssimpView"; Filename: "{app}\bin\x86\assimp_view.exe"; Components: tools; Check: not IsWin64 From 800616e83a7898f38ab851b4ac3144d4ad0e49d7 Mon Sep 17 00:00:00 2001 From: kimkulling Date: Tue, 30 Apr 2019 15:51:32 +0200 Subject: [PATCH 25/47] Fix if block --- appveyor.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index c8a5a27b9..851d9c096 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -56,8 +56,7 @@ after_build: - if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" ( if "%platform%"=="x64" ( iscc packaging\windows-innosetup\script_x64.iss - ) - if "%platform%"!="x64" ( + ) else ( iscc packaging\windows-innosetup\script_x86.iss ) ) From a2ca6910726414c7e2eba18477e7b7e0db99b367 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 1 May 2019 11:09:20 +0200 Subject: [PATCH 26/47] Update script_x86.iss Fix invalid folder names. --- packaging/windows-innosetup/script_x86.iss | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packaging/windows-innosetup/script_x86.iss b/packaging/windows-innosetup/script_x86.iss index cf2660235..6dfba80b2 100644 --- a/packaging/windows-innosetup/script_x86.iss +++ b/packaging/windows-innosetup/script_x86.iss @@ -49,8 +49,8 @@ Source: "WEB"; DestDir: "{app}" Source: "..\..\scripts\*"; DestDir: "{app}\scripts"; Flags: recursesubdirs ; x86 binaries -Source: "..\..\bin\release\x86\assimp-vc141-mt.dll"; DestDir: "{app}\bin\x86" -Source: "..\..\bin\release\x86\assimp_viewer.exe"; DestDir: "{app}\bin\x86"; Components: tools +Source: "..\..\bin\release\assimp-vc140-mt.dll"; DestDir: "{app}\bin\x86" +Source: "..\..\bin\release\assimp_viewer.exe"; DestDir: "{app}\bin\x86"; Components: tools Source: "C:\Windows\SysWOW64\D3DCompiler_42.dll"; DestDir: "{app}\bin\x86"; Components: tools Source: "C:\Windows\SysWOW64\D3DX9_42.dll"; DestDir: "{app}\bin\x86"; Components: tools Source: "..\..\bin\release\x86\assimp.exe"; DestDir: "{app}\bin\x86"; Components: tools @@ -66,7 +66,7 @@ Source: "..\..\samples\*"; DestDir: "{app}\samples"; Flags: recursesubdirs; Comp Source: "..\..\include\*"; DestDir: "{app}\include"; Flags: recursesubdirs [Icons] -Name: "{group}\Assimp Manual"; Filename: "{app}\doc\AssimpDoc.chm" ; Components: help -Name: "{group}\Assimp Command Line Manual"; Filename: "{app}\doc\AssimpCmdDoc.chm"; Components: help -Name: "{group}\AssimpView"; Filename: "{app}\bin\x64\assimp_view.exe"; Components: tools; Check: IsWin64 -Name: "{group}\AssimpView"; Filename: "{app}\bin\x86\assimp_view.exe"; Components: tools; Check: not IsWin64 +; Name: "{group}\Assimp Manual"; Filename: "{app}\doc\AssimpDoc.chm" ; Components: help +; Name: "{group}\Assimp Command Line Manual"; Filename: "{app}\doc\AssimpCmdDoc.chm"; Components: help +; Name: "{group}\AssimpView"; Filename: "{app}\bin\x64\assimp_view.exe"; Components: tools; Check: IsWin64 +; Name: "{group}\AssimpView"; Filename: "{app}\bin\x86\assimp_view.exe"; Components: tools; Check: not IsWin64 From 6ff7635338e35ce54ced3950ade4f5271976d982 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 1 May 2019 11:10:16 +0200 Subject: [PATCH 27/47] Update script_x64.iss put icons into comments. --- packaging/windows-innosetup/script_x64.iss | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packaging/windows-innosetup/script_x64.iss b/packaging/windows-innosetup/script_x64.iss index 1738fd4b1..57182fcf5 100644 --- a/packaging/windows-innosetup/script_x64.iss +++ b/packaging/windows-innosetup/script_x64.iss @@ -65,7 +65,7 @@ Source: "..\..\samples\*"; DestDir: "{app}\samples"; Flags: recursesubdirs; Comp Source: "..\..\include\*"; DestDir: "{app}\include"; Flags: recursesubdirs [Icons] -Name: "{group}\Assimp Manual"; Filename: "{app}\doc\AssimpDoc.chm" ; Components: help -Name: "{group}\Assimp Command Line Manual"; Filename: "{app}\doc\AssimpCmdDoc.chm"; Components: help -Name: "{group}\AssimpView"; Filename: "{app}\bin\x64\assimp_view.exe"; Components: tools; Check: IsWin64 -Name: "{group}\AssimpView"; Filename: "{app}\bin\x86\assimp_view.exe"; Components: tools; Check: not IsWin64 +; Name: "{group}\Assimp Manual"; Filename: "{app}\doc\AssimpDoc.chm" ; Components: help +; Name: "{group}\Assimp Command Line Manual"; Filename: "{app}\doc\AssimpCmdDoc.chm"; Components: help +; Name: "{group}\AssimpView"; Filename: "{app}\bin\x64\assimp_view.exe"; Components: tools; Check: IsWin64 +; Name: "{group}\AssimpView"; Filename: "{app}\bin\x86\assimp_view.exe"; Components: tools; Check: not IsWin64 From 84e7f542fba2d788490584e3af37e3f4f762f24e Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 1 May 2019 12:10:52 +0200 Subject: [PATCH 28/47] Update script_x86.iss Fix version of dll. --- packaging/windows-innosetup/script_x86.iss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/windows-innosetup/script_x86.iss b/packaging/windows-innosetup/script_x86.iss index 6dfba80b2..8b8278c58 100644 --- a/packaging/windows-innosetup/script_x86.iss +++ b/packaging/windows-innosetup/script_x86.iss @@ -49,7 +49,7 @@ Source: "WEB"; DestDir: "{app}" Source: "..\..\scripts\*"; DestDir: "{app}\scripts"; Flags: recursesubdirs ; x86 binaries -Source: "..\..\bin\release\assimp-vc140-mt.dll"; DestDir: "{app}\bin\x86" +Source: "..\..\bin\release\assimp-vc141-mt.dll"; DestDir: "{app}\bin\x86" Source: "..\..\bin\release\assimp_viewer.exe"; DestDir: "{app}\bin\x86"; Components: tools Source: "C:\Windows\SysWOW64\D3DCompiler_42.dll"; DestDir: "{app}\bin\x86"; Components: tools Source: "C:\Windows\SysWOW64\D3DX9_42.dll"; DestDir: "{app}\bin\x86"; Components: tools From 615a78e38f80f8baddebb78e408b6370dc137dff Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 1 May 2019 14:41:51 +0200 Subject: [PATCH 29/47] Update script_x86.iss Fix wrong folder for assimp.exe --- packaging/windows-innosetup/script_x86.iss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/windows-innosetup/script_x86.iss b/packaging/windows-innosetup/script_x86.iss index 8b8278c58..1ecd13c7f 100644 --- a/packaging/windows-innosetup/script_x86.iss +++ b/packaging/windows-innosetup/script_x86.iss @@ -53,7 +53,7 @@ Source: "..\..\bin\release\assimp-vc141-mt.dll"; DestDir: "{app}\bin\x86" Source: "..\..\bin\release\assimp_viewer.exe"; DestDir: "{app}\bin\x86"; Components: tools Source: "C:\Windows\SysWOW64\D3DCompiler_42.dll"; DestDir: "{app}\bin\x86"; Components: tools Source: "C:\Windows\SysWOW64\D3DX9_42.dll"; DestDir: "{app}\bin\x86"; Components: tools -Source: "..\..\bin\release\x86\assimp.exe"; DestDir: "{app}\bin\x86"; Components: tools +Source: "..\..\bin\release\assimp.exe"; DestDir: "{app}\bin\x86"; Components: tools ; Import libraries From 3ee85a8cc8d117afd3987d5d9dbb24340808eeb1 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 1 May 2019 15:13:56 +0200 Subject: [PATCH 30/47] Update script_x86.iss Fix another wrong folder. --- packaging/windows-innosetup/script_x86.iss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/windows-innosetup/script_x86.iss b/packaging/windows-innosetup/script_x86.iss index 1ecd13c7f..f1999860e 100644 --- a/packaging/windows-innosetup/script_x86.iss +++ b/packaging/windows-innosetup/script_x86.iss @@ -57,7 +57,7 @@ Source: "..\..\bin\release\assimp.exe"; DestDir: "{app}\bin\x86"; Comp ; Import libraries -Source: "..\..\lib\release\x86\assimp.lib"; DestDir: "{app}\lib\x86" +Source: "..\..\lib\release\assimp.lib"; DestDir: "{app}\lib\x86" ; Samples Source: "..\..\samples\*"; DestDir: "{app}\samples"; Flags: recursesubdirs; Components: samples From c93886e87bcc315837b312d858854d422aad5a81 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 1 May 2019 15:52:27 +0200 Subject: [PATCH 31/47] Update script_x64.iss Fix eport lib name. --- packaging/windows-innosetup/script_x64.iss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/windows-innosetup/script_x64.iss b/packaging/windows-innosetup/script_x64.iss index 57182fcf5..cd4837f0a 100644 --- a/packaging/windows-innosetup/script_x64.iss +++ b/packaging/windows-innosetup/script_x64.iss @@ -56,7 +56,7 @@ Source: "C:\Windows\SysWOW64\D3DX9_42.dll"; DestDir: "{app}\bin\x64"; Dest Source: "..\..\bin\release\assimp.exe"; DestDir: "{app}\bin\x64"; Components: tools ; Import libraries -Source: "..\..\lib\release\assimp-vc140-mt.lib"; DestDir: "{app}\lib\x64" +Source: "..\..\lib\release\assimp-vc141-mt.lib"; DestDir: "{app}\lib\x64" ; Samples Source: "..\..\samples\*"; DestDir: "{app}\samples"; Flags: recursesubdirs; Components: samples From d9cfc48a665adaba251dcdf1d0fa145388812ec7 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 1 May 2019 15:53:04 +0200 Subject: [PATCH 32/47] Update script_x86.iss fix export lib name --- packaging/windows-innosetup/script_x86.iss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/windows-innosetup/script_x86.iss b/packaging/windows-innosetup/script_x86.iss index f1999860e..9aca78550 100644 --- a/packaging/windows-innosetup/script_x86.iss +++ b/packaging/windows-innosetup/script_x86.iss @@ -57,7 +57,7 @@ Source: "..\..\bin\release\assimp.exe"; DestDir: "{app}\bin\x86"; Comp ; Import libraries -Source: "..\..\lib\release\assimp.lib"; DestDir: "{app}\lib\x86" +Source: "..\..\lib\release\assimp-vc141-mt.lib"; DestDir: "{app}\lib\x86" ; Samples Source: "..\..\samples\*"; DestDir: "{app}\samples"; Flags: recursesubdirs; Components: samples From fcff12b219963af6012f948edee9f6200afa84f2 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 5 May 2019 13:39:10 +0200 Subject: [PATCH 33/47] closes https://github.com/assimp/assimp/issues/2054: make empty bone validation optional. --- code/ASELoader.cpp | 2 +- code/ASEParser.cpp | 2 +- code/ASEParser.h | 10 +++++----- code/FBXConverter.cpp | 21 ++++++++++----------- code/FBXConverter.h | 4 +++- code/FBXImportSettings.h | 34 ++++++++++++++++++++-------------- code/FBXImporter.cpp | 3 ++- code/ValidateDataStructure.cpp | 26 ++++++++++---------------- 8 files changed, 52 insertions(+), 50 deletions(-) diff --git a/code/ASELoader.cpp b/code/ASELoader.cpp index 321e8548a..556e8ce66 100644 --- a/code/ASELoader.cpp +++ b/code/ASELoader.cpp @@ -1299,7 +1299,7 @@ void ASEImporter::BuildMaterialIndices() } } - // Dekete our temporary array + // Delete our temporary array delete[] pcIntMaterials; } diff --git a/code/ASEParser.cpp b/code/ASEParser.cpp index e8d6febc2..f21f49eeb 100644 --- a/code/ASEParser.cpp +++ b/code/ASEParser.cpp @@ -45,7 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * @brief Implementation of the ASE parser class */ - +#pragma once #ifndef ASSIMP_BUILD_NO_ASE_IMPORTER #ifndef ASSIMP_BUILD_NO_3DS_IMPORTER diff --git a/code/ASEParser.h b/code/ASEParser.h index b8c820632..0cfd5313c 100644 --- a/code/ASEParser.h +++ b/code/ASEParser.h @@ -188,10 +188,11 @@ struct Animation { } mRotationType, mScalingType, mPositionType; Animation() AI_NO_EXCEPT - : mRotationType (TRACK) - , mScalingType (TRACK) - , mPositionType (TRACK) - {} + : mRotationType (TRACK) + , mScalingType (TRACK) + , mPositionType (TRACK) { + // empty + } //! List of track rotation keyframes std::vector< aiQuatKey > akeyRotations; @@ -243,7 +244,6 @@ struct BaseNode { mTargetPosition.x = qnan; } - //! Name of the mesh std::string mName; diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index 0abfdafdc..8d7c087ca 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -76,7 +76,7 @@ namespace Assimp { #define CONVERT_FBX_TIME(time) static_cast(time) / 46186158000L - FBXConverter::FBXConverter(aiScene* out, const Document& doc) + FBXConverter::FBXConverter(aiScene* out, const Document& doc, bool removeEmptyBones) : defaultMaterialIndex() , lights() , cameras() @@ -89,7 +89,8 @@ namespace Assimp { , mNodeNames() , anim_fps() , out(out) - , doc(doc) { + , doc(doc) + , mRemoveEmptyBones( removeEmptyBones ) { // animations need to be converted first since this will // populate the node_anim_chain_bits map, which is needed // to determine which nodes need to be generated. @@ -1407,9 +1408,9 @@ namespace Assimp { const WeightIndexArray& indices = cluster->GetIndices(); - if (indices.empty()) { + /*if (indices.empty()) { continue; - } + }*/ const MatIndexArray& mats = geo.GetMaterialIndices(); @@ -1439,13 +1440,11 @@ namespace Assimp { if (index_out_indices.back() == no_index_sentinel) { index_out_indices.back() = out_indices.size(); - } if (no_mat_check) { out_indices.push_back(out_idx[i]); - } - else { + } else { // this extra lookup is in O(logn), so the entire algorithm becomes O(nlogn) const std::vector::iterator it = std::lower_bound( outputVertStartIndices->begin(), @@ -1465,10 +1464,10 @@ namespace Assimp { // if we found at least one, generate the output bones // XXX this could be heavily simplified by collecting the bone // data in a single step. - if (ok) { + //if (ok) { ConvertCluster(bones, model, *cluster, out_indices, index_out_indices, count_out_indices, node_global_transform); - } + //} } } catch (std::exception&) { @@ -3525,9 +3524,9 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial* out_mat, const PropertyTa } // ------------------------------------------------------------------------------------------------ - void ConvertToAssimpScene(aiScene* out, const Document& doc) + void ConvertToAssimpScene(aiScene* out, const Document& doc, bool removeEmptyBones) { - FBXConverter converter(out, doc); + FBXConverter converter(out, doc, removeEmptyBones); } } // !FBX diff --git a/code/FBXConverter.h b/code/FBXConverter.h index 50637468b..fe4e916be 100644 --- a/code/FBXConverter.h +++ b/code/FBXConverter.h @@ -112,7 +112,7 @@ public: }; public: - FBXConverter(aiScene* out, const Document& doc); + FBXConverter(aiScene* out, const Document& doc, bool removeEmptyBones ); ~FBXConverter(); private: @@ -453,6 +453,8 @@ private: aiScene* const out; const FBX::Document& doc; + + bool mRemoveEmptyBones; }; } diff --git a/code/FBXImportSettings.h b/code/FBXImportSettings.h index d5e1c2060..eaf127382 100644 --- a/code/FBXImportSettings.h +++ b/code/FBXImportSettings.h @@ -53,19 +53,21 @@ namespace FBX { struct ImportSettings { ImportSettings() - : strictMode(true) - , readAllLayers(true) - , readAllMaterials(false) - , readMaterials(true) - , readTextures(true) - , readCameras(true) - , readLights(true) - , readAnimations(true) - , readWeights(true) - , preservePivots(true) - , optimizeEmptyAnimationCurves(true) - , useLegacyEmbeddedTextureNaming(false) - {} + : strictMode(true) + , readAllLayers(true) + , readAllMaterials(false) + , readMaterials(true) + , readTextures(true) + , readCameras(true) + , readLights(true) + , readAnimations(true) + , readWeights(true) + , preservePivots(true) + , optimizeEmptyAnimationCurves(true) + , useLegacyEmbeddedTextureNaming(false) + , removeEmptyBones( true ) { + // empty + } /** enable strict mode: @@ -141,8 +143,12 @@ struct ImportSettings bool optimizeEmptyAnimationCurves; /** use legacy naming for embedded textures eg: (*0, *1, *2) - **/ + */ bool useLegacyEmbeddedTextureNaming; + + /** Empty bones shall be removed + */ + bool removeEmptyBones; }; diff --git a/code/FBXImporter.cpp b/code/FBXImporter.cpp index 2cc8bffc2..60a19223c 100644 --- a/code/FBXImporter.cpp +++ b/code/FBXImporter.cpp @@ -140,6 +140,7 @@ void FBXImporter::SetupProperties(const Importer* pImp) settings.preservePivots = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_PRESERVE_PIVOTS, true); settings.optimizeEmptyAnimationCurves = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_OPTIMIZE_EMPTY_ANIMATION_CURVES, true); settings.useLegacyEmbeddedTextureNaming = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING, false); + settings.removeEmptyBones = pImp->GetPropertyBool(AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES, true); } // ------------------------------------------------------------------------------------------------ @@ -184,7 +185,7 @@ void FBXImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS Document doc(parser,settings); // convert the FBX DOM to aiScene - ConvertToAssimpScene(pScene,doc); + ConvertToAssimpScene(pScene,doc, settings.removeEmptyBones); std::for_each(tokens.begin(),tokens.end(),Util::delete_fun()); } diff --git a/code/ValidateDataStructure.cpp b/code/ValidateDataStructure.cpp index 657b0361b..58f700b0e 100644 --- a/code/ValidateDataStructure.cpp +++ b/code/ValidateDataStructure.cpp @@ -46,8 +46,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * the data structure returned by Assimp. */ - - // internal headers #include "ValidateDataStructure.h" #include @@ -110,8 +108,8 @@ void ValidateDSProcess::ReportWarning(const char* msg,...) } // ------------------------------------------------------------------------------------------------ -inline int HasNameMatch(const aiString& in, aiNode* node) -{ +inline +int HasNameMatch(const aiString& in, aiNode* node) { int result = (node->mName == in ? 1 : 0 ); for (unsigned int i = 0; i < node->mNumChildren;++i) { result += HasNameMatch(in,node->mChildren[i]); @@ -121,9 +119,8 @@ inline int HasNameMatch(const aiString& in, aiNode* node) // ------------------------------------------------------------------------------------------------ template -inline void ValidateDSProcess::DoValidation(T** parray, unsigned int size, - const char* firstName, const char* secondName) -{ +inline +void ValidateDSProcess::DoValidation(T** parray, unsigned int size, const char* firstName, const char* secondName) { // validate all entries if (size) { @@ -516,13 +513,12 @@ void ValidateDSProcess::Validate( const aiMesh* pMesh) } // ------------------------------------------------------------------------------------------------ -void ValidateDSProcess::Validate( const aiMesh* pMesh, - const aiBone* pBone,float* afSum) -{ +void ValidateDSProcess::Validate( const aiMesh* pMesh, const aiBone* pBone,float* afSum) { this->Validate(&pBone->mName); if (!pBone->mNumWeights) { - ReportError("aiBone::mNumWeights is zero"); + // ReportError("aiBone::mNumWeights is zero"); + } // check whether all vertices affected by this bone are valid @@ -563,9 +559,6 @@ void ValidateDSProcess::Validate( const aiAnimation* pAnimation) else { ReportError("aiAnimation::mNumChannels is 0. At least one node animation channel must be there."); } - - // Animation duration is allowed to be zero in cases where the anim contains only a single key frame. - // if (!pAnimation->mDuration)this->ReportError("aiAnimation::mDuration is zero"); } // ------------------------------------------------------------------------------------------------ @@ -746,8 +739,9 @@ void ValidateDSProcess::Validate( const aiMaterial* pMaterial) "AI_MATKEY_SHININESS_STRENGTH key is 0.0"); } break; - default: ; - }; + default: + break; + } } if (AI_SUCCESS == aiGetMaterialFloat( pMaterial,AI_MATKEY_OPACITY,&fTemp) && (!fTemp || fTemp > 1.01)) { From 69ece762d13cb38be2147399d5d56d74aa0488f1 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 5 May 2019 16:00:57 +0200 Subject: [PATCH 34/47] fix the build: remove errorenous pragma statement. --- code/ASEParser.cpp | 1 - code/FBXConverter.cpp | 15 +++++++++------ code/ValidateDataStructure.cpp | 11 +++++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/code/ASEParser.cpp b/code/ASEParser.cpp index f21f49eeb..14b962320 100644 --- a/code/ASEParser.cpp +++ b/code/ASEParser.cpp @@ -45,7 +45,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * @brief Implementation of the ASE parser class */ -#pragma once #ifndef ASSIMP_BUILD_NO_ASE_IMPORTER #ifndef ASSIMP_BUILD_NO_3DS_IMPORTER diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index 8d7c087ca..76b6c6b4e 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -388,6 +388,7 @@ namespace Assimp { break; default: ai_assert(false); + break; } } @@ -978,7 +979,9 @@ namespace Assimp { unsigned int epcount = 0; for (unsigned i = 0; i < indices.size(); i++) { - if (indices[i] < 0) epcount++; + if (indices[i] < 0) { + epcount++; + } } unsigned int pcount = static_cast( indices.size() ); unsigned int scount = out_mesh->mNumFaces = pcount - epcount; @@ -1408,9 +1411,9 @@ namespace Assimp { const WeightIndexArray& indices = cluster->GetIndices(); - /*if (indices.empty()) { + if (indices.empty() && mRemoveEmptyBones ) { continue; - }*/ + } const MatIndexArray& mats = geo.GetMaterialIndices(); @@ -1460,14 +1463,14 @@ namespace Assimp { } } } - + // if we found at least one, generate the output bones // XXX this could be heavily simplified by collecting the bone // data in a single step. - //if (ok) { + if (ok && mRemoveEmptyBones) { ConvertCluster(bones, model, *cluster, out_indices, index_out_indices, count_out_indices, node_global_transform); - //} + } } } catch (std::exception&) { diff --git a/code/ValidateDataStructure.cpp b/code/ValidateDataStructure.cpp index 58f700b0e..712fd6943 100644 --- a/code/ValidateDataStructure.cpp +++ b/code/ValidateDataStructure.cpp @@ -178,7 +178,8 @@ inline void ValidateDSProcess::DoValidationEx(T** parray, unsigned int size, // ------------------------------------------------------------------------------------------------ template inline -void ValidateDSProcess::DoValidationWithNameCheck(T** array, unsigned int size, const char* firstName, const char* secondName) { +void ValidateDSProcess::DoValidationWithNameCheck(T** array, unsigned int size, const char* firstName, + const char* secondName) { // validate all entries DoValidationEx(array,size,firstName,secondName); @@ -198,9 +199,8 @@ void ValidateDSProcess::DoValidationWithNameCheck(T** array, unsigned int size, // ------------------------------------------------------------------------------------------------ // Executes the post processing step on the given imported data. -void ValidateDSProcess::Execute( aiScene* pScene) -{ - this->mScene = pScene; +void ValidateDSProcess::Execute( aiScene* pScene) { + mScene = pScene; ASSIMP_LOG_DEBUG("ValidateDataStructureProcess begin"); // validate the node graph of the scene @@ -517,8 +517,7 @@ void ValidateDSProcess::Validate( const aiMesh* pMesh, const aiBone* pBone,float this->Validate(&pBone->mName); if (!pBone->mNumWeights) { - // ReportError("aiBone::mNumWeights is zero"); - + //ReportError("aiBone::mNumWeights is zero"); } // check whether all vertices affected by this bone are valid From 1324409c7b50ba8afa686facdb2b9468bd606bb5 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 5 May 2019 16:23:42 +0200 Subject: [PATCH 35/47] fix build: fix wrong function prototype. --- code/FBXConverter.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/code/FBXConverter.h b/code/FBXConverter.h index fe4e916be..a77cb4310 100644 --- a/code/FBXConverter.h +++ b/code/FBXConverter.h @@ -79,9 +79,10 @@ class Document; /** * Convert a FBX #Document to #aiScene * @param out Empty scene to be populated - * @param doc Parsed FBX document + * @param doc Parsed FBX document + * @param removeEmptyBones Will remove bones, which do not have any references to vertices. */ -void ConvertToAssimpScene(aiScene* out, const Document& doc); +void ConvertToAssimpScene(aiScene* out, const Document& doc, bool removeEmptyBones ); /** Dummy class to encapsulate the conversion process */ class FBXConverter { From eb1a2586c3e4ee5097b207b07feb5cfb61cd05bf Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 5 May 2019 17:44:15 +0200 Subject: [PATCH 36/47] add missing define in config.h.in --- include/assimp/config.h.in | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/assimp/config.h.in b/include/assimp/config.h.in index a37ff0b8c..50a5512e2 100644 --- a/include/assimp/config.h.in +++ b/include/assimp/config.h.in @@ -657,7 +657,11 @@ enum aiComponent */ #define AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING \ "AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING" - + +// --------------------------------------------------------------------------- +#define AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES \ + "AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES" + // --------------------------------------------------------------------------- /** @brief Set the vertex animation keyframe to be imported * From 1203d4658c157a188b1ba78547f6d503069a6798 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 6 May 2019 18:44:30 +0200 Subject: [PATCH 37/47] Add missing doc. --- include/assimp/config.h.in | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/assimp/config.h.in b/include/assimp/config.h.in index 50a5512e2..ba027cf40 100644 --- a/include/assimp/config.h.in +++ b/include/assimp/config.h.in @@ -651,14 +651,18 @@ enum aiComponent // --------------------------------------------------------------------------- /** @brief Set whether the fbx importer will use the legacy embedded texture naming. -* -* The default value is false (0) -* Property type: bool -*/ + * + * The default value is false (0) + * Property type: bool + */ #define AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING \ "AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING" // --------------------------------------------------------------------------- +/** @brief Set wether the FBX importer shall not remove empty bones. + * + * Empty bone are often used to define connections for other models. + * #define AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES \ "AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES" From 02324123e54bd967c20070f99fcff58a80574003 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 6 May 2019 19:15:28 +0200 Subject: [PATCH 38/47] Fix typo in comment. --- include/assimp/config.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/assimp/config.h.in b/include/assimp/config.h.in index ba027cf40..07be7cdad 100644 --- a/include/assimp/config.h.in +++ b/include/assimp/config.h.in @@ -662,7 +662,7 @@ enum aiComponent /** @brief Set wether the FBX importer shall not remove empty bones. * * Empty bone are often used to define connections for other models. - * + */ #define AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES \ "AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES" From 4a9cd0845171070fb971eb90c03f7ca6b8234039 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 6 May 2019 20:51:04 +0200 Subject: [PATCH 39/47] Prepaation for conversion. --- code/FBXConverter.cpp | 7 ++++++- code/FBXConverter.h | 17 +++++++++++++++++ code/FBXMeshGeometry.cpp | 4 ++-- code/FBXParser.cpp | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index 76b6c6b4e..ab600e53d 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -90,7 +90,8 @@ namespace Assimp { , anim_fps() , out(out) , doc(doc) - , mRemoveEmptyBones( removeEmptyBones ) { + , mRemoveEmptyBones( removeEmptyBones ) + , mCurrentUnit( FbxUnit::Undefined ) { // animations need to be converted first since this will // populate the node_anim_chain_bits map, which is needed // to determine which nodes need to be generated. @@ -3474,6 +3475,10 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial* out_mat, const PropertyTa out->mMetaData->Set(14, "CustomFrameRate", doc.GlobalSettings().CustomFrameRate()); } + void FBXConverter::ConvertToUnitScale(FbxUnit unit) { + + } + void FBXConverter::TransferDataToScene() { ai_assert(!out->mMeshes); diff --git a/code/FBXConverter.h b/code/FBXConverter.h index a77cb4310..75f24713e 100644 --- a/code/FBXConverter.h +++ b/code/FBXConverter.h @@ -415,6 +415,21 @@ private: void ConvertGlobalSettings(); + enum class FbxUnit { + cm = 0, + m, + km, + inch, + foot, + mile, + yard, + NumUnits, + + Undefined + }; + + void ConvertToUnitScale(FbxUnit unit); + // ------------------------------------------------------------------------------------------------ // copy generated meshes, animations, lights, cameras and textures to the output scene void TransferDataToScene(); @@ -456,6 +471,8 @@ private: const FBX::Document& doc; bool mRemoveEmptyBones; + + FbxUnit mCurrentUnit; }; } diff --git a/code/FBXMeshGeometry.cpp b/code/FBXMeshGeometry.cpp index 2debfa651..468ba1c2e 100644 --- a/code/FBXMeshGeometry.cpp +++ b/code/FBXMeshGeometry.cpp @@ -568,8 +568,8 @@ void MeshGeometry::ReadVertexDataColors(std::vector& colors_out, cons } // ------------------------------------------------------------------------------------------------ -static const std::string TangentIndexToken = "TangentIndex"; -static const std::string TangentsIndexToken = "TangentsIndex"; +static const char *TangentIndexToken = "TangentIndex"; +static const char *TangentsIndexToken = "TangentsIndex"; void MeshGeometry::ReadVertexDataTangents(std::vector& tangents_out, const Scope& source, const std::string& MappingInformationType, diff --git a/code/FBXParser.cpp b/code/FBXParser.cpp index b255c4734..fe63866a0 100644 --- a/code/FBXParser.cpp +++ b/code/FBXParser.cpp @@ -117,7 +117,7 @@ namespace FBX { Element::Element(const Token& key_token, Parser& parser) : key_token(key_token) { - TokenPtr n = NULL; + TokenPtr n = nullptr; do { n = parser.AdvanceToNextToken(); if(!n) { From 4155f005bee4a06c4bb724d748e9a3c69166d1c8 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 6 May 2019 21:21:58 +0200 Subject: [PATCH 40/47] Add implementation to convert from cm to m. --- code/FBXConverter.cpp | 44 +++++++++++++++++++++++++++++++++++--- code/FBXConverter.h | 6 ++---- code/FBXImportSettings.h | 7 +++++- code/FBXImporter.cpp | 1 + code/FBXMeshGeometry.cpp | 2 +- include/assimp/config.h.in | 9 +++++++- 6 files changed, 59 insertions(+), 10 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index ab600e53d..bd8347408 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -91,7 +91,7 @@ namespace Assimp { , out(out) , doc(doc) , mRemoveEmptyBones( removeEmptyBones ) - , mCurrentUnit( FbxUnit::Undefined ) { + , mCurrentUnit(FbxUnit::cm) { // animations need to be converted first since this will // populate the node_anim_chain_bits map, which is needed // to determine which nodes need to be generated. @@ -119,6 +119,7 @@ namespace Assimp { ConvertGlobalSettings(); TransferDataToScene(); + ConvertToUnitScale(doc.GlobalSettings().UnitScaleFactor()); // if we didn't read any meshes set the AI_SCENE_FLAGS_INCOMPLETE // to make sure the scene passes assimp's validation. FBX files @@ -3410,8 +3411,9 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial* out_mat, const PropertyTa na->mNumScalingKeys = static_cast(keys.size()); na->mScalingKeys = new aiVectorKey[keys.size()]; - if (keys.size() > 0) + if (keys.size() > 0) { InterpolateKeys(na->mScalingKeys, keys, inputs, aiVector3D(1.0f, 1.0f, 1.0f), maxTime, minTime); + } } void FBXConverter::ConvertTranslationKeys(aiNodeAnim* na, const std::vector& nodes, @@ -3475,8 +3477,44 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial* out_mat, const PropertyTa out->mMetaData->Set(14, "CustomFrameRate", doc.GlobalSettings().CustomFrameRate()); } - void FBXConverter::ConvertToUnitScale(FbxUnit unit) { + void FBXConverter::ConvertToUnitScale( FbxUnit unit ) { + if (mCurrentUnit == unit) { + return; + } + ai_real scale = 1.0; + if (mCurrentUnit == FbxUnit::cm) { + if (unit == FbxUnit::m) { + scale = (ai_real)0.01; + } else if (unit == FbxUnit::km) { + scale = (ai_real)0.00001; + } + } else if (mCurrentUnit == FbxUnit::m) { + if (unit == FbxUnit::cm) { + scale = (ai_real)100.0; + } else if (unit == FbxUnit::km) { + scale = (ai_real)0.001; + } + } else if (mCurrentUnit == FbxUnit::km) { + if (unit == FbxUnit::cm) { + scale = (ai_real)100000.0; + } else if (unit == FbxUnit::m) { + scale = (ai_real)1000.0; + } + } + + for (auto mesh : meshes) { + if (nullptr == mesh) { + continue; + } + + if (mesh->HasPositions()) { + for (unsigned int i = 0; i < mesh->mNumVertices; ++i) { + aiVector3D &pos = mesh->mVertices[i]; + pos *= scale; + } + } + } } void FBXConverter::TransferDataToScene() diff --git a/code/FBXConverter.h b/code/FBXConverter.h index 75f24713e..dbbeee158 100644 --- a/code/FBXConverter.h +++ b/code/FBXConverter.h @@ -419,15 +419,13 @@ private: cm = 0, m, km, - inch, - foot, - mile, - yard, NumUnits, Undefined }; + // ------------------------------------------------------------------------------------------------ + // Will perform the conversion from a given unit to the requested unit. void ConvertToUnitScale(FbxUnit unit); // ------------------------------------------------------------------------------------------------ diff --git a/code/FBXImportSettings.h b/code/FBXImportSettings.h index eaf127382..1a4c80f8b 100644 --- a/code/FBXImportSettings.h +++ b/code/FBXImportSettings.h @@ -65,7 +65,8 @@ struct ImportSettings , preservePivots(true) , optimizeEmptyAnimationCurves(true) , useLegacyEmbeddedTextureNaming(false) - , removeEmptyBones( true ) { + , removeEmptyBones( true ) + , convertToMeters( false ) { // empty } @@ -149,6 +150,10 @@ struct ImportSettings /** Empty bones shall be removed */ bool removeEmptyBones; + + /** Set to true to perform a conversion from cm to meter after the import + */ + bool convertToMeters; }; diff --git a/code/FBXImporter.cpp b/code/FBXImporter.cpp index 60a19223c..4f75b9c2e 100644 --- a/code/FBXImporter.cpp +++ b/code/FBXImporter.cpp @@ -141,6 +141,7 @@ void FBXImporter::SetupProperties(const Importer* pImp) settings.optimizeEmptyAnimationCurves = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_OPTIMIZE_EMPTY_ANIMATION_CURVES, true); settings.useLegacyEmbeddedTextureNaming = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING, false); settings.removeEmptyBones = pImp->GetPropertyBool(AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES, true); + settings.convertToMeters = pImpl->GetPropertyBool(AI_CONFIG_FBX_CONVERT_TO_M, false); } // ------------------------------------------------------------------------------------------------ diff --git a/code/FBXMeshGeometry.cpp b/code/FBXMeshGeometry.cpp index 468ba1c2e..44a0264ca 100644 --- a/code/FBXMeshGeometry.cpp +++ b/code/FBXMeshGeometry.cpp @@ -576,7 +576,7 @@ void MeshGeometry::ReadVertexDataTangents(std::vector& tangents_out, const std::string& ReferenceInformationType) { const char * str = source.Elements().count( "Tangents" ) > 0 ? "Tangents" : "Tangent"; - const char * strIdx = source.Elements().count( "Tangents" ) > 0 ? TangentsIndexToken.c_str() : TangentIndexToken.c_str(); + const char * strIdx = source.Elements().count( "Tangents" ) > 0 ? TangentsIndexToken : TangentIndexToken; ResolveVertexDataArray(tangents_out,source,MappingInformationType,ReferenceInformationType, str, strIdx, diff --git a/include/assimp/config.h.in b/include/assimp/config.h.in index 07be7cdad..c42aa63da 100644 --- a/include/assimp/config.h.in +++ b/include/assimp/config.h.in @@ -659,13 +659,20 @@ enum aiComponent "AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING" // --------------------------------------------------------------------------- -/** @brief Set wether the FBX importer shall not remove empty bones. +/** @brief Set wether the importer shall not remove empty bones. * * Empty bone are often used to define connections for other models. */ #define AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES \ "AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES" + +// --------------------------------------------------------------------------- +/** @brief Set wether the FBX importer shall convert the unit from cm to m. + */ +#define AI_CONFIG_FBX_CONVERT_TO_M \ + "AI_CONFIG_FBX_CONVERT_TO_M" + // --------------------------------------------------------------------------- /** @brief Set the vertex animation keyframe to be imported * From e917b288a160e466288982cb0e148d5ac7ce6945 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 6 May 2019 21:38:45 +0200 Subject: [PATCH 41/47] fix a typo. --- code/FBXImporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/FBXImporter.cpp b/code/FBXImporter.cpp index 4f75b9c2e..339a9421a 100644 --- a/code/FBXImporter.cpp +++ b/code/FBXImporter.cpp @@ -141,7 +141,7 @@ void FBXImporter::SetupProperties(const Importer* pImp) settings.optimizeEmptyAnimationCurves = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_OPTIMIZE_EMPTY_ANIMATION_CURVES, true); settings.useLegacyEmbeddedTextureNaming = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING, false); settings.removeEmptyBones = pImp->GetPropertyBool(AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES, true); - settings.convertToMeters = pImpl->GetPropertyBool(AI_CONFIG_FBX_CONVERT_TO_M, false); + settings.convertToMeters = pImp->GetPropertyBool(AI_CONFIG_FBX_CONVERT_TO_M, false); } // ------------------------------------------------------------------------------------------------ From 390452bd06f510c3c2933ab5915ef2add1b35fec Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 7 May 2019 20:32:45 +0200 Subject: [PATCH 42/47] Fix the build. --- code/FBXConverter.cpp | 8 ++++---- code/FBXConverter.h | 22 +++++++++++----------- code/FBXImporter.cpp | 6 +++++- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index bd8347408..f45129cae 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -76,7 +76,7 @@ namespace Assimp { #define CONVERT_FBX_TIME(time) static_cast(time) / 46186158000L - FBXConverter::FBXConverter(aiScene* out, const Document& doc, bool removeEmptyBones) + FBXConverter::FBXConverter(aiScene* out, const Document& doc, bool removeEmptyBones, FbxUnit unit ) : defaultMaterialIndex() , lights() , cameras() @@ -119,7 +119,7 @@ namespace Assimp { ConvertGlobalSettings(); TransferDataToScene(); - ConvertToUnitScale(doc.GlobalSettings().UnitScaleFactor()); + ConvertToUnitScale(unit); // if we didn't read any meshes set the AI_SCENE_FLAGS_INCOMPLETE // to make sure the scene passes assimp's validation. FBX files @@ -3570,9 +3570,9 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial* out_mat, const PropertyTa } // ------------------------------------------------------------------------------------------------ - void ConvertToAssimpScene(aiScene* out, const Document& doc, bool removeEmptyBones) + void ConvertToAssimpScene(aiScene* out, const Document& doc, bool removeEmptyBones, FbxUnit unit) { - FBXConverter converter(out, doc, removeEmptyBones); + FBXConverter converter(out, doc, removeEmptyBones, unit); } } // !FBX diff --git a/code/FBXConverter.h b/code/FBXConverter.h index dbbeee158..f75222d5b 100644 --- a/code/FBXConverter.h +++ b/code/FBXConverter.h @@ -76,13 +76,22 @@ namespace FBX { class Document; +enum class FbxUnit { + cm = 0, + m, + km, + NumUnits, + + Undefined +}; + /** * Convert a FBX #Document to #aiScene * @param out Empty scene to be populated * @param doc Parsed FBX document * @param removeEmptyBones Will remove bones, which do not have any references to vertices. */ -void ConvertToAssimpScene(aiScene* out, const Document& doc, bool removeEmptyBones ); +void ConvertToAssimpScene(aiScene* out, const Document& doc, bool removeEmptyBones, FbxUnit unit); /** Dummy class to encapsulate the conversion process */ class FBXConverter { @@ -113,7 +122,7 @@ public: }; public: - FBXConverter(aiScene* out, const Document& doc, bool removeEmptyBones ); + FBXConverter(aiScene* out, const Document& doc, bool removeEmptyBones, FbxUnit unit); ~FBXConverter(); private: @@ -415,15 +424,6 @@ private: void ConvertGlobalSettings(); - enum class FbxUnit { - cm = 0, - m, - km, - NumUnits, - - Undefined - }; - // ------------------------------------------------------------------------------------------------ // Will perform the conversion from a given unit to the requested unit. void ConvertToUnitScale(FbxUnit unit); diff --git a/code/FBXImporter.cpp b/code/FBXImporter.cpp index 339a9421a..988735a77 100644 --- a/code/FBXImporter.cpp +++ b/code/FBXImporter.cpp @@ -185,8 +185,12 @@ void FBXImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS // take the raw parse-tree and convert it to a FBX DOM Document doc(parser,settings); + FbxUnit unit(FbxUnit::cm); + if (settings.convertToMeters) { + unit = FbxUnit::m; + } // convert the FBX DOM to aiScene - ConvertToAssimpScene(pScene,doc, settings.removeEmptyBones); + ConvertToAssimpScene(pScene,doc, settings.removeEmptyBones, unit); std::for_each(tokens.begin(),tokens.end(),Util::delete_fun()); } From 6736f3d24b6c83389326207b704211696b0e8e2c Mon Sep 17 00:00:00 2001 From: Matias Date: Thu, 9 May 2019 11:19:05 +0200 Subject: [PATCH 43/47] Don't call PutString with an empty string. Both DumpChildrenAscii and EndAscii can return without modifyting the string, so we need to check the string before calling PutString. This used to cause a crash. --- code/FBXExportNode.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/code/FBXExportNode.cpp b/code/FBXExportNode.cpp index e5215466a..e90a50e67 100644 --- a/code/FBXExportNode.cpp +++ b/code/FBXExportNode.cpp @@ -252,7 +252,8 @@ void FBX::Node::DumpChildren( } else { std::ostringstream ss; DumpChildrenAscii(ss, indent); - s.PutString(ss.str()); + if (ss.tellp() > 0) + s.PutString(ss.str()); } } @@ -266,7 +267,8 @@ void FBX::Node::End( } else { std::ostringstream ss; EndAscii(ss, indent, has_children); - s.PutString(ss.str()); + if (ss.tellp() > 0) + s.PutString(ss.str()); } } From 575ef4d9276c4755ce168e116e8248d123b93d2a Mon Sep 17 00:00:00 2001 From: Matias Date: Thu, 9 May 2019 14:50:22 +0200 Subject: [PATCH 44/47] Added support for embedded textures to the FBXExporter (both binary and ASCII). Also made the FBX-namespaces more consistent (we had both Assimp::FBX:: and FBX::). Since we seem to support two types of embedded texture references (both asterisk+texture_id and filepath) I made the exporter use aiScene::GetEmbeddedTexture for looking up texture reference and integrated @loebl 's modification of the function to support the old ("*1") type of references (https://github.com/loebl/assimp/commit/e217358) --- code/FBXCommon.h | 4 +-- code/FBXExportNode.cpp | 11 ++++--- code/FBXExportNode.h | 3 +- code/FBXExportProperty.cpp | 4 +-- code/FBXExportProperty.h | 3 +- code/FBXExporter.cpp | 48 +++++++++++++++++++++++------- code/FBXUtil.cpp | 60 ++++++++++++++++++++++++++++++++++++++ code/FBXUtil.h | 9 ++++++ include/assimp/scene.h | 8 +++++ 9 files changed, 130 insertions(+), 20 deletions(-) diff --git a/code/FBXCommon.h b/code/FBXCommon.h index fcb20a5ca..e51644913 100644 --- a/code/FBXCommon.h +++ b/code/FBXCommon.h @@ -47,7 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ASSIMP_BUILD_NO_FBX_EXPORTER - +namespace Assimp { namespace FBX { const std::string NULL_RECORD = { // 13 null bytes @@ -80,7 +80,7 @@ namespace FBX TransformInheritance_MAX // end-of-enum sentinel }; } - +} #endif // ASSIMP_BUILD_NO_FBX_EXPORTER #endif // AI_FBXCOMMON_H_INC diff --git a/code/FBXExportNode.cpp b/code/FBXExportNode.cpp index e5215466a..06c89cee4 100644 --- a/code/FBXExportNode.cpp +++ b/code/FBXExportNode.cpp @@ -54,6 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include // ostringstream #include // shared_ptr +namespace Assimp { // AddP70 helpers... there's no usable pattern here, // so all are defined as separate functions. // Even "animatable" properties are often completely different @@ -252,7 +253,8 @@ void FBX::Node::DumpChildren( } else { std::ostringstream ss; DumpChildrenAscii(ss, indent); - s.PutString(ss.str()); + if (ss.tellp() > 0) + s.PutString(ss.str()); } } @@ -266,7 +268,8 @@ void FBX::Node::End( } else { std::ostringstream ss; EndAscii(ss, indent, has_children); - s.PutString(ss.str()); + if (ss.tellp() > 0) + s.PutString(ss.str()); } } @@ -367,7 +370,7 @@ void FBX::Node::EndBinary( bool has_children ) { // if there were children, add a null record - if (has_children) { s.PutString(FBX::NULL_RECORD); } + if (has_children) { s.PutString(Assimp::FBX::NULL_RECORD); } // now go back and write initial pos this->end_pos = s.Tell(); @@ -563,6 +566,6 @@ void FBX::Node::WritePropertyNode( FBX::Node::WritePropertyNodeAscii(name, v, s, indent); } } - +} #endif // ASSIMP_BUILD_NO_FBX_EXPORTER #endif // ASSIMP_BUILD_NO_EXPORT diff --git a/code/FBXExportNode.h b/code/FBXExportNode.h index e1ebc3696..b388a4f86 100644 --- a/code/FBXExportNode.h +++ b/code/FBXExportNode.h @@ -54,6 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +namespace Assimp { namespace FBX { class Node; } @@ -264,7 +265,7 @@ private: // static helper functions ); }; - +} #endif // ASSIMP_BUILD_NO_FBX_EXPORTER diff --git a/code/FBXExportProperty.cpp b/code/FBXExportProperty.cpp index 9981d6b1c..ac464c806 100644 --- a/code/FBXExportProperty.cpp +++ b/code/FBXExportProperty.cpp @@ -52,7 +52,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include // ostringstream - +namespace Assimp { // constructors for single element properties FBX::Property::Property(bool v) @@ -359,6 +359,6 @@ void FBX::Property::DumpAscii(std::ostream& s, int indent) throw runtime_error(err.str()); } } - +} #endif // ASSIMP_BUILD_NO_FBX_EXPORTER #endif // ASSIMP_BUILD_NO_EXPORT diff --git a/code/FBXExportProperty.h b/code/FBXExportProperty.h index 9c9d37c36..424bf8b32 100644 --- a/code/FBXExportProperty.h +++ b/code/FBXExportProperty.h @@ -56,6 +56,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include // is_void +namespace Assimp { namespace FBX { class Property; } @@ -123,7 +124,7 @@ private: char type; std::vector data; }; - +} #endif // ASSIMP_BUILD_NO_FBX_EXPORTER #endif // AI_FBXEXPORTPROPERTY_H_INC diff --git a/code/FBXExporter.cpp b/code/FBXExporter.cpp index 6b1ac0e5e..24ae88e6b 100644 --- a/code/FBXExporter.cpp +++ b/code/FBXExporter.cpp @@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "FBXExportNode.h" #include "FBXExportProperty.h" #include "FBXCommon.h" +#include "FBXUtil.h" #include // aiGetVersion #include @@ -73,7 +74,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. const ai_real DEG = ai_real( 57.29577951308232087679815481 ); // degrees per radian +using namespace Assimp; +using namespace Assimp::FBX; + // some constants that we'll use for writing metadata +namespace Assimp { namespace FBX { const std::string EXPORT_VERSION_STR = "7.4.0"; const uint32_t EXPORT_VERSION_INT = 7400; // 7.4 == 2014/2015 @@ -92,11 +97,6 @@ namespace FBX { ";------------------------------------------------------------------"; } -using namespace Assimp; -using namespace FBX; - -namespace Assimp { - // --------------------------------------------------------------------- // Worker function for exporting a scene to binary FBX. // Prototyped and registered in Exporter.cpp @@ -121,6 +121,7 @@ namespace Assimp { IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties + ){ // initialize the exporter FBXExporter exporter(pScene, pProperties); @@ -1393,10 +1394,6 @@ void FBXExporter::WriteObjects () // FbxVideo - stores images used by textures. for (const auto &it : uid_by_image) { - if (it.first.compare(0, 1, "*") == 0) { - // TODO: embedded textures - continue; - } FBX::Node n("Video"); const int64_t& uid = it.second; const std::string name = ""; // TODO: ... name??? @@ -1406,7 +1403,38 @@ void FBXExporter::WriteObjects () // TODO: get full path... relative path... etc... ugh... // for now just use the same path for everything, // and hopefully one of them will work out. - const std::string& path = it.first; + std::string path = it.first; + // try get embedded texture + const aiTexture* embedded_texture = mScene->GetEmbeddedTexture(it.first.c_str()); + if (embedded_texture != nullptr) + { + // change the path (use original filename, if available. If name is ampty, concatenate texture index with file extension) + std::stringstream newPath; + if (embedded_texture->mFilename.length > 0) + newPath << embedded_texture->mFilename.C_Str(); + else if (embedded_texture->achFormatHint[0]) + { + int texture_index = std::stoi(path.substr(1, path.size() - 1)); + newPath << texture_index << "." << embedded_texture->achFormatHint; + } + path = newPath.str(); + // embed the texture + size_t texture_size = static_cast(embedded_texture->mWidth * std::max(embedded_texture->mHeight, 1u)); + if (binary) + { + // embed texture as binary data + std::vector tex_data; + tex_data.resize(texture_size); + memcpy(&tex_data[0], (char*)embedded_texture->pcData, texture_size); + n.AddChild("Content", tex_data); + } + else + { + // embed texture in base64 encoding + std::string encoded_texture = FBX::Util::EncodeBase64((char*)embedded_texture->pcData, texture_size); + n.AddChild("Content", encoded_texture); + } + } p.AddP70("Path", "KString", "XRefUrl", "", path); n.AddChild(p); n.AddChild("UseMipMap", int32_t(0)); diff --git a/code/FBXUtil.cpp b/code/FBXUtil.cpp index fb483161b..068683f7d 100644 --- a/code/FBXUtil.cpp +++ b/code/FBXUtil.cpp @@ -157,6 +157,66 @@ size_t DecodeBase64(const char* in, size_t inLength, uint8_t*& out) return outLength; } +static const char to_base64_string[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +char EncodeBase64(char byte) +{ + return to_base64_string[(size_t)byte]; +} + +/** Encodes a block of 4 bytes to base64 encoding +* +* @param bytes Bytes to encode. +* @param out_string String to write encoded values to. +* @param string_pos Position in out_string.*/ +void EncodeByteBlock(const char* bytes, std::string& out_string, size_t string_pos) +{ + char b0 = (bytes[0] & 0b11111100) >> 2; + char b1 = (bytes[0] & 0b00000011) << 4 | ((bytes[1] & 0b11110000) >> 4); + char b2 = (bytes[1] & 0b00001111) << 2 | ((bytes[2] & 0b11000000) >> 6); + char b3 = (bytes[2] & 0b00111111); + + out_string[string_pos + 0] = EncodeBase64(b0); + out_string[string_pos + 1] = EncodeBase64(b1); + out_string[string_pos + 2] = EncodeBase64(b2); + out_string[string_pos + 3] = EncodeBase64(b3); +} + +std::string EncodeBase64(const char* data, size_t length) +{ + // calculate extra bytes needed to get a multiple of 3 + size_t extraBytes = 3 - length % 3; + + // number of base64 bytes + size_t encodedBytes = 4 * (length + extraBytes) / 3; + + std::string encoded_string(encodedBytes, '='); + + // read blocks of 3 bytes + for (size_t ib3 = 0; ib3 < length / 3; ib3++) + { + const size_t iByte = ib3 * 3; + const size_t iEncodedByte = ib3 * 4; + const char* currData = &data[iByte]; + + EncodeByteBlock(currData, encoded_string, iEncodedByte); + } + + // if size of data is not a multiple of 3, also encode the final bytes (and add zeros where needed) + if (extraBytes > 0) + { + char finalBytes[4] = { 0,0,0,0 }; + memcpy(&finalBytes[0], &data[length - length % 3], length % 3); + + const size_t iEncodedByte = encodedBytes - 4; + EncodeByteBlock(&finalBytes[0], encoded_string, iEncodedByte); + + // add '=' at the end + for (size_t i = 0; i < 4 * extraBytes / 3; i++) + encoded_string[encodedBytes - i - 1] = '='; + } + return encoded_string; +} + } // !Util } // !FBX } // !Assimp diff --git a/code/FBXUtil.h b/code/FBXUtil.h index 6890e015b..b26eba5d5 100644 --- a/code/FBXUtil.h +++ b/code/FBXUtil.h @@ -113,6 +113,15 @@ uint8_t DecodeBase64(char ch); * @return size of the decoded data (number of bytes)*/ size_t DecodeBase64(const char* in, size_t inLength, uint8_t*& out); +char EncodeBase64(char byte); + +/** Encode bytes in base64-encoding +* +* @param data Binary data to encode. +* @param inLength Number of bytes to encode. +* @return base64-encoded string*/ +std::string EncodeBase64(const char* data, size_t length); + } } } diff --git a/include/assimp/scene.h b/include/assimp/scene.h index de0239702..e973f6c5b 100644 --- a/include/assimp/scene.h +++ b/include/assimp/scene.h @@ -389,6 +389,14 @@ struct aiScene //! Returns an embedded texture const aiTexture* GetEmbeddedTexture(const char* filename) const { + // lookup using texture ID (if referenced like: "*1", "*2", etc.) + if ('*' == *filename) { + int index = std::atoi(filename + 1); + if (0 > index || mNumTextures <= static_cast(index)) + return nullptr; + return mTextures[index]; + } + // lookup using filename const char* shortFilename = GetShortFilename(filename); for (unsigned int i = 0; i < mNumTextures; i++) { const char* shortTextureFilename = GetShortFilename(mTextures[i]->mFilename.C_Str()); From 9903504c42f62c8caf1a7ed8a852e1ff8d7ca97f Mon Sep 17 00:00:00 2001 From: Matias Date: Thu, 9 May 2019 14:57:18 +0200 Subject: [PATCH 45/47] Removed some code that I didn't mean to fix (I already submitted this in another PR: https://github.com/assimp/assimp/pull/2450). --- code/FBXExportNode.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/code/FBXExportNode.cpp b/code/FBXExportNode.cpp index 06c89cee4..8cb12d619 100644 --- a/code/FBXExportNode.cpp +++ b/code/FBXExportNode.cpp @@ -253,8 +253,7 @@ void FBX::Node::DumpChildren( } else { std::ostringstream ss; DumpChildrenAscii(ss, indent); - if (ss.tellp() > 0) - s.PutString(ss.str()); + s.PutString(ss.str()); } } @@ -268,8 +267,7 @@ void FBX::Node::End( } else { std::ostringstream ss; EndAscii(ss, indent, has_children); - if (ss.tellp() > 0) - s.PutString(ss.str()); + s.PutString(ss.str()); } } From a44354498690f41d3174b48e0cab75499c70ed19 Mon Sep 17 00:00:00 2001 From: Matias Date: Thu, 9 May 2019 15:28:00 +0200 Subject: [PATCH 46/47] Replaced binary literals with hex literals (since binary literals was introduced in C++14) --- code/FBXUtil.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/FBXUtil.cpp b/code/FBXUtil.cpp index 068683f7d..557d0d843 100644 --- a/code/FBXUtil.cpp +++ b/code/FBXUtil.cpp @@ -170,10 +170,10 @@ char EncodeBase64(char byte) * @param string_pos Position in out_string.*/ void EncodeByteBlock(const char* bytes, std::string& out_string, size_t string_pos) { - char b0 = (bytes[0] & 0b11111100) >> 2; - char b1 = (bytes[0] & 0b00000011) << 4 | ((bytes[1] & 0b11110000) >> 4); - char b2 = (bytes[1] & 0b00001111) << 2 | ((bytes[2] & 0b11000000) >> 6); - char b3 = (bytes[2] & 0b00111111); + char b0 = (bytes[0] & 0xFC) >> 2; + char b1 = (bytes[0] & 0x03) << 4 | ((bytes[1] & 0xF0) >> 4); + char b2 = (bytes[1] & 0x0F) << 2 | ((bytes[2] & 0xC0) >> 6); + char b3 = (bytes[2] & 0x3F); out_string[string_pos + 0] = EncodeBase64(b0); out_string[string_pos + 1] = EncodeBase64(b1); From 700954c11542035a479052ad036ea5ff000e9143 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 10 May 2019 09:09:47 +0200 Subject: [PATCH 47/47] Update FBXExporter.cpp Just fixed some typos. --- code/FBXExporter.cpp | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/code/FBXExporter.cpp b/code/FBXExporter.cpp index 24ae88e6b..ddfac6d34 100644 --- a/code/FBXExporter.cpp +++ b/code/FBXExporter.cpp @@ -1406,30 +1406,25 @@ void FBXExporter::WriteObjects () std::string path = it.first; // try get embedded texture const aiTexture* embedded_texture = mScene->GetEmbeddedTexture(it.first.c_str()); - if (embedded_texture != nullptr) - { - // change the path (use original filename, if available. If name is ampty, concatenate texture index with file extension) + if (embedded_texture != nullptr) { + // change the path (use original filename, if available. If name is empty, concatenate texture index with file extension) std::stringstream newPath; - if (embedded_texture->mFilename.length > 0) + if (embedded_texture->mFilename.length > 0) { newPath << embedded_texture->mFilename.C_Str(); - else if (embedded_texture->achFormatHint[0]) - { + } else if (embedded_texture->achFormatHint[0]) { int texture_index = std::stoi(path.substr(1, path.size() - 1)); newPath << texture_index << "." << embedded_texture->achFormatHint; } path = newPath.str(); // embed the texture size_t texture_size = static_cast(embedded_texture->mWidth * std::max(embedded_texture->mHeight, 1u)); - if (binary) - { + if (binary) { // embed texture as binary data std::vector tex_data; tex_data.resize(texture_size); memcpy(&tex_data[0], (char*)embedded_texture->pcData, texture_size); n.AddChild("Content", tex_data); - } - else - { + } else { // embed texture in base64 encoding std::string encoded_texture = FBX::Util::EncodeBase64((char*)embedded_texture->pcData, texture_size); n.AddChild("Content", encoded_texture); @@ -1447,17 +1442,17 @@ void FBXExporter::WriteObjects () // referenced by material_index/texture_type pairs. std::map,int64_t> texture_uids; const std::map prop_name_by_tt = { - {aiTextureType_DIFFUSE, "DiffuseColor"}, - {aiTextureType_SPECULAR, "SpecularColor"}, - {aiTextureType_AMBIENT, "AmbientColor"}, - {aiTextureType_EMISSIVE, "EmissiveColor"}, - {aiTextureType_HEIGHT, "Bump"}, - {aiTextureType_NORMALS, "NormalMap"}, - {aiTextureType_SHININESS, "ShininessExponent"}, - {aiTextureType_OPACITY, "TransparentColor"}, + {aiTextureType_DIFFUSE, "DiffuseColor"}, + {aiTextureType_SPECULAR, "SpecularColor"}, + {aiTextureType_AMBIENT, "AmbientColor"}, + {aiTextureType_EMISSIVE, "EmissiveColor"}, + {aiTextureType_HEIGHT, "Bump"}, + {aiTextureType_NORMALS, "NormalMap"}, + {aiTextureType_SHININESS, "ShininessExponent"}, + {aiTextureType_OPACITY, "TransparentColor"}, {aiTextureType_DISPLACEMENT, "DisplacementColor"}, //{aiTextureType_LIGHTMAP, "???"}, - {aiTextureType_REFLECTION, "ReflectionColor"} + {aiTextureType_REFLECTION, "ReflectionColor"} //{aiTextureType_UNKNOWN, ""} }; for (size_t i = 0; i < mScene->mNumMaterials; ++i) {