/* * 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 // Needed for CGFContent.h #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace AZ { namespace RC { namespace SceneUtil = AZ::SceneAPI::Utilities; namespace SceneContainer = AZ::SceneAPI::Containers; namespace SceneDataTypes = AZ::SceneAPI::DataTypes; const AZStd::string SkinLodExporter::s_fileExtension = "skin"; SkinLodExporter::SkinLodExporter(IAssetWriter* writer, IConvertContext* convertContext) : m_assetWriter(writer) , m_convertContext(convertContext) { BindToCall(&SkinLodExporter::ProcessContext); ActivateBindings(); } SceneEvents::ProcessingResult SkinLodExporter::ProcessContext(SkinGroupExportContext& context) const { if (context.m_phase != Phase::Filling) { return SceneEvents::ProcessingResult::Ignored; } AZStd::shared_ptr lodRule = context.m_group.GetRuleContainerConst().FindFirstByType(); if (!lodRule) { return SceneEvents::ProcessingResult::Ignored; } SceneEvents::ProcessingResultCombiner result; for (size_t index = 0; index < lodRule->GetLodCount(); ++index) { AZ_TraceContext("Skin lod level", static_cast(index)); AZStd::string filename = SceneUtil::FileUtilities::CreateOutputFileName( context.m_group.GetName() + "_LOD" + AZStd::to_string(static_cast(index + 1)), context.m_outputDirectory, s_fileExtension); AZ_TraceContext("Skin lod filename", filename); if (filename.empty() || !SceneUtil::FileUtilities::EnsureTargetFolderExists(filename)) { AZ_TracePrintf(AZ::SceneAPI::Utilities::ErrorWindow, "Invalid file name for skin"); result += SceneEvents::ProcessingResult::Failure; break; } CContentCGF cgfContent(filename.c_str()); ConfigureSkinContent(cgfContent); // Process mesh // For each selected mesh, find its skinned skeleton's root bone. Make sure the root bone is consistent through all selected skin meshes. const SceneContainer::SceneGraph& graph = context.m_scene.GetGraph(); AZStd::vector targetNodes = SceneUtil::SceneGraphSelector::GenerateTargetNodes(graph, lodRule->GetSceneNodeSelectionList(index), SceneUtil::SceneGraphSelector::IsMesh); result += ProcessSkins(context, cgfContent, targetNodes); if (m_assetWriter) { if (m_assetWriter->WriteSKIN(&cgfContent, m_convertContext, false)) { static const AZ::Data::AssetType skinnedMeshLodsAssetType("{58E5824F-C27B-46FD-AD48-865BA41B7A51}"); // Using the same guid as the parent group/cgf as this needs to be a lod of that cgf. // Setting the lod to index+1 as 0 means the base mesh and 1-6 are lod levels 0-5. context.m_products.AddProduct(AZStd::move(filename), context.m_group.GetId(), skinnedMeshLodsAssetType, index + 1, AZStd::nullopt); } else { AZ_TracePrintf(AZ::SceneAPI::Utilities::ErrorWindow, "Writing Skin has failed."); result += SceneEvents::ProcessingResult::Failure; break; } } else { AZ_TracePrintf(AZ::SceneAPI::Utilities::ErrorWindow, "No asset writer found. Unable to write skin to disk"); result += SceneEvents::ProcessingResult::Failure; break; } } return result.GetResult(); } } // namespace RC } // namespace AZ