Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
763ecff93d | |||
e527e85b9c | |||
9d0d2d1dfd | |||
7755150ae8 | |||
ddf5ea30a6 | |||
8f0e583c62 | |||
bf1b5d78e5 | |||
3adfddf44f |
100
.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
generated
100
.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
generated
@@ -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": {
|
"keyToString": {
|
||||||
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
"C++ Project.enginecustom.executor": "Run",
|
"C++ Project.enginecustom.executor": "Run",
|
||||||
"C/C++ Project.KhaoticDemo.executor": "Run",
|
"C/C++ Project.KhaoticDemo.executor": "Run",
|
||||||
"C/C++ Project.enginecustom.executor": "Run",
|
"C/C++ Project.enginecustom.executor": "Run",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
"git-widget-placeholder": "main",
|
"git-widget-placeholder": "main",
|
||||||
"ignore.virus.scanning.warn.message": "true",
|
"ignore.virus.scanning.warn.message": "true",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
"settings.editor.selected.configurable": "preferences.environmentSetup",
|
"settings.editor.selected.configurable": "preferences.environmentSetup",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"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">
|
||||||
@@ -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" />
|
||||||
|
@@ -1 +0,0 @@
|
|||||||
1 isosphere 0 10 0 0 -0 0 1 1 1 Content/Assets/Kobject/isosphere.obj ALPHA_MAPPING 1 Unknown 1 0 2 assets/Texture/Bricks2K.png F:\Github_Repo\khaotic-engine-Reborn\enginecustom\assets\Texture\moss01.png 1 assets/Texture/BricksNRM2K.png 1 assets/Texture/BricksGLOSS2K.png 1 F:\Github_Repo\khaotic-engine-Reborn\enginecustom\assets\Texture\alpha01.png
|
|
@@ -1 +0,0 @@
|
|||||||
0 vaisseautri 0 50 0 0 -0 0 1 1 1 Content/Assets/Kobject/vaisseautri.obj CEL_SHADING 1 Unknown 1 0 1 F:\Github_Repo\khaotic-engine-Reborn\enginecustom\assets\Texture\marble01.png 1 assets/Texture/BricksNRM2K.png 1 assets/Texture/BricksGLOSS2K.png 0
|
|
1
enginecustom/DemoScene_V12.6.0.ker
Normal file
1
enginecustom/DemoScene_V12.6.0.ker
Normal file
@@ -0,0 +1 @@
|
|||||||
|
1 CubePart_0_0_0 0 0 0 0 -0 0 1 1 1 LIGHTING 0 Terrain 0 0 1 assets/Texture/Bricks2K.png 1 assets/Texture/BricksNRM2K.png 1 assets/Texture/BricksGLOSS2K.png 0
|
@@ -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" />
|
||||||
@@ -143,7 +144,6 @@
|
|||||||
<ClInclude Include="src\inc\system\physics.h" />
|
<ClInclude Include="src\inc\system\physics.h" />
|
||||||
<ClInclude Include="src\inc\system\position_class.h" />
|
<ClInclude Include="src\inc\system\position_class.h" />
|
||||||
<ClInclude Include="src\inc\system\render_texture_class.h" />
|
<ClInclude Include="src\inc\system\render_texture_class.h" />
|
||||||
<ClInclude Include="src\inc\system\sceneManager.h" />
|
|
||||||
<ClInclude Include="src\inc\system\scene_manager.h" />
|
<ClInclude Include="src\inc\system\scene_manager.h" />
|
||||||
<ClInclude Include="src\inc\system\shadow_map.h" />
|
<ClInclude Include="src\inc\system\shadow_map.h" />
|
||||||
<ClInclude Include="src\inc\system\Skybox.h" />
|
<ClInclude Include="src\inc\system\Skybox.h" />
|
||||||
|
@@ -27,7 +27,7 @@ Collapsed=0
|
|||||||
DockId=0x0000000B,0
|
DockId=0x0000000B,0
|
||||||
|
|
||||||
[Window][Terrain]
|
[Window][Terrain]
|
||||||
Pos=0,19
|
Pos=236,19
|
||||||
Size=266,842
|
Size=266,842
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000007,0
|
DockId=0x00000007,0
|
||||||
@@ -53,7 +53,7 @@ DockId=0x00000006,0
|
|||||||
[Docking][Data]
|
[Docking][Data]
|
||||||
DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=0,19 Size=1584,842 Split=Y
|
DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=0,19 Size=1584,842 Split=Y
|
||||||
DockNode ID=0x00000003 Parent=0xCCBD8CF7 SizeRef=1584,609 Split=X
|
DockNode ID=0x00000003 Parent=0xCCBD8CF7 SizeRef=1584,609 Split=X
|
||||||
DockNode ID=0x0000000B Parent=0x00000003 SizeRef=234,842 Selected=0x321620B2
|
DockNode ID=0x0000000B Parent=0x00000003 SizeRef=234,842 Selected=0x031DC75C
|
||||||
DockNode ID=0x0000000C Parent=0x00000003 SizeRef=1348,842 Split=X
|
DockNode ID=0x0000000C Parent=0x00000003 SizeRef=1348,842 Split=X
|
||||||
DockNode ID=0x00000007 Parent=0x0000000C SizeRef=266,842 Selected=0x393905AB
|
DockNode ID=0x00000007 Parent=0x0000000C SizeRef=266,842 Selected=0x393905AB
|
||||||
DockNode ID=0x00000008 Parent=0x0000000C SizeRef=1316,842 Split=X
|
DockNode ID=0x00000008 Parent=0x0000000C SizeRef=1316,842 Split=X
|
||||||
|
@@ -7,7 +7,6 @@
|
|||||||
///////////////////////
|
///////////////////////
|
||||||
#include "d_3d_class.h"
|
#include "d_3d_class.h"
|
||||||
#include "camera_class.h"
|
#include "camera_class.h"
|
||||||
#include "object.h"
|
|
||||||
#include "light_class.h"
|
#include "light_class.h"
|
||||||
|
|
||||||
#include "bitmap_class.h"
|
#include "bitmap_class.h"
|
||||||
@@ -38,6 +37,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>
|
||||||
@@ -105,17 +105,12 @@ public:
|
|||||||
void set_speed(const float speed) { this->speed_ = speed; };
|
void set_speed(const float speed) { this->speed_ = speed; };
|
||||||
|
|
||||||
void add_cube();
|
void add_cube();
|
||||||
void delete_kobject(int index);
|
void delete_entity_by_id(int entity_id);
|
||||||
size_t get_cube_count() const { return cubes_.size(); };
|
|
||||||
size_t get_terrain_cube_count() const { return terrain_chunk_.size(); };
|
|
||||||
std::vector<object*> get_cubes() const { return cubes_; };
|
|
||||||
std::vector<object*> get_terrain_cubes() const { return terrain_chunk_; };
|
|
||||||
std::vector<object*> get_kobjects() const { return object_; };
|
|
||||||
void set_kobjects(std::vector<object*> kobjects) { object_ = kobjects; };
|
|
||||||
void add_kobject(std::wstring& filepath);
|
void add_kobject(std::wstring& filepath);
|
||||||
void set_path(WCHAR* path) { path_ = path; };
|
void set_path(WCHAR* path) { path_ = path; };
|
||||||
void set_w_folder(const std::filesystem::path& w_folder) { w_folder_ = w_folder; };
|
void set_w_folder(const std::filesystem::path& w_folder) { w_folder_ = w_folder; };
|
||||||
std::filesystem::path get_w_folder() const { return w_folder_; };
|
std::filesystem::path get_w_folder() const { return w_folder_; };
|
||||||
|
int get_terrain_entity_count();
|
||||||
|
|
||||||
int get_object_id() const { return object_id_; };
|
int get_object_id() const { return object_id_; };
|
||||||
void set_object_id(int object_id) { object_id_ = object_id; };
|
void set_object_id(int object_id) { object_id_ = object_id; };
|
||||||
@@ -178,20 +173,23 @@ public:
|
|||||||
stats* get_stats() const { return stats_; };
|
stats* get_stats() const { return stats_; };
|
||||||
fps_class* get_fps() const { return fps_; };
|
fps_class* get_fps() const { return fps_; };
|
||||||
|
|
||||||
|
ecs::EntityManager* get_entity_manager() const { return entity_manager_.get(); };
|
||||||
|
void update_stats_after_modification();
|
||||||
|
std::map<std::string, std::shared_ptr<model_class>>& get_model_cache() { return g_model_cache; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool render(float, float, float, float, float);
|
bool render(float, float, float, float, float);
|
||||||
bool render_physics(bool key_left, bool key_right, bool key_up, bool key_down, float delta_time);
|
bool render_physics(float delta_time);
|
||||||
bool update_mouse_strings(int, int, bool);
|
bool update_mouse_strings(int, int, bool);
|
||||||
bool update_fps();
|
bool update_fps();
|
||||||
bool update_render_count_string(int);
|
bool update_render_count_string(int);
|
||||||
bool render_scene_to_texture(float);
|
bool render_scene_to_texture(float);
|
||||||
bool render_refraction_to_texture();
|
bool render_refraction_to_texture();
|
||||||
bool render_reflection_to_texture();
|
bool render_reflection_to_texture();
|
||||||
bool render_pass(const std::vector<std::reference_wrapper<std::vector<object*>>>& RenderQueues, XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection);
|
bool render_pass(XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection);
|
||||||
|
|
||||||
void update_skybox_position();
|
void update_skybox_position();
|
||||||
void culling_thread_function();
|
void culling_thread_function();
|
||||||
void update_stats_after_modification();
|
|
||||||
|
|
||||||
public :
|
public :
|
||||||
std::vector<ID3D11ShaderResourceView*> textures;
|
std::vector<ID3D11ShaderResourceView*> textures;
|
||||||
@@ -245,14 +243,10 @@ private :
|
|||||||
std::unique_ptr<ecs::EntityManager> entity_manager_;
|
std::unique_ptr<ecs::EntityManager> entity_manager_;
|
||||||
|
|
||||||
object* selected_object_;
|
object* selected_object_;
|
||||||
std::vector<object*> cubes_;
|
|
||||||
std::vector<object*> terrain_chunk_;
|
|
||||||
std::vector<object*> object_;
|
|
||||||
|
|
||||||
float speed_ = 0.1f; // speed for the demo spinning object
|
float speed_ = 0.1f; // speed for the demo spinning object
|
||||||
std::vector<object*> imported_object_;
|
std::vector<object*> imported_object_;
|
||||||
int object_id_ = 0;
|
int object_id_ = 0;
|
||||||
std::vector<std::reference_wrapper<std::vector<object*>>> render_queues_;
|
|
||||||
std::vector<object*> skybox_;
|
std::vector<object*> skybox_;
|
||||||
|
|
||||||
// ----------------------------------- //
|
// ----------------------------------- //
|
||||||
|
@@ -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
|
@@ -54,6 +54,18 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtenir toutes les entit<69>s
|
||||||
|
std::vector<std::shared_ptr<Entity>> GetAllEntities() {
|
||||||
|
std::vector<std::shared_ptr<Entity>> result;
|
||||||
|
result.reserve(m_Entities.size());
|
||||||
|
|
||||||
|
for (const auto& [id, entity] : m_Entities) {
|
||||||
|
result.push_back(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// Obtenir toutes les entit<69>s qui ont un composant sp<73>cifique
|
// Obtenir toutes les entit<69>s qui ont un composant sp<73>cifique
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::vector<std::shared_ptr<Entity>> GetEntitiesWithComponent() {
|
std::vector<std::shared_ptr<Entity>> GetEntitiesWithComponent() {
|
||||||
|
@@ -3,6 +3,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "ecs/entity.h"
|
||||||
|
|
||||||
class d_3d_class;
|
class d_3d_class;
|
||||||
class object;
|
class object;
|
||||||
class application_class;
|
class application_class;
|
||||||
@@ -26,6 +28,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<ecs::Entity>> entity_;
|
||||||
|
|
||||||
application_class* app_;
|
application_class* app_;
|
||||||
std::string scene_path_;
|
std::string scene_path_;
|
||||||
std::vector<object*> object_vec_;
|
std::vector<object*> object_vec_;
|
||||||
|
@@ -28,10 +28,6 @@ application_class::application_class() : should_quit_(false)
|
|||||||
reflection_texture_ = nullptr;
|
reflection_texture_ = nullptr;
|
||||||
scene_texture_ = nullptr;
|
scene_texture_ = nullptr;
|
||||||
physics_ = nullptr;
|
physics_ = nullptr;
|
||||||
cubes_.clear();
|
|
||||||
terrain_chunk_.clear();
|
|
||||||
object_.clear();
|
|
||||||
render_queues_.clear();
|
|
||||||
skybox_.clear();
|
skybox_.clear();
|
||||||
lights_.clear();
|
lights_.clear();
|
||||||
sun_light_ = nullptr;
|
sun_light_ = nullptr;
|
||||||
@@ -86,11 +82,6 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
|
|||||||
bool result;
|
bool result;
|
||||||
HRESULT Hresult;
|
HRESULT Hresult;
|
||||||
|
|
||||||
render_queues_.push_back(std::ref(skybox_)); // Skybox doit <20>tre rendu en premier pour <20>tre derri<72>re touts les autres objets
|
|
||||||
render_queues_.push_back(std::ref(object_));
|
|
||||||
render_queues_.push_back(std::ref(cubes_));
|
|
||||||
render_queues_.push_back(std::ref(terrain_chunk_));
|
|
||||||
|
|
||||||
// create entity manager
|
// create entity manager
|
||||||
entity_manager_ = std::make_unique<ecs::EntityManager>();
|
entity_manager_ = std::make_unique<ecs::EntityManager>();
|
||||||
|
|
||||||
@@ -1138,7 +1129,7 @@ bool application_class::render(float rotation, float x, float y, float z, float
|
|||||||
// active_camera_->render();
|
// active_camera_->render();
|
||||||
// // Render the objects in the render queues. with depth only pass.
|
// // Render the objects in the render queues. with depth only pass.
|
||||||
// active_camera_->get_view_matrix(viewMatrix);
|
// active_camera_->get_view_matrix(viewMatrix);
|
||||||
result = render_pass(render_queues_, diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix);
|
result = render_pass(diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Could not render the model using any shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
Logger::Get().Log("Could not render the model using any shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
@@ -1301,9 +1292,10 @@ int application_class::get_screen_height() const
|
|||||||
|
|
||||||
void application_class::generate_terrain()
|
void application_class::generate_terrain()
|
||||||
{
|
{
|
||||||
Logger::Get().Log("G<EFBFBD>n<EFBFBD>ration du terrain avec instanciation", __FILE__, __LINE__, Logger::LogLevel::Info);
|
Logger::Get().Log("G<EFBFBD>n<EFBFBD>ration du terrain avec ECS", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
|
||||||
terrain_chunk_.clear();
|
// delete previous terrain if it exists
|
||||||
|
delete_terrain();
|
||||||
|
|
||||||
// Dimensions du terrain
|
// Dimensions du terrain
|
||||||
float scaleX = 10.0f;
|
float scaleX = 10.0f;
|
||||||
@@ -1312,56 +1304,75 @@ void application_class::generate_terrain()
|
|||||||
int gridSizeX = 20;
|
int gridSizeX = 20;
|
||||||
int gridSizeZ = 20;
|
int gridSizeZ = 20;
|
||||||
|
|
||||||
// Cr<EFBFBD>er un conteneur de textures_ partag<61>
|
// V<EFBFBD>rifier si le mod<6F>le existe d<>j<EFBFBD> dans le cache
|
||||||
TextureContainer textureContainer;
|
std::string modelName = "assets/Model/OBJ/plane.obj";
|
||||||
textureContainer.diffusePaths.push_back(L"assets/Texture/Bricks2K.png");
|
std::shared_ptr<model_class> sharedModel;
|
||||||
textureContainer.normalPaths.push_back(L"assets/Texture/BricksNRM2K.png");
|
|
||||||
textureContainer.specularPaths.push_back(L"assets/Texture/BricksGLOSS2K.png");
|
|
||||||
|
|
||||||
// Pr<50>charger les textures_ une seule fois
|
auto it = g_model_cache.find(modelName);
|
||||||
model_class* sharedModel = new model_class();
|
if (it != g_model_cache.end()) {
|
||||||
sharedModel->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), textureContainer);
|
// Utiliser le mod<6F>le existant du cache
|
||||||
|
Logger::Get().Log("Using cached model for terrain: " + modelName, __FILE__, __LINE__);
|
||||||
|
sharedModel = it->second;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Cr<43>er un conteneur de textures partag<61>
|
||||||
|
TextureContainer textureContainer;
|
||||||
|
textureContainer.diffusePaths.push_back(L"assets/Texture/Bricks2K.png");
|
||||||
|
textureContainer.normalPaths.push_back(L"assets/Texture/BricksNRM2K.png");
|
||||||
|
textureContainer.specularPaths.push_back(L"assets/Texture/BricksGLOSS2K.png");
|
||||||
|
|
||||||
char modelFilename[128];
|
// Cr<43>er et initialiser le mod<6F>le si non trouv<75>
|
||||||
strcpy_s(modelFilename, "assets/Model/OBJ/plane.obj");
|
char modelFilename[128];
|
||||||
|
strcpy_s(modelFilename, modelName.c_str());
|
||||||
|
|
||||||
// G<>n<EFBFBD>rer les tuiles de terrain
|
auto newModel = std::make_shared<model_class>();
|
||||||
for (int i = 0; i < gridSizeX; i++)
|
newModel->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), textureContainer);
|
||||||
{
|
|
||||||
for (int j = 0; j < gridSizeZ; j++)
|
|
||||||
{
|
|
||||||
// Cr<43>er un nouvel objet de terrain
|
|
||||||
object* terrain = new object(*this);
|
|
||||||
|
|
||||||
// Initialiser avec le mod<6F>le et les textures_ pr<70>charg<72>es
|
if (!newModel->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, textureContainer)) {
|
||||||
if (!terrain->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, textureContainer))
|
Logger::Get().Log("Impossible d'initialiser le mod<6F>le du terrain", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
{
|
return;
|
||||||
Logger::Get().Log("<EFBFBD>chec de l'initialisation d'une tuile de terrain", __FILE__, __LINE__, Logger::LogLevel::Error);
|
}
|
||||||
delete terrain;
|
|
||||||
continue;
|
// Ajouter le mod<6F>le au cache
|
||||||
|
g_model_cache[modelName] = newModel;
|
||||||
|
sharedModel = newModel;
|
||||||
|
Logger::Get().Log("Added terrain model to cache: " + modelName, __FILE__, __LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
// V<>rifier si l'entity manager est disponible
|
||||||
|
if (entity_manager_) {
|
||||||
|
// G<>n<EFBFBD>rer les tuiles de terrain avec le syst<73>me ECS
|
||||||
|
for (int i = 0; i < gridSizeX; i++) {
|
||||||
|
for (int j = 0; j < gridSizeZ; j++) {
|
||||||
|
// Cr<43>er une entit<69>
|
||||||
|
auto entity = entity_manager_->CreateEntity();
|
||||||
|
|
||||||
|
// Ajouter un composant d'identit<69>
|
||||||
|
auto identity = entity->AddComponent<ecs::IdentityComponent>(object_id_++);
|
||||||
|
identity->SetName("TerrainTile_" + std::to_string(i) + "_" + std::to_string(j));
|
||||||
|
identity->SetType(ecs::ObjectType::Terrain);
|
||||||
|
|
||||||
|
// Ajouter un composant de transformation
|
||||||
|
auto transform = entity->AddComponent<ecs::TransformComponent>();
|
||||||
|
transform->SetPosition(XMVectorSet(i * scaleX, -12.0f, j * scaleZ, 0.0f));
|
||||||
|
transform->SetScale(XMVectorSet(scaleX, scaleY, scaleZ, 0.0f));
|
||||||
|
transform->UpdateWorldMatrix();
|
||||||
|
|
||||||
|
// Ajouter un composant de rendu
|
||||||
|
auto render = entity->AddComponent<ecs::RenderComponent>();
|
||||||
|
render->InitializeWithModel(sharedModel);
|
||||||
|
|
||||||
|
// Ajouter un composant de shader
|
||||||
|
auto shader = entity->AddComponent<ecs::ShaderComponent>();
|
||||||
|
shader->SetActiveShader(ecs::ShaderType::SUNLIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// D<>finir la position dans la grille
|
|
||||||
XMFLOAT3 position(i * scaleX, -12.0f, j * scaleZ);
|
|
||||||
XMFLOAT3 scale(scaleX, scaleY, scaleZ);
|
|
||||||
|
|
||||||
terrain->SetPosition(XMLoadFloat3(&position));
|
|
||||||
terrain->SetScale(XMLoadFloat3(&scale));
|
|
||||||
|
|
||||||
// Configurer les propri<72>t<EFBFBD>s
|
|
||||||
terrain->SetName("TerrainTile_" + std::to_string(i) + "_" + std::to_string(j));
|
|
||||||
terrain->SetType(ObjectType::Cube);
|
|
||||||
terrain->SetActiveShader(ShaderType::SUNLIGHT);
|
|
||||||
terrain->SetId(object_id_++);
|
|
||||||
|
|
||||||
// Ajouter <20> la liste des chunks de terrain
|
|
||||||
terrain_chunk_.push_back(terrain);
|
|
||||||
|
|
||||||
update_stats_after_modification();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Get().Log("Terrain g<>n<EFBFBD>r<EFBFBD> avec " + std::to_string(terrain_chunk_.size()) + " tuiles", __FILE__, __LINE__, Logger::LogLevel::Info);
|
update_stats_after_modification();
|
||||||
|
|
||||||
|
int totalTiles = gridSizeX * gridSizeZ;
|
||||||
|
Logger::Get().Log("Terrain g<>n<EFBFBD>r<EFBFBD> avec " + std::to_string(totalTiles) + " tuiles", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void application_class::add_kobject(std::wstring& filepath)
|
void application_class::add_kobject(std::wstring& filepath)
|
||||||
@@ -1370,7 +1381,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 +1397,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<6F>le existe d<>j<EFBFBD> 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<6F>le existant du cache
|
||||||
|
Logger::Get().Log("Using cached model for " + modelKey, __FILE__, __LINE__);
|
||||||
|
sharedModel = it->second;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Cr<43>er un nouveau mod<6F>le
|
||||||
|
sharedModel = std::make_shared<model_class>();
|
||||||
|
|
||||||
|
// Pr<50>charger les textures
|
||||||
|
sharedModel->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), KobjectsTextures);
|
||||||
|
|
||||||
|
// Initialiser le mod<6F>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<6F>le au cache
|
||||||
|
g_model_cache[modelKey] = sharedModel;
|
||||||
|
Logger::Get().Log("Added model to cache: " + modelKey, __FILE__, __LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cr<43>er une nouvelle entit<69>
|
||||||
|
auto entity = entity_manager_->CreateEntity();
|
||||||
|
|
||||||
|
// Ajouter un composant d'identit<69>
|
||||||
|
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<6F>le partag<61>
|
||||||
|
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<6F>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<72>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()
|
||||||
@@ -1414,37 +1466,80 @@ void application_class::add_cube()
|
|||||||
std::lock_guard<std::mutex> lock(objects_mutex_);
|
std::lock_guard<std::mutex> lock(objects_mutex_);
|
||||||
Logger::Get().Log("Adding cube", __FILE__, __LINE__);
|
Logger::Get().Log("Adding cube", __FILE__, __LINE__);
|
||||||
|
|
||||||
char modelFilename[128];
|
std::string model_name = "assets/Model/TXT/cube.txt";
|
||||||
TextureContainer CubeTexture;
|
std::shared_ptr<model_class> sharedModel;
|
||||||
// Set the file name of the model.
|
|
||||||
strcpy_s(modelFilename, "assets/Model/TXT/cube.txt");
|
|
||||||
|
|
||||||
// Liste des fichiers de texture
|
auto it = g_model_cache.find(model_name);
|
||||||
std::vector<std::wstring> cubeTexture = {
|
if (it != g_model_cache.end())
|
||||||
L"assets/Texture/Bricks2K.png"
|
{
|
||||||
};
|
Logger::Get().Log("Using cached model: " + model_name, __FILE__, __LINE__);
|
||||||
|
sharedModel = it->second;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TextureContainer cube_textures;
|
||||||
|
cube_textures.diffusePaths.push_back(L"assets/Texture/Bricks2K.png");
|
||||||
|
cube_textures.normalPaths.push_back(L"assets/Texture/BricksNRM2K.png");
|
||||||
|
cube_textures.specularPaths.push_back(L"assets/Texture/BricksGLOSS2K.png");
|
||||||
|
|
||||||
static int cubeCount = 0;
|
char model_filename[128];
|
||||||
float position = cubeCount * 2.0f;
|
strcpy_s(model_filename, model_name.c_str());
|
||||||
object* newCube = new object(*this);
|
|
||||||
newCube->LoadTexturesFromPath(cubeTexture, CubeTexture, direct_3d_); // Load textures_ from the path
|
|
||||||
newCube->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, CubeTexture);
|
|
||||||
newCube->SetTranslateMatrix(XMMatrixTranslation(position, 0.0f, 0.0f));
|
|
||||||
|
|
||||||
cubes_.push_back(newCube);
|
auto newModel = std::make_shared<model_class>();
|
||||||
|
newModel->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), cube_textures);
|
||||||
|
if (!newModel->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), model_filename, cube_textures)) {
|
||||||
|
Logger::Get().Log("Failed to initialize cube model", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_model_cache[model_name] = newModel;
|
||||||
|
sharedModel = newModel;
|
||||||
|
Logger::Get().Log("Added cube model to cache: " + model_name, __FILE__, __LINE__);
|
||||||
|
|
||||||
|
|
||||||
|
if (entity_manager_)
|
||||||
|
{
|
||||||
|
auto entity = entity_manager_->CreateEntity();
|
||||||
|
|
||||||
|
auto identity = entity->AddComponent<ecs::IdentityComponent>(object_id_++);
|
||||||
|
identity->SetName("Cube");
|
||||||
|
identity->SetType(ecs::ObjectType::Cube);
|
||||||
|
|
||||||
|
auto transform = entity->AddComponent<ecs::TransformComponent>();
|
||||||
|
transform->SetPosition(XMVectorSet(0.0f, 10.0f, 0.0f, 0.0f));
|
||||||
|
transform->SetScale(XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f));
|
||||||
|
transform->UpdateWorldMatrix();
|
||||||
|
|
||||||
|
auto render = entity->AddComponent<ecs::RenderComponent>();
|
||||||
|
render->InitializeWithModel(sharedModel);
|
||||||
|
|
||||||
|
auto shader = entity->AddComponent<ecs::ShaderComponent>();
|
||||||
|
shader->SetActiveShader(ecs::ShaderType::TEXTURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
update_stats_after_modification();
|
update_stats_after_modification();
|
||||||
|
Logger::Get().Log("Cube added successfully", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void application_class::delete_kobject(int index)
|
void application_class::delete_entity_by_id(int entity_id)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(objects_mutex_);
|
std::lock_guard<std::mutex> lock(objects_mutex_);
|
||||||
Logger::Get().Log("Deleting object", __FILE__, __LINE__);
|
Logger::Get().Log("Deleting entity with ID: " + std::to_string(entity_id), __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
|
||||||
if (index < object_.size())
|
if (entity_manager_) {
|
||||||
{
|
// Rechercher l'entit<69> avec l'ID sp<73>cifi<66> via le composant IdentityComponent
|
||||||
object_.erase(object_.begin() + index);
|
auto entities_with_identity = entity_manager_->GetEntitiesWithComponent<ecs::IdentityComponent>();
|
||||||
|
for (auto& entity : entities_with_identity) {
|
||||||
|
auto identity = entity->GetComponent<ecs::IdentityComponent>();
|
||||||
|
if (identity && identity->GetId() == entity_id) {
|
||||||
|
// Supprimer l'entit<69>
|
||||||
|
entity_manager_->DestroyEntity(entity->GetID());
|
||||||
|
Logger::Get().Log("Entity with ID " + std::to_string(entity_id) + " successfully deleted", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update_stats_after_modification();
|
update_stats_after_modification();
|
||||||
@@ -1453,8 +1548,19 @@ void application_class::delete_kobject(int index)
|
|||||||
void application_class::delete_terrain()
|
void application_class::delete_terrain()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(objects_mutex_);
|
std::lock_guard<std::mutex> lock(objects_mutex_);
|
||||||
Logger::Get().Log("Deleting terrain", __FILE__, __LINE__);
|
Logger::Get().Log("Deleting terrain", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
terrain_chunk_.clear();
|
|
||||||
|
// Get all entities with the Terrain type
|
||||||
|
auto entities_with_terrain = entity_manager_->GetEntitiesWithComponent<ecs::IdentityComponent>();
|
||||||
|
for (auto& entity : entities_with_terrain) {
|
||||||
|
auto identity = entity->GetComponent<ecs::IdentityComponent>();
|
||||||
|
if (identity && identity->GetType() == ecs::ObjectType::Terrain) {
|
||||||
|
// Destroy the entity
|
||||||
|
entity_manager_->DestroyEntity(entity->GetID());
|
||||||
|
Logger::Get().Log("Terrain entity with ID " + std::to_string(identity->GetId()) + " successfully deleted", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
update_stats_after_modification();
|
update_stats_after_modification();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1685,36 +1791,34 @@ void application_class::culling_thread_function()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Traitement des files d'objets normaux (sans la skybox)
|
// Traitement des files d'objets normaux (sans la skybox)
|
||||||
std::vector<std::reference_wrapper<std::vector<object*>>> queues = {
|
auto all_entity = entity_manager_->GetAllEntities();
|
||||||
std::ref(object_), std::ref(cubes_), std::ref(terrain_chunk_)
|
|
||||||
};
|
|
||||||
|
|
||||||
for (auto& queueRef : queues)
|
for (auto& entity : all_entity)
|
||||||
{
|
{
|
||||||
std::vector<object*>& queue = queueRef.get();
|
std::lock_guard<std::mutex> lock(objects_mutex_);
|
||||||
|
auto renderComponent = entity->GetComponent<ecs::RenderComponent>();
|
||||||
|
if (renderComponent && renderComponent->GetModel())
|
||||||
|
{
|
||||||
|
// Extraction des donn<6E>es de position via le composant TransformComponent
|
||||||
|
auto transformComponent = entity->GetComponent<ecs::TransformComponent>();
|
||||||
|
if (transformComponent)
|
||||||
|
{
|
||||||
|
XMVECTOR transformPosition = transformComponent->GetPosition();
|
||||||
|
float x = XMVectorGetX(transformPosition);
|
||||||
|
float y = XMVectorGetY(transformPosition);
|
||||||
|
float z = XMVectorGetZ(transformPosition);
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(objects_mutex_);
|
// Calcul du rayon approximatif
|
||||||
|
XMVECTOR scale = transformComponent->GetScale();
|
||||||
|
float radius = max(max(XMVectorGetX(scale), XMVectorGetY(scale)), XMVectorGetZ(scale));
|
||||||
|
|
||||||
for (auto* object : queue)
|
// verification du frustum
|
||||||
{
|
bool visible = frustum_culling_.CheckCube(x, y, z, radius, get_frustum_tolerance());
|
||||||
if (!object) continue;
|
renderComponent->SetVisible(visible);
|
||||||
|
}
|
||||||
|
|
||||||
// Extraction des donn<6E>es de position
|
}
|
||||||
XMVECTOR position = object->GetPosition();
|
}
|
||||||
float x = XMVectorGetX(position);
|
|
||||||
float y = XMVectorGetY(position);
|
|
||||||
float z = XMVectorGetZ(position);
|
|
||||||
|
|
||||||
// Calcul du rayon approximatif
|
|
||||||
XMVECTOR scale = object->GetScale();
|
|
||||||
float radius = max(max(XMVectorGetX(scale), XMVectorGetY(scale)), XMVectorGetZ(scale));
|
|
||||||
|
|
||||||
// V<>rification du frustum
|
|
||||||
bool visible = frustum_culling_.CheckCube(x, y, z, radius, get_frustum_tolerance());
|
|
||||||
object->SetVisible(visible);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pause pour <20>viter de surcharger le CPU
|
// Pause pour <20>viter de surcharger le CPU
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(16)); // ~60 Hz
|
std::this_thread::sleep_for(std::chrono::milliseconds(16)); // ~60 Hz
|
||||||
@@ -1725,7 +1829,7 @@ void application_class::culling_thread_function()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool application_class::render_pass(const std::vector<std::reference_wrapper<std::vector<object*>>>& RenderQueues, XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection)
|
bool application_class::render_pass(XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(objects_mutex_);
|
std::lock_guard<std::mutex> lock(objects_mutex_);
|
||||||
XMMATRIX scaleMatrix, rotateMatrix, translateMatrix;
|
XMMATRIX scaleMatrix, rotateMatrix, translateMatrix;
|
||||||
@@ -1856,83 +1960,16 @@ void application_class::update_skybox_position()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool application_class::render_physics(bool key_left, bool key_right, bool key_up, bool key_down, float delta_time) {
|
bool application_class::render_physics(float delta_time) {
|
||||||
const float maxSpeed = 50.0f; // Limite de vitesse maximale
|
|
||||||
|
|
||||||
for (auto& object : object_) {
|
// update the physical entity if they have the physics component
|
||||||
if (object == nullptr) {
|
auto entities_with_physics = entity_manager_->GetEntitiesWithComponent<ecs::PhysicsComponent>();
|
||||||
Logger::Get().Log("object is null", __FILE__, __LINE__, Logger::LogLevel::Error);
|
for (auto& entity : entities_with_physics) {
|
||||||
return false;
|
auto physicsComponent = entity->GetComponent<ecs::PhysicsComponent>();
|
||||||
|
if (physicsComponent) {
|
||||||
|
// Update the physics component with the input keys and delta time
|
||||||
|
physicsComponent->Update(delta_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!object->IsPhysicsEnabled()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset acceleration for the new frame
|
|
||||||
object->SetAcceleration(XMVectorZero());
|
|
||||||
object->SetGrounded(false);
|
|
||||||
|
|
||||||
for (auto& chunk : terrain_chunk_) {
|
|
||||||
if (!physics_->IsColliding(object, chunk)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
object->SetVelocity(XMVectorSetY(object->GetVelocity(), 0.0f));
|
|
||||||
object->SetAcceleration(XMVectorSetY(object->GetAcceleration(), 0.0f));
|
|
||||||
object->SetGrounded(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto& object2 : object_) {
|
|
||||||
if (object->GetId() == object2->GetId()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!physics_->IsColliding(object, object2)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
object->SetVelocity(XMVectorZero());
|
|
||||||
object->SetAcceleration(XMVectorZero());
|
|
||||||
}
|
|
||||||
|
|
||||||
float forceX = 0, forceY = 0, forceZ = 0, forceW = 0;
|
|
||||||
|
|
||||||
if (key_left) {
|
|
||||||
forceX = -40.0f;
|
|
||||||
}
|
|
||||||
if (key_right) {
|
|
||||||
forceX = 40.0f;
|
|
||||||
}
|
|
||||||
if (key_up) {
|
|
||||||
forceY = 40.0f;
|
|
||||||
}
|
|
||||||
if (key_down && !object->IsGrounded()) {
|
|
||||||
forceY = -40.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
XMVECTOR force = XMVectorSet(forceX, forceY, forceZ, forceW);
|
|
||||||
physics_->AddForce(object, force);
|
|
||||||
|
|
||||||
object->AddVelocity(delta_time);
|
|
||||||
|
|
||||||
XMVECTOR velocity = object->GetVelocity();
|
|
||||||
float speed = XMVectorGetX(XMVector3Length(velocity));
|
|
||||||
if (speed > maxSpeed) {
|
|
||||||
velocity = XMVectorScale(velocity, maxSpeed / speed);
|
|
||||||
object->SetVelocity(velocity);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (object->m_gravityEnabled) {
|
|
||||||
physics_->ApplyGravity(object, delta_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (XMVectorGetY(object->GetPosition()) < -30.0f) {
|
|
||||||
XMVECTOR currentPosition = object->GetPosition();
|
|
||||||
object->SetPosition(XMVectorSetY(currentPosition, 50.0f));
|
|
||||||
}
|
|
||||||
|
|
||||||
object->m_previousPosition = object->GetPosition();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -1951,7 +1988,7 @@ void application_class::physics_thread_function()
|
|||||||
lastTime = now;
|
lastTime = now;
|
||||||
|
|
||||||
float deltaTime = 1.0f / static_cast<float>(physics_tick_rate_);
|
float deltaTime = 1.0f / static_cast<float>(physics_tick_rate_);
|
||||||
bool result = render_physics(inputs_.key_left, inputs_.key_right, inputs_.key_up, inputs_.key_down, deltaTime);
|
bool result = render_physics(deltaTime);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Could not render the physics scene", __FILE__, __LINE__, Logger::LogLevel::Error);
|
Logger::Get().Log("Could not render the physics scene", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
@@ -1993,54 +2030,33 @@ bool application_class::create_big_cube(int side_count)
|
|||||||
sharedModel = newModel;
|
sharedModel = newModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version ECS - Cr<43>er les entit<69>s pour le cube
|
for (int x = 0; x < side_count; x++) {
|
||||||
if (entity_manager_) {
|
for (int y = 0; y < side_count; y++) {
|
||||||
for (int x = 0; x < side_count; x++) {
|
for (int z = 0; z < side_count; z++) {
|
||||||
for (int y = 0; y < side_count; y++) {
|
// Cr<43>er une entit<69>
|
||||||
for (int z = 0; z < side_count; z++) {
|
auto entity = entity_manager_->CreateEntity();
|
||||||
// Cr<43>er une entit<69>
|
|
||||||
auto entity = entity_manager_->CreateEntity();
|
|
||||||
|
|
||||||
// Ajouter un composant d'identit<69>
|
// Ajouter un composant d'identit<69>
|
||||||
auto identity = entity->AddComponent<ecs::IdentityComponent>(object_id_++);
|
auto identity = entity->AddComponent<ecs::IdentityComponent>(object_id_++);
|
||||||
identity->SetName("CubePart_" + std::to_string(x) + "_" + std::to_string(y) + "_" + std::to_string(z));
|
identity->SetName("CubePart_" + std::to_string(x) + "_" + std::to_string(y) + "_" + std::to_string(z));
|
||||||
identity->SetType(ecs::ObjectType::Cube);
|
identity->SetType(ecs::ObjectType::Terrain);
|
||||||
|
|
||||||
// Ajouter un composant de transformation
|
// Ajouter un composant de transformation
|
||||||
auto transform = entity->AddComponent<ecs::TransformComponent>();
|
auto transform = entity->AddComponent<ecs::TransformComponent>();
|
||||||
transform->SetPosition(XMVectorSet(static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), 0.0f));
|
transform->SetPosition(XMVectorSet(static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), 0.0f));
|
||||||
transform->SetScale(XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f));
|
transform->SetScale(XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f));
|
||||||
transform->UpdateWorldMatrix();
|
transform->UpdateWorldMatrix();
|
||||||
|
|
||||||
// Ajouter un composant de rendu
|
// Ajouter un composant de rendu
|
||||||
auto render = entity->AddComponent<ecs::RenderComponent>();
|
auto render = entity->AddComponent<ecs::RenderComponent>();
|
||||||
render->InitializeWithModel(sharedModel);
|
render->InitializeWithModel(sharedModel);
|
||||||
|
|
||||||
// Ajouter un composant de shader
|
// Ajouter un composant de shader
|
||||||
auto shader = entity->AddComponent<ecs::ShaderComponent>();
|
auto shader = entity->AddComponent<ecs::ShaderComponent>();
|
||||||
shader->SetActiveShader(ecs::ShaderType::LIGHTING);
|
shader->SetActiveShader(ecs::ShaderType::LIGHTING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Ancien syst<73>me - Cr<43>er temporairement les cubes dans un vecteur local
|
|
||||||
std::vector<object*> tempCubes;
|
|
||||||
tempCubes.reserve(side_count * side_count * side_count);
|
|
||||||
|
|
||||||
// G<>n<EFBFBD>rer side_count<6E> cubes
|
|
||||||
for (int x = 0; x < side_count; x++) {
|
|
||||||
for (int y = 0; y < side_count; y++) {
|
|
||||||
for (int z = 0; z < side_count; z++) {
|
|
||||||
object* cubePart = new object(*this);
|
|
||||||
cubePart->SetModel(sharedModel);
|
|
||||||
cubePart->SetTranslateMatrix(XMMatrixTranslation(static_cast<float>(x), static_cast<float>(y), static_cast<float>(z)));
|
|
||||||
tempCubes.push_back(cubePart);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Transf<73>rer les cubes du vecteur temporaire au vecteur membre
|
|
||||||
cubes_ = std::move(tempCubes);
|
|
||||||
}
|
|
||||||
|
|
||||||
update_stats_after_modification();
|
update_stats_after_modification();
|
||||||
|
|
||||||
@@ -2054,3 +2070,20 @@ void application_class::update_stats_after_modification()
|
|||||||
stats_ -> update_geometric_stats();
|
stats_ -> update_geometric_stats();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int application_class::get_terrain_entity_count()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(objects_mutex_);
|
||||||
|
int terrainCount = 0;
|
||||||
|
|
||||||
|
// Get all entities with the Terrain type
|
||||||
|
auto entities_with_terrain = entity_manager_->GetEntitiesWithComponent<ecs::IdentityComponent>();
|
||||||
|
for (auto& entity : entities_with_terrain) {
|
||||||
|
auto identity = entity->GetComponent<ecs::IdentityComponent>();
|
||||||
|
if (identity && identity->GetType() == ecs::ObjectType::Terrain) {
|
||||||
|
terrainCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return terrainCount;
|
||||||
|
}
|
||||||
|
@@ -386,290 +386,313 @@ void imguiManager::WidgetAddObject()
|
|||||||
|
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::Text("Number of cubes: %d", app_->get_cube_count());
|
ImGui::Text("Number of cubes: %d", app_->get_entity_manager()->GetEntityCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void imguiManager::WidgetObjectWindow()
|
void imguiManager::WidgetObjectWindow()
|
||||||
{
|
{
|
||||||
ImGui::Begin("Objects", &showObjectWindow);
|
ImGui::Begin("Objects", &showObjectWindow);
|
||||||
|
|
||||||
|
// Obtenir toutes les entit<69>s avec un composant d'identit<69> et de transformation
|
||||||
|
auto entities = app_->get_entity_manager()->GetEntitiesWithComponent<ecs::IdentityComponent>();
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (auto& object : app_->get_kobjects())
|
for (auto& entity : entities)
|
||||||
{
|
{
|
||||||
std::string headerName = object->GetName() + " " + std::to_string(index);
|
auto identity = entity->GetComponent<ecs::IdentityComponent>();
|
||||||
if (ImGui::CollapsingHeader(headerName.c_str()))
|
auto transform = entity->GetComponent<ecs::TransformComponent>();
|
||||||
|
auto render = entity->GetComponent<ecs::RenderComponent>();
|
||||||
|
auto shader = entity->GetComponent<ecs::ShaderComponent>();
|
||||||
|
auto physics = entity->GetComponent<ecs::PhysicsComponent>();
|
||||||
|
|
||||||
|
if (identity && transform)
|
||||||
{
|
{
|
||||||
|
std::string headerName = identity->GetName() + " " + std::to_string(identity->GetId());
|
||||||
XMVECTOR position = object->GetPosition();
|
if (ImGui::CollapsingHeader(headerName.c_str()))
|
||||||
XMVECTOR rotation = object->GetRotation();
|
|
||||||
XMVECTOR scale = object->GetScale();
|
|
||||||
|
|
||||||
float pos[3] = { XMVectorGetX(position), XMVectorGetY(position), XMVectorGetZ(position) };
|
|
||||||
std::string posLabel = "Position##" + std::to_string(index);
|
|
||||||
if (ImGui::DragFloat3(posLabel.c_str(), pos))
|
|
||||||
{
|
{
|
||||||
object->SetPosition(XMVectorSet(pos[0], pos[1], pos[2], 0.0f));
|
// Position, Rotation, Scale
|
||||||
}
|
XMVECTOR position = transform->GetPosition();
|
||||||
|
XMVECTOR rotation = transform->GetRotation();
|
||||||
|
XMVECTOR scale = transform->GetScale();
|
||||||
|
|
||||||
float rot[3] = { XMVectorGetX(rotation), XMVectorGetY(rotation), XMVectorGetZ(rotation) };
|
float pos[3] = { XMVectorGetX(position), XMVectorGetY(position), XMVectorGetZ(position) };
|
||||||
std::string rotLabel = "Rotation##" + std::to_string(index);
|
std::string posLabel = "Position##" + std::to_string(identity->GetId());
|
||||||
if (ImGui::DragFloat3(rotLabel.c_str(), rot))
|
if (ImGui::DragFloat3(posLabel.c_str(), pos))
|
||||||
{
|
|
||||||
object->SetRotation(XMVectorSet(rot[0], rot[1], rot[2], 0.0f));
|
|
||||||
}
|
|
||||||
|
|
||||||
float scl[3] = { XMVectorGetX(scale), XMVectorGetY(scale), XMVectorGetZ(scale) };
|
|
||||||
std::string sclLabel = "Scale##" + std::to_string(index);
|
|
||||||
if (ImGui::DragFloat3(sclLabel.c_str(), scl))
|
|
||||||
{
|
|
||||||
object->SetScale(XMVectorSet(scl[0], scl[1], scl[2], 0.0f));
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::Separator();
|
|
||||||
|
|
||||||
// D<>finir les types de textures_
|
|
||||||
std::vector<std::string> textureCategories = {
|
|
||||||
"Diffuse", "Normal", "Specular", "Alpha"
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<TextureType> textureTypes = {
|
|
||||||
TextureType::Diffuse, TextureType::Normal,
|
|
||||||
TextureType::Specular, TextureType::Alpha
|
|
||||||
};
|
|
||||||
|
|
||||||
// Cr<43>er un espace pour afficher les textures_ avec d<>filement
|
|
||||||
ImGui::BeginChild("TextureChild", ImVec2(0, 200), true, ImGuiWindowFlags_HorizontalScrollbar);
|
|
||||||
|
|
||||||
// Pour chaque type de texture
|
|
||||||
for (int typeIndex = 0; typeIndex < textureCategories.size(); typeIndex++)
|
|
||||||
{
|
|
||||||
TextureType type = textureTypes[typeIndex];
|
|
||||||
std::string typeName = textureCategories[typeIndex];
|
|
||||||
|
|
||||||
// Afficher le titre de la cat<61>gorie
|
|
||||||
ImGui::Text("%s:", typeName.c_str());
|
|
||||||
ImGui::SameLine();
|
|
||||||
|
|
||||||
// Compter combien de textures_ de ce type existent
|
|
||||||
int textureCount = 0;
|
|
||||||
while (object->get_model()->GetTexture(type, textureCount) != nullptr)
|
|
||||||
{
|
|
||||||
textureCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Afficher toutes les textures_ existantes
|
|
||||||
ImGui::BeginGroup();
|
|
||||||
for (int texIndex = 0; texIndex < textureCount; texIndex++)
|
|
||||||
{
|
|
||||||
ID3D11ShaderResourceView* texture = object->get_model()->GetTexture(type, texIndex);
|
|
||||||
if (texture)
|
|
||||||
{
|
|
||||||
// ID unique pour chaque bouton de texture
|
|
||||||
std::string buttonId = "tex##" + std::to_string(index) + "_" +
|
|
||||||
std::to_string(typeIndex) + "_" +
|
|
||||||
std::to_string(texIndex);
|
|
||||||
|
|
||||||
if (ImGui::ImageButton(buttonId.c_str(), (ImTextureID)texture, ImVec2(48, 48)))
|
|
||||||
{
|
|
||||||
// Ouvrir une bo<62>te de dialogue pour changer la texture
|
|
||||||
OPENFILENAME ofn;
|
|
||||||
WCHAR szFile[260];
|
|
||||||
ZeroMemory(&ofn, sizeof(ofn));
|
|
||||||
ofn.lStructSize = sizeof(ofn);
|
|
||||||
ofn.hwndOwner = NULL;
|
|
||||||
ofn.lpstrFile = szFile;
|
|
||||||
szFile[0] = '\0';
|
|
||||||
ofn.nMaxFile = sizeof(szFile);
|
|
||||||
ofn.lpstrFilter = L"Texture\0*.png;*.jpg;*.dds\0";
|
|
||||||
ofn.nFilterIndex = 1;
|
|
||||||
ofn.lpstrInitialDir = NULL;
|
|
||||||
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
|
|
||||||
|
|
||||||
if (GetOpenFileName(&ofn))
|
|
||||||
{
|
|
||||||
// Changer la texture existante
|
|
||||||
object->get_model()->ChangeTexture(m_device, m_deviceContext, ofn.lpstrFile, type, texIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Afficher l'indice de texture et pr<70>visualisation au survol
|
|
||||||
if (ImGui::IsItemHovered())
|
|
||||||
{
|
|
||||||
ImGui::BeginTooltip();
|
|
||||||
ImGui::Text("%s %d", typeName.c_str(), texIndex);
|
|
||||||
ImGui::Image((ImTextureID)texture, ImVec2(192, 192));
|
|
||||||
ImGui::EndTooltip();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bouton pour ajouter une nouvelle texture
|
|
||||||
std::string addButtonLabel = "+##" + std::to_string(index) + "_" + std::to_string(typeIndex);
|
|
||||||
if (ImGui::Button(addButtonLabel.c_str(), ImVec2(48, 48)))
|
|
||||||
{
|
|
||||||
// Ouvrir une bo<62>te de dialogue pour ajouter une texture
|
|
||||||
OPENFILENAME ofn;
|
|
||||||
WCHAR szFile[260];
|
|
||||||
ZeroMemory(&ofn, sizeof(ofn));
|
|
||||||
ofn.lStructSize = sizeof(ofn);
|
|
||||||
ofn.hwndOwner = NULL;
|
|
||||||
ofn.lpstrFile = szFile;
|
|
||||||
szFile[0] = '\0';
|
|
||||||
ofn.nMaxFile = sizeof(szFile);
|
|
||||||
ofn.lpstrFilter = L"Texture\0*.png;*.jpg;*.dds\0";
|
|
||||||
ofn.nFilterIndex = 1;
|
|
||||||
ofn.lpstrInitialDir = NULL;
|
|
||||||
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
|
|
||||||
|
|
||||||
if (GetOpenFileName(&ofn))
|
|
||||||
{
|
|
||||||
// Ajouter une nouvelle texture
|
|
||||||
object->get_model()->AddTexture(m_device, m_deviceContext, ofn.lpstrFile, type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndGroup();
|
|
||||||
ImGui::Separator();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndChild();
|
|
||||||
|
|
||||||
ImGui::Separator();
|
|
||||||
|
|
||||||
// Delete button
|
|
||||||
std::string deleteLabel = "Delete##" + std::to_string(index);
|
|
||||||
if (ImGui::Button(deleteLabel.c_str()))
|
|
||||||
{
|
|
||||||
app_->delete_kobject(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::Separator();
|
|
||||||
|
|
||||||
// Liste des options
|
|
||||||
const char* shaderOptions[] = {
|
|
||||||
"Enable Global Lighting",
|
|
||||||
"Enable Lighting",
|
|
||||||
"Enable Cel Shading",
|
|
||||||
"Enable Normal Mapping",
|
|
||||||
"Enable Specular Mapping",
|
|
||||||
"Enable Alpha Mapping"
|
|
||||||
};
|
|
||||||
|
|
||||||
ShaderType shaderTypes[] = {
|
|
||||||
ShaderType::SUNLIGHT,
|
|
||||||
ShaderType::LIGHTING,
|
|
||||||
ShaderType::CEL_SHADING,
|
|
||||||
ShaderType::NORMAL_MAPPING,
|
|
||||||
ShaderType::SPECULAR_MAPPING,
|
|
||||||
ShaderType::ALPHA_MAPPING
|
|
||||||
};
|
|
||||||
|
|
||||||
// Variable pour stocker l'option s<>lectionn<6E>e
|
|
||||||
static int currentShader = 0; // Index de l'option actuellement s<>lectionn<6E>e
|
|
||||||
|
|
||||||
// Cr<43>ation du menu d<>roulant
|
|
||||||
if (ImGui::BeginCombo("Shader Options", shaderOptions[currentShader]))
|
|
||||||
{
|
|
||||||
for (int i = 0; i < IM_ARRAYSIZE(shaderOptions); i++)
|
|
||||||
{
|
{
|
||||||
// Cr<43>e une option s<>lectionnable pour chaque shader
|
transform->SetPosition(XMVectorSet(pos[0], pos[1], pos[2], 0.0f));
|
||||||
bool isSelected = (currentShader == i);
|
transform->UpdateWorldMatrix();
|
||||||
if (ImGui::Selectable(shaderOptions[i], isSelected))
|
}
|
||||||
|
|
||||||
|
float rot[3] = { XMVectorGetX(rotation), XMVectorGetY(rotation), XMVectorGetZ(rotation) };
|
||||||
|
std::string rotLabel = "Rotation##" + std::to_string(identity->GetId());
|
||||||
|
if (ImGui::DragFloat3(rotLabel.c_str(), rot))
|
||||||
|
{
|
||||||
|
transform->SetRotation(XMVectorSet(rot[0], rot[1], rot[2], 0.0f));
|
||||||
|
transform->UpdateWorldMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
float scl[3] = { XMVectorGetX(scale), XMVectorGetY(scale), XMVectorGetZ(scale) };
|
||||||
|
std::string sclLabel = "Scale##" + std::to_string(identity->GetId());
|
||||||
|
if (ImGui::DragFloat3(sclLabel.c_str(), scl))
|
||||||
|
{
|
||||||
|
transform->SetScale(XMVectorSet(scl[0], scl[1], scl[2], 0.0f));
|
||||||
|
transform->UpdateWorldMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
// Textures - Seulement si le composant de rendu existe
|
||||||
|
if (render && render->GetModel())
|
||||||
|
{
|
||||||
|
// D<>finir les types de textures_
|
||||||
|
std::vector<std::string> textureCategories = {
|
||||||
|
"Diffuse", "Normal", "Specular", "Alpha"
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<TextureType> textureTypes = {
|
||||||
|
TextureType::Diffuse, TextureType::Normal,
|
||||||
|
TextureType::Specular, TextureType::Alpha
|
||||||
|
};
|
||||||
|
|
||||||
|
// Cr<43>er un espace pour afficher les textures_ avec d<>filement
|
||||||
|
std::string textureChildId = "TextureChild##" + std::to_string(identity->GetId());
|
||||||
|
ImGui::BeginChild(textureChildId.c_str(), ImVec2(0, 200), true, ImGuiWindowFlags_HorizontalScrollbar);
|
||||||
|
|
||||||
|
// Pour chaque type de texture
|
||||||
|
for (int typeIndex = 0; typeIndex < textureCategories.size(); typeIndex++)
|
||||||
{
|
{
|
||||||
// Met <20> jour l'option s<>lectionn<6E>e
|
TextureType type = textureTypes[typeIndex];
|
||||||
currentShader = i;
|
std::string typeName = textureCategories[typeIndex];
|
||||||
object->SetActiveShader(shaderTypes[i]);
|
|
||||||
|
// Afficher le titre de la cat<61>gorie
|
||||||
|
std::string categoryLabel = typeName + "##" + std::to_string(identity->GetId());
|
||||||
|
ImGui::Text("%s:", typeName.c_str());
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
// Compter combien de textures_ de ce type existent
|
||||||
|
int textureCount = 0;
|
||||||
|
while (render->GetModel()->GetTexture(type, textureCount) != nullptr)
|
||||||
|
{
|
||||||
|
textureCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Afficher toutes les textures_ existantes
|
||||||
|
std::string groupId = "TextureGroup_" + std::to_string(identity->GetId()) + "_" + std::to_string(typeIndex);
|
||||||
|
ImGui::BeginGroup();
|
||||||
|
for (int texIndex = 0; texIndex < textureCount; texIndex++)
|
||||||
|
{
|
||||||
|
ID3D11ShaderResourceView* texture = render->GetModel()->GetTexture(type, texIndex);
|
||||||
|
if (texture)
|
||||||
|
{
|
||||||
|
// ID unique pour chaque bouton de texture
|
||||||
|
std::string buttonId = "tex##" + std::to_string(identity->GetId()) + "_" +
|
||||||
|
std::to_string(typeIndex) + "_" +
|
||||||
|
std::to_string(texIndex);
|
||||||
|
|
||||||
|
if (ImGui::ImageButton(buttonId.c_str(), (ImTextureID)texture, ImVec2(48, 48)))
|
||||||
|
{
|
||||||
|
// Ouvrir une bo<62>te de dialogue pour changer la texture
|
||||||
|
OPENFILENAME ofn;
|
||||||
|
WCHAR szFile[260] = {0};
|
||||||
|
ZeroMemory(&ofn, sizeof(ofn));
|
||||||
|
ofn.lStructSize = sizeof(ofn);
|
||||||
|
ofn.hwndOwner = NULL;
|
||||||
|
ofn.lpstrFile = szFile;
|
||||||
|
ofn.nMaxFile = sizeof(szFile);
|
||||||
|
ofn.lpstrFilter = L"Texture\0*.png;*.jpg;*.dds\0";
|
||||||
|
ofn.nFilterIndex = 1;
|
||||||
|
ofn.lpstrInitialDir = NULL;
|
||||||
|
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
|
||||||
|
|
||||||
|
if (GetOpenFileName(&ofn))
|
||||||
|
{
|
||||||
|
// Changer la texture existante
|
||||||
|
render->GetModel()->ChangeTexture(m_device, m_deviceContext, ofn.lpstrFile, type, texIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Afficher l'indice de texture et pr<70>visualisation au survol
|
||||||
|
if (ImGui::IsItemHovered())
|
||||||
|
{
|
||||||
|
ImGui::BeginTooltip();
|
||||||
|
ImGui::Text("%s %d", typeName.c_str(), texIndex);
|
||||||
|
ImGui::Image((ImTextureID)texture, ImVec2(192, 192));
|
||||||
|
ImGui::EndTooltip();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bouton pour ajouter une nouvelle texture
|
||||||
|
std::string addButtonLabel = "+##" + std::to_string(identity->GetId()) + "_" + std::to_string(typeIndex);
|
||||||
|
if (ImGui::Button(addButtonLabel.c_str(), ImVec2(48, 48)))
|
||||||
|
{
|
||||||
|
// Ouvrir une bo<62>te de dialogue pour ajouter une texture
|
||||||
|
OPENFILENAME ofn;
|
||||||
|
WCHAR szFile[260] = {0};
|
||||||
|
ZeroMemory(&ofn, sizeof(ofn));
|
||||||
|
ofn.lStructSize = sizeof(ofn);
|
||||||
|
ofn.hwndOwner = NULL;
|
||||||
|
ofn.lpstrFile = szFile;
|
||||||
|
ofn.nMaxFile = sizeof(szFile);
|
||||||
|
ofn.lpstrFilter = L"Texture\0*.png;*.jpg;*.dds\0";
|
||||||
|
ofn.nFilterIndex = 1;
|
||||||
|
ofn.lpstrInitialDir = NULL;
|
||||||
|
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
|
||||||
|
|
||||||
|
if (GetOpenFileName(&ofn))
|
||||||
|
{
|
||||||
|
// Ajouter une nouvelle texture
|
||||||
|
render->GetModel()->AddTexture(m_device, m_deviceContext, ofn.lpstrFile, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndGroup();
|
||||||
|
ImGui::Separator();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si l'option s<>lectionn<6E>e est active, nous mettons en surbrillance
|
ImGui::EndChild();
|
||||||
if (isSelected)
|
|
||||||
ImGui::SetItemDefaultFocus();
|
|
||||||
}
|
}
|
||||||
ImGui::EndCombo();
|
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
// Delete button
|
||||||
|
std::string deleteLabel = "Delete##" + std::to_string(identity->GetId());
|
||||||
|
if (ImGui::Button(deleteLabel.c_str()))
|
||||||
|
{
|
||||||
|
app_->delete_entity_by_id(identity->GetId());
|
||||||
|
// Sortir du boucle apr<70>s suppression pour <20>viter des acc<63>s invalides
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
// Shader options
|
||||||
|
if (shader)
|
||||||
|
{
|
||||||
|
// Liste des options de shader
|
||||||
|
const char* shaderOptions[] = {
|
||||||
|
"Enable Global Lighting",
|
||||||
|
"Enable Lighting",
|
||||||
|
"Enable Cel Shading",
|
||||||
|
"Enable Normal Mapping",
|
||||||
|
"Enable Specular Mapping",
|
||||||
|
"Enable Alpha Mapping"
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<ecs::ShaderType> shaderTypes = {
|
||||||
|
ecs::ShaderType::SUNLIGHT,
|
||||||
|
ecs::ShaderType::LIGHTING,
|
||||||
|
ecs::ShaderType::CEL_SHADING,
|
||||||
|
ecs::ShaderType::NORMAL_MAPPING,
|
||||||
|
ecs::ShaderType::SPECULAR_MAPPING,
|
||||||
|
ecs::ShaderType::ALPHA_MAPPING
|
||||||
|
};
|
||||||
|
|
||||||
|
// Trouver l'index actuel du shader pour cette entit<69> sp<73>cifique
|
||||||
|
int currentShader = 0;
|
||||||
|
ecs::ShaderType activeShader = shader->GetActiveShader();
|
||||||
|
for (size_t i = 0; i < shaderTypes.size(); i++)
|
||||||
|
{
|
||||||
|
if (shaderTypes[i] == activeShader)
|
||||||
|
{
|
||||||
|
currentShader = static_cast<int>(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cr<43>ation du menu d<>roulant avec un ID unique pour chaque entit<69>
|
||||||
|
std::string shaderComboId = "Shader Options##" + std::to_string(identity->GetId());
|
||||||
|
if (ImGui::BeginCombo(shaderComboId.c_str(), shaderOptions[currentShader]))
|
||||||
|
{
|
||||||
|
for (int i = 0; i < IM_ARRAYSIZE(shaderOptions); i++)
|
||||||
|
{
|
||||||
|
// Cr<43>e une option s<>lectionnable pour chaque shader avec ID unique
|
||||||
|
std::string shaderSelectableId = std::to_string(i) + "##shader_" + std::to_string(identity->GetId());
|
||||||
|
bool isSelected = (currentShader == i);
|
||||||
|
if (ImGui::Selectable(shaderOptions[i], isSelected))
|
||||||
|
{
|
||||||
|
// Met <20> jour l'option s<>lectionn<6E>e uniquement pour cette entit<69>
|
||||||
|
currentShader = i;
|
||||||
|
shader->SetActiveShader(shaderTypes[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si l'option s<>lectionn<6E>e est active, nous mettons en surbrillance
|
||||||
|
if (isSelected)
|
||||||
|
ImGui::SetItemDefaultFocus();
|
||||||
|
}
|
||||||
|
ImGui::EndCombo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
// Physics
|
||||||
|
bool isPhysicsEnabled = (physics != nullptr);
|
||||||
|
std::string physicsLabel = "Physics##" + std::to_string(identity->GetId());
|
||||||
|
|
||||||
|
if (ImGui::Checkbox(physicsLabel.c_str(), &isPhysicsEnabled))
|
||||||
|
{
|
||||||
|
if (isPhysicsEnabled && !physics)
|
||||||
|
{
|
||||||
|
// Ajouter un composant de physique
|
||||||
|
physics = entity->AddComponent<ecs::PhysicsComponent>();
|
||||||
|
physics->Initialize();
|
||||||
|
}
|
||||||
|
else if (!isPhysicsEnabled && physics)
|
||||||
|
{
|
||||||
|
// Retirer le composant de physique
|
||||||
|
entity->RemoveComponent<ecs::PhysicsComponent>();
|
||||||
|
physics = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (physics)
|
||||||
|
{
|
||||||
|
// Gravity Enabled checkbox
|
||||||
|
bool gravityEnabled = physics->IsGravityEnabled();
|
||||||
|
std::string gravityLabel = "Gravity##" + std::to_string(identity->GetId());
|
||||||
|
if (ImGui::Checkbox(gravityLabel.c_str(), &gravityEnabled))
|
||||||
|
{
|
||||||
|
physics->SetGravityEnabled(gravityEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3 radio buttons pour le type d'objet physique avec IDs uniques
|
||||||
|
std::string typeLabel = "Type##" + std::to_string(identity->GetId());
|
||||||
|
ecs::ObjectType type = identity->GetType();
|
||||||
|
|
||||||
|
if (ImGui::RadioButton(("None##" + std::to_string(identity->GetId())).c_str(),
|
||||||
|
type == ecs::ObjectType::Unknown))
|
||||||
|
{
|
||||||
|
identity->SetType(ecs::ObjectType::Unknown);
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton(("Cube##" + std::to_string(identity->GetId())).c_str(),
|
||||||
|
type == ecs::ObjectType::Cube))
|
||||||
|
{
|
||||||
|
identity->SetType(ecs::ObjectType::Cube);
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton(("Sphere##" + std::to_string(identity->GetId())).c_str(),
|
||||||
|
type == ecs::ObjectType::Sphere))
|
||||||
|
{
|
||||||
|
identity->SetType(ecs::ObjectType::Sphere);
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton(("Terrain##" + std::to_string(identity->GetId())).c_str(),
|
||||||
|
type == ecs::ObjectType::Terrain))
|
||||||
|
{
|
||||||
|
identity->SetType(ecs::ObjectType::Terrain);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Separator();
|
||||||
}
|
}
|
||||||
|
index++;
|
||||||
|
|
||||||
ImGui::Separator();
|
|
||||||
|
|
||||||
// physics
|
|
||||||
std::string physicsLabel = "physics##" + std::to_string(index);
|
|
||||||
|
|
||||||
if (ImGui::Checkbox(physicsLabel.c_str(), &m_isPhyiscsEnabled))
|
|
||||||
{
|
|
||||||
object->SetPhysicsEnabled(m_isPhyiscsEnabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gravity Enabled checkbox
|
|
||||||
std::string gravityLabel = "Gravity##" + std::to_string(index);
|
|
||||||
if (ImGui::Checkbox(gravityLabel.c_str(), &object->m_gravityEnabled))
|
|
||||||
{
|
|
||||||
object->SetGravityEnabled(object->m_gravityEnabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 3 radio button on the same line to set the ObjectType
|
|
||||||
std::string typeLabel = "Type##" + std::to_string(index);
|
|
||||||
ObjectType type = object->GetType();
|
|
||||||
if (ImGui::RadioButton("None", type == ObjectType::Unknown))
|
|
||||||
{
|
|
||||||
object->SetType(ObjectType::Unknown);
|
|
||||||
}
|
|
||||||
ImGui::SameLine();
|
|
||||||
if (ImGui::RadioButton("Cube", type == ObjectType::Cube))
|
|
||||||
{
|
|
||||||
object->SetType(ObjectType::Cube);
|
|
||||||
}
|
|
||||||
ImGui::SameLine();
|
|
||||||
if (ImGui::RadioButton("Sphere", type == ObjectType::Sphere))
|
|
||||||
{
|
|
||||||
object->SetType(ObjectType::Sphere);
|
|
||||||
}
|
|
||||||
|
|
||||||
// button to launch the object
|
|
||||||
std::string launchLabel = "Launch##" + std::to_string(index);
|
|
||||||
|
|
||||||
// paraeter to set the alpha, initial stretch and spring constant
|
|
||||||
float alpha = object->GetAlpha();
|
|
||||||
float initialStretch = object->GetInitialStretch();
|
|
||||||
float springConstant = object->GetSpringConstant();
|
|
||||||
if (ImGui::DragFloat("Alpha##" , &alpha, 0.01f, 0.0f, 1.0f))
|
|
||||||
{
|
|
||||||
object->SetAlpha(alpha);
|
|
||||||
}
|
|
||||||
if (ImGui::DragFloat("Initial Stretch##", &initialStretch, 0.01f, 0.0f, 1.0f))
|
|
||||||
{
|
|
||||||
object->SetInitialStretch(initialStretch);
|
|
||||||
}
|
|
||||||
if (ImGui::DragFloat("Spring Constant##", &springConstant, 0.01f, 0.0f, 100.0f))
|
|
||||||
{
|
|
||||||
object->SetSpringConstant(springConstant);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui::Button(launchLabel.c_str()))
|
|
||||||
{
|
|
||||||
object->LaunchObject();
|
|
||||||
}
|
|
||||||
ImGui::SameLine();
|
|
||||||
// button to stop the object
|
|
||||||
std::string stopLabel = "Stop##" + std::to_string(index);
|
|
||||||
if (ImGui::Button(stopLabel.c_str()))
|
|
||||||
{
|
|
||||||
object->SetVelocity(XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f));
|
|
||||||
object->SetPosition(XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ImGui::Separator();
|
|
||||||
|
|
||||||
// Demo spinning
|
|
||||||
std::string demoLabel = "Demo spinning##" + std::to_string(index);
|
|
||||||
ImGui::Checkbox(demoLabel.c_str(), &object->m_demoSpinning);
|
|
||||||
}
|
}
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
@@ -679,7 +702,7 @@ void imguiManager::WidgetTerrainWindow()
|
|||||||
{
|
{
|
||||||
ImGui::Begin("Terrain", &showTerrainWindow);
|
ImGui::Begin("Terrain", &showTerrainWindow);
|
||||||
|
|
||||||
ImGui::Text("Number of terrain cubes: %d", app_->get_terrain_cube_count());
|
ImGui::Text("Number of terrain cubes: %d", app_->get_terrain_entity_count());
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
@@ -1107,3 +1130,4 @@ void imguiManager::WidgetRenderStats()
|
|||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -52,7 +52,7 @@ bool scene_manager::save_scene_as() {
|
|||||||
|
|
||||||
// Mettre <20> jour le chemin de sc<73>ne
|
// Mettre <20> jour le chemin de sc<73>ne
|
||||||
scene_path_ = convert_w_string_to_string(filepath.wstring());
|
scene_path_ = convert_w_string_to_string(filepath.wstring());
|
||||||
object_vec_ = app_->get_kobjects();
|
//object_vec_ = app_->get_kobjects(); // TODO
|
||||||
|
|
||||||
// Sauvegarder la sc<73>ne avec le nouveau chemin
|
// Sauvegarder la sc<73>ne avec le nouveau chemin
|
||||||
save_scene();
|
save_scene();
|
||||||
@@ -67,29 +67,32 @@ bool scene_manager::save_scene_as() {
|
|||||||
bool scene_manager::load_scene() {
|
bool scene_manager::load_scene() {
|
||||||
Logger::Get().Log("Loading scene from " , __FILE__, __LINE__, Logger::LogLevel::Info);
|
Logger::Get().Log("Loading scene from " , __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
|
||||||
object_vec_ = app_->get_kobjects();
|
|
||||||
object_id_ = app_->get_object_id();
|
object_id_ = app_->get_object_id();
|
||||||
w_folder_ = app_->get_w_folder();
|
w_folder_ = app_->get_w_folder();
|
||||||
direct_3d_ = app_->get_direct_3d();
|
direct_3d_ = app_->get_direct_3d();
|
||||||
std::wstring scenePath = get_scene_path();
|
std::wstring scenePath = get_scene_path();
|
||||||
|
|
||||||
|
if (!scenePath.empty()) {
|
||||||
if (!scenePath.empty())
|
|
||||||
{
|
|
||||||
scene_path_ = convert_w_string_to_string(scenePath);
|
scene_path_ = convert_w_string_to_string(scenePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ifstream inFile(scene_path_);
|
std::ifstream inFile(scene_path_);
|
||||||
if (!inFile.is_open()) {
|
if (!inFile.is_open()) {
|
||||||
Logger::Get().Log("Failed to open file for loading scene: ", __FILE__, __LINE__, Logger::LogLevel::Error);
|
Logger::Get().Log("Failed to open file for loading scene: " + scene_path_, __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
object_vec_.clear();
|
// R<>initialiser l'ID d'objet le plus <20>lev<65>
|
||||||
object_id_ = 0;
|
object_id_ = 0;
|
||||||
|
|
||||||
// Sauvegarder le r<EFBFBD>pertoire de travail actuel
|
// R<>cup<75>rer l'EntityManager pour cr<EFBFBD>er de nouvelles entit<69>s
|
||||||
std::wstring currentDirectory = w_folder_;
|
auto entity_manager = app_->get_entity_manager();
|
||||||
|
|
||||||
|
// Supprimer toutes les entit<69>s existantes
|
||||||
|
entity_manager->Clear();
|
||||||
|
|
||||||
|
// Sauvegarder le r<>pertoire de travail actuel
|
||||||
|
std::wstring currentDirectory = w_folder_;
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(inFile, line)) {
|
while (std::getline(inFile, line)) {
|
||||||
@@ -104,47 +107,61 @@ bool scene_manager::load_scene() {
|
|||||||
float mass;
|
float mass;
|
||||||
bool physicsEnabled;
|
bool physicsEnabled;
|
||||||
|
|
||||||
// Lire les donn<6E>es de base de l'objet
|
// Lire les donn<6E>es de base de l'entit<EFBFBD>
|
||||||
iss >> id >> name
|
iss >> id >> name
|
||||||
>> position.x >> position.y >> position.z
|
>> position.x >> position.y >> position.z
|
||||||
>> rotation.x >> rotation.y >> rotation.z
|
>> rotation.x >> rotation.y >> rotation.z
|
||||||
>> scale.x >> scale.y >> scale.z
|
>> scale.x >> scale.y >> scale.z;
|
||||||
>> modelPath >> shaderTypeStr
|
|
||||||
|
// Lire le chemin du mod<6F>le - v<>rifier s'il est vide
|
||||||
|
iss >> modelPath;
|
||||||
|
|
||||||
|
// Si le chemin du mod<6F>le est vide ou commence par une lettre majuscule (probablement un type de shader),
|
||||||
|
// c'est qu'il a <20>t<EFBFBD> omis - utilisez une valeur par d<>faut
|
||||||
|
if (modelPath.empty() || (modelPath[0] >= 'A' && modelPath[0] <= 'Z')) {
|
||||||
|
// Reculer le curseur de lecture pour lire le type de shader <20> la place
|
||||||
|
iss.seekg(-static_cast<int>(modelPath.length()), std::ios::cur);
|
||||||
|
modelPath = "assets/Model/TXT/cube.txt"; // Valeur par d<>faut
|
||||||
|
}
|
||||||
|
|
||||||
|
iss >> shaderTypeStr
|
||||||
>> boundingRadius >> objectTypeStr
|
>> boundingRadius >> objectTypeStr
|
||||||
>> mass >> physicsEnabled;
|
>> mass >> physicsEnabled;
|
||||||
|
|
||||||
if (iss.fail()) {
|
if (iss.fail()) {
|
||||||
Logger::Get().Log("Failed to parse object data", __FILE__, __LINE__, Logger::LogLevel::Error);
|
Logger::Get().Log("Failed to parse entity data: " + line, __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cr<EFBFBD>er un nouvel objet
|
// Mettre <20> jour l'ID d'objet le plus <20>lev<65> si n<>cessaire
|
||||||
object* newObject = new object();
|
if (id >= object_id_) {
|
||||||
|
object_id_ = id + 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Convertir le chemin du mod<6F>le en wstring
|
// Convertir le chemin du mod<6F>le en wstring
|
||||||
std::wstring wModelPath(modelPath.begin(), modelPath.end());
|
std::wstring wModelPath(modelPath.begin(), modelPath.end());
|
||||||
|
|
||||||
// V<>rifier si le chemin est relatif (ne commence pas par un disque comme C:)
|
// V<>rifier si le chemin est relatif
|
||||||
if (modelPath.length() > 1 && modelPath[1] != ':') {
|
if (modelPath != "NoModel" && modelPath.length() > 1 && modelPath[1] != ':') {
|
||||||
// C'est un chemin relatif, pr<70>fixer avec le r<>pertoire de travail
|
// C'est un chemin relatif, pr<70>fixer avec le r<>pertoire de travail
|
||||||
if (currentDirectory.back() != L'/' && currentDirectory.back() != L'\\') {
|
if (currentDirectory.back() != L'/' && currentDirectory.back() != L'\\') {
|
||||||
// Ajouter un s<>parateur si n<>cessaire
|
// Ajouter un s<>parateur si n<>cessaire
|
||||||
wModelPath = currentDirectory + L"\\" + wModelPath;
|
wModelPath = currentDirectory + L"\\" + wModelPath;
|
||||||
} else {
|
} else {
|
||||||
wModelPath = currentDirectory + wModelPath;
|
wModelPath = currentDirectory + wModelPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cr<43>er le conteneur de textures_ pour stocker les chemins
|
// Cr<43>er le conteneur de textures pour stocker les chemins
|
||||||
TextureContainer objectTextures;
|
TextureContainer objectTextures;
|
||||||
|
|
||||||
// IMPORTANT: Vider les conteneurs de chemins de textures_
|
// Vider les conteneurs de chemins de textures
|
||||||
objectTextures.diffusePaths.clear();
|
objectTextures.diffusePaths.clear();
|
||||||
objectTextures.normalPaths.clear();
|
objectTextures.normalPaths.clear();
|
||||||
objectTextures.specularPaths.clear();
|
objectTextures.specularPaths.clear();
|
||||||
objectTextures.alphaPaths.clear();
|
objectTextures.alphaPaths.clear();
|
||||||
|
|
||||||
// Lire les chemins des textures_ diffuses
|
// Lire les chemins des textures diffuses
|
||||||
int diffuseTextureCount;
|
int diffuseTextureCount;
|
||||||
iss >> diffuseTextureCount;
|
iss >> diffuseTextureCount;
|
||||||
for (int i = 0; i < diffuseTextureCount; i++) {
|
for (int i = 0; i < diffuseTextureCount; i++) {
|
||||||
@@ -154,7 +171,7 @@ bool scene_manager::load_scene() {
|
|||||||
objectTextures.diffusePaths.push_back(wTexturePath);
|
objectTextures.diffusePaths.push_back(wTexturePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lire les chemins des textures_ normales
|
// Lire les chemins des textures normales
|
||||||
int normalTextureCount;
|
int normalTextureCount;
|
||||||
iss >> normalTextureCount;
|
iss >> normalTextureCount;
|
||||||
for (int i = 0; i < normalTextureCount; i++) {
|
for (int i = 0; i < normalTextureCount; i++) {
|
||||||
@@ -164,7 +181,7 @@ bool scene_manager::load_scene() {
|
|||||||
objectTextures.normalPaths.push_back(wTexturePath);
|
objectTextures.normalPaths.push_back(wTexturePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lire les chemins des textures_ sp<73>culaires
|
// Lire les chemins des textures sp<73>culaires
|
||||||
int specularTextureCount;
|
int specularTextureCount;
|
||||||
iss >> specularTextureCount;
|
iss >> specularTextureCount;
|
||||||
for (int i = 0; i < specularTextureCount; i++) {
|
for (int i = 0; i < specularTextureCount; i++) {
|
||||||
@@ -174,7 +191,7 @@ bool scene_manager::load_scene() {
|
|||||||
objectTextures.specularPaths.push_back(wTexturePath);
|
objectTextures.specularPaths.push_back(wTexturePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lire les chemins des textures_ alpha
|
// Lire les chemins des textures alpha
|
||||||
int alphaTextureCount;
|
int alphaTextureCount;
|
||||||
iss >> alphaTextureCount;
|
iss >> alphaTextureCount;
|
||||||
for (int i = 0; i < alphaTextureCount; i++) {
|
for (int i = 0; i < alphaTextureCount; i++) {
|
||||||
@@ -184,60 +201,100 @@ bool scene_manager::load_scene() {
|
|||||||
objectTextures.alphaPaths.push_back(wTexturePath);
|
objectTextures.alphaPaths.push_back(wTexturePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// preload texture
|
// V<>rifier si on a un mod<6F>le <20> charger
|
||||||
if (!newObject->get_model()->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), objectTextures))
|
if (modelPath == "NoModel") {
|
||||||
{
|
Logger::Get().Log("Skipping entity without model: " + name, __FILE__, __LINE__, Logger::LogLevel::Warning);
|
||||||
// G<>rer l'erreur
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialiser l'objet avec le mod<6F>le et les chemins de textures_
|
|
||||||
char modelFilename[256];
|
|
||||||
size_t convertedChars = 0;
|
|
||||||
wcstombs_s(&convertedChars, modelFilename, sizeof(modelFilename), wModelPath.c_str(), _TRUNCATE);
|
|
||||||
|
|
||||||
Logger::Get().Log("Loading model: " + std::string(modelFilename), __FILE__, __LINE__, Logger::LogLevel::Info);
|
|
||||||
|
|
||||||
// NE PAS charger les textures_ avant initialize
|
|
||||||
// Laisser la m<>thode initialize s'en charger <20> partir des chemins
|
|
||||||
if (!newObject->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, objectTextures)) {
|
|
||||||
Logger::Get().Log("Failed to initialize object: " + name, __FILE__, __LINE__, Logger::LogLevel::Error);
|
|
||||||
delete newObject;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// D<EFBFBD>finir les propri<72>t<EFBFBD>s de l'objet
|
// R<EFBFBD>cup<EFBFBD>rer le cache de mod<6F>les de l'application
|
||||||
newObject->SetId(id);
|
auto& modelCache = app_->get_model_cache();
|
||||||
newObject->SetName(name);
|
std::shared_ptr<model_class> sharedModel;
|
||||||
newObject->SetPosition(XMLoadFloat3(&position));
|
|
||||||
newObject->SetRotation(XMLoadFloat3(&rotation));
|
|
||||||
newObject->SetScale(XMLoadFloat3(&scale));
|
|
||||||
newObject->SetModelPath(wModelPath);
|
|
||||||
newObject->SetActiveShader(newObject->StringToShaderType(shaderTypeStr));
|
|
||||||
newObject->SetBoundingRadius(boundingRadius);
|
|
||||||
newObject->SetType(newObject->StringToObjectType(objectTypeStr));
|
|
||||||
newObject->SetMass(mass);
|
|
||||||
newObject->SetPhysicsEnabled(physicsEnabled);
|
|
||||||
|
|
||||||
// Mettre <20> jour l'ID global si n<>cessaire
|
// V<EFBFBD>rifier si le mod<6F>le existe d<>j<EFBFBD> dans le cache
|
||||||
if (id >= object_id_) {
|
std::string modelKey = modelPath;
|
||||||
object_id_ = id + 1;
|
auto it = modelCache.find(modelKey);
|
||||||
app_->set_object_id(object_id_);
|
if (it != modelCache.end()) {
|
||||||
|
// Utiliser le mod<6F>le existant du cache
|
||||||
|
Logger::Get().Log("Using cached model for: " + modelKey, __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
sharedModel = it->second;
|
||||||
|
} else {
|
||||||
|
// Cr<43>er un nouveau mod<6F>le
|
||||||
|
char modelFilename[256];
|
||||||
|
size_t convertedChars = 0;
|
||||||
|
wcstombs_s(&convertedChars, modelFilename, sizeof(modelFilename), wModelPath.c_str(), _TRUNCATE);
|
||||||
|
|
||||||
|
Logger::Get().Log("Loading model: " + std::string(modelFilename), __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
|
||||||
|
// Cr<43>er et initialiser le mod<6F>le
|
||||||
|
auto newModel = std::make_shared<model_class>();
|
||||||
|
|
||||||
|
// Pr<50>charger les textures
|
||||||
|
if (!newModel->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), objectTextures)) {
|
||||||
|
Logger::Get().Log("Failed to preload textures for: " + name, __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!newModel->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, objectTextures)) {
|
||||||
|
Logger::Get().Log("Failed to initialize model: " + name, __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ajouter le mod<6F>le au cache
|
||||||
|
modelCache[modelKey] = newModel;
|
||||||
|
sharedModel = newModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
object_vec_.push_back(newObject);
|
// Cr<43>er une nouvelle entit<69> avec l'EntityManager
|
||||||
Logger::Get().Log("Loaded object: " + name, __FILE__, __LINE__, Logger::LogLevel::Info);
|
auto entity = entity_manager->CreateEntity();
|
||||||
|
|
||||||
|
// Ajouter un composant d'identit<69>
|
||||||
|
auto identityComponent = entity->AddComponent<ecs::IdentityComponent>(id);
|
||||||
|
identityComponent->SetName(name);
|
||||||
|
identityComponent->SetType(ecs::IdentityComponent::StringToObjectType(objectTypeStr));
|
||||||
|
|
||||||
|
// Ajouter un composant de transformation
|
||||||
|
auto transformComponent = entity->AddComponent<ecs::TransformComponent>();
|
||||||
|
transformComponent->SetPosition(XMLoadFloat3(&position));
|
||||||
|
transformComponent->SetRotation(XMLoadFloat3(&rotation));
|
||||||
|
transformComponent->SetScale(XMLoadFloat3(&scale));
|
||||||
|
transformComponent->UpdateWorldMatrix();
|
||||||
|
|
||||||
|
// Ajouter un composant de rendu avec le mod<6F>le
|
||||||
|
auto renderComponent = entity->AddComponent<ecs::RenderComponent>();
|
||||||
|
renderComponent->InitializeWithModel(sharedModel);
|
||||||
|
|
||||||
|
// Ajouter un composant de shader
|
||||||
|
auto shaderComponent = entity->AddComponent<ecs::ShaderComponent>();
|
||||||
|
shaderComponent->SetActiveShader(ecs::ShaderComponent::StringToShaderType(shaderTypeStr));
|
||||||
|
|
||||||
|
// Ajouter un composant de chemin de mod<6F>le
|
||||||
|
auto modelPathComponent = entity->AddComponent<ecs::ModelPathComponent>();
|
||||||
|
modelPathComponent->SetPath(wModelPath);
|
||||||
|
|
||||||
|
// Ajouter un composant de physique si n<>cessaire
|
||||||
|
auto physicsComponent = entity->AddComponent<ecs::PhysicsComponent>();
|
||||||
|
physicsComponent->Initialize();
|
||||||
|
physicsComponent->SetMass(mass);
|
||||||
|
physicsComponent->SetBoundingRadius(boundingRadius);
|
||||||
|
physicsComponent->SetPhysicsEnabled(physicsEnabled);
|
||||||
|
|
||||||
|
Logger::Get().Log("Entity loaded: " + name + " with ID: " + std::to_string(id), __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pass the vec to the application
|
// Mettre <20> jour l'ID global dans l'application
|
||||||
app_->set_kobjects(object_vec_);
|
app_->set_object_id(object_id_);
|
||||||
|
|
||||||
Logger::Get().Log("Scene loaded successfully from ", __FILE__, __LINE__, Logger::LogLevel::Info);
|
// Mettre <20> jour les statistiques apr<70>s le chargement
|
||||||
|
app_->update_stats_after_modification();
|
||||||
|
|
||||||
|
Logger::Get().Log("Scene loaded successfully from " + scene_path_, __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool scene_manager::save_scene() {
|
bool scene_manager::save_scene() {
|
||||||
|
|
||||||
|
entity_ = app_->get_entity_manager()->GetAllEntities();
|
||||||
|
|
||||||
if (scene_path_.empty()) {
|
if (scene_path_.empty()) {
|
||||||
Logger::Get().Log("Scene path is empty. Cannot save scene.", __FILE__, __LINE__, Logger::LogLevel::Error);
|
Logger::Get().Log("Scene path is empty. Cannot save scene.", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
@@ -250,56 +307,104 @@ bool scene_manager::save_scene() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& object : object_vec_) {
|
for (const auto& object : entity_) {
|
||||||
XMFLOAT3 position, scale, rotation;
|
XMFLOAT3 position, scale, rotation;
|
||||||
XMStoreFloat3(&position, object->GetPosition());
|
int id = 0;
|
||||||
XMStoreFloat3(&scale, object->GetScale());
|
int mass = 0;
|
||||||
XMStoreFloat3(&rotation, object->GetRotation());
|
float boundingRadius = 0;
|
||||||
|
std::string name = "NONE";
|
||||||
|
std::string shaderType = "NONE";
|
||||||
|
std::string objectType = "NONE";
|
||||||
|
std::wstring model_path = L"";
|
||||||
|
bool physics_enabled = false;
|
||||||
|
|
||||||
|
auto transform = object->GetComponent<ecs::TransformComponent>();
|
||||||
|
if (transform) {
|
||||||
|
// convert XMVECTOR to XMFLOAT3
|
||||||
|
XMStoreFloat3(&position, transform->GetPosition());
|
||||||
|
XMStoreFloat3(&rotation, transform->GetRotation());
|
||||||
|
XMStoreFloat3(&scale, transform->GetScale());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
auto identity = object->GetComponent<ecs::IdentityComponent>();
|
||||||
|
if (identity) {
|
||||||
|
|
||||||
|
id = identity->GetId();
|
||||||
|
name = identity->GetName();
|
||||||
|
objectType = identity->ObjectTypeToString(identity->GetType());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
auto model_path_component = object->GetComponent<ecs::ModelPathComponent>();
|
||||||
|
if (model_path_component) {
|
||||||
|
|
||||||
|
model_path = model_path_component->GetPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto shader = object->GetComponent<ecs::ShaderComponent>();
|
||||||
|
if (shader)
|
||||||
|
{
|
||||||
|
shaderType = shader->ShaderTypeToString(shader->GetActiveShader());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto physics = object->GetComponent<ecs::PhysicsComponent>();
|
||||||
|
if (physics) {
|
||||||
|
physics_enabled = physics->IsPhysicsEnabled();
|
||||||
|
mass = physics->GetMass();
|
||||||
|
boundingRadius = physics->GetBoundingRadius();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// <20>crire les donn<6E>es de base de l'objet
|
// <20>crire les donn<6E>es de base de l'objet
|
||||||
outFile << object->GetId() << " "
|
outFile << id << " "
|
||||||
<< object->GetName() << " "
|
<< name << " "
|
||||||
<< position.x << " " << position.y << " " << position.z << " "
|
<< position.x << " " << position.y << " " << position.z << " "
|
||||||
<< rotation.x << " " << rotation.y << " " << rotation.z << " "
|
<< rotation.x << " " << rotation.y << " " << rotation.z << " "
|
||||||
<< scale.x << " " << scale.y << " " << scale.z << " "
|
<< scale.x << " " << scale.y << " " << scale.z << " "
|
||||||
<< convert_w_string_to_string(object->GetModelPath()) << " "
|
<< convert_w_string_to_string(model_path) << " "
|
||||||
<< object->ShaderTypeToString(object->GetActiveShader()) << " "
|
<< shaderType << " "
|
||||||
<< object->GetBoundingRadius() << " "
|
<< boundingRadius << " "
|
||||||
<< object->ObjectTypeToString(object->GetType()) << " "
|
<< objectType << " "
|
||||||
<< object->GetMass() << " "
|
<< mass << " "
|
||||||
<< object->IsPhysicsEnabled();
|
<< physics_enabled;
|
||||||
|
|
||||||
// Sauvegarder les chemins des textures_
|
// Sauvegarder les chemins des textures_
|
||||||
// Format: nombre de textures_ diffuses, puis les chemins
|
// Format: nombre de textures_ diffuses, puis les chemins
|
||||||
// M<>me chose pour les autres types de textures_
|
// M<>me chose pour les autres types de textures_
|
||||||
|
|
||||||
// Textures diffuses
|
|
||||||
const auto& diffusePaths = object->get_model()->GetTextureContainer().GetPaths(TextureType::Diffuse);
|
auto render = object->GetComponent<ecs::RenderComponent>();
|
||||||
outFile << " " << diffusePaths.size();
|
if (render)
|
||||||
for (const auto& path : diffusePaths) {
|
{
|
||||||
outFile << " " << convert_w_string_to_string(path);
|
const auto& model = render->GetModel();
|
||||||
|
|
||||||
|
const auto& textureContainer = model->GetTextureContainer();
|
||||||
|
|
||||||
|
const auto& diffusePaths = textureContainer.GetPaths(TextureType::Diffuse);
|
||||||
|
outFile << " " << diffusePaths.size();
|
||||||
|
for (const auto& path : diffusePaths) {
|
||||||
|
outFile << " " << convert_w_string_to_string(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& normalPaths = textureContainer.GetPaths(TextureType::Normal);
|
||||||
|
outFile << " " << normalPaths.size();
|
||||||
|
for (const auto& path : normalPaths) {
|
||||||
|
outFile << " " << convert_w_string_to_string(path);
|
||||||
|
}
|
||||||
|
const auto& specularPaths = textureContainer.GetPaths(TextureType::Specular);
|
||||||
|
outFile << " " << specularPaths.size();
|
||||||
|
for (const auto& path : specularPaths) {
|
||||||
|
outFile << " " << convert_w_string_to_string(path);
|
||||||
|
}
|
||||||
|
const auto& alphaPaths = textureContainer.GetPaths(TextureType::Alpha);
|
||||||
|
outFile << " " << alphaPaths.size();
|
||||||
|
for (const auto& path : alphaPaths) {
|
||||||
|
outFile << " " << convert_w_string_to_string(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Textures normales
|
|
||||||
const auto& normalPaths = object->get_model()->GetTextureContainer().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 = object->get_model()->GetTextureContainer().GetPaths(TextureType::Specular);
|
|
||||||
outFile << " " << specularPaths.size();
|
|
||||||
for (const auto& path : specularPaths) {
|
|
||||||
outFile << " " << convert_w_string_to_string(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Textures alpha
|
|
||||||
const auto& alphaPaths = object->get_model()->GetTextureContainer().GetPaths(TextureType::Alpha);
|
|
||||||
outFile << " " << alphaPaths.size();
|
|
||||||
for (const auto& path : alphaPaths) {
|
|
||||||
outFile << " " << convert_w_string_to_string(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
outFile << std::endl;
|
outFile << std::endl;
|
||||||
}
|
}
|
||||||
@@ -344,3 +449,4 @@ std::string scene_manager::convert_w_string_to_string(const std::wstring& wstr)
|
|||||||
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str[0], size_needed, NULL, NULL);
|
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str[0], size_needed, NULL, NULL);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -36,16 +36,16 @@ bool stats::initialize(application_class* app)
|
|||||||
|
|
||||||
void stats::update_geometric_stats()
|
void stats::update_geometric_stats()
|
||||||
{
|
{
|
||||||
|
// Utiliser le syst<73>me ECS pour acc<63>der aux entit<69>s avec des composants de rendu
|
||||||
|
if (app_ && app_->get_entity_manager())
|
||||||
|
{
|
||||||
|
*total_vertex_count_ = get_total_vertex_count();
|
||||||
|
*total_triangle_count_ = get_total_triangle_count();
|
||||||
|
|
||||||
object_vec_ = app_->get_kobjects();
|
update_visible_count();
|
||||||
cubes_vec_ = app_->get_cubes();
|
|
||||||
terrain_chunk_vec_ = app_->get_terrain_cubes();
|
|
||||||
|
|
||||||
|
Logger::Get().Log("Statistics updated: " + std::to_string(*total_vertex_count_) + " vertices, " + std::to_string(*total_triangle_count_) + " triangles", __FILE__, __LINE__, Logger::LogLevel::Debug);
|
||||||
*total_vertex_count_ = get_total_vertex_count();
|
}
|
||||||
*total_triangle_count_ = get_total_triangle_count();
|
|
||||||
|
|
||||||
update_visible_count();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void stats::update_visible_count()
|
void stats::update_visible_count()
|
||||||
@@ -66,88 +66,143 @@ void stats::update_display_stats()
|
|||||||
int stats::get_total_vertex_count() const
|
int stats::get_total_vertex_count() const
|
||||||
{
|
{
|
||||||
int totalVertices = 0;
|
int totalVertices = 0;
|
||||||
|
|
||||||
|
// Utiliser le syst<73>me ECS pour acc<63>der aux entit<69>s avec des composants de rendu
|
||||||
|
if (app_ && app_->get_entity_manager())
|
||||||
|
{
|
||||||
|
auto entities = app_->get_entity_manager()->GetEntitiesWithComponent<ecs::RenderComponent>();
|
||||||
|
|
||||||
|
for (const auto& entity : entities)
|
||||||
|
{
|
||||||
|
auto renderComponent = entity->GetComponent<ecs::RenderComponent>();
|
||||||
|
if (renderComponent && renderComponent->GetModel())
|
||||||
|
{
|
||||||
|
totalVertices += renderComponent->GetModel()->GetVertexCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ajouter <20>galement les <20>ventuels objets restants de l'ancien syst<73>me
|
||||||
for (const auto& obj : object_vec_)
|
for (const auto& obj : object_vec_)
|
||||||
{
|
{
|
||||||
if (obj)
|
if (obj && obj->get_model())
|
||||||
{
|
{
|
||||||
totalVertices += obj->get_model()->GetVertexCount();
|
totalVertices += obj->get_model()->GetVertexCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Ajoutez le nombre de sommets pour les cubes
|
|
||||||
for (const auto& cube : cubes_vec_)
|
for (const auto& cube : cubes_vec_)
|
||||||
{
|
{
|
||||||
if (cube)
|
if (cube && cube->get_model())
|
||||||
{
|
{
|
||||||
totalVertices += cube->get_model()->GetVertexCount();
|
totalVertices += cube->get_model()->GetVertexCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Ajoutez le nombre de sommets pour le terrain
|
|
||||||
for (const auto& chunk : terrain_chunk_vec_)
|
for (const auto& chunk : terrain_chunk_vec_)
|
||||||
{
|
{
|
||||||
if (chunk)
|
if (chunk && chunk->get_model())
|
||||||
{
|
{
|
||||||
totalVertices += chunk->get_model()->GetVertexCount();
|
totalVertices += chunk->get_model()->GetVertexCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return totalVertices;
|
return totalVertices;
|
||||||
}
|
}
|
||||||
|
|
||||||
int stats::get_total_triangle_count() const
|
int stats::get_total_triangle_count() const
|
||||||
{
|
{
|
||||||
int totalTriangles = 0;
|
int totalTriangles = 0;
|
||||||
|
|
||||||
|
// Utiliser le syst<73>me ECS pour acc<63>der aux entit<69>s avec des composants de rendu
|
||||||
|
if (app_ && app_->get_entity_manager())
|
||||||
|
{
|
||||||
|
auto entities = app_->get_entity_manager()->GetEntitiesWithComponent<ecs::RenderComponent>();
|
||||||
|
|
||||||
|
for (const auto& entity : entities)
|
||||||
|
{
|
||||||
|
auto renderComponent = entity->GetComponent<ecs::RenderComponent>();
|
||||||
|
if (renderComponent && renderComponent->GetModel())
|
||||||
|
{
|
||||||
|
// Dans une topologie de liste de triangles, chaque triangle utilise 3 indices
|
||||||
|
totalTriangles += renderComponent->GetModel()->GetIndexCount() / 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ajouter <20>galement les <20>ventuels objets restants de l'ancien syst<73>me
|
||||||
for (const auto& obj : object_vec_)
|
for (const auto& obj : object_vec_)
|
||||||
{
|
{
|
||||||
if (obj)
|
if (obj && obj->get_model())
|
||||||
{
|
{
|
||||||
// Dans une topologie de liste de triangles, chaque triangle utilise 3 indices
|
|
||||||
totalTriangles += obj->get_model()->GetIndexCount() / 3;
|
totalTriangles += obj->get_model()->GetIndexCount() / 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Ajoutez le nombre de triangles pour les cubes
|
|
||||||
for (const auto& cube : cubes_vec_)
|
for (const auto& cube : cubes_vec_)
|
||||||
{
|
{
|
||||||
if (cube)
|
if (cube && cube->get_model())
|
||||||
{
|
{
|
||||||
totalTriangles += cube->get_model()->GetIndexCount() / 3;
|
totalTriangles += cube->get_model()->GetIndexCount() / 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Ajoutez le nombre de triangles pour le terrain
|
|
||||||
for (const auto& chunk : terrain_chunk_vec_)
|
for (const auto& chunk : terrain_chunk_vec_)
|
||||||
{
|
{
|
||||||
if (chunk)
|
if (chunk && chunk->get_model())
|
||||||
{
|
{
|
||||||
totalTriangles += chunk->get_model()->GetIndexCount() / 3;
|
totalTriangles += chunk->get_model()->GetIndexCount() / 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return totalTriangles;
|
return totalTriangles;
|
||||||
}
|
}
|
||||||
|
|
||||||
int stats::get_visible_triangle_count() const
|
int stats::get_visible_triangle_count() const
|
||||||
{
|
{
|
||||||
int visibleTriangles = 0;
|
int visibleTriangles = 0;
|
||||||
|
|
||||||
|
// Utiliser le syst<73>me ECS pour acc<63>der aux entit<69>s avec des composants de rendu
|
||||||
|
if (app_ && app_->get_entity_manager())
|
||||||
|
{
|
||||||
|
auto entities = app_->get_entity_manager()->GetEntitiesWithComponent<ecs::RenderComponent>();
|
||||||
|
|
||||||
|
for (const auto& entity : entities)
|
||||||
|
{
|
||||||
|
auto renderComponent = entity->GetComponent<ecs::RenderComponent>();
|
||||||
|
if (renderComponent && renderComponent->GetModel() && renderComponent->IsVisible())
|
||||||
|
{
|
||||||
|
// Dans une topologie de liste de triangles, chaque triangle utilise 3 indices
|
||||||
|
visibleTriangles += renderComponent->GetModel()->GetIndexCount() / 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ajouter <20>galement les <20>ventuels objets restants de l'ancien syst<73>me
|
||||||
for (const auto& obj : object_vec_)
|
for (const auto& obj : object_vec_)
|
||||||
{
|
{
|
||||||
if (obj && obj->IsVisible())
|
if (obj && obj->get_model() && obj->IsVisible())
|
||||||
{
|
{
|
||||||
visibleTriangles += obj->get_model()->GetIndexCount() / 3;
|
visibleTriangles += obj->get_model()->GetIndexCount() / 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Ajoutez le nombre de triangles visibles pour les cubes
|
|
||||||
for (const auto& cube : cubes_vec_)
|
for (const auto& cube : cubes_vec_)
|
||||||
{
|
{
|
||||||
if (cube && cube->IsVisible())
|
if (cube && cube->get_model() && cube->IsVisible())
|
||||||
{
|
{
|
||||||
visibleTriangles += cube->get_model()->GetIndexCount() / 3;
|
visibleTriangles += cube->get_model()->GetIndexCount() / 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Ajoutez le nombre de triangles visibles pour le terrain
|
|
||||||
for (const auto& chunk : terrain_chunk_vec_)
|
for (const auto& chunk : terrain_chunk_vec_)
|
||||||
{
|
{
|
||||||
if (chunk && chunk->IsVisible())
|
if (chunk && chunk->get_model() && chunk->IsVisible())
|
||||||
{
|
{
|
||||||
visibleTriangles += chunk->get_model()->GetIndexCount() / 3;
|
visibleTriangles += chunk->get_model()->GetIndexCount() / 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return visibleTriangles;
|
return visibleTriangles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user