Minor - Improves scene loading and audio component - V13.6.0

Refactors scene loading to properly initialize models and textures from the scene file.

Adds audio component deserialization and file path handling.

Fixes model loading and texture application in scene manager.
Addresses potential issues with missing components during scene loading.
This commit is contained in:
2025-09-17 00:01:13 +02:00
parent de05631608
commit 7fc4b08808
7 changed files with 223 additions and 171 deletions

View File

@@ -6,13 +6,11 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="e81d6e08-efc7-40a0-909d-ec4943d948e9" name="Changes" comment=""> <list default="true" id="e81d6e08-efc7-40a0-909d-ec4943d948e9" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/camera_class.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/camera_class.h" afterDir="false" /> <change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/ecs/component.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/ecs/component.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/ecs/components/audio_component.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/ecs/components/audio_component.h" afterDir="false" /> <change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/ecs/components/audio_component.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/ecs/components/audio_component.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/ecs/components/render_component.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/ecs/components/render_component.h" afterDir="false" /> <change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/ecs/components/render_component.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/ecs/components/render_component.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/ecs/components/transform_component.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/ecs/components/transform_component.h" afterDir="false" /> <change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/model_class.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/model_class.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/ecs/entity.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/ecs/entity.h" afterDir="false" /> <change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/scene_manager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/scene_manager.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/ecs/entity_manager.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/ecs/entity_manager.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/application_class.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/application_class.cpp" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -26,6 +24,7 @@
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component> </component>
<component name="HighlightingSettingsPerFile"> <component name="HighlightingSettingsPerFile">
<setting file="cidr-memory-view://8" root0="FORCE_HIGHLIGHTING" />
<setting file="file://C:/Program Files (x86)/Windows Kits/10/Include/10.0.26100.0/um/d3d11.h" root0="SKIP_HIGHLIGHTING" /> <setting file="file://C:/Program Files (x86)/Windows Kits/10/Include/10.0.26100.0/um/d3d11.h" root0="SKIP_HIGHLIGHTING" />
<setting file="file://C:/Program Files (x86)/Windows Kits/10/Include/10.0.26100.0/um/dinput.h" root0="SKIP_HIGHLIGHTING" /> <setting file="file://C:/Program Files (x86)/Windows Kits/10/Include/10.0.26100.0/um/dinput.h" root0="SKIP_HIGHLIGHTING" />
<setting file="file://C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/include/memory" root0="SKIP_HIGHLIGHTING" /> <setting file="file://C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/include/memory" root0="SKIP_HIGHLIGHTING" />
@@ -42,7 +41,6 @@
<setting file="file://$PROJECT_DIR$/enginecustom/src/inc/system/ecs/entity.h" root0="FORCE_HIGHLIGHTING" /> <setting file="file://$PROJECT_DIR$/enginecustom/src/inc/system/ecs/entity.h" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/enginecustom/src/inc/system/ecs/entity_manager.h" root0="FORCE_HIGHLIGHTING" /> <setting file="file://$PROJECT_DIR$/enginecustom/src/inc/system/ecs/entity_manager.h" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/enginecustom/src/inc/system/ecs/systems/render_system.h" root0="FORCE_HIGHLIGHTING" /> <setting file="file://$PROJECT_DIR$/enginecustom/src/inc/system/ecs/systems/render_system.h" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/enginecustom/src/inc/system/ecs/systems/types.h" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/../../IDE_VS/VC/Tools/MSVC/14.38.33130/include/type_traits" root0="SKIP_HIGHLIGHTING" /> <setting file="file://$PROJECT_DIR$/../../IDE_VS/VC/Tools/MSVC/14.38.33130/include/type_traits" root0="SKIP_HIGHLIGHTING" />
</component> </component>
<component name="KubernetesApiPersistence">{}</component> <component name="KubernetesApiPersistence">{}</component>
@@ -64,26 +62,26 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;, "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
&quot;C++ Project.enginecustom.executor&quot;: &quot;Run&quot;, "C++ Project.enginecustom.executor": "Run",
&quot;C/C++ Project.KhaoticDemo.executor&quot;: &quot;Run&quot;, "C/C++ Project.KhaoticDemo.executor": "Run",
&quot;C/C++ Project.enginecustom.executor&quot;: &quot;Run&quot;, "C/C++ Project.enginecustom.executor": "Run",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;, "RunOnceActivity.git.unshallow": "true",
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;, "SHARE_PROJECT_CONFIGURATION_FILES": "true",
&quot;git-widget-placeholder&quot;: &quot;main&quot;, "git-widget-placeholder": "main",
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;, "ignore.virus.scanning.warn.message": "true",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "nodejs_package_manager_path": "npm",
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;, "settings.editor.selected.configurable": "preferences.pluginManager",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "vue.rearranger.settings.migration": "true"
} }
}</component> }]]></component>
<component name="RunManager" selected="C/C++ Project.enginecustom"> <component name="RunManager" selected="C/C++ Project.enginecustom">
<configuration name="KhaoticDemo" type="CppProject" factoryName="C++ Project"> <configuration name="KhaoticDemo" type="CppProject" factoryName="C++ Project">
<configuration_1 setup="1"> <configuration_1 setup="1">
@@ -260,7 +258,8 @@
<workItem from="1757952791669" duration="4499000" /> <workItem from="1757952791669" duration="4499000" />
<workItem from="1757959923169" duration="1930000" /> <workItem from="1757959923169" duration="1930000" />
<workItem from="1757961888820" duration="9053000" /> <workItem from="1757961888820" duration="9053000" />
<workItem from="1758030961823" duration="8967000" /> <workItem from="1758030961823" duration="9125000" />
<workItem from="1758053825034" duration="6187000" />
</task> </task>
<task id="LOCAL-00001" summary="Minor update - viewport window tweak"> <task id="LOCAL-00001" summary="Minor update - viewport window tweak">
<option name="closed" value="true" /> <option name="closed" value="true" />

