# Khaotic Engine Reborn: ecs::RenderComponent Class Reference

Loading...
Searching...
No Matches
ecs::RenderComponent Class Reference
Inheritance diagram for ecs::RenderComponent:

## Public Member Functions

| RenderComponent ()
void | Initialize () override
void | Update (float deltaTime) override
bool | InitializeWithModel (std::shared_ptr< model_class > model)
bool | InitializeFromFile (ID3D11Device *device, ID3D11DeviceContext *deviceContext, const char *modelFilename, TextureContainer &textureContainer)
bool | LoadTexturesFromPath (std::vector< std::wstring > &texturePaths, TextureContainer &texturesContainer, ID3D11Device *device, ID3D11DeviceContext *deviceContext)
std::shared_ptr< model_class > | GetModel () const
void | SetModel (std::shared_ptr< model_class > model)
const std::string & | GetModelFilePath () const
void | SetModelFilePath (const std::string &path)
bool | IsVisible () const
void | SetVisible (bool visible)
ID3D11ShaderResourceView * | GetTexture (TextureType type, int index=0)
int | GetIndexCount () const
void | Render (ID3D11DeviceContext *deviceContext)
Public Member Functions inherited from ecs::Component
| Component (const Component &)=delete
Component & | operator= (const Component &)=delete
| Component (Component &&)=default
Component & | operator= (Component &&)=default

## Detailed Description

Definition at line 29 of file render_component.h.

## Constructor & Destructor Documentation

## RenderComponent()

ecs::RenderComponent::RenderComponent | ( |  | ) |

inline

Builder for the RenderComponent class.

Definition at line 34 of file render_component.h.

: m_model(nullptr), m_isVisible(true) {}

## Member Function Documentation

## GetIndexCount()

int ecs::RenderComponent::GetIndexCount | ( |  | ) | const

inline

Get the number of vertices in the model. This method retrieves the vertex count from the model.

Returns
  The number of vertices as an integer.

Definition at line 174 of file render_component.h.

{
return m_model ? m_model->GetIndexCount() : 0;
}

## GetModel()

std::shared_ptr< model_class > ecs::RenderComponent::GetModel | ( |  | ) | const

inline

Get the model associated with this RenderComponent.

Returns
  A shared pointer to the model_class instance.

Definition at line 113 of file render_component.h.

{ return m_model; }

## GetModelFilePath()

const std::string & ecs::RenderComponent::GetModelFilePath | ( |  | ) | const

inline

Get the file path of the model associated with this RenderComponent.

Returns
  The file path as a string.

Definition at line 125 of file render_component.h.

{ return m_modelFilePath; }

## GetTexture()

ID3D11ShaderResourceView * ecs::RenderComponent::GetTexture | ( | TextureType | type,
|  | int | index = 0 )

inline

Get a texture of a specific type by index. This method retrieves the texture from the model based on the specified type and index.

Parameters

  type | The type of texture to retrieve (Diffuse, Normal, Specular, Alpha).
  index | The index of the texture to retrieve (default is 0).

Returns
  A pointer to the ID3D11ShaderResourceView of the texture, or nullptr if not found.

Definition at line 152 of file render_component.h.

{
if (!m_model) return nullptr;
switch (type) {
case TextureType::Diffuse:
return m_model->GetTexture(::TextureType::Diffuse, index);
case TextureType::Normal:
return m_model->GetTexture(::TextureType::Normal, index);
case TextureType::Specular:
return m_model->GetTexture(::TextureType::Specular, index);
case TextureType::Alpha:
return m_model->GetTexture(::TextureType::Alpha, index);
default:
return nullptr;
}
}

## Initialize()

void ecs::RenderComponent::Initialize | ( |  | ) |

inlineoverridevirtual

Virtual function to initialize the component.

Reimplemented from ecs::Component.

Definition at line 37 of file render_component.h.

{}

## InitializeFromFile()

bool ecs::RenderComponent::InitializeFromFile | ( | ID3D11Device * | device,
|  | ID3D11DeviceContext * | deviceContext,
|  | const char * | modelFilename,
|  | TextureContainer & | textureContainer )

inline

Initialize the RenderComponent from a model file. This method checks if the model is already cached; if not, it loads the model from the specified file.

