Merge branch 'master' into master

pull/4481/head
Kim Kulling 2022-04-19 15:23:09 +02:00 committed by GitHub
commit 7f913c180b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 161 additions and 54 deletions

View File

@ -47,6 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/types.h> #include <assimp/types.h>
#include <map> #include <map>
#include <vector> #include <vector>
#include "Common/Maybe.h"
namespace Assimp { namespace Assimp {
namespace ObjFile { namespace ObjFile {
@ -183,15 +184,15 @@ struct Material {
aiColor3D transparent; aiColor3D transparent;
//! PBR Roughness //! PBR Roughness
ai_real roughness; Maybe<ai_real> roughness;
//! PBR Metallic //! PBR Metallic
ai_real metallic; Maybe<ai_real> metallic;
//! PBR Metallic //! PBR Metallic
aiColor3D sheen; Maybe<aiColor3D> sheen;
//! PBR Clearcoat Thickness //! PBR Clearcoat Thickness
ai_real clearcoat_thickness; Maybe<ai_real> clearcoat_thickness;
//! PBR Clearcoat Rougness //! PBR Clearcoat Rougness
ai_real clearcoat_roughness; Maybe<ai_real> clearcoat_roughness;
//! PBR Anisotropy //! PBR Anisotropy
ai_real anisotropy; ai_real anisotropy;
@ -206,11 +207,11 @@ struct Material {
illumination_model(1), illumination_model(1),
ior(ai_real(1.0)), ior(ai_real(1.0)),
transparent(ai_real(1.0), ai_real(1.0), ai_real(1.0)), transparent(ai_real(1.0), ai_real(1.0), ai_real(1.0)),
roughness(ai_real(1.0)), roughness(),
metallic(ai_real(0.0)), metallic(),
sheen(ai_real(1.0), ai_real(1.0), ai_real(1.0)), sheen(),
clearcoat_thickness(ai_real(0.0)), clearcoat_thickness(),
clearcoat_roughness(ai_real(0.0)), clearcoat_roughness(),
anisotropy(ai_real(0.0)), anisotropy(ai_real(0.0)),
bump_multiplier(ai_real(1.0)) { bump_multiplier(ai_real(1.0)) {
std::fill_n(clamp, static_cast<unsigned int>(TextureTypeCount), false); std::fill_n(clamp, static_cast<unsigned int>(TextureTypeCount), false);

View File

@ -616,11 +616,16 @@ void ObjFileImporter::createMaterials(const ObjFile::Model *pModel, aiScene *pSc
mat->AddProperty(&pCurrentMaterial->shineness, 1, AI_MATKEY_SHININESS); mat->AddProperty(&pCurrentMaterial->shineness, 1, AI_MATKEY_SHININESS);
mat->AddProperty(&pCurrentMaterial->alpha, 1, AI_MATKEY_OPACITY); mat->AddProperty(&pCurrentMaterial->alpha, 1, AI_MATKEY_OPACITY);
mat->AddProperty(&pCurrentMaterial->transparent, 1, AI_MATKEY_COLOR_TRANSPARENT); mat->AddProperty(&pCurrentMaterial->transparent, 1, AI_MATKEY_COLOR_TRANSPARENT);
mat->AddProperty(&pCurrentMaterial->roughness, 1, AI_MATKEY_ROUGHNESS_FACTOR); if (pCurrentMaterial->roughness)
mat->AddProperty(&pCurrentMaterial->metallic, 1, AI_MATKEY_METALLIC_FACTOR); mat->AddProperty(&pCurrentMaterial->roughness.Get(), 1, AI_MATKEY_ROUGHNESS_FACTOR);
mat->AddProperty(&pCurrentMaterial->sheen, 1, AI_MATKEY_SHEEN_COLOR_FACTOR); if (pCurrentMaterial->metallic)
mat->AddProperty(&pCurrentMaterial->clearcoat_thickness, 1, AI_MATKEY_CLEARCOAT_FACTOR); mat->AddProperty(&pCurrentMaterial->metallic.Get(), 1, AI_MATKEY_METALLIC_FACTOR);
mat->AddProperty(&pCurrentMaterial->clearcoat_roughness, 1, AI_MATKEY_CLEARCOAT_ROUGHNESS_FACTOR); if (pCurrentMaterial->sheen)
mat->AddProperty(&pCurrentMaterial->sheen.Get(), 1, AI_MATKEY_SHEEN_COLOR_FACTOR);
if (pCurrentMaterial->clearcoat_thickness)
mat->AddProperty(&pCurrentMaterial->clearcoat_thickness.Get(), 1, AI_MATKEY_CLEARCOAT_FACTOR);
if (pCurrentMaterial->clearcoat_roughness)
mat->AddProperty(&pCurrentMaterial->clearcoat_roughness.Get(), 1, AI_MATKEY_CLEARCOAT_ROUGHNESS_FACTOR);
mat->AddProperty(&pCurrentMaterial->anisotropy, 1, AI_MATKEY_ANISOTROPY_FACTOR); mat->AddProperty(&pCurrentMaterial->anisotropy, 1, AI_MATKEY_ANISOTROPY_FACTOR);
// Adding refraction index // Adding refraction index

View File

@ -205,7 +205,7 @@ void ObjFileMtlImporter::load() {
break; break;
case 's': case 's':
++m_DataIt; ++m_DataIt;
getColorRGBA(&m_pModel->m_pCurrentMaterial->sheen); getColorRGBA(m_pModel->m_pCurrentMaterial->sheen);
break; break;
case 'c': case 'c':
++m_DataIt; ++m_DataIt;
@ -268,6 +268,12 @@ void ObjFileMtlImporter::getColorRGBA(aiColor3D *pColor) {
pColor->b = b; pColor->b = b;
} }
void ObjFileMtlImporter::getColorRGBA(Maybe<aiColor3D> &value) {
aiColor3D v;
getColorRGBA(&v);
value = Maybe<aiColor3D>(v);
}
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Loads the kind of illumination model. // Loads the kind of illumination model.
void ObjFileMtlImporter::getIlluminationModel(int &illum_model) { void ObjFileMtlImporter::getIlluminationModel(int &illum_model) {
@ -275,6 +281,7 @@ void ObjFileMtlImporter::getIlluminationModel(int &illum_model) {
illum_model = atoi(&m_buffer[0]); illum_model = atoi(&m_buffer[0]);
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Loads a single float value. // Loads a single float value.
void ObjFileMtlImporter::getFloatValue(ai_real &value) { void ObjFileMtlImporter::getFloatValue(ai_real &value) {
@ -288,6 +295,15 @@ void ObjFileMtlImporter::getFloatValue(ai_real &value) {
value = (ai_real)fast_atof(&m_buffer[0]); value = (ai_real)fast_atof(&m_buffer[0]);
} }
void ObjFileMtlImporter::getFloatValue(Maybe<ai_real> &value) {
m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, &m_buffer[0], BUFFERSIZE);
size_t len = std::strlen(&m_buffer[0]);
if (len)
value = Maybe<ai_real>(fast_atof(&m_buffer[0]));
else
value = Maybe<ai_real>();
}
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Creates a material from loaded data. // Creates a material from loaded data.
void ObjFileMtlImporter::createMaterial() { void ObjFileMtlImporter::createMaterial() {

View File

@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/defs.h> #include <assimp/defs.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include "Common/Maybe.h"
struct aiColor3D; struct aiColor3D;
struct aiString; struct aiString;
@ -81,10 +82,12 @@ private:
void load(); void load();
/// Get color data. /// Get color data.
void getColorRGBA(aiColor3D *pColor); void getColorRGBA(aiColor3D *pColor);
void getColorRGBA(Maybe<aiColor3D> &value);
/// Get illumination model from loaded data /// Get illumination model from loaded data
void getIlluminationModel(int &illum_model); void getIlluminationModel(int &illum_model);
/// Gets a float value from data. /// Gets a float value from data.
void getFloatValue(ai_real &value); void getFloatValue(ai_real &value);
void getFloatValue(Maybe<ai_real> &value);
/// Creates a new material from loaded data. /// Creates a new material from loaded data.
void createMaterial(); void createMaterial();
/// Get texture name from loaded data. /// Get texture name from loaded data.

View File

@ -606,7 +606,10 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
} }
} }
if (needTangents) { if (needTangents) {
if (target.tangent[0]->count != aim->mNumVertices) { if (!aiAnimMesh.HasNormals()) {
// prevent nullptr access to aiAnimMesh.mNormals below when no normals are available
ASSIMP_LOG_WARN("Bitangents of target ", i, " in mesh \"", mesh.name, "\" can't be computed, because mesh has no normals.");
} else if (target.tangent[0]->count != aim->mNumVertices) {
ASSIMP_LOG_WARN("Tangents of target ", i, " in mesh \"", mesh.name, "\" does not match the vertex count"); ASSIMP_LOG_WARN("Tangents of target ", i, " in mesh \"", mesh.name, "\" does not match the vertex count");
} else { } else {
Tangent *tangent = nullptr; Tangent *tangent = nullptr;

View File

@ -182,6 +182,7 @@ SET( Common_SRCS
Common/DefaultIOSystem.cpp Common/DefaultIOSystem.cpp
Common/ZipArchiveIOSystem.cpp Common/ZipArchiveIOSystem.cpp
Common/PolyTools.h Common/PolyTools.h
Common/Maybe.h
Common/Importer.cpp Common/Importer.cpp
Common/IFF.h Common/IFF.h
Common/SGSpatialSort.cpp Common/SGSpatialSort.cpp

View File

@ -0,0 +1,29 @@
#pragma once
#include <assimp/ai_assert.h>
template <typename T>
struct Maybe {
private:
T _val;
bool _valid;
public:
Maybe() :
_valid(false) {}
explicit Maybe(const T &val) :
_val(val), _valid(true) {
}
operator bool() const {
return _valid;
}
const T &Get() const {
ai_assert(_valid);
return _val;
}
private:
Maybe &operator&() = delete;
};

View File

@ -0,0 +1 @@
output

View File

@ -1,28 +1,76 @@
@echo off @echo off
set ASSIMP_PATH=D:\projects\asset-importer-lib\assimp set ANDROID_PLATFORM=21
set CMAKE_PATH="C:\Program Files\CMake\bin\cmake.exe" set /p ANDROID_PLATFORM="Enter Android platform - Enter to use %ANDROID_PLATFORM%: "
set ANDROID_NDK_PATH=C:\Users\kimkulling\AppData\Local\Android\Sdk\ndk-bundle
set ANDROID_CMAKE_PATH=contrib\android-cmake
pushd %ASSIMP_PATH% set ANDROID_ABI=armeabi-v7a
set /p ANDROID_ABI="Enter Android ABI ( armeabi-v7a, arm64-v8a , x86 , x86_64 ) - Enter to use %ANDROID_ABI% : "
rmdir /s /q build set COMMON_CXX_FLAGS=-DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fexceptions -frtti -stdlib=libc++
mkdir build set COMMON_C_FLAGS=-DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fexceptions
cd build
%CMAKE_PATH% .. ^ if %ANDROID_ABI% == armeabi-v7a (
-G"MinGW Makefiles" ^ set CXX_FLAGS="%COMMON_CXX_FLAGS% -march=armv7-a -mthumb --target=armv7-none-linux-androideabi%ANDROID_PLATFORM%"
set C_FLAGS="%COMMON_C_FLAGS% -march=armv7-a -mthumb --target=armv7-none-linux-androideabi%ANDROID_PLATFORM%"
)
if %ANDROID_ABI% == arm64-v8a (
set CXX_FLAGS="%COMMON_CXX_FLAGS% -march=armv8-a --target=aarch64-none-linux-android%ANDROID_PLATFORM%"
set C_FLAGS="%COMMON_C_FLAGS% -march=armv8-a --target=aarch64-none-linux-android%ANDROID_PLATFORM%"
)
if %ANDROID_ABI% == x86 (
set CXX_FLAGS="%COMMON_CXX_FLAGS% --target=i686-none-linux-android%ANDROID_PLATFORM%"
set C_FLAGS="%COMMON_C_FLAGS% --target=i686-none-linux-android%ANDROID_PLATFORM%"
)
if %ANDROID_ABI% == x86_64 (
set CXX_FLAGS="%COMMON_CXX_FLAGS%"
set C_FLAGS="%COMMON_C_FLAGS%"
)
set CMAKE_PATH="%ProgramFiles%\CMake\bin\cmake.exe"
if exist %CMAKE_PATH% (
echo Found cmake at %CMAKE_PATH%
) else (
set /p CMAKE_PATH="Enter cmake.exe path: "
)
set ANDROID_NDK_PATH=""
FOR /F "tokens=* USEBACKQ" %%F IN (`dir "%LocalAppData%\Android\Sdk\ndk" /b /o:n /a:d`) DO (
SET ANDROID_NDK_PATH="%LocalAppData%\Android\Sdk\ndk\%%F"
)
if exist %ANDROID_NDK_PATH% (
echo Found NDK at %ANDROID_NDK_PATH%
) else (
set /p ANDROID_NDK_PATH="Enter ndk path: "
)
set BUILD_FOLDER=build
rmdir /s /q %BUILD_FOLDER%
mkdir %BUILD_FOLDER%
%CMAKE_PATH% ^
-G"Unix Makefiles" ^
-DCMAKE_BUILD_TYPE=Release ^ -DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_TOOLCHAIN_FILE=%ANDROID_CMAKE_PATH%\android.toolchain.cmake ^ -DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK_PATH%\build\cmake\android.toolchain.cmake ^
-DCMAKE_MAKE_PROGRAM=%ANDROID_NDK_PATH%\prebuilt\windows-x86_64\bin\make.exe ^ -DCMAKE_MAKE_PROGRAM=%ANDROID_NDK_PATH%\prebuilt\windows-x86_64\bin\make.exe ^
-DANDROID_NDK=%ANDROID_NDK_PATH% ^ -DANDROID_NDK=%ANDROID_NDK_PATH% ^
-DANDROID_NATIVE_API_LEVEL=android-9 ^ -DOPERATING_SYSTEM="Android" ^
-DANDROID_PLATFORM=%ANDROID_PLATFORM% ^
-DANDROID_ABI=%ANDROID_ABI% ^
-DASSIMP_ANDROID_JNIIOSYSTEM=ON ^ -DASSIMP_ANDROID_JNIIOSYSTEM=ON ^
-DANDROID_ABI=arm64-v8a ^ -DASSIMP_BUILD_TESTS=OFF ^
-DASSIMP_BUILD_ZLIB=ON ^ -DCMAKE_CXX_FLAGS=%CXX_FLAGS% ^
-DASSIMP_BUILD_TESTS=OFF -DMAKE_C_FLAGS=%C_FLAGS% ^
-S "..\.." ^
-B ".\%BUILD_FOLDER%\"
%CMAKE_PATH% --build . %CMAKE_PATH% --build ".\%BUILD_FOLDER%\"" -- -j 4"
popd set OUTPUT_FOLDER=.\output\
mkdir %OUTPUT_FOLDER%
mkdir "%OUTPUT_FOLDER%\lib\%ANDROID_ABI%"
copy "%BUILD_FOLDER%\bin\libassimp.so" "%OUTPUT_FOLDER%\lib\%ANDROID_ABI%\"
xcopy %BUILD_FOLDER%\include\assimp\ %OUTPUT_FOLDER%\include\assimp\ /y /s /e
xcopy ..\..\include\assimp\ %OUTPUT_FOLDER%\include\assimp\ /y /s /e
rmdir /s /q %BUILD_FOLDER%