/* * 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. * */ #pragma once #include #include #include #include #include #include namespace EMotionFX { namespace Integration { /** * */ class EMotionFXAsset : public AZ::Data::AssetData { public: AZ_RTTI(EMotionFXAsset, "{043F606A-A483-4910-8110-D8BC4B78922C}", AZ::Data::AssetData) AZ_CLASS_ALLOCATOR(EMotionFXAsset, EMotionFXAllocator, 0) EMotionFXAsset(AZ::Data::AssetId id = AZ::Data::AssetId()) : AZ::Data::AssetData(id) {} AZStd::vector m_emfxNativeData; }; /** * */ template class EMotionFXAssetHandler : public AZ::Data::AssetHandler , private AZ::AssetTypeInfoBus::Handler { public: AZ_CLASS_ALLOCATOR(EMotionFXAssetHandler, EMotionFXAllocator, 0) EMotionFXAssetHandler() { Register(); } ~EMotionFXAssetHandler() override { Unregister(); } AZ::Data::AssetPtr CreateAsset(const AZ::Data::AssetId& id, const AZ::Data::AssetType& type) override { (void)type; return aznew DataType(id); } AZ::Data::AssetId AssetMissingInCatalog(const AZ::Data::Asset& asset) override { // missing assets should at least get escalated to the top of the list. Sub-handlers could override this and do // additional things like substitute some default asset Id. AzFramework::AssetSystemRequestBus::Broadcast(&AzFramework::AssetSystem::AssetSystemRequests::EscalateAssetByUuid, asset.GetId().m_guid); return AZ::Data::AssetId(); } bool LoadAssetData(const AZ::Data::Asset& asset, AZ::IO::GenericStream* stream, const AZ::Data::AssetFilterCB& assetLoadFilterCB) override { (void)assetLoadFilterCB; DataType* assetData = asset.GetAs(); if (stream->GetLength() > 0) { assetData->m_emfxNativeData.resize(stream->GetLength()); stream->Read(stream->GetLength(), assetData->m_emfxNativeData.data()); return true; } return false; } bool LoadAssetData(const AZ::Data::Asset& asset, const char* assetPath, const AZ::Data::AssetFilterCB& assetLoadFilterCB) override { (void)assetLoadFilterCB; AZ::IO::FileIOBase* fileIO = AZ::IO::FileIOBase::GetInstance(); if (fileIO) { AZ::IO::FileIOStream stream(assetPath, AZ::IO::OpenMode::ModeRead); if (stream.IsOpen()) { return LoadAssetData(asset, &stream, assetLoadFilterCB); } } return false; } bool SaveAssetData(const AZ::Data::Asset& asset, AZ::IO::GenericStream* stream) override { (void)asset; (void)stream; AZ_Error("EMotionFX", false, "Asset handler does not support asset saving."); return false; } void DestroyAsset(AZ::Data::AssetPtr ptr) override { delete ptr; } void GetHandledAssetTypes(AZStd::vector& assetTypes) override { assetTypes.push_back(azrtti_typeid()); } void Register() { AZ_Assert(AZ::Data::AssetManager::IsReady(), "Asset database isn't ready!"); AZ::Data::AssetManager::Instance().RegisterHandler(this, azrtti_typeid()); AZ::AssetTypeInfoBus::Handler::BusConnect(azrtti_typeid()); } void Unregister() { AZ::AssetTypeInfoBus::Handler::BusDisconnect(azrtti_typeid()); if (AZ::Data::AssetManager::IsReady()) { AZ::Data::AssetManager::Instance().UnregisterHandler(this); } } void InitAsset(const AZ::Data::Asset& asset, bool loadStageSucceeded, bool isReload) override { if (!loadStageSucceeded || !OnInitAsset(asset)) { AssetHandler::InitAsset(asset, false, isReload); return; } AssetHandler::InitAsset(asset, true, isReload); } virtual bool OnInitAsset(const AZ::Data::Asset& asset) { (void)asset; return true; } const char* GetGroup() const override { return "Animation"; } }; } // namespace Integration } // namespace EMotionFX