BVB Source Codes

CRYENGINE Show MFXDecalEffect.cpp Source code

Return Download CRYENGINE: download MFXDecalEffect.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  File name:   MFXDecalEffect.cpp
  5. //  Version:     v1.00
  6. //  Created:     28/11/2006 by JohnN/AlexL
  7. //  Compilers:   Visual Studio.NET
  8. //  Description: Decal effect
  9. // -------------------------------------------------------------------------
  10. //  History:
  11. //
  12. ////////////////////////////////////////////////////////////////////////////
  13. #include "StdAfx.h"
  14. #include "MFXDecalEffect.h"
  15.  
  16. CMFXDecalEffect::CMFXDecalEffect()
  17.         : CMFXEffectBase(eMFXPF_Decal)
  18.         , m_decalParams()
  19.         , m_material(0)
  20. {
  21. }
  22.  
  23. CMFXDecalEffect::~CMFXDecalEffect()
  24. {
  25.         ReleaseMaterial();
  26. }
  27.  
  28. void CMFXDecalEffect::LoadParamsFromXml(const XmlNodeRef& paramsNode)
  29. {
  30.         // Xml data format
  31.         /*
  32.            <Decal minScale="..." maxscale="..." rotation="..." growTime="..." assembledecals="..." forceedge="..." lifetime="..." >
  33.            <Material>MaterialToUse</Material>
  34.            </Decal>
  35.          */
  36.  
  37.         XmlNodeRef material = paramsNode->findChild("Material");
  38.         if (material)
  39.         {
  40.                 m_decalParams.material = material->getContent();
  41.         }
  42.  
  43.         m_decalParams.minscale = 1.f;
  44.         m_decalParams.maxscale = 1.f;
  45.         m_decalParams.rotation = -1.f;
  46.         m_decalParams.growTime = 0.f;
  47.         m_decalParams.assemble = false;
  48.         m_decalParams.lifetime = 10.0f;
  49.         m_decalParams.forceedge = false;
  50.  
  51.         paramsNode->getAttr("minscale", m_decalParams.minscale);
  52.         paramsNode->getAttr("maxscale", m_decalParams.maxscale);
  53.  
  54.         paramsNode->getAttr("rotation", m_decalParams.rotation);
  55.         m_decalParams.rotation = DEG2RAD(m_decalParams.rotation);
  56.  
  57.         paramsNode->getAttr("growTime", m_decalParams.growTime);
  58.         paramsNode->getAttr("assembledecals", m_decalParams.assemble);
  59.         paramsNode->getAttr("forceedge", m_decalParams.forceedge);
  60.         paramsNode->getAttr("lifetime", m_decalParams.lifetime);
  61. }
  62.  
  63. void CMFXDecalEffect::PreLoadAssets()
  64. {
  65.         if (m_decalParams.material.c_str())
  66.         {
  67.                 // store as smart pointer
  68.                 m_material = gEnv->p3DEngine->GetMaterialManager()->LoadMaterial(
  69.                   m_decalParams.material.c_str(), false);
  70.         }
  71. }
  72.  
  73. void CMFXDecalEffect::ReleasePreLoadAssets()
  74. {
  75.         ReleaseMaterial();
  76. }
  77.  
  78. void CMFXDecalEffect::ReleaseMaterial()
  79. {
  80.         // Release material (smart pointer)
  81.         m_material = 0;
  82. }
  83.  
  84. void CMFXDecalEffect::Execute(const SMFXRunTimeEffectParams& params)
  85. {
  86.         FUNCTION_PROFILER(gEnv->pSystem, PROFILE_ACTION);
  87.  
  88.         const float angle = (params.angle != MFX_INVALID_ANGLE) ? params.angle : cry_random(0.f, gf_PI2);
  89.  
  90.         if (!params.trgRenderNode && !params.trg)
  91.         {
  92.                 CryEngineDecalInfo terrainDecal;
  93.  
  94.                 {
  95.                         // 2d terrain
  96.                         const float terrainHeight(gEnv->p3DEngine->GetTerrainElevation(params.pos.x, params.pos.y));
  97.                         const float terrainDelta(params.pos.z - terrainHeight);
  98.  
  99.                         if (terrainDelta > 2.0f || terrainDelta < -0.5f)
  100.                                 return;
  101.  
  102.                         terrainDecal.vPos = Vec3(params.decalPos.x, params.decalPos.y, terrainHeight);
  103.                 }
  104.  
  105.                 terrainDecal.vNormal = params.normal;
  106.                 terrainDecal.vHitDirection = params.dir[0].GetNormalized();
  107.                 terrainDecal.fLifeTime = m_decalParams.lifetime;
  108.                 terrainDecal.fGrowTime = m_decalParams.growTime;
  109.  
  110.                 if (!m_decalParams.material.empty())
  111.                         cry_strcpy(terrainDecal.szMaterialName, m_decalParams.material.c_str());
  112.                 else
  113.                         CryWarning(VALIDATOR_MODULE_3DENGINE, VALIDATOR_WARNING, "CMFXDecalEffect::Execute: Decal material name is not specified");
  114.  
  115.                 terrainDecal.fSize = cry_random(m_decalParams.minscale, m_decalParams.maxscale);
  116.  
  117.                 if (m_decalParams.rotation >= 0.f)
  118.                         terrainDecal.fAngle = m_decalParams.rotation;
  119.                 else
  120.                         terrainDecal.fAngle = angle;
  121.  
  122.                 if (terrainDecal.fSize <= params.fDecalPlacementTestMaxSize)
  123.                         gEnv->p3DEngine->CreateDecal(terrainDecal);
  124.         }
  125.         else
  126.         {
  127.                 CryEngineDecalInfo decal;
  128.  
  129.                 IEntity* pEnt = gEnv->pEntitySystem->GetEntity(params.trg);
  130.                 IRenderNode* pRenderNode = NULL;
  131.                 if (pEnt)
  132.                 {
  133.                         IEntityRender* pIEntityRender = pEnt->GetRenderInterface();
  134.                        
  135.                                 pRenderNode = pIEntityRender->GetRenderNode();
  136.                 }
  137.                 else
  138.                 {
  139.                         pRenderNode = params.trgRenderNode;
  140.                 }
  141.  
  142.                 // filter out ropes
  143.                 if (pRenderNode && pRenderNode->GetRenderNodeType() == eERType_Rope)
  144.                         return;
  145.  
  146.                 decal.ownerInfo.pRenderNode = pRenderNode;
  147.  
  148.                 decal.vPos = params.pos;
  149.                 decal.vNormal = params.normal;
  150.                 decal.vHitDirection = params.dir[0].GetNormalized();
  151.                 decal.fLifeTime = m_decalParams.lifetime;
  152.                 decal.fGrowTime = m_decalParams.growTime;
  153.                 decal.bAssemble = m_decalParams.assemble;
  154.                 decal.bForceEdge = m_decalParams.forceedge;
  155.  
  156.                 if (!m_decalParams.material.empty())
  157.                         cry_strcpy(decal.szMaterialName, m_decalParams.material.c_str());
  158.                 else
  159.                         CryWarning(VALIDATOR_MODULE_3DENGINE, VALIDATOR_WARNING, "CMFXDecalEffect::Execute: Decal material name is not specified");
  160.  
  161.                 decal.fSize = cry_random(m_decalParams.minscale, m_decalParams.maxscale);
  162.                 if (m_decalParams.rotation >= 0.f)
  163.                         decal.fAngle = m_decalParams.rotation;
  164.                 else
  165.                         decal.fAngle = angle;
  166.  
  167.                 if (decal.fSize <= params.fDecalPlacementTestMaxSize)
  168.                         gEnv->p3DEngine->CreateDecal(decal);
  169.         }
  170. }
  171.  
  172. void CMFXDecalEffect::GetResources(SMFXResourceList& resourceList) const
  173. {
  174.         SMFXDecalListNode* listNode = SMFXDecalListNode::Create();
  175.         listNode->m_decalParams.material = m_decalParams.material.c_str();
  176.         listNode->m_decalParams.minscale = m_decalParams.minscale;
  177.         listNode->m_decalParams.maxscale = m_decalParams.maxscale;
  178.         listNode->m_decalParams.rotation = m_decalParams.rotation;
  179.         listNode->m_decalParams.assemble = m_decalParams.assemble;
  180.         listNode->m_decalParams.forceedge = m_decalParams.forceedge;
  181.         listNode->m_decalParams.lifetime = m_decalParams.lifetime;
  182.  
  183.         SMFXDecalListNode* next = resourceList.m_decalList;
  184.  
  185.         if (!next)
  186.                 resourceList.m_decalList = listNode;
  187.         else
  188.         {
  189.                 while (next->pNext)
  190.                         next = next->pNext;
  191.  
  192.                 next->pNext = listNode;
  193.         }
  194. }
  195.  
  196. void CMFXDecalEffect::GetMemoryUsage(ICrySizer* pSizer) const
  197. {
  198.         pSizer->AddObject(this, sizeof(*this));
  199.         pSizer->AddObject(m_decalParams.material);
  200. }
  201.  
downloadMFXDecalEffect.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top