Created
September 6, 2019 10:33
-
-
Save afrostalin/34c9ec77466f3fa6090ae00122cb49ef to your computer and use it in GitHub Desktop.
Snow entity component for CRYENGINE 5.5 - 5.6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (C) 2018-2019 Space Raccoon Game Studio. All rights reserved. Contacts: <[email protected]> | |
// Created by AfroStalin | |
#pragma once | |
#include "StdAfx.h" | |
#include "Snow.h" | |
namespace Game | |
{ | |
Cry::Entity::EventFlags CSnow::GetEventMask() const | |
{ | |
return EEntityEvent::Update | EEntityEvent::Remove | EEntityEvent::Hidden; | |
} | |
void CSnow::ProcessEvent(const SEntityEvent & event) | |
{ | |
switch (event.event) | |
{ | |
case ENTITY_EVENT_UPDATE: | |
{ | |
const Vec3 vCamPos = GetISystem()->GetViewCamera().GetPosition(); | |
Vec3 vR = (GetEntity()->GetWorldPos() - vCamPos) / max(m_options.m_radius, 1e-3f); | |
// todo: only update when things have changed. | |
gEnv->p3DEngine->SetSnowSurfaceParams(GetEntity()->GetWorldPos(), m_options.m_radius, m_options.m_snowAmmount, m_options.m_frostAmmount, m_options.m_surfaceFreezing); | |
gEnv->p3DEngine->SetSnowFallParams(m_options.m_snowFlakeCount, m_options.m_snowFlakeSize, m_options.m_snowFallBrightness, m_options.m_snowFallGravityScale, m_options.m_snowFallWindScale, m_options.m_snowFallTurbulence, m_options.m_snowFallTurbulenceFreq); | |
break; | |
} | |
case ENTITY_EVENT_DONE: | |
case ENTITY_EVENT_HIDE: | |
{ | |
if (gEnv && gEnv->p3DEngine) | |
{ | |
static const Vec3 vZero(ZERO); | |
gEnv->p3DEngine->SetSnowSurfaceParams(vZero, 0, 0, 0, 0); | |
gEnv->p3DEngine->SetSnowFallParams(0, 0, 0, 0, 0, 0, 0); | |
} | |
break; | |
} | |
default: | |
break; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (C) 2018-2019 Space Raccoon Game Studio. All rights reserved. Contacts: <[email protected]> | |
// Created by AfroStalin | |
#pragma once | |
#include <CryEntitySystem/IEntityComponent.h> | |
#include <CryEntitySystem/IEntity.h> | |
namespace Game | |
{ | |
class CSnow final : public IEntityComponent | |
{ | |
public: | |
CSnow() = default; | |
virtual ~CSnow() {}; | |
public: | |
// IEntityComponent | |
virtual Cry::Entity::EventFlags GetEventMask() const override; | |
virtual void ProcessEvent(const SEntityEvent& event) override; | |
// ~IEntityComponent | |
public: | |
static void ReflectType(Schematyc::CTypeDesc<CSnow>& desc) | |
{ | |
desc.SetGUID("{F813DA76-9FE2-421A-9F50-3788A5FF3EC1}"_cry_guid); | |
desc.SetEditorCategory("Game"); | |
desc.SetLabel("Snow"); | |
desc.SetDescription("Snow"); | |
desc.SetComponentFlags({ IEntityComponent::EFlags::Transform }); | |
desc.AddMember(&CSnow::m_options, 'opt', "Options", "Options", "Snow options", CSnow::SOptions()); | |
} | |
struct SOptions | |
{ | |
inline bool operator==(const SOptions &rhs) const { return 0 == memcmp(this, &rhs, sizeof(rhs)); } | |
static void ReflectType(Schematyc::CTypeDesc<SOptions>& desc) | |
{ | |
desc.SetGUID("{1D619FFE-D7A3-4C14-B1C1-6AB15605D950}"_cry_guid); | |
desc.AddMember(&CSnow::SOptions::m_isEnabled, 'enbl', "IsEnabled", "IsEnabled", nullptr, true); | |
desc.AddMember(&CSnow::SOptions::m_radius, 'rads', "Radius", "Radius", nullptr, 50.0f); | |
desc.AddMember(&CSnow::SOptions::m_snowAmmount, 'snam', "SnowAmmount", "SnowAmmount", nullptr, 10.0f); | |
desc.AddMember(&CSnow::SOptions::m_frostAmmount, 'frst', "FrostAmmount", "FrostAmmount", nullptr, 1.0f); | |
desc.AddMember(&CSnow::SOptions::m_surfaceFreezing, 'frs0', "SurfaceFreezing", "SurfaceFreezing", nullptr, 1.0f); | |
desc.AddMember(&CSnow::SOptions::m_snowFlakeCount, 'flkc', "SnowFlakeCount", "SnowFlakeCount", nullptr, 100); | |
desc.AddMember(&CSnow::SOptions::m_snowFlakeSize, 'flk0', "SnowFlakeSize", "SnowFlakeSize", nullptr, 1.0f); | |
desc.AddMember(&CSnow::SOptions::m_snowFallBrightness, 'flbr', "SnowFallBrightness", "SnowFallBrightness", nullptr, 1.0f); | |
desc.AddMember(&CSnow::SOptions::m_snowFallGravityScale, 'flgs', "SnowFallGravityScale", "SnowFallGravityScale", nullptr, 0.1f); | |
desc.AddMember(&CSnow::SOptions::m_snowFallWindScale, 'wnsl', "SnowFallWindScale", "SnowFallWindScale", nullptr, 0.1f); | |
desc.AddMember(&CSnow::SOptions::m_snowFallTurbulence, 'fltb', "SnowFallTurbulence", "SnowFallTurbulence", nullptr, 0.5f); | |
desc.AddMember(&CSnow::SOptions::m_snowFallTurbulenceFreq, 'ftbf', "SnowFallTurbulenceFreq", "SnowFallTurbulenceFreq", nullptr, 0.1f); | |
} | |
bool m_isEnabled = true; | |
float m_radius = 50.0f; | |
float m_snowAmmount = 10.0f; | |
float m_frostAmmount = 1.0f; | |
float m_surfaceFreezing = 1.0f; | |
int m_snowFlakeCount = 100; | |
float m_snowFlakeSize = 1.0f; | |
float m_snowFallBrightness = 1.0f; | |
float m_snowFallGravityScale = 0.1f; | |
float m_snowFallWindScale = 0.1f; | |
float m_snowFallTurbulence = 0.5f; | |
float m_snowFallTurbulenceFreq = 0.1f; | |
}; | |
private: | |
SOptions m_options; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment