diff --git a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
index 5cb53d8..bb8075a 100644
--- a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
+++ b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
@@ -4,16 +4,7 @@
-
-
-
-
-
-
-
-
-
-
+
@@ -26,52 +17,20 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
{}
@@ -93,26 +52,26 @@
- {
+ "keyToString": {
+ "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "C++ Project.enginecustom.executor": "Run",
+ "C/C++ Project.KhaoticDemo.executor": "Run",
+ "C/C++ Project.enginecustom.executor": "Run",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "RunOnceActivity.git.unshallow": "true",
+ "SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "git-widget-placeholder": "main",
+ "ignore.virus.scanning.warn.message": "true",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "settings.editor.selected.configurable": "preferences.environmentSetup",
+ "vue.rearranger.settings.migration": "true"
}
-}]]>
+}
@@ -263,6 +222,7 @@
+
diff --git a/enginecustom/enginecustom.vcxproj b/enginecustom/enginecustom.vcxproj
index f24c322..dce4560 100644
--- a/enginecustom/enginecustom.vcxproj
+++ b/enginecustom/enginecustom.vcxproj
@@ -121,6 +121,7 @@
+
diff --git a/enginecustom/src/inc/system/application_class.h b/enginecustom/src/inc/system/application_class.h
index a6e5081..357de4d 100644
--- a/enginecustom/src/inc/system/application_class.h
+++ b/enginecustom/src/inc/system/application_class.h
@@ -38,6 +38,7 @@
#include "ecs/components/physics_component.h"
#include "ecs/components/shader_component.h"
#include "ecs/systems/render_system.h"
+#include "ecs/components/model_path_component.h"
#include
#include
diff --git a/enginecustom/src/inc/system/ecs/components/model_path_component.h b/enginecustom/src/inc/system/ecs/components/model_path_component.h
new file mode 100644
index 0000000..b3ca873
--- /dev/null
+++ b/enginecustom/src/inc/system/ecs/components/model_path_component.h
@@ -0,0 +1,24 @@
+#pragma once
+#include "../component.h"
+#include
+
+namespace ecs {
+
+class ModelPathComponent : public Component {
+public:
+ ModelPathComponent() = default;
+ explicit ModelPathComponent(const std::wstring& path) : m_path(path) {}
+ ~ModelPathComponent() = default;
+
+ void Initialize() override {}
+ void Update(float deltaTime) override {}
+
+ // Getters et setters
+ const std::wstring& GetPath() const { return m_path; }
+ void SetPath(const std::wstring& path) { m_path = path; }
+
+private:
+ std::wstring m_path;
+};
+
+} // namespace ecs
diff --git a/enginecustom/src/src/system/application_class.cpp b/enginecustom/src/src/system/application_class.cpp
index c3a2564..8b9d8ce 100644
--- a/enginecustom/src/src/system/application_class.cpp
+++ b/enginecustom/src/src/system/application_class.cpp
@@ -1368,9 +1368,8 @@ void application_class::add_kobject(std::wstring& filepath)
{
std::lock_guard lock(objects_mutex_);
Logger::Get().Log("Adding object", __FILE__, __LINE__);
-
+
char modelFilename[128];
- vector Filename;
TextureContainer KobjectsTextures;
filesystem::path p(filepath);
string filename = p.stem().string();
@@ -1386,27 +1385,69 @@ void application_class::add_kobject(std::wstring& filepath)
L"assets/Texture/BricksNRM2K.png",
L"assets/Texture/BricksGLOSS2K.png"
};
+
+ // Configurer les chemins des textures dans le conteneur
+ KobjectsTextures.diffusePaths.push_back(kobjTexture[0]);
+ if (kobjTexture.size() > 1) KobjectsTextures.normalPaths.push_back(kobjTexture[1]);
+ if (kobjTexture.size() > 2) KobjectsTextures.specularPaths.push_back(kobjTexture[2]);
- object* newObject = new object(*this);
- newObject->LoadTexturesFromPath(kobjTexture,KobjectsTextures, direct_3d_); // Load textures_ from the path
- newObject->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, KobjectsTextures);
- newObject->SetMass(1.0f);
- newObject->SetTranslateMatrix(XMMatrixTranslation(0.0f, 50.0f, 0.0f));
- newObject->SetName(filename);
- newObject->SetId(object_id_);
- newObject->SetModelPath(filepath); // Store the path as std::wstring
+ // Vérifier si le modèle existe déjà dans le cache
+ std::string modelKey = std::string(modelFilename);
+ std::shared_ptr sharedModel;
+
+ auto it = g_model_cache.find(modelKey);
+ if (it != g_model_cache.end()) {
+ // Utiliser le modèle existant du cache
+ Logger::Get().Log("Using cached model for " + modelKey, __FILE__, __LINE__);
+ sharedModel = it->second;
+ }
+ else {
+ // Créer un nouveau modèle
+ sharedModel = std::make_shared();
+
+ // Précharger les textures
+ sharedModel->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), KobjectsTextures);
+
+ // Initialiser le modèle
+ if (!sharedModel->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, KobjectsTextures)) {
+ Logger::Get().Log("Failed to initialize model for object: " + modelKey, __FILE__, __LINE__, Logger::LogLevel::Error);
+ return;
+ }
+
+ // Ajouter le modèle au cache
+ g_model_cache[modelKey] = sharedModel;
+ Logger::Get().Log("Added model to cache: " + modelKey, __FILE__, __LINE__);
+ }
+
+ // Créer une nouvelle entité
+ auto entity = entity_manager_->CreateEntity();
+
+ // Ajouter un composant d'identité
+ auto identity = entity->AddComponent(object_id_++);
+ identity->SetName(filename);
+ identity->SetType(ecs::ObjectType::Unknown);
+
+ // Ajouter un composant de transformation
+ auto transform = entity->AddComponent();
+ transform->SetPosition(XMVectorSet(0.0f, 50.0f, 0.0f, 0.0f));
+ transform->SetScale(XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f));
+ transform->UpdateWorldMatrix();
+
+ // Ajouter un composant de rendu avec le modèle partagé
+ auto render = entity->AddComponent();
+ render->InitializeWithModel(sharedModel);
+
+ // Ajouter un composant de shader
+ auto shader = entity->AddComponent();
+ shader->SetActiveShader(ecs::ShaderType::LIGHTING);
+
+ // Stocker le chemin du modèle
+ auto modelPath = entity->AddComponent();
+ modelPath->SetPath(filepath);
- object_id_++;
-
- object_.push_back(newObject);
+ Logger::Get().Log("ECS entity created with ID: " + std::to_string(identity->GetId()), __FILE__, __LINE__);
update_stats_after_modification();
-
- // Vérifiez que l'objet a bien reçu les textures_
- if (newObject->get_model()->GetTexture(TextureType::Diffuse,0) == nullptr)
- {
- Logger::Get().Log("object texture is null after initialization", __FILE__, __LINE__, Logger::LogLevel::Error);
- }
}
void application_class::add_cube()