Parameters

  device | The Direct3D device used for rendering.
  deviceContext | The Direct3D device context used for rendering.
  modelFilename | The path to the model file to load.
  textureContainer | The container for textures used by the model.

Returns
  True if initialization was successful, false otherwise.

Definition at line 61 of file render_component.h.

{
// Vérifier si le modèle existe déjà dans le cache
std::string filename(modelFilename);
auto it = g_model_cache.find(filename);
if (it != g_model_cache.end()) {
m_model = it->second;
} else {
// Créer un nouveau modèle
auto new_model = std::make_shared<model_class>();
if (!new_model->Initialize(device, deviceContext, const_cast<char*>(modelFilename), textureContainer)) {
return false;
}
g_model_cache[filename] = new_model;
m_model = new_model;
}
m_modelFilePath = modelFilename;
return true;
}

## InitializeWithModel()

bool ecs::RenderComponent::InitializeWithModel | ( | std::shared_ptr< model_class > | model | ) |

inline

Initialize the RenderComponent with a model. This method allows the component to be initialized with an existing model instance.

Parameters

  model | A shared pointer to the model_class instance to use.

Returns
  True if initialization was successful, false otherwise.

Definition at line 46 of file render_component.h.

{
if (!model) return false;
m_model = model;
return true;
}

## IsVisible()

bool ecs::RenderComponent::IsVisible | ( |  | ) | const

inline

Check if the model is currently visible.

Returns
  True if the model is visible, false otherwise.

Definition at line 137 of file render_component.h.

{ return m_isVisible; }

## LoadTexturesFromPath()

bool ecs::RenderComponent::LoadTexturesFromPath | ( | std::vector< std::wstring > & | texturePaths,
|  | TextureContainer & | texturesContainer,
|  | ID3D11Device * | device,
|  | ID3D11DeviceContext * | deviceContext )

inline

Load textures from a list of file paths into the texture container. This method uses DirectX's WIC texture loader to load textures from the specified paths.

Parameters

  texturePaths | A vector of file paths to the textures to load.
  texturesContainer | The container where the loaded textures will be stored.
  device | The Direct3D device used for rendering.
  deviceContext | The Direct3D device context used for rendering.

Returns
  True if all textures were loaded successfully, false otherwise.

Definition at line 91 of file render_component.h.

{
HRESULT result;
int i = 0;
for (const auto& texturePath : texturePaths) {
ID3D11ShaderResourceView* texture = nullptr;
result = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
if (FAILED(result)) {
return false;
}
texturesContainer.AssignTexture(texturesContainer, texture, texturePath, i);
i++;
}
return true;
}

## Render()

void ecs::RenderComponent::Render | ( | ID3D11DeviceContext * | deviceContext | ) |

inline

Render the model using the provided device context. This method calls the Render method of the model if it is initialized and visible.

Parameters

  deviceContext | The Direct3D device context used for rendering.

Definition at line 183 of file render_component.h.

{
if (m_model && m_isVisible) {
m_model->Render(deviceContext);
}
}

## SetModel()

void ecs::RenderComponent::SetModel | ( | std::shared_ptr< model_class > | model | ) |

inline

Set the model for this RenderComponent. This method allows the component to be set with an existing model instance.

Parameters

  model | A shared pointer to the model_class instance to set.

Definition at line 119 of file render_component.h.

{ m_model = model; }

## SetModelFilePath()

void ecs::RenderComponent::SetModelFilePath | ( | const std::string & | path | ) |

inline

Set the file path of the model for this RenderComponent. This method allows the component to be set with a specific model file path.

Parameters

  path | The file path to set as a string.

Definition at line 131 of file render_component.h.

{ m_modelFilePath = path; }

## SetVisible()

void ecs::RenderComponent::SetVisible | ( | bool | visible | ) |

inline

Set the visibility of the model. This method allows the component to control whether the model should be rendered or not.

Parameters

  visible | True to make the model visible, false to hide it.

Definition at line 143 of file render_component.h.

{ m_isVisible = visible; }

## Update()

void ecs::RenderComponent::Update | ( | float | deltaTime | ) |

inlineoverridevirtual

Virtual function to update the component.

Parameters

  deltaTime | Time since the last update.

Reimplemented from ecs::Component.

Definition at line 38 of file render_component.h.

{}

The documentation for this class was generated from the following file:

- enginecustom/src/inc/system/ecs/components/render_component.h