Chernecoff's VideoPlayer plugin to Flash MovieClip

#1
Hi all,

I would like to share some code to allow using chernecoff's VideoPlayer plugin to flash, or any other texture content to flash ui. It use just a flownode driving LoadTexIntoMc() function. It is inspired from original Hendrik's flownode for users that know him back in the days !

Here is the code

Code: Select all

#include "StdAfx.h" #include "CryFlowGraph\IFlowBaseNode.h" #include "ActorSystem.h" #include "FlashUI\FlashUI.h" namespace VideoplayerPlugin { class CFlowVideoOutputScaleformMovieClipNode : public CFlowBaseNode<eNCT_Instanced> { private: int m_nID; string m_sName; ITexture* m_pTex; IUIElement* m_pElement; IUIElement* m_pInstance; int m_nInstanceId; enum EInputPorts { EIP_OVERRIDE = 0, EIP_TEXTURENAME, EIP_MOVIECLIP, EIP_INSTANCEID, }; public: CFlowVideoOutputScaleformMovieClipNode(SActivationInfo* pActInfo) { m_nID = -1; m_sName = ""; m_pElement = NULL; m_pInstance = NULL; m_nInstanceId = -1; m_pTex = NULL; } virtual ~CFlowVideoOutputScaleformMovieClipNode() { } virtual IFlowNodePtr Clone(SActivationInfo* pActInfo) { return new CFlowVideoOutputScaleformMovieClipNode(pActInfo); } virtual void GetMemoryUsage(ICrySizer* s) const { s->Add(*this); } void Serialize(SActivationInfo* pActInfo, TSerialize ser) { } virtual void GetConfiguration(SFlowNodeConfig& config) { static const SInputPortConfig inputs[] = { InputPortConfig_Void("Override", _HELP("override material now")), InputPortConfig<string>("TextureName", _HELP("texture name"), "nTextureName"), InputPortConfig<string>("uiMovieclips_MovieClip", "", _HELP("movieclip to be modified"), "sMovieClip", _UICONFIG("")), InputPortConfig<int>("InstanceID", -1, _HELP("Instance ID for the element, -1 = all instances (lazy init), -2 = all initialized instances"), "nInstanceID"), { 0 }, }; config.pInputPorts = inputs; config.pOutputPorts = NULL; config.sDescription = _HELP("Videodestination/Texture for use in Scaleform MovieClips"); config.SetCategory(EFLN_APPROVED); } void TexIntoMc(bool bLoad) { if (m_pElement) { size_t nPos = m_sName.rfind(':'); if (string::npos != nPos) { string sMC = m_sName.substr(nPos + 1); if (m_nInstanceId < 0) { IUIElementIteratorPtr iter = m_pElement->GetInstances(); while (m_pInstance = iter->Next()) { if (m_nInstanceId == -2 && !m_pInstance->IsInit()) { continue; } if (bLoad) { m_pInstance->LoadTexIntoMc(sMC, m_pTex); } else { m_pElement->UnloadTexFromMc(sMC, m_pTex); } } } else if (m_pInstance = m_pElement->GetInstance(m_nInstanceId)) { if (bLoad) { m_pInstance->LoadTexIntoMc(sMC, m_pTex); } else { m_pElement->UnloadTexFromMc(sMC, m_pTex); } } } } } virtual void ProcessEvent(EFlowEvent evt, SActivationInfo* pActInfo) { switch (evt) { case eFE_Suspend: pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false); break; case eFE_Resume: pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, true); break; case eFE_Initialize: break; case eFE_Activate: if (IsPortActive(pActInfo, EIP_OVERRIDE) /*&& !m_pVideo*/) { m_sName = GetPortString(pActInfo, EIP_MOVIECLIP); pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, true); } else { // Set changed properties if (IsPortActive(pActInfo, EIP_TEXTURENAME)) { m_sName = GetPortString(pActInfo, EIP_MOVIECLIP); } } break; case eFE_Update: m_pTex = gEnv->pRenderer->EF_GetTextureByName(GetPortString(pActInfo, EIP_TEXTURENAME)); if (m_pTex) { m_nID = m_pTex->GetTextureID(); size_t nPos = m_sName.rfind(':'); if (string::npos != nPos) { m_pElement = gEnv->pFlashUI->GetUIElement(m_sName.substr(0, nPos).c_str()); m_nInstanceId = GetPortInt(pActInfo, EIP_INSTANCEID); TexIntoMc(true); } } else { pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false); m_pTex = NULL; m_nID = -1; m_pElement = NULL; } break; } } }; } REGISTER_FLOW_NODE_EX("Videoplayer:OutputScaleformMovieClip", VideoplayerPlugin::CFlowVideoOutputScaleformMovieClipNode, CFlowVideoOutputScaleformMovieClipNode);
And a basic usage in flowgraph : Image As you can see VideoPlayer output texture name is the same as Scaleform node N texture name... Of course, you need a declared movie clip in your scene that can embed your content.

Nicolas

Who is online

Users browsing this forum: No registered users and 1 guest