Integrating latest 47acbe8

This commit is contained in:
alexpete
2021-03-25 13:57:57 -07:00
parent 448c549698
commit 75dc720198
10312 changed files with 2711566 additions and 671451 deletions
@@ -11,6 +11,7 @@
*/
#include <assimp/scene.h>
#include <assimp/material.h>
#include <AzCore/Debug/Trace.h>
#include <AzCore/Math/Sha1.h>
#include <AzCore/Debug/Trace.h>
@@ -99,6 +100,105 @@ namespace AZ
return shininess;
}
bool AssImpMaterialWrapper::GetUseColorMap() const
{
// AssImp stores values as floats, so load as float and convert to bool.
float useMap = 0.0f;
if (m_assImpMaterial->Get(AI_MATKEY_USE_COLOR_MAP, useMap) == aiReturn::aiReturn_FAILURE)
{
AZ_Warning(AZ::SceneAPI::Utilities::WarningWindow, false, "Unable to get useColorMap from the material. Using default.");
}
return useMap != 0.0f;
}
AZ::Vector3 AssImpMaterialWrapper::GetBaseColor() const
{
aiColor3D color(1.f, 1.f, 1.f);
if (m_assImpMaterial->Get(AI_MATKEY_BASE_COLOR, color) == aiReturn::aiReturn_FAILURE)
{
// If a base color is not set, fall back to the diffuse color.
// Before PBR support was added, the base color was set to the diffuse color, so
// this will match that behavior.
return GetDiffuseColor();
}
return AZ::Vector3(color.r, color.g, color.b);
}
bool AssImpMaterialWrapper::GetUseMetallicMap() const
{
// AssImp stores values as floats, so load as float and convert to bool.
float useMap = 0.0f;
if (m_assImpMaterial->Get(AI_MATKEY_USE_METALLIC_MAP, useMap) == aiReturn::aiReturn_FAILURE)
{
AZ_Warning(AZ::SceneAPI::Utilities::WarningWindow, false, "Unable to get useMetallicMap from the material. Using default.");
}
return useMap != 0.0f;
}
float AssImpMaterialWrapper::GetMetallicFactor() const
{
float metallic = 0.0f;
if (m_assImpMaterial->Get(AI_MATKEY_METALLIC_FACTOR, metallic) == aiReturn::aiReturn_FAILURE)
{
AZ_Warning(AZ::SceneAPI::Utilities::WarningWindow, false, "Unable to get metallic from the material. Using default.");
}
return metallic;
}
bool AssImpMaterialWrapper::GetUseRoughnessMap() const
{
// AssImp stores values as floats, so load as float and convert to bool.
float useMap = 0.0f;
if (m_assImpMaterial->Get(AI_MATKEY_USE_ROUGHNESS_MAP, useMap) == aiReturn::aiReturn_FAILURE)
{
AZ_Warning(AZ::SceneAPI::Utilities::WarningWindow, false, "Unable to get useRoughnessMap from the material. Using default.");
}
return useMap != 0.0f;
}
float AssImpMaterialWrapper::GetRoughnessFactor() const
{
float roughness = 0.0f;
if (m_assImpMaterial->Get(AI_MATKEY_ROUGHNESS_FACTOR, roughness) == aiReturn::aiReturn_FAILURE)
{
AZ_Warning(AZ::SceneAPI::Utilities::WarningWindow, false, "Unable to get roughness from the material. Using default.");
}
return roughness;
}
bool AssImpMaterialWrapper::GetUseEmissiveMap() const
{
// AssImp stores values as floats, so load as float and convert to bool.
float useMap = 0.0f;
if (m_assImpMaterial->Get(AI_MATKEY_USE_EMISSIVE_MAP, useMap) == aiReturn::aiReturn_FAILURE)
{
AZ_Warning(
AZ::SceneAPI::Utilities::WarningWindow, false, "Unable to get useEmissiveMap from the material. Using default.");
}
return useMap != 0.0f;
}
float AssImpMaterialWrapper::GetEmissiveIntensity() const
{
float emissiveIntensity = 0.0f;
if (m_assImpMaterial->Get(AI_MATKEY_EMISSIVE_INTENSITY, emissiveIntensity) == aiReturn::aiReturn_FAILURE)
{
AZ_Warning(AZ::SceneAPI::Utilities::WarningWindow, false, "Unable to get emissive intensity from the material. Using default.");
}
return emissiveIntensity;
}
bool AssImpMaterialWrapper::GetUseAOMap() const
{
// AssImp stores values as floats, so load as float and convert to bool.
float useMap = 0.0f;
if (m_assImpMaterial->Get(AI_MATKEY_USE_AO_MAP, useMap) == aiReturn::aiReturn_FAILURE)
{
AZ_Warning(AZ::SceneAPI::Utilities::WarningWindow, false, "Unable to get useAOMap from the material. Using default.");
}
return useMap != 0.0f;
}
AZStd::string AssImpMaterialWrapper::GetTextureFileName(MaterialMapType textureType) const
{
/// Engine currently doesn't support multiple textures. Right now we only use first texture.
@@ -130,6 +230,43 @@ namespace AZ
m_assImpMaterial->GetTexture(aiTextureType_NORMALS, textureIndex, &absTexturePath);
}
break;
case MaterialMapType::Metallic:
if (m_assImpMaterial->GetTextureCount(aiTextureType_METALNESS) > textureIndex)
{
m_assImpMaterial->GetTexture(aiTextureType_METALNESS, textureIndex, &absTexturePath);
}
break;
case MaterialMapType::Roughness:
if (m_assImpMaterial->GetTextureCount(aiTextureType_DIFFUSE_ROUGHNESS) > textureIndex)
{
m_assImpMaterial->GetTexture(aiTextureType_DIFFUSE_ROUGHNESS, textureIndex, &absTexturePath);
}
break;
case MaterialMapType::AmbientOcclusion:
if (m_assImpMaterial->GetTextureCount(aiTextureType_AMBIENT_OCCLUSION) > textureIndex)
{
m_assImpMaterial->GetTexture(aiTextureType_AMBIENT_OCCLUSION, textureIndex, &absTexturePath);
}
break;
case MaterialMapType::Emissive:
if (m_assImpMaterial->GetTextureCount(aiTextureType_EMISSION_COLOR) > textureIndex)
{
m_assImpMaterial->GetTexture(aiTextureType_EMISSION_COLOR, textureIndex, &absTexturePath);
}
break;
case MaterialMapType::BaseColor:
if (m_assImpMaterial->GetTextureCount(aiTextureType_BASE_COLOR) > textureIndex)
{
m_assImpMaterial->GetTexture(aiTextureType_BASE_COLOR, textureIndex, &absTexturePath);
}
// If the base color texture isn't available, fall back to using the diffuse texture.
// Before PBR support was added, the renderer just defaulted to using the diffuse texture
// in the base color texture property of the material.
else if (m_assImpMaterial->GetTextureCount(aiTextureType_DIFFUSE) > textureIndex)
{
m_assImpMaterial->GetTexture(aiTextureType_DIFFUSE, textureIndex, &absTexturePath);
}
break;
default:
AZ_TraceContext("Unknown value", aznumeric_cast<int>(textureType));
AZ_TracePrintf(SceneAPI::Utilities::WarningWindow, "Unrecognized MaterialMapType retrieved");
@@ -32,6 +32,16 @@ namespace AZ
float GetOpacity() const override;
float GetShininess() const override;
AZStd::string GetTextureFileName(MaterialMapType textureType) const override;
bool GetUseColorMap() const;
AZ::Vector3 GetBaseColor() const;
bool GetUseMetallicMap() const;
float GetMetallicFactor() const;
bool GetUseRoughnessMap() const;
float GetRoughnessFactor() const;
bool GetUseEmissiveMap() const;
float GetEmissiveIntensity() const;
bool GetUseAOMap() const;
};
} // namespace AssImpSDKWrapper
}// namespace AZ
@@ -65,6 +65,19 @@ namespace AZ
return m_assImpNode->mNumMeshes != 0;
}
bool AssImpNodeWrapper::ContainsBones(const aiScene& scene) const
{
for (unsigned meshIndex = 0; meshIndex < m_assImpNode->mNumMeshes; ++meshIndex)
{
if (scene.mMeshes[m_assImpNode->mMeshes[meshIndex]]->HasBones())
{
return true;
}
}
return false;
}
int AssImpNodeWrapper::GetMaterialCount() const
{
// one mesh uses only a single material
@@ -12,6 +12,9 @@
#pragma once
#include <SceneAPI/SDKWrapper/NodeWrapper.h>
struct aiScene;
namespace AZ
{
namespace AssImpSDKWrapper
@@ -27,6 +30,7 @@ namespace AZ
int GetChildCount() const override;
const std::shared_ptr<NodeWrapper> GetChild(int childIndex) const override;
const bool ContainsMesh();
bool ContainsBones(const aiScene& scene) const;
int GetMaterialCount() const override;
};
} // namespace AssImpSDKWrapper
@@ -38,12 +38,11 @@ namespace AZ
{
AZ_TracePrintf(SceneAPI::Utilities::LogWindow, "AssImpSceneWrapper::LoadSceneFromFile %s", fileName);
AZ_TraceContext("Filename", fileName);
m_importer.SetPropertyBool(AI_CONFIG_IMPORT_FBX_PRESERVE_PIVOTS, false);
m_sceneFileName = fileName;
m_assImpScene = m_importer.ReadFile(fileName,
aiProcess_CalcTangentSpace //Calculates the tangents and bitangents for the imported meshes
| aiProcess_Triangulate //Triangulates all faces of all meshes
aiProcess_Triangulate //Triangulates all faces of all meshes
| aiProcess_JoinIdenticalVertices //Identifies and joins identical vertex data sets for the imported meshes
| aiProcess_SortByPType //Splits meshes with more than one primitive type into homogeneous sub - meshes
| aiProcess_FixInfacingNormals //Fixes inward facing normals, AssImp documentation recommends setting this
| aiProcess_GenNormals); //Generate normals for meshes
if (!m_assImpScene)
{
@@ -44,9 +44,15 @@ namespace AZ
AZStd::pair<AxisVector, int32_t> GetUpVectorAndSign() const;
AZStd::pair<AxisVector, int32_t> GetFrontVectorAndSign() const;
AZStd::string GetSceneFileName() const { return m_sceneFileName; }
protected:
Assimp::Importer m_importer;
// FBX SDK automatically resolved relative paths to textures based on the current file location.
// AssImp does not, so it needs to be specifically handled.
AZStd::string m_sceneFileName;
};
} // namespace AssImpSDKWrapper
@@ -56,5 +56,10 @@ namespace AZ
{
return AZ::SceneAPI::DataTypes::Color(color.r, color.g, color.b, color.a);
}
AZ::Vector3 AssImpTypeConverter::ToVector3(const aiVector3D& vector3)
{
return AZ::Vector3(vector3.x, vector3.y, vector3.z);
}
} //AssImpSDKWrapper
} // namespace AZ
@@ -33,6 +33,7 @@ namespace AZ
static SceneAPI::DataTypes::MatrixType ToTransform(const aiMatrix4x4& matrix);
static SceneAPI::DataTypes::MatrixType ToTransform(const AZ::Matrix4x4& matrix);
static SceneAPI::DataTypes::Color ToColor(const aiColor4D& color);
static AZ::Vector3 ToVector3(const aiVector3D& vector3);
};
} // namespace AssImpSDKWrapper
} // namespace AZ
@@ -18,43 +18,38 @@ namespace AZ
{
MaterialWrapper::MaterialWrapper(fbxsdk::FbxSurfaceMaterial* fbxMaterial)
:m_fbxMaterial(fbxMaterial)
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
, m_assImpMaterial(nullptr)
#endif
{
}
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
MaterialWrapper::MaterialWrapper(aiMaterial* assImpMaterial)
:m_fbxMaterial(nullptr)
, m_assImpMaterial(assImpMaterial)
{
}
#endif
MaterialWrapper::~MaterialWrapper()
{
m_fbxMaterial = nullptr;
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
m_assImpMaterial = nullptr;
#endif
}
fbxsdk::FbxSurfaceMaterial* MaterialWrapper::GetFbxMaterial()
{
return m_fbxMaterial;
}
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
aiMaterial* MaterialWrapper::GetAssImpMaterial()
{
return m_assImpMaterial;
}
#endif
AZStd::string MaterialWrapper::GetName() const
{
return AZStd::string();
}
uint64_t MaterialWrapper::GetUniqueId() const
AZ::u64 MaterialWrapper::GetUniqueId() const
{
return uint64_t();
}
@@ -20,9 +20,8 @@ namespace fbxsdk
class FbxSurfaceMaterial;
}
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
struct aiMaterial;
#endif
namespace AZ
{
@@ -37,22 +36,23 @@ namespace AZ
Diffuse,
Specular,
Bump,
Normal
Normal,
Metallic,
Roughness,
AmbientOcclusion,
Emissive,
BaseColor
};
MaterialWrapper(fbxsdk::FbxSurfaceMaterial* fbxMaterial);
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
MaterialWrapper(aiMaterial* assImpmaterial);
#endif
virtual ~MaterialWrapper();
fbxsdk::FbxSurfaceMaterial* GetFbxMaterial();
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
aiMaterial* GetAssImpMaterial();
#endif
virtual AZStd::string GetName() const;
virtual uint64_t GetUniqueId() const;
virtual AZ::u64 GetUniqueId() const;
virtual AZStd::string GetTextureFileName(MaterialMapType textureType) const;
virtual AZ::Vector3 GetDiffuseColor() const;
virtual AZ::Vector3 GetSpecularColor() const;
@@ -62,9 +62,7 @@ namespace AZ
protected:
fbxsdk::FbxSurfaceMaterial* m_fbxMaterial = nullptr;
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
aiMaterial* m_assImpMaterial = nullptr;
#endif
};
} // namespace SDKMaterial
} // namespace AZ
@@ -18,37 +18,31 @@ namespace AZ
{
NodeWrapper::NodeWrapper(fbxsdk::FbxNode* fbxNode)
:m_fbxNode(fbxNode)
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
, m_assImpNode(nullptr)
#endif
{
}
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
NodeWrapper::NodeWrapper(aiNode* aiNode)
:m_fbxNode(nullptr)
, m_assImpNode(aiNode)
{
}
#endif
NodeWrapper::~NodeWrapper()
{
m_fbxNode = nullptr;
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
m_assImpNode = nullptr;
#endif
}
fbxsdk::FbxNode* NodeWrapper::GetFbxNode()
{
return m_fbxNode;
}
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
aiNode* NodeWrapper::GetAssImpNode()
{
return m_assImpNode;
}
#endif
const char* NodeWrapper::GetName() const
{
+2 -8
View File
@@ -15,9 +15,9 @@ namespace fbxsdk
{
class FbxNode;
}
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
struct aiNode;
#endif
namespace AZ
{
namespace SDKNode
@@ -29,9 +29,7 @@ namespace AZ
NodeWrapper() = default;
NodeWrapper(fbxsdk::FbxNode* fbxNode);
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
NodeWrapper(aiNode* aiNode);
#endif
virtual ~NodeWrapper();
enum CurveNodeComponent
@@ -42,9 +40,7 @@ namespace AZ
};
fbxsdk::FbxNode* GetFbxNode();
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
aiNode* GetAssImpNode();
#endif
virtual const char* GetName() const;
virtual AZ::u64 GetUniqueId() const;
@@ -55,9 +51,7 @@ namespace AZ
fbxsdk::FbxNode* m_fbxNode = nullptr;
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
aiNode* m_assImpNode = nullptr;
#endif
};
} //namespace Node
} //namespace AZ
@@ -1,11 +0,0 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
@@ -1,11 +0,0 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
@@ -1,21 +0,0 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
set(FILES
../../AssImpSceneWrapper.cpp
../../AssImpNodeWrapper.cpp
../../AssImpSceneWrapper.h
../../AssImpNodeWrapper.h
../../AssImpMaterialWrapper.h
../../AssImpMaterialWrapper.cpp
../../AssImpTypeConverter.cpp
../../AssImpTypeConverter.h
)
@@ -19,18 +19,16 @@ namespace AZ
SceneWrapperBase::SceneWrapperBase(fbxsdk::FbxScene* fbxScene)
:m_fbxScene(fbxScene)
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
, m_assImpScene(nullptr)
#endif
{
}
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
SceneWrapperBase::SceneWrapperBase(aiScene* aiScene)
:m_fbxScene(nullptr)
, m_assImpScene(aiScene)
{
}
#endif
bool SceneWrapperBase::LoadSceneFromFile([[maybe_unused]] const char* fileName)
{
@@ -59,12 +57,10 @@ namespace AZ
return m_fbxScene;
}
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
const aiScene* SceneWrapperBase::GetAssImpScene() const
{
return m_assImpScene;
}
#endif
} //namespace Scene
@@ -17,9 +17,9 @@ namespace fbxsdk
{
class FbxScene;
}
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
struct aiScene;
#endif
namespace AZ
{
@@ -32,9 +32,7 @@ namespace AZ
SceneWrapperBase() = default;
SceneWrapperBase(fbxsdk::FbxScene* fbxScene);
virtual ~SceneWrapperBase() = default;
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
SceneWrapperBase(aiScene* aiScene);
#endif
virtual bool LoadSceneFromFile(const char* fileName);
virtual bool LoadSceneFromFile(const AZStd::string& fileName);
@@ -45,14 +43,10 @@ namespace AZ
virtual void Clear();
virtual fbxsdk::FbxScene* GetFbxScene() const;
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
virtual const aiScene* GetAssImpScene() const;
#endif
fbxsdk::FbxScene* m_fbxScene = nullptr;
#ifdef ASSET_IMPORTER_SDK_SUPPORTED_TRAIT
const aiScene* m_assImpScene = nullptr;
#endif
static const char* s_defaultSceneName;
};
@@ -16,4 +16,12 @@ set(FILES
NodeWrapper.cpp
MaterialWrapper.h
MaterialWrapper.cpp
AssImpSceneWrapper.cpp
AssImpNodeWrapper.cpp
AssImpSceneWrapper.h
AssImpNodeWrapper.h
AssImpMaterialWrapper.h
AssImpMaterialWrapper.cpp
AssImpTypeConverter.cpp
AssImpTypeConverter.h
)