View File

@@ -0,0 +1,8 @@
Entity:0:86
IdentityComponent:0:86:Unknown
TransformComponent:0:50:0:0:-0:0:1:1:1
RenderComponent:HasModel:1:assets/Texture/Bricks2K.png:1:assets/Texture/BricksNRM2K.png:1:assets/Texture/BricksGLOSS2K.png:0:
ShaderComponent:LIGHTING
ModelPathComponent:Content/Assets/Kobject/86.obj
AudioComponent:F:\Github_Repo\khaotic-engine-Reborn\x64\Release\assets\sounds\default.mp3;1:0:1:1:0:0:128:1:0
EndEntity

View File

@@ -5,6 +5,8 @@
#include <imgui.h> #include <imgui.h>
#include "entity.h" #include "entity.h"
#include "Logger.h"
/** /**
* namespace for the Entity-Component-System (ECS) * namespace for the Entity-Component-System (ECS)
*/ */

View File

@@ -18,6 +18,14 @@ class AudioComponent : public Component {
public: public:
AudioComponent() : m_sound(nullptr), m_channel(nullptr) {} AudioComponent() : m_sound(nullptr), m_channel(nullptr) {}
~AudioComponent() override { ~AudioComponent() override {
// stop the sound if it's playing
if (m_channel) {
bool isPlaying = false;
m_channel->isPlaying(&isPlaying);
if (isPlaying) {
m_channel->stop();
}
}
if (m_sound) m_sound->release(); if (m_sound) m_sound->release();
// Ne pas lib<69>rer m_system ici car il peut <20>tre partag<61> // Ne pas lib<69>rer m_system ici car il peut <20>tre partag<61>
} }
@@ -51,10 +59,13 @@ public:
if (!m_system) return false; if (!m_system) return false;
} }
Logger::Get().Log("Loading audio file: " + path, __FILE__, __LINE__, Logger::LogLevel::Info);
m_soundPath = path; m_soundPath = path;
if (!std::filesystem::exists(path)) { if (!std::filesystem::exists(path)) {
m_lastError = "Fichier non trouv<75>: " + path; m_lastError = "Fichier non trouv<75>: " + path;
Logger::Get().Log(m_lastError, __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@@ -437,7 +448,7 @@ public:
std::string Serialize() const override { std::string Serialize() const override {
std::stringstream ss; std::stringstream ss;
ss << "AudioComponent:" ss << "AudioComponent:"
<< m_soundPath << ":" << m_soundPath << ";"
<< m_volume << ":" << m_volume << ":"
<< m_pan << ":" << m_pan << ":"
<< m_pitch << ":" << m_pitch << ":"
@@ -465,7 +476,7 @@ public:
std::string s_volume, s_pan, s_pitch, s_looping, s_muted, s_paused, s_priority, s_spatialized, s_use_velocity; std::string s_volume, s_pan, s_pitch, s_looping, s_muted, s_paused, s_priority, s_spatialized, s_use_velocity;
std::getline(ss, m_soundPath, ':'); std::getline(ss, m_soundPath, ';');
std::getline(ss, s_volume, ':'); std::getline(ss, s_volume, ':');
std::getline(ss, s_pan, ':'); std::getline(ss, s_pan, ':');
std::getline(ss, s_pitch, ':'); std::getline(ss, s_pitch, ':');
@@ -476,6 +487,8 @@ public:
std::getline(ss, s_spatialized, ':'); std::getline(ss, s_spatialized, ':');
std::getline(ss, s_use_velocity, ':'); std::getline(ss, s_use_velocity, ':');
Logger::Get().Log("Deserializing AudioComponent: path=" + m_soundPath, __FILE__, __LINE__, Logger::LogLevel::Warning);
m_volume = std::stof(s_volume); m_volume = std::stof(s_volume);
m_pan = std::stof(s_pan); m_pan = std::stof(s_pan);
m_pitch = std::stof(s_pitch); m_pitch = std::stof(s_pitch);

View File

@@ -35,6 +35,9 @@ public:
SetDevice(parent->GetDevice()); SetDevice(parent->GetDevice());
SetContext(parent->GetContext()); SetContext(parent->GetContext());
} }
texture_container_buffer = TextureContainer();
} }
void Update(float deltaTime) override {} void Update(float deltaTime) override {}
@@ -195,11 +198,41 @@ public:
std::string Serialize() const override { std::string Serialize() const override {
if (!m_model) return "RenderComponent:NoModel"; if (!m_model) return "RenderComponent:NoModel";
TextureContainer texture_container_buffer = m_model->GetTextureContainer();
auto serializePaths = [](const std::vector<std::wstring> &paths) -> std::string {
std::string result;
for (size_t i = 0; i < paths.size(); ++i) {
std::string p = std::string(paths[i].begin(), paths[i].end());
result += p;
if (i + 1 < paths.size()) {
result += ","; // virgule entre chemins mais pas apr<70>s dernier
}
}
return result;
};
int diffuse_count = (int)texture_container_buffer.diffuse.size();
int normal_count = (int)texture_container_buffer.normal.size();
int specular_count = (int)texture_container_buffer.specular.size();
int alpha_count = (int)texture_container_buffer.alpha.size();
std::string diffuse_paths_ = serializePaths(texture_container_buffer.diffusePaths);
std::string normal_paths_ = serializePaths(texture_container_buffer.normalPaths);
std::string specular_paths_ = serializePaths(texture_container_buffer.specularPaths);
std::string alpha_paths_ = serializePaths(texture_container_buffer.alphaPaths);
std::stringstream ss; std::stringstream ss;
ss << "RenderComponent:HasModel"; ss << "RenderComponent:HasModel:"
<< diffuse_count << ":" << diffuse_paths_ << ":"
<< normal_count << ":" << normal_paths_ << ":"
<< specular_count << ":" << specular_paths_ << ":"
<< alpha_count << ":" << alpha_paths_;
return ss.str(); return ss.str();
} }
/** /**
* Deserialize the RenderComponent's state from a string. * Deserialize the RenderComponent's state from a string.
* This method parses the string and sets the component's properties accordingly. * This method parses the string and sets the component's properties accordingly.
@@ -210,14 +243,81 @@ public:
bool Deserialize(const std::string& data) override { bool Deserialize(const std::string& data) override {
std::stringstream ss(data); std::stringstream ss(data);
std::string type; std::string type;
std::getline(ss, type, ':');
if (type != "RenderComponent") return false; if (!std::getline(ss, type, ':') || type != "RenderComponent")
return false;
std::string hasModel; std::string token;
std::getline(ss, hasModel);
if (!std::getline(ss, token, ':') || token != "HasModel")
return false;
int diffuse_count = 0, normal_count = 0, specular_count = 0, alpha_count = 0;
std::vector<std::wstring> paths_diffuse, paths_normal, paths_specular, paths_alpha;
auto read_count = [&](int& count) -> bool {
if (!std::getline(ss, token, ':'))
return false;
try {
count = std::stoi(token);
}
catch (...) {
return false;
}
return true;
};
auto clean_token = [](std::string& str) {
// Retirer virgules et espaces
str.erase(std::remove(str.begin(), str.end(), ','), str.end());
str.erase(0, str.find_first_not_of(" \t\n\r"));
str.erase(str.find_last_not_of(" \t\n\r") + 1);
};
auto read_paths = [&](int count, std::vector<std::wstring>& paths) -> bool {
for (int i = 0; i < count; ++i) {
if (!std::getline(ss, token, ':'))
return false;
clean_token(token);
if (!token.empty()) {
paths.emplace_back(token.begin(), token.end());
Logger::Get().Log("Loaded path: " + std::string(token.begin(), token.end()), __FILE__, __LINE__, Logger::LogLevel::Info);
}
}
return true;
};
if (!read_count(diffuse_count)) return false;
if (!read_paths(diffuse_count, paths_diffuse)) return false;
if (!read_count(normal_count)) return false;
if (!read_paths(normal_count, paths_normal)) return false;
if (!read_count(specular_count)) return false;
if (!read_paths(specular_count, paths_specular)) return false;
if (!read_count(alpha_count)) return false;
if (!read_paths(alpha_count, paths_alpha)) return false;
// Lib<69>rer textures existantes
for (auto& tex : texture_container_buffer.diffuse) if (tex) { tex->Release(); tex = nullptr; }
for (auto& tex : texture_container_buffer.normal) if (tex) { tex->Release(); tex = nullptr; }
for (auto& tex : texture_container_buffer.specular) if (tex) { tex->Release(); tex = nullptr; }
for (auto& tex : texture_container_buffer.alpha) if (tex) { tex->Release(); tex = nullptr; }
texture_container_buffer.diffuse.clear();
texture_container_buffer.normal.clear();
texture_container_buffer.specular.clear();
texture_container_buffer.alpha.clear();
texture_container_buffer.diffusePaths = std::move(paths_diffuse);
texture_container_buffer.normalPaths = std::move(paths_normal);
texture_container_buffer.specularPaths = std::move(paths_specular);
texture_container_buffer.alphaPaths = std::move(paths_alpha);
// Le mod<6F>le sera charg<72> s<>par<61>ment
return true; return true;
} }
@@ -350,12 +450,16 @@ public:
void SetDevice (ID3D11Device* dev) { device = dev; } void SetDevice (ID3D11Device* dev) { device = dev; }
void SetContext(ID3D11DeviceContext* ctx) { context = ctx; } void SetContext(ID3D11DeviceContext* ctx) { context = ctx; }
void SetTextureContainer(const TextureContainer& texContainer) { texture_container_buffer = texContainer; }
const TextureContainer& GetTextureContainerBuffer() const { return texture_container_buffer; }
private: private:
std::shared_ptr<model_class> m_model; std::shared_ptr<model_class> m_model;
std::string m_modelFilePath; std::string m_modelFilePath;
bool m_isVisible; bool m_isVisible;
ID3D11Device* device; ID3D11Device* device;
ID3D11DeviceContext* context; ID3D11DeviceContext* context;
TextureContainer texture_container_buffer;
}; };
} // namespace ecs } // namespace ecs

View File

@@ -279,6 +279,7 @@ bool model_class::LoadObjModel(char* filename)
{ {
XMFLOAT3 pos; XMFLOAT3 pos;
sscanf_s(line.c_str() + 2, "%f %f %f", &pos.x, &pos.y, &pos.z); sscanf_s(line.c_str() + 2, "%f %f %f", &pos.x, &pos.y, &pos.z);
pos.z = -pos.z; // Inversion de l'axe Z pour DirectX
temp_positions.push_back(pos); temp_positions.push_back(pos);
} }
else if (line[1] == 't') // Coordonn<6E>es de texture else if (line[1] == 't') // Coordonn<6E>es de texture
@@ -313,19 +314,19 @@ bool model_class::LoadObjModel(char* filename)
if (normIndex[i] < 0) normIndex[i] += temp_normals.size() + 1; if (normIndex[i] < 0) normIndex[i] += temp_normals.size() + 1;
} }
for (int i = 0; i < 3; i++) for (int i = 2; i >= 0; --i)
{ {
ModelType vertex{}; ModelType vertex{};
vertex.x = temp_positions[posIndex[i] - 1].x; vertex.x = temp_positions[posIndex[i] - 1].x;
vertex.y = temp_positions[posIndex[i] - 1].y; vertex.y = temp_positions[posIndex[i] - 1].y;
vertex.z = temp_positions[posIndex[i] - 1].z; vertex.z = temp_positions[posIndex[i] - 1].z;
vertex.tu = temp_texcoords[texIndex[i] - 1].x; vertex.tu = temp_texcoords[texIndex[i] - 1].x;
vertex.tv = temp_texcoords[texIndex[i] - 1].y; vertex.tv = temp_texcoords[texIndex[i] - 1].y;
vertex.nx = temp_normals[normIndex[i] - 1].x; vertex.nx = temp_normals[normIndex[i] - 1].x;
vertex.ny = temp_normals[normIndex[i] - 1].y; vertex.ny = temp_normals[normIndex[i] - 1].y;
vertex.nz = temp_normals[normIndex[i] - 1].z; vertex.nz = temp_normals[normIndex[i] - 1].z;
temp_model.push_back(vertex); temp_model.push_back(vertex);
} }
} }
} }

View File

@@ -153,96 +153,60 @@ bool scene_manager::load_scene() {
// Finaliser l'entit<69> - chargement du mod<6F>le si n<>cessaire // Finaliser l'entit<69> - chargement du mod<6F>le si n<>cessaire
if (currentEntity) { if (currentEntity) {
auto modelPathComponent = currentEntity->GetComponent<ecs::ModelPathComponent>(); auto modelPathComponent = currentEntity->GetComponent<ecs::ModelPathComponent>();
if (modelPathComponent && !modelPathComponent->GetPath().empty()) {
std::wstring modelPath = modelPathComponent->GetPath();
std::string modelKey = convert_w_string_to_string(modelPath);
// V<>rifier si le mod<6F>le existe dans le cache if (!modelPathComponent) {
std::shared_ptr<model_class> model; Logger::Get().Log("ModelPathComponent missing for entity ID: " + std::to_string(currentEntity->GetID()), __FILE__, __LINE__, Logger::LogLevel::Warning);
auto it = modelCache.find(modelKey); }
if (it != modelCache.end()) {
model = it->second;
} else {
// Cr<43>er et initialiser un nouveau mod<6F>le
model = std::make_shared<model_class>();
// Pr<50>charger les textures if (!modelPathComponent || modelPathComponent->GetPath().empty()) {
if (!model->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), currentTextures)) { Logger::Get().Log("No model path specified for entity ID: " + std::to_string(currentEntity->GetID()), __FILE__, __LINE__, Logger::LogLevel::Warning);
Logger::Get().Log("<EFBFBD>chec du pr<70>chargement des textures", __FILE__, __LINE__, Logger::LogLevel::Error); }
}
char modelFilename[256]; auto renderComponent = currentEntity->GetComponent<ecs::RenderComponent>();
size_t convertedChars = 0;
wcstombs_s(&convertedChars, modelFilename, sizeof(modelFilename), modelPath.c_str(), _TRUNCATE);
if (!model->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, currentTextures)) { if (!renderComponent)
Logger::Get().Log("<EFBFBD>chec d'initialisation du mod<6F>le", __FILE__, __LINE__, Logger::LogLevel::Error); {
} else { Logger::Get().Log("RenderComponent missing for entity ID: " + std::to_string(currentEntity->GetID()), __FILE__, __LINE__, Logger::LogLevel::Warning);
// Ajouter au cache }
modelCache[modelKey] = model;
} currentTextures = renderComponent->GetTextureContainerBuffer();
std::wstring modelPath = modelPathComponent->GetPath();
std::string modelKey = convert_w_string_to_string(modelPath);
// V<>rifier si le mod<6F>le existe dans le cache
std::shared_ptr<model_class> model;
auto it = modelCache.find(modelKey);
if (it != modelCache.end()) {
model = it->second;
} else {
// Cr<43>er et initialiser un nouveau mod<6F>le
model = std::make_shared<model_class>();
// Pr<50>charger les textures
if (!model->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), currentTextures)) {
Logger::Get().Log("<EFBFBD>chec du pr<70>chargement des textures", __FILE__, __LINE__, Logger::LogLevel::Error);
} }
// Ajouter le composant de rendu avec le mod<6F>le char modelFilename[256];
if (model) { size_t convertedChars = 0;
auto renderComponent = currentEntity->GetComponent<ecs::RenderComponent>(); wcstombs_s(&convertedChars, modelFilename, sizeof(modelFilename), modelPath.c_str(), _TRUNCATE);
if (!renderComponent) {
renderComponent = currentEntity->AddComponent<ecs::RenderComponent>(); if (!model->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, currentTextures)) {
} Logger::Get().Log("<EFBFBD>chec d'initialisation du mod<6F>le", __FILE__, __LINE__, Logger::LogLevel::Error);
renderComponent->InitializeWithModel(model); } else {
// Ajouter au cache
modelCache[modelKey] = model;
} }
} }
// Ajouter le composant de rendu avec le mod<6F>le
if (model) renderComponent->InitializeWithModel(model);
} }
currentEntity = nullptr; currentEntity = nullptr;
} }
else if (!line.empty() && line.find("TextureData:") == 0) {
Logger::Get().Log(line.substr(11), __FILE__, __LINE__, Logger::LogLevel::Info);
if (currentEntity) {
std::stringstream ss(line.substr(11));
std::string token;
// log the token values for debugging
Logger::Get().Log( token, __FILE__, __LINE__, Logger::LogLevel::Info);
std::getline(ss, token, ':');
// Diffuse
int diffuseCount = 0;
if (std::getline(ss, token, ':') && !token.empty())
diffuseCount = std::stoi(token);
for (int i = 0; i < diffuseCount; i++) {
if (std::getline(ss, token, ':'))
currentTextures.diffusePaths.push_back(std::wstring(token.begin(), token.end()));
}
// Normal
int normalCount = 0;
if (std::getline(ss, token, ':') && !token.empty())
normalCount = std::stoi(token);
for (int i = 0; i < normalCount; i++) {
if (std::getline(ss, token, ':'))
currentTextures.normalPaths.push_back(std::wstring(token.begin(), token.end()));
}
// Textures sp<73>culaires
int specularCount = 0;
if (std::getline(ss, token, ':') && !token.empty())
specularCount = std::stoi(token);
for (int i = 0; i < specularCount; i++) {
if (std::getline(ss, token, ':'))
currentTextures.specularPaths.push_back(std::wstring(token.begin(), token.end()));
}
// Textures alpha
int alphaCount = 0;
if (std::getline(ss, token, ':') && !token.empty())
alphaCount = std::stoi(token);
for (int i = 0; i < alphaCount; i++) {
if (std::getline(ss, token, ':'))
currentTextures.alphaPaths.push_back(std::wstring(token.begin(), token.end()));
}
}
}
else if (currentEntity) { else if (currentEntity) {
// D<>terminer le type de composant // D<>terminer le type de composant
std::string componentType = line.substr(0, line.find(':')); std::string componentType = line.substr(0, line.find(':'));
@@ -291,45 +255,6 @@ bool scene_manager::save_scene() {
} }
} }
// S<>rialiser les textures pour les composants de rendu
auto renderComponent = entity->GetComponent<ecs::RenderComponent>();
if (renderComponent && renderComponent->GetModel()) {
const auto& model = renderComponent->GetModel();
const auto& textureContainer = model->GetTextureContainer();
outFile << "TextureData:";
// Textures diffuses
const auto& diffusePaths = textureContainer.GetPaths(TextureType::Diffuse);
outFile << diffusePaths.size();
for (const auto& path : diffusePaths) {
outFile << ":" << convert_w_string_to_string(path);
}
// Textures normales
const auto& normalPaths = textureContainer.GetPaths(TextureType::Normal);
outFile << ":" << normalPaths.size();
for (const auto& path : normalPaths) {
outFile << ":" << convert_w_string_to_string(path);
}
// Textures sp<73>culaires
const auto& specularPaths = textureContainer.GetPaths(TextureType::Specular);
outFile << ":" << specularPaths.size();
for (const auto& path : specularPaths) {
outFile << ":" << convert_w_string_to_string(path);
}
// Textures alpha
const auto& alphaPaths = textureContainer.GetPaths(TextureType::Alpha);
outFile << ":" << alphaPaths.size();
for (const auto& path : alphaPaths) {
outFile << ":" << convert_w_string_to_string(path);
}
outFile << std::endl;
}
outFile << "EndEntity" << std::endl; outFile << "EndEntity" << std::endl;
} }