/* * 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. * */ #include #include #include #include #include #include #include namespace { const char* s_physicalisedAttributeName = "physicalize"; const char* s_proxyNoDraw = "ProxyNoDraw"; } namespace AZ { namespace FbxSDKWrapper { FbxMaterialWrapper::FbxMaterialWrapper(FbxSurfaceMaterial* fbxMaterial) : m_fbxMaterial(fbxMaterial) { AZ_Assert(fbxMaterial, "Invalid FbxSurfaceMaterial input to initialize FbxMaterialWrapper"); } FbxMaterialWrapper::~FbxMaterialWrapper() { m_fbxMaterial = nullptr; } AZStd::string FbxMaterialWrapper::GetName() const { return m_fbxMaterial->GetInitialName(); } AZ::Vector3 FbxMaterialWrapper::GetDiffuseColor() const { if (m_fbxMaterial->GetClassId().Is(FbxSurfaceLambert::ClassId)) { FbxSurfaceLambert* lambertMat = static_cast(m_fbxMaterial); const FbxDouble3 fbxValue = lambertMat->Diffuse.Get(); const float power = static_cast(lambertMat->DiffuseFactor.Get()); return power * AZ::Vector3(static_cast(fbxValue[0]), static_cast(fbxValue[1]), static_cast(fbxValue[2])); } else if (m_fbxMaterial->GetClassId().Is(FbxSurfacePhong::ClassId)) { FbxSurfacePhong* phongMat = static_cast(m_fbxMaterial); const FbxDouble3 fbxValue = phongMat->Diffuse.Get(); const float power = static_cast(phongMat->DiffuseFactor.Get()); return power * AZ::Vector3(static_cast(fbxValue[0]), static_cast(fbxValue[1]), static_cast(fbxValue[2])); } return AZ::Vector3::CreateOne(); } AZ::Vector3 FbxMaterialWrapper::GetSpecularColor() const { if (m_fbxMaterial->GetClassId().Is(FbxSurfacePhong::ClassId)) { FbxSurfacePhong* phongMat = static_cast(m_fbxMaterial); const FbxDouble3 fbxValue = phongMat->Specular.Get(); const float power = static_cast(phongMat->SpecularFactor.Get()); return power * AZ::Vector3(static_cast(fbxValue[0]), static_cast(fbxValue[1]), static_cast(fbxValue[2])); } return AZ::Vector3::CreateZero(); } AZ::Vector3 FbxMaterialWrapper::GetEmissiveColor() const { if (m_fbxMaterial->GetClassId().Is(FbxSurfaceLambert::ClassId)) { FbxSurfaceLambert* lambertMat = static_cast(m_fbxMaterial); const FbxDouble3 fbxValue = lambertMat->Emissive.Get(); const float power = static_cast(lambertMat->EmissiveFactor.Get()); return power * AZ::Vector3(static_cast(fbxValue[0]), static_cast(fbxValue[1]), static_cast(fbxValue[2])); } else if (m_fbxMaterial->GetClassId().Is(FbxSurfacePhong::ClassId)) { FbxSurfacePhong* phongMat = static_cast(m_fbxMaterial); const FbxDouble3 fbxValue = phongMat->Emissive.Get(); const float power = static_cast(phongMat->EmissiveFactor.Get()); return power * AZ::Vector3(static_cast(fbxValue[0]), static_cast(fbxValue[1]), static_cast(fbxValue[2])); } return AZ::Vector3::CreateZero(); } float FbxMaterialWrapper::GetShininess() const { if (m_fbxMaterial->GetClassId().Is(FbxSurfacePhong::ClassId)) { FbxSurfacePhong* phongMat = static_cast(m_fbxMaterial); return static_cast(phongMat->Shininess.Get()); } return 10.f; } uint64_t FbxMaterialWrapper::GetUniqueId() const { return m_fbxMaterial->GetUniqueID(); } float FbxMaterialWrapper::GetOpacity() const { // FBX materials are erroneously reporting a TransparencyFactor of 1.0 (fully transparent) // even for values that are 0.0 in Maya. It is instead storing it in the components // for TransparentColor, so extract from there instead. if (m_fbxMaterial->GetClassId().Is(FbxSurfaceLambert::ClassId)) { FbxSurfaceLambert* lambertMat = static_cast(m_fbxMaterial); const FbxDouble3 fbxValue = lambertMat->TransparentColor.Get(); return 1.f - AZ::GetMin(AZ::GetMin(static_cast(fbxValue[0]), static_cast(fbxValue[1])), static_cast(fbxValue[2])); } else if (m_fbxMaterial->GetClassId().Is(FbxSurfacePhong::ClassId)) { FbxSurfacePhong* phongMat = static_cast(m_fbxMaterial); const FbxDouble3 fbxValue = phongMat->TransparentColor.Get(); return 1.f - AZ::GetMin(AZ::GetMin(static_cast(fbxValue[0]), static_cast(fbxValue[1])), static_cast(fbxValue[2])); } return 1.f; } AZStd::string FbxMaterialWrapper::GetTextureFileName(const char* textureType) const { FbxFileTexture* fileTexture = nullptr; FbxProperty property = m_fbxMaterial->FindProperty(textureType); FbxDataType propertyType = property.GetPropertyDataType(); /// Engine currently doesn't support multiple textures. Right now we only use first texture of first layer. int layeredTextureCount = property.GetSrcObjectCount(); if (layeredTextureCount > 0) { FbxLayeredTexture* layeredTexture = FbxCast(property.GetSrcObject(0)); int textureCount = layeredTexture->GetSrcObjectCount(); if (textureCount > 0) { fileTexture = FbxCast(layeredTexture->GetSrcObject(0)); } } else { int textureCount = property.GetSrcObjectCount(); if (textureCount > 0) { fileTexture = FbxCast(property.GetSrcObject(0)); } } return fileTexture ? fileTexture->GetFileName() : AZStd::string(); } AZStd::string FbxMaterialWrapper::GetTextureFileName(const AZStd::string& textureType) const { return GetTextureFileName(textureType.c_str()); } AZStd::string FbxMaterialWrapper::GetTextureFileName(MaterialMapType textureType) const { switch (textureType) { case MaterialMapType::Diffuse: return GetTextureFileName(FbxSurfaceMaterial::sDiffuse); case MaterialMapType::Specular: return GetTextureFileName(FbxSurfaceMaterial::sSpecular); case MaterialMapType::Bump: return GetTextureFileName(FbxSurfaceMaterial::sBump); case MaterialMapType::Normal: return GetTextureFileName(FbxSurfaceMaterial::sNormalMap); default: AZ_TraceContext("Unknown value", aznumeric_cast(textureType)); AZ_TracePrintf(SceneAPI::Utilities::WarningWindow, "Unrecognized MaterialMapType retrieved"); return AZStd::string(); } } } // namespace FbxSDKWrapper } // namespace AZ