/* * 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 #include #include #include #include #include #include namespace AZ { namespace SceneAPI { namespace FbxSceneImporter { AssetImporterSettings::AssetImporterSettings() { // Default supported extension in case the settings file isn't found m_supportedFileTypeExtensions.emplace(".fbx"); } void AssetImporterSettings::Reflect(AZ::ReflectContext* context) { if (auto serializeContext = azrtti_cast(context); serializeContext) { serializeContext->Class() ->Version(1) ->Field("SupportedFileTypeExtensions", &AssetImporterSettings::m_supportedFileTypeExtensions); } } void FbxImportRequestHandler::Activate() { // Attempt to load the Slice Builder Settings file AZ::IO::LocalFileIO localFileIO; // This will point to @assets@/SettingsFilename, which loads from the cache // We don't really want this but it works for now // Trying to use AzToolsFramework::AssetSystemRequestBus::Events::GetSourceInfoBySourcePath at this point // would fail because components seem to activate before the AP has populated its file list AZ::IO::Path sliceBuilderSettingsIoPath(SettingsFilename); auto result = AzFramework::FileFunc::ReadJsonFile(sliceBuilderSettingsIoPath, &localFileIO); if (result.IsSuccess()) { AZ::JsonSerializationResult::ResultCode serializationResult = AZ::JsonSerialization::Load(m_settings, result.GetValue()); if (serializationResult.GetProcessing() == AZ::JsonSerializationResult::Processing::Halted) { AZ_Warning("", false, "Error in Asset Importer Settings file.\nUsing default settings."); } } else { AZ_Warning("", false, "Failed to load Asset Importer Settings file.\nUsing default settings."); } BusConnect(); } void FbxImportRequestHandler::Deactivate() { BusDisconnect(); } void FbxImportRequestHandler::Reflect(ReflectContext* context) { AssetImporterSettings::Reflect(context); SerializeContext* serializeContext = azrtti_cast(context); if (serializeContext) { serializeContext->Class()->Version(1)->Attribute( AZ::Edit::Attributes::SystemComponentTags, AZStd::vector({AssetBuilderSDK::ComponentTags::AssetBuilder})); } } void FbxImportRequestHandler::GetSupportedFileExtensions(AZStd::unordered_set& extensions) { extensions.insert(m_settings.m_supportedFileTypeExtensions.begin(), m_settings.m_supportedFileTypeExtensions.end()); } Events::LoadingResult FbxImportRequestHandler::LoadAsset(Containers::Scene& scene, const AZStd::string& path, const Uuid& guid, [[maybe_unused]] RequestingApplication requester) { AZStd::string extension; AzFramework::StringFunc::Path::GetExtension(path.c_str(), extension); if (!m_settings.m_supportedFileTypeExtensions.contains(extension)) { return Events::LoadingResult::Ignored; } scene.SetSource(path, guid); // Push contexts Events::ProcessingResultCombiner contextResult; contextResult += Events::Process(path); contextResult += Events::Process(path, scene); contextResult += Events::Process(scene); if (contextResult.GetResult() == Events::ProcessingResult::Success) { return Events::LoadingResult::AssetLoaded; } else { return Events::LoadingResult::AssetFailure; } } } // namespace Import } // namespace SceneAPI } // namespace AZ