/* * 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 namespace SceneBuilder { void SceneSerializationHandler::Activate() { BusConnect(); } void SceneSerializationHandler::Deactivate() { BusDisconnect(); } void SceneSerializationHandler::Reflect(AZ::ReflectContext* context) { AZ::SerializeContext* serializeContext = azrtti_cast(context); if (serializeContext) { serializeContext->Class()->Version(1) ->Attribute(AZ::Edit::Attributes::SystemComponentTags, AZStd::vector({ AssetBuilderSDK::ComponentTags::AssetBuilder })) ; } } AZStd::shared_ptr SceneSerializationHandler::LoadScene( const AZStd::string& filePath, AZ::Uuid sceneSourceGuid) { namespace Utilities = AZ::SceneAPI::Utilities; using AZ::SceneAPI::Events::AssetImportRequest; AZ_TraceContext("File", filePath); if (sceneSourceGuid.IsNull()) { AZ_TracePrintf(Utilities::ErrorWindow, "Invalid source guid for the scene file."); return nullptr; } if (AZ::SceneAPI::Events::AssetImportRequest::IsManifestExtension(filePath.c_str())) { AZ_TracePrintf(Utilities::ErrorWindow, "Provided path contains the manifest path, not the path to the source file."); return nullptr; } if (!AZ::SceneAPI::Events::AssetImportRequest::IsSceneFileExtension(filePath.c_str())) { AZ_TracePrintf(Utilities::ErrorWindow, "Provided path doesn't contain an extension supported by the SceneAPI."); return nullptr; } if (AzFramework::StringFunc::Path::IsRelative(filePath.c_str())) { AZ_TracePrintf(Utilities::ErrorWindow, "Given file path is relative where an absolute path was expected."); return nullptr; } if (!AZ::IO::SystemFile::Exists(filePath.c_str())) { AZ_TracePrintf(Utilities::ErrorWindow, "No file exists at given source path."); return nullptr; } AZStd::shared_ptr scene = AssetImportRequest::LoadSceneFromVerifiedPath(filePath, sceneSourceGuid, AssetImportRequest::RequestingApplication::AssetProcessor); if (!scene) { AZ_TracePrintf(Utilities::ErrorWindow, "Failed to load the requested scene."); return nullptr; } return scene; } } // namespace SceneBuilder