Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,89 @@
/*
* 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 <AzCore/Component/Component.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Asset/AssetCommon.h>
class ITexture;
namespace TextureAtlasNamespace
{
//! Struct that represents a slot on a texture atlas
struct AtlasCoordinates
{
AZ_CLASS_ALLOCATOR(AtlasCoordinates, AZ::SystemAllocator, 0);
AZ_TYPE_INFO(AtlasCoordinates, "{FC5D6A60-1056-4F6C-96F7-6A47912F8A35}");
private:
int m_left;
int m_width;
int m_top;
int m_height;
public:
AtlasCoordinates() {}
//! The left-right style is prefferable for input because thats what the asset builder operates with
AtlasCoordinates(int left, int right, int top, int bottom)
{
m_left = left;
m_width = right - left;
m_top = top;
m_height = bottom - top;
}
int GetRight() const { return m_left + m_width; }
void SetRight(int value) { m_width = value - m_left; }
int GetBottom() const { return m_top + m_height; }
void SetBottom(int value) { m_height = value - m_top; }
int GetLeft() const { return m_left; }
void SetLeft(int value) { m_left = value; }
int GetTop() const { return m_top; }
void SetTop(int value) { m_top = value; }
int GetWidth() const { return m_width; }
void SetWidth(int value) { m_width = value; }
int GetHeight() const { return m_height; }
void SetHeight(int value) { m_height = value; }
static void Reflect(AZ::ReflectContext* context);
};
//! An abstract class that exposes atlas pointers to the rest of the codebase
class TextureAtlas
{
public:
AZ_CLASS_ALLOCATOR(TextureAtlas, AZ::SystemAllocator, 0);
AZ_TYPE_INFO(TextureAtlas, "{56FF34CF-7C5B-4BBC-9E2B-AFCA1C6C7561}");
virtual ~TextureAtlas() {}
//! Retrieve a coordinate set from the Atlas by its handle
virtual AtlasCoordinates GetAtlasCoordinates(const AZStd::string& handle) const = 0;
//! Links this atlas to an image pointer
virtual void SetTexture(ITexture* image) = 0;
//! Returns the image linked to this atlas
virtual ITexture* GetTexture() const = 0;
//! Returns the width of the atlas
virtual int GetWidth() const = 0;
//! Returns the height of the atlas
virtual int GetHeight() const = 0;
};
} // namespace TextureAtlasNamespace
@@ -0,0 +1,60 @@
/*
* 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 <AzCore/EBus/EBus.h>
#include <AzCore/Serialization/Utils.h>
#include <AzCore/RTTI/TypeInfo.h>
#include <AzFramework/Asset/SimpleAsset.h>
#include "TextureAtlas/TextureAtlas.h"
namespace TextureAtlasNamespace
{
using AtlasCoordinateSets = AZStd::vector<AZStd::pair<AZStd::string, AtlasCoordinates>>;
class TextureAtlasRequests : public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
//////////////////////////////////////////////////////////////////////////
// Put your public methods here
//! Saves a texture atlas to file
virtual void SaveAtlasToFile(const AZStd::string& outputPath,
AtlasCoordinateSets& handles, int width, int height) = 0;
//! Tells the TextureAtlas system to load an Atlas and return a pointer for the atlas
virtual TextureAtlas* LoadAtlas(const AZStd::string& filePath) = 0;
//! Tells the TextureAtlas system to unload an Atlas
virtual void UnloadAtlas(TextureAtlas* atlas) = 0;
//! Returns a pointer to the first Atlas that contains the image, or nullptr if no atlas contains it.
//! Does not add a reference, use the notification bus to know when to unload
virtual TextureAtlas* FindAtlasContainingImage(const AZStd::string& filePath) = 0;
};
using TextureAtlasRequestBus = AZ::EBus<TextureAtlasRequests>;
class TextureAtlasAsset
{
public:
AZ_TYPE_INFO(TextureAtlasAsset, "{BFC6C91F-66CE-4D78-B68A-7F697C9EA2E8}")
static const char* GetFileFilter() { return "*.texatlas"; }
};
} // namespace TextureAtlasNamespace
@@ -0,0 +1,50 @@
/*
* 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 <AzCore/EBus/EBus.h>
#include <AzCore/Serialization/Utils.h>
#include <AzCore/RTTI/TypeInfo.h>
#include <AzFramework/Asset/SimpleAsset.h>
#include "TextureAtlas/TextureAtlas.h"
namespace TextureAtlasNamespace
{
class TextureAtlasNotifications : public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
//////////////////////////////////////////////////////////////////////////
// Put your public methods here
//! Listener for new atlases being loaded
virtual void OnAtlasLoaded(const TextureAtlas* atlas) = 0;
//! Notify that an atlas is being unloaded
virtual void OnAtlasUnloaded(const TextureAtlas* atlas) = 0;
//! Notify that an atlas is being reloaded
virtual void OnAtlasReloaded(const TextureAtlas* atlas)
{
OnAtlasUnloaded(atlas);
OnAtlasLoaded(atlas);
};
};
using TextureAtlasNotificationBus = AZ::EBus<TextureAtlasNotifications>;
} // namespace TextureAtlasNamespace