| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include <AzCore/Serialization/SerializeContext.h>
- #include "LayerNode.h"
- #include "Maestro/Types/AnimNodeType.h"
- #include "Maestro/Types/AnimValueType.h"
- #include "Maestro/Types/AnimParamType.h"
- //////////////////////////////////////////////////////////////////////////
- namespace
- {
- bool s_nodeParamsInitialized = false;
- AZStd::vector<CAnimNode::SParamInfo> s_nodeParams;
- void AddSupportedParam(const char* sName, AnimParamType paramId, AnimValueType valueType)
- {
- CAnimNode::SParamInfo param;
- param.name = sName;
- param.paramType = paramId;
- param.valueType = valueType;
- s_nodeParams.push_back(param);
- }
- };
- //-----------------------------------------------------------------------------
- CLayerNode::CLayerNode()
- : CLayerNode(0)
- {
- }
- CLayerNode::CLayerNode(const int id)
- : CAnimNode(id, AnimNodeType::Layer)
- , m_bInit(false)
- , m_bPreVisibility(true)
- {
- CLayerNode::Initialize();
- }
- //-----------------------------------------------------------------------------
- void CLayerNode::Initialize()
- {
- if (!s_nodeParamsInitialized)
- {
- s_nodeParamsInitialized = true;
- s_nodeParams.reserve(1);
- AddSupportedParam("Visibility", AnimParamType::Visibility, AnimValueType::Bool);
- }
- }
- //-----------------------------------------------------------------------------
- void CLayerNode::Animate(SAnimContext& ec)
- {
- int trackCount = NumTracks();
- for (int paramIndex = 0; paramIndex < trackCount; paramIndex++)
- {
- CAnimParamType paramType = m_tracks[paramIndex]->GetParameterType();
- IAnimTrack* pTrack = m_tracks[paramIndex].get();
- if (pTrack->GetNumKeys() == 0)
- {
- continue;
- }
- if (pTrack->GetFlags() & IAnimTrack::eAnimTrackFlags_Disabled)
- {
- continue;
- }
- if (pTrack->IsMasked(ec.trackMask))
- {
- continue;
- }
- switch (paramType.GetType())
- {
- case AnimParamType::Visibility:
- if (!ec.resetting)
- {
- IAnimTrack* visTrack = pTrack;
- bool visible = true;
- visTrack->GetValue(ec.time, visible);
- if (m_bInit)
- {
- if (visible != m_bPreVisibility)
- {
- m_bPreVisibility = visible;
- }
- }
- else
- {
- m_bInit = true;
- m_bPreVisibility = visible;
- }
- }
- break;
- }
- }
- }
- //-----------------------------------------------------------------------------
- void CLayerNode::CreateDefaultTracks()
- {
- CreateTrack(AnimParamType::Visibility);
- }
- //-----------------------------------------------------------------------------
- void CLayerNode::OnReset()
- {
- m_bInit = false;
- }
- //-----------------------------------------------------------------------------
- void CLayerNode::Activate(bool bActivate)
- {
- CAnimNode::Activate(bActivate);
- }
- //-----------------------------------------------------------------------------
- /// @deprecated Serialization for Sequence data in Component Entity Sequences now occurs through AZ::SerializeContext and the Sequence Component
- void CLayerNode::Serialize(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks)
- {
- CAnimNode::Serialize(xmlNode, bLoading, bLoadEmptyTracks);
- //Nothing to be serialized at this moment.
- }
- //-----------------------------------------------------------------------------
- unsigned int CLayerNode::GetParamCount() const
- {
- return static_cast<unsigned int>(s_nodeParams.size());
- }
- //-----------------------------------------------------------------------------
- CAnimParamType CLayerNode::GetParamType(unsigned int nIndex) const
- {
- if (nIndex < (int)s_nodeParams.size())
- {
- return s_nodeParams[nIndex].paramType;
- }
- return AnimParamType::Invalid;
- }
- //-----------------------------------------------------------------------------
- bool CLayerNode::GetParamInfoFromType(const CAnimParamType& paramId, SParamInfo& info) const
- {
- for (unsigned int i = 0; i < s_nodeParams.size(); i++)
- {
- if (s_nodeParams[i].paramType == paramId)
- {
- info = s_nodeParams[i];
- return true;
- }
- }
- return false;
- }
- //////////////////////////////////////////////////////////////////////////
- void CLayerNode::Reflect(AZ::ReflectContext* context)
- {
- if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
- {
- serializeContext->Class<CLayerNode, CAnimNode>()
- ->Version(1);
- }
- }
|