Minor - ECS use for import object - V12.1.0

This commit is contained in:
CatChow0 2025-06-24 15:36:45 +02:00
parent 039b034175
commit 3adfddf44f
5 changed files with 116 additions and 89 deletions

View File

@ -4,16 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<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$/enginecustom/imgui.ini" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/imgui.ini" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/application_class.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/application_class.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/imguiManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/imguiManager.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/stats.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/stats.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" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/imguiManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/imguiManager.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/stats.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/stats.cpp" afterDir="false" />
</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" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -26,52 +17,20 @@
<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="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="cidr-memory-view://10" 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" />
<setting file="file://$PROJECT_DIR$/enginecustom/include/Inc/VertexTypes.h" root0="SKIP_HIGHLIGHTING" /> <setting file="file://$PROJECT_DIR$/enginecustom/include/Inc/VertexTypes.h" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/enginecustom/include/Vulkan/Include/vulkan/vulkan_core.h" root0="SKIP_HIGHLIGHTING" /> <setting file="file://$PROJECT_DIR$/enginecustom/include/Vulkan/Include/vulkan/vulkan_core.h" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/enginecustom/src/inc/system/ecs/component.h" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/enginecustom/src/inc/system/ecs/components/identity_component.h" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/enginecustom/src/inc/system/ecs/components/physics_component.h" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/enginecustom/src/inc/system/ecs/components/render_component.h" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/enginecustom/src/inc/system/ecs/components/shader_component.h" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/enginecustom/src/inc/system/ecs/components/transform_component.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/systems/render_system.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>
@ -93,26 +52,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"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true", &quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
"C++ Project.enginecustom.executor": "Run", &quot;C++ Project.enginecustom.executor&quot;: &quot;Run&quot;,
"C/C++ Project.KhaoticDemo.executor": "Run", &quot;C/C++ Project.KhaoticDemo.executor&quot;: &quot;Run&quot;,
"C/C++ Project.enginecustom.executor": "Run", &quot;C/C++ Project.enginecustom.executor&quot;: &quot;Run&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.git.unshallow": "true", &quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
"SHARE_PROJECT_CONFIGURATION_FILES": "true", &quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
"git-widget-placeholder": "main", &quot;git-widget-placeholder&quot;: &quot;main&quot;,
"ignore.virus.scanning.warn.message": "true", &quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.detected.package.tslint": "true", &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"node.js.selected.package.tslint": "(autodetect)", &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"settings.editor.selected.configurable": "preferences.environmentSetup", &quot;settings.editor.selected.configurable&quot;: &quot;preferences.environmentSetup&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
} }
}]]></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">
@ -263,6 +222,7 @@
<workItem from="1750420267631" duration="148000" /> <workItem from="1750420267631" duration="148000" />
<workItem from="1750592598277" duration="332000" /> <workItem from="1750592598277" duration="332000" />
<workItem from="1750699146323" duration="10385000" /> <workItem from="1750699146323" duration="10385000" />
<workItem from="1750763086646" duration="4874000" />
</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

@ -121,6 +121,7 @@
<ClInclude Include="src\inc\system\display_plane_class.h" /> <ClInclude Include="src\inc\system\display_plane_class.h" />
<ClInclude Include="src\inc\system\ecs\component.h" /> <ClInclude Include="src\inc\system\ecs\component.h" />
<ClInclude Include="src\inc\system\ecs\components\identity_component.h" /> <ClInclude Include="src\inc\system\ecs\components\identity_component.h" />
<ClInclude Include="src\inc\system\ecs\components\model_path_component.h" />
<ClInclude Include="src\inc\system\ecs\components\physics_component.h" /> <ClInclude Include="src\inc\system\ecs\components\physics_component.h" />
<ClInclude Include="src\inc\system\ecs\components\render_component.h" /> <ClInclude Include="src\inc\system\ecs\components\render_component.h" />
<ClInclude Include="src\inc\system\ecs\components\shader_component.h" /> <ClInclude Include="src\inc\system\ecs\components\shader_component.h" />

View File

@ -38,6 +38,7 @@
#include "ecs/components/physics_component.h" #include "ecs/components/physics_component.h"
#include "ecs/components/shader_component.h" #include "ecs/components/shader_component.h"
#include "ecs/systems/render_system.h" #include "ecs/systems/render_system.h"
#include "ecs/components/model_path_component.h"
#include <fstream> #include <fstream>
#include <WICTextureLoader.h> #include <WICTextureLoader.h>

View File

@ -0,0 +1,24 @@
#pragma once
#include "../component.h"
#include <string>
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

View File

@ -1370,7 +1370,6 @@ void application_class::add_kobject(std::wstring& filepath)
Logger::Get().Log("Adding object", __FILE__, __LINE__); Logger::Get().Log("Adding object", __FILE__, __LINE__);
char modelFilename[128]; char modelFilename[128];
vector<string> Filename;
TextureContainer KobjectsTextures; TextureContainer KobjectsTextures;
filesystem::path p(filepath); filesystem::path p(filepath);
string filename = p.stem().string(); string filename = p.stem().string();
@ -1387,26 +1386,68 @@ void application_class::add_kobject(std::wstring& filepath)
L"assets/Texture/BricksGLOSS2K.png" L"assets/Texture/BricksGLOSS2K.png"
}; };
object* newObject = new object(*this); // Configurer les chemins des textures dans le conteneur
newObject->LoadTexturesFromPath(kobjTexture,KobjectsTextures, direct_3d_); // Load textures_ from the path KobjectsTextures.diffusePaths.push_back(kobjTexture[0]);
newObject->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, KobjectsTextures); if (kobjTexture.size() > 1) KobjectsTextures.normalPaths.push_back(kobjTexture[1]);
newObject->SetMass(1.0f); if (kobjTexture.size() > 2) KobjectsTextures.specularPaths.push_back(kobjTexture[2]);
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
object_id_++; // Vérifier si le modèle existe déjà dans le cache
std::string modelKey = std::string(modelFilename);
std::shared_ptr<model_class> sharedModel;
object_.push_back(newObject); 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<model_class>();
// 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<ecs::IdentityComponent>(object_id_++);
identity->SetName(filename);
identity->SetType(ecs::ObjectType::Unknown);
// Ajouter un composant de transformation
auto transform = entity->AddComponent<ecs::TransformComponent>();
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<ecs::RenderComponent>();
render->InitializeWithModel(sharedModel);
// Ajouter un composant de shader
auto shader = entity->AddComponent<ecs::ShaderComponent>();
shader->SetActiveShader(ecs::ShaderType::LIGHTING);
// Stocker le chemin du modèle
auto modelPath = entity->AddComponent<ecs::ModelPathComponent>();
modelPath->SetPath(filepath);
Logger::Get().Log("ECS entity created with ID: " + std::to_string(identity->GetId()), __FILE__, __LINE__);
update_stats_after_modification(); 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() void application_class::add_cube()