# Khaotic Engine Reborn: model_class Class Reference

Loading...
Searching...
No Matches
model_class Class Reference

## Classes

struct | Face
struct | ModelType
struct | Normal
struct | TempVertexType
struct | Texture
struct | VectorType
struct | Vertex
struct | VertexType

## Public Member Functions

| model_class (const model_class &)=delete
model_class & | operator= (const model_class &)=delete
bool | Initialize (ID3D11Device *, ID3D11DeviceContext *, char *, const TextureContainer &)
bool | Initialize (ID3D11Device *, ID3D11DeviceContext *, char *)
void | Shutdown ()
void | Render (ID3D11DeviceContext *)
int | GetIndexCount ()
int | GetVertexCount () const
ID3D11ShaderResourceView * | GetTexture (TextureType type, int index) const
bool | ChangeTexture (ID3D11Device *device, ID3D11DeviceContext *deviceContext, std::wstring filename, TextureType type, int index)
bool | AddTexture (ID3D11Device *device, ID3D11DeviceContext *deviceContext, std::wstring filename, TextureType type)
bool | AddTexture (ID3D11ShaderResourceView *texture, TextureType type)
void | SetTextureContainer (TextureContainer &texturesContainer)
TextureContainer | GetTextureContainer () const
bool | PreloadTextures (ID3D11Device *device, ID3D11DeviceContext *deviceContext, TextureContainer &textureContainer)

## Protected Attributes

int | m_vertexCount
int | m_indexCount
ID3D11Buffer * | m_vertexBuffer
ID3D11Buffer * | m_indexBuffer

## Detailed Description

Definition at line 150 of file model_class.h.

## Constructor & Destructor Documentation

## model_class()

model_class::model_class | ( |  | ) |

Definition at line 4 of file model_class.cpp.

{
m_vertexBuffer = 0;
m_indexBuffer = 0;
m_model = 0;
m_vertexCount = 0;
m_indexCount = 0;
m_Textures.diffuse.clear();
m_Textures.normal.clear();
m_Textures.specular.clear();
m_Textures.alpha.clear();
m_Textures.diffusePaths.clear();
m_Textures.normalPaths.clear();
m_Textures.specularPaths.clear();
m_Textures.alphaPaths.clear();
}

## ~model_class()

model_class::~model_class | ( |  | ) |

Definition at line 21 of file model_class.cpp.

{
// Destructor
Shutdown();
}

## Member Function Documentation

## AddTexture() [1/2]

bool model_class::AddTexture | ( | ID3D11Device * | device,
|  | ID3D11DeviceContext * | deviceContext,
|  | std::wstring | filename,
|  | TextureType | type )

Definition at line 646 of file model_class.cpp.

{
Logger::Get().Log("Adding texture", __FILE__, __LINE__, Logger::LogLevel::Initialize);
HRESULT result;
ID3D11ShaderResourceView* newTexture = nullptr;
// Charger la nouvelle texture
result = DirectX::CreateWICTextureFromFile(device, deviceContext, filename.c_str(), nullptr, &newTexture);
if (FAILED(result)) {
Logger::Get().Log("Failed to load texture: " + std::string(filename.begin(), filename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Ajouter la texture au vecteur approprié selon le type
auto& textureVector = m_Textures.Get(type);
textureVector.push_back(newTexture);
// Ajouter le chemin de la texture au vecteur approprié selon le type
switch (type) {
case TextureType::Diffuse:
m_Textures.diffusePaths.push_back(filename);
break;
case TextureType::Normal:
m_Textures.normalPaths.push_back(filename);
break;
case TextureType::Specular:
m_Textures.specularPaths.push_back(filename);
break;
case TextureType::Alpha:
m_Textures.alphaPaths.push_back(filename);
break;
}
Logger::Get().Log("Texture added successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize);
return true;
}

## AddTexture() [2/2]

bool model_class::AddTexture | ( | ID3D11ShaderResourceView * | texture,
|  | TextureType | type )

Definition at line 683 of file model_class.cpp.

{
if (!texture) {
Logger::Get().Log("Cannot add null texture", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Ajouter la texture au vecteur approprié
auto& textureVector = m_Textures.Get(type);
textureVector.push_back(texture);
// Ajouter un chemin vide ou générique pour maintenir la synchronisation
switch (type) {
case TextureType::Diffuse:
m_Textures.diffusePaths.push_back(L"[texture préchargée]");
break;
case TextureType::Normal:
m_Textures.normalPaths.push_back(L"[texture préchargée]");
break;
case TextureType::Specular:
m_Textures.specularPaths.push_back(L"[texture préchargée]");
break;
case TextureType::Alpha:
m_Textures.alphaPaths.push_back(L"[texture préchargée]");
break;
}
return true;
}

## ChangeTexture()

bool model_class::ChangeTexture | ( | ID3D11Device * | device,
|  | ID3D11DeviceContext * | deviceContext,
|  | std::wstring | filename,
|  | TextureType | type,
|  | int | index )

Definition at line 585 of file model_class.cpp.

{
Logger::Get().Log("Changing texture", __FILE__, __LINE__, Logger::LogLevel::Initialize);
HRESULT result;
ID3D11ShaderResourceView* newTexture = nullptr;
// Charger la nouvelle texture
result = DirectX::CreateWICTextureFromFile(device, deviceContext, filename.c_str(), nullptr, &newTexture);
if (FAILED(result)) {
Logger::Get().Log("Failed to load texture: " + std::string(filename.begin(), filename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Récupérer le vecteur correspondant au type de texture
auto& textureVector = m_Textures.Get(type);
// Si l'index est hors limites, redimensionner le vecteur
if (index >= textureVector.size()) {
textureVector.resize(index + 1, nullptr);
}
// Libérer l'ancienne texture si elle existe
if (textureVector[index]) {
textureVector[index]->Release();
}
// Assigner la nouvelle texture
textureVector[index] = newTexture;
// Mettre à jour le chemin dans le conteneur approprié selon le type
switch (type) {
case TextureType::Diffuse:
if (index >= m_Textures.diffusePaths.size()) {
m_Textures.diffusePaths.resize(index + 1, L"");
}
m_Textures.diffusePaths[index] = filename;
break;
case TextureType::Normal:
if (index >= m_Textures.normalPaths.size()) {
m_Textures.normalPaths.resize(index + 1, L"");
}
m_Textures.normalPaths[index] = filename;
break;
case TextureType::Specular:
if (index >= m_Textures.specularPaths.size()) {
m_Textures.specularPaths.resize(index + 1, L"");
}
m_Textures.specularPaths[index] = filename;
break;
case TextureType::Alpha:
if (index >= m_Textures.alphaPaths.size()) {
m_Textures.alphaPaths.resize(index + 1, L"");
}
m_Textures.alphaPaths[index] = filename;
break;
}
Logger::Get().Log("Texture changed successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize);
return true;
}

## GetIndexCount()

int model_class::GetIndexCount | ( |  | ) |

Definition at line 88 of file model_class.cpp.

{
return m_indexCount;
}

## GetTexture()

ID3D11ShaderResourceView * model_class::GetTexture | ( | TextureType | type,
|  | int | index ) const

Definition at line 93 of file model_class.cpp.

{
return m_Textures.GetTexture(type, index);
}

## GetTextureContainer()

TextureContainer model_class::GetTextureContainer | ( |  | ) | const

inline

Definition at line 232 of file model_class.h.

{ return m_Textures; }

## GetVertexCount()

int model_class::GetVertexCount | ( |  | ) | const

inline

Definition at line 217 of file model_class.h.

{ return m_vertexCount; }

## Initialize() [1/2]

bool model_class::Initialize | ( | ID3D11Device * | device,
|  | ID3D11DeviceContext * | deviceContext,
|  | char * | modelFilename )

Definition at line 40 of file model_class.cpp.

{
bool result;
// Load in the model data.
result = LoadModel(modelFilename);
if (!result) {
Logger::Get().Log("Failed to load model data", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Calculate the tangent and binormal vectors for the model.
CalculateModelVectors();
// Initialize the vertex and index buffers.
result = InitializeBuffers(device);
if (!result) {
Logger::Get().Log("Failed to initialize buffers", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
return true;
}

## Initialize() [2/2]

bool model_class::Initialize | ( | ID3D11Device * | device,
|  | ID3D11DeviceContext * | deviceContext,
|  | char * | modelFilename,
|  | const TextureContainer & | textures )

Definition at line 28 of file model_class.cpp.

{
bool result = Initialize(device, deviceContext, modelFilename);
if (!result) {
return false;
}
m_Textures = textures; // Copie de la structure de textures
return true;
}

## PreloadTextures()

bool model_class::PreloadTextures | ( | ID3D11Device * | device,
|  | ID3D11DeviceContext * | deviceContext,
|  | TextureContainer & | textureContainer )

Definition at line 526 of file model_class.cpp.

{
HRESULT hResult;
// Charger les textures diffuses
for (const auto& texturePath : textureContainer.diffusePaths)
{
ID3D11ShaderResourceView* texture = nullptr;
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
if (FAILED(hResult))
{
Logger::Get().Log("Échec du chargement de la texture diffuse: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
textureContainer.diffuse.push_back(texture);
}
// Charger les textures normales
for (const auto& texturePath : textureContainer.normalPaths)
{
ID3D11ShaderResourceView* texture = nullptr;
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
if (FAILED(hResult))
{
Logger::Get().Log("Échec du chargement de la texture normale: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
textureContainer.normal.push_back(texture);
}
// Charger les textures spéculaires
for (const auto& texturePath : textureContainer.specularPaths)
{
ID3D11ShaderResourceView* texture = nullptr;
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
if (FAILED(hResult))
{
Logger::Get().Log("Échec du chargement de la texture spéculaire: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
textureContainer.specular.push_back(texture);
}
// Charger les textures alpha
for (const auto& texturePath : textureContainer.alphaPaths)
{
ID3D11ShaderResourceView* texture = nullptr;
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
if (FAILED(hResult))
{
Logger::Get().Log("Échec du chargement de la texture alpha: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
textureContainer.alpha.push_back(texture);
}
return true;
}

## Render()

void model_class::Render | ( | ID3D11DeviceContext * | deviceContext | ) |

Definition at line 79 of file model_class.cpp.

{
// Put the vertex and index buffers on the graphics pipeline to prepare them for drawing.
RenderBuffers(deviceContext);
return;
}

## SetTextureContainer()

void model_class::SetTextureContainer | ( | TextureContainer & | texturesContainer | ) |

inline

Definition at line 231 of file model_class.h.

{ m_Textures = texturesContainer; }

## Shutdown()

void model_class::Shutdown | ( |  | ) |

Definition at line 64 of file model_class.cpp.

{
// Release the model textures.
ReleaseTextures();
// Shutdown the vertex and index buffers.
ShutdownBuffers();
// Release the model data.
ReleaseModel();
return;
}

## Member Data Documentation

## m_indexBuffer

ID3D11Buffer * model_class::m_indexBuffer

protected

Definition at line 238 of file model_class.h.

## m_indexCount

int model_class::m_indexCount

protected

Definition at line 237 of file model_class.h.

## m_vertexBuffer

ID3D11Buffer* model_class::m_vertexBuffer

protected

Definition at line 238 of file model_class.h.

## m_vertexCount

int model_class::m_vertexCount

protected

Definition at line 237 of file model_class.h.

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

- enginecustom/src/inc/system/model_class.h
- enginecustom/src/src/system/model_class.cpp