11 Commits

19 changed files with 1005 additions and 522 deletions

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AndroidProjectSystem">
<option name="providerId" value="RiderAndroidProjectSystem" />
</component>
</project>

View File

@@ -2,6 +2,7 @@
<project version="4"> <project version="4">
<component name="RiderProjectSettingsUpdater"> <component name="RiderProjectSettingsUpdater">
<option name="singleClickDiffPreview" value="1" /> <option name="singleClickDiffPreview" value="1" />
<option name="unhandledExceptionsIgnoreList" value="1" />
<option name="vcsConfiguration" value="3" /> <option name="vcsConfiguration" value="3" />
</component> </component>
</project> </project>

View File

@@ -6,7 +6,10 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="e81d6e08-efc7-40a0-909d-ec4943d948e9" name="Changes" comment=""> <list default="true" id="e81d6e08-efc7-40a0-909d-ec4943d948e9" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/assets/Model/OBJ/skysphere.obj" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/assets/Model/OBJ/skysphere.obj" afterDir="false" /> <change beforePath="$PROJECT_DIR$/enginecustom/assets/Texture/imgui.ini" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/assets/Texture/imgui.ini" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/object.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/object.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/object.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/object.cpp" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -20,6 +23,31 @@
<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="cidr-memory-view://3" root0="FORCE_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/src/shader/CelShadingShader.cpp" root0="FORCE_HIGHLIGHTING" /> <setting file="file://$PROJECT_DIR$/enginecustom/src/src/shader/CelShadingShader.cpp" 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" />
@@ -36,25 +64,25 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;, "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
&quot;C++ Project.enginecustom.executor&quot;: &quot;Run&quot;, "C++ Project.enginecustom.executor": "Run",
&quot;C/C++ Project.enginecustom.executor&quot;: &quot;Run&quot;, "C/C++ Project.enginecustom.executor": "Run",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;, "RunOnceActivity.git.unshallow": "true",
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;, "SHARE_PROJECT_CONFIGURATION_FILES": "true",
&quot;git-widget-placeholder&quot;: &quot;main&quot;, "git-widget-placeholder": "main",
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;, "ignore.virus.scanning.warn.message": "true",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "nodejs_package_manager_path": "npm",
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;, "settings.editor.selected.configurable": "preferences.build.unityPlugin",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "vue.rearranger.settings.migration": "true"
} }
}</component> }]]></component>
<component name="RunManager" selected="C/C++ Project.enginecustom"> <component name="RunManager" selected="C/C++ Project.enginecustom">
<configuration name="KhaoticDemo" type="CppProject" factoryName="C++ Project"> <configuration name="KhaoticDemo" type="CppProject" factoryName="C++ Project">
<configuration_1 setup="1"> <configuration_1 setup="1">
@@ -165,6 +193,16 @@
<workItem from="1746113092234" duration="1477000" /> <workItem from="1746113092234" duration="1477000" />
<workItem from="1746117455914" duration="5976000" /> <workItem from="1746117455914" duration="5976000" />
<workItem from="1746126812110" duration="180000" /> <workItem from="1746126812110" duration="180000" />
<workItem from="1746188920194" duration="1870000" />
<workItem from="1746274246641" duration="89000" />
<workItem from="1746274352144" duration="8039000" />
<workItem from="1746444660572" duration="7742000" />
<workItem from="1746456965664" duration="13000" />
<workItem from="1746469494034" duration="799000" />
<workItem from="1746526901276" duration="2023000" />
<workItem from="1746536290167" duration="1908000" />
<workItem from="1746538260893" duration="5781000" />
<workItem from="1746546014271" duration="1490000" />
</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" />
@@ -208,6 +246,22 @@
<option name="LAST_COMMIT_MESSAGE" value="Patch update - add menu button" /> <option name="LAST_COMMIT_MESSAGE" value="Patch update - add menu button" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<breakpoint enabled="true" type="DotNet_Exception_Breakpoints">
<properties exception="System.OperationCanceledException" breakIfHandledByOtherCode="false" displayValue="System.OperationCanceledException" />
<option name="timeStamp" value="1" />
</breakpoint>
<breakpoint enabled="true" type="DotNet_Exception_Breakpoints">
<properties exception="System.Threading.Tasks.TaskCanceledException" breakIfHandledByOtherCode="false" displayValue="System.Threading.Tasks.TaskCanceledException" />
<option name="timeStamp" value="2" />
</breakpoint>
<breakpoint enabled="true" type="DotNet_Exception_Breakpoints">
<properties exception="System.Threading.ThreadAbortException" breakIfHandledByOtherCode="false" displayValue="System.Threading.ThreadAbortException" />
<option name="timeStamp" value="3" />
</breakpoint>
</breakpoints>
</breakpoint-manager>
<watches-manager> <watches-manager>
<configuration name="CppProject"> <configuration name="CppProject">
<watch expression="((class ModelClass &amp;) (*(*(*this).m_Application).m_object[0]))" /> <watch expression="((class ModelClass &amp;) (*(*(*this).m_Application).m_object[0]))" />

View File

@@ -36,13 +36,20 @@ This **DirectX11** based engine uses **ImGui** with an abstraction layer to enab
**SHADER** : **SHADER** :
+ Sunlight shader + Sunlight shader
+ Cel Shading (Work In Progress) + Cel Shading
+ Skysphere
**Interface Graphique** : **Interface Graphique** :
+ Console link to the Logger object + Console link to the Logger object
+ Shader Manager + Shader Manager
+ Engine Settings + Engine Settings
+ Sunlight Settings
**Save And Load of a Scene** :
+ Save All Custom object
+ Save All Custom Texture for Custom Object
**Texture File** : **Texture File** :
@@ -53,6 +60,7 @@ This **DirectX11** based engine uses **ImGui** with an abstraction layer to enab
- Shader rendering - Shader rendering
- Frustum culling - Frustum culling
- Object rendering - Object rendering
- Terrain Instancing
## Demo : ## Demo :

View File

View File

@@ -1,49 +1,89 @@
[Window][DockSpace]
Pos=0,0
Size=2048,1129
Collapsed=0
[Window][Debug##Default] [Window][Debug##Default]
Pos=60,60 Pos=60,60
Size=400,400 Size=400,400
Collapsed=0 Collapsed=0
[Window][Khaotic Engine] [Window][Khaotic Engine]
Pos=1687,27 Pos=1697,27
Size=353,1094 Size=343,1094
Collapsed=0
DockId=0x00000002,0
[Window][Objects]
Pos=8,27
Size=345,896
Collapsed=0 Collapsed=0
DockId=0x00000005,0 DockId=0x00000005,0
[Window][Engine Settings] [Window][Objects]
Pos=1687,27 Pos=8,27
Size=353,1094 Size=289,547
Collapsed=0 Collapsed=0
DockId=0x00000002,1 DockId=0x00000007,0
[Window][Terrain] [Window][Terrain]
Pos=8,27 Pos=8,576
Size=345,896 Size=289,545
Collapsed=0 Collapsed=0
DockId=0x00000005,1 DockId=0x00000008,0
[Window][Light] [Window][Light]
Pos=8,925 Pos=8,27
Size=345,196 Size=290,866
Collapsed=0
DockId=0x0000000B,1
[Window][Shader Manager]
Pos=8,27
Size=330,487
Collapsed=0
DockId=0x00000001,2
[Window][Engine Settings]
Pos=8,27
Size=289,826
Collapsed=0
DockId=0x00000007,0
[Window][DockSpace Demo]
Size=1584,861
Collapsed=0
[Window][Render Window]
Pos=8,27
Size=1559,974
Collapsed=0
DockId=0x00000007,0
[Window][DockSpace]
Pos=0,0
Size=2048,1129
Collapsed=0
[Window][Add Object]
Pos=1188,0
Size=396,430
Collapsed=0
[Window][Log]
Pos=8,518
Size=1568,335
Collapsed=0
DockId=0x0000000C,0
[Window][Log Window]
Pos=8,37
Size=16,19
Collapsed=0 Collapsed=0
DockId=0x00000006,0 DockId=0x00000006,0
[Docking][Data] [Docking][Data]
DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=8,27 Size=2032,1094 Split=X DockSpace ID=0xC0DFADC4 Pos=8,27 Size=1568,826 Split=X
DockNode ID=0x00000003 Parent=0xCCBD8CF7 SizeRef=345,826 Split=Y Selected=0x393905AB DockNode ID=0x00000001 Parent=0xC0DFADC4 SizeRef=330,1094 Selected=0x393905AB
DockNode ID=0x00000005 Parent=0x00000003 SizeRef=345,896 Selected=0x393905AB DockNode ID=0x00000003 Parent=0xC0DFADC4 SizeRef=1700,1094 CentralNode=1
DockNode ID=0x00000006 Parent=0x00000003 SizeRef=345,196 Selected=0x321620B2 DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=8,27 Size=2032,1094 Split=Y
DockNode ID=0x00000004 Parent=0xCCBD8CF7 SizeRef=1221,826 Split=X DockNode ID=0x00000004 Parent=0xCCBD8CF7 SizeRef=1568,598 Split=X
DockNode ID=0x00000001 Parent=0x00000004 SizeRef=866,826 CentralNode=1 DockNode ID=0x00000009 Parent=0x00000004 SizeRef=289,974 Split=Y Selected=0x031DC75C
DockNode ID=0x00000002 Parent=0x00000004 SizeRef=353,826 Selected=0x9F035453 DockNode ID=0x00000007 Parent=0x00000009 SizeRef=289,547 Selected=0x031DC75C
DockNode ID=0x00000008 Parent=0x00000009 SizeRef=289,545 Selected=0x393905AB
DockNode ID=0x0000000D Parent=0x00000004 SizeRef=1613,974 Split=X
DockNode ID=0x00000002 Parent=0x0000000D SizeRef=1268,826 Split=Y
DockNode ID=0x0000000B Parent=0x00000002 SizeRef=1568,637 CentralNode=1
DockNode ID=0x0000000C Parent=0x00000002 SizeRef=1568,335 Selected=0x139FDA3F
DockNode ID=0x00000005 Parent=0x0000000D SizeRef=343,826 Selected=0x9F035453
DockNode ID=0x00000006 Parent=0xCCBD8CF7 SizeRef=1568,226 Selected=0xAB74BEE9

View File

@@ -1 +1 @@
0 86 111.063 12.7056 0 0 -0 0 1 1 1 Content/Assets/Kobject/86.obj CEL_SHADING 1 Cube 1 1 1 isosphere 0 10 0 0 -0 0 1 1 1 F:\Github_Repo\khaotic-engine-Reborn\x64\Debug\Content/Assets/Kobject/isosphere.obj SUNLIGHT 1 Unknown 1 0 2 F:\Github_Repo\khaotic-engine-Reborn\enginecustom\assets\Texture\stone01.png F:\Github_Repo\khaotic-engine-Reborn\enginecustom\assets\Texture\dirt01.png 1 assets/Texture/BricksNRM2K.png 1 assets/Texture/BricksGLOSS2K.png 1 F:\Github_Repo\khaotic-engine-Reborn\enginecustom\assets\Texture\alpha01.png

View File

@@ -310,6 +310,22 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CopyFileToFolders Include="font01.tga" /> <CopyFileToFolders Include="font01.tga" />
<CopyFileToFolders Include="assets\Texture\Bricks2K.png">
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)\assets\Texture</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)\assets\Texture</DestinationFolders>
</CopyFileToFolders>
<CopyFileToFolders Include="assets\Texture\BricksGLOSS2K.png">
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)\assets\Texture</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)\assets\Texture</DestinationFolders>
</CopyFileToFolders>
<CopyFileToFolders Include="assets\Texture\BricksNRM2K.png">
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)\assets\Texture</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)\assets\Texture</DestinationFolders>
</CopyFileToFolders>
<CopyFileToFolders Include="assets\Skybox\skybox.png">
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)\assets\Skybox</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)\assets\Skybox</DestinationFolders>
</CopyFileToFolders>
<Image Include="KhaoticIcon.ico" /> <Image Include="KhaoticIcon.ico" />
<CopyFileToFolders Include="sprite01.tga" /> <CopyFileToFolders Include="sprite01.tga" />
<CopyFileToFolders Include="sprite02.tga" /> <CopyFileToFolders Include="sprite02.tga" />

View File

@@ -480,5 +480,17 @@
<CopyFileToFolders Include="assets\Model\OBJ\skysphere.obj"> <CopyFileToFolders Include="assets\Model\OBJ\skysphere.obj">
<Filter>Assets\Model\OBJ</Filter> <Filter>Assets\Model\OBJ</Filter>
</CopyFileToFolders> </CopyFileToFolders>
<CopyFileToFolders Include="assets\Texture\BricksNRM2K.png">
<Filter>Texture</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="assets\Texture\BricksGLOSS2K.png">
<Filter>Texture</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="assets\Texture\Bricks2K.png">
<Filter>Texture</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="assets\Skybox\skybox.png">
<Filter>Assets\Skybox</Filter>
</CopyFileToFolders>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -13,11 +13,11 @@ DockId=0x00000005,0
Pos=8,27 Pos=8,27
Size=289,826 Size=289,826
Collapsed=0 Collapsed=0
DockId=0x00000009,1 DockId=0x00000009,0
[Window][Terrain] [Window][Terrain]
Pos=8,27 Pos=8,27
Size=250,974 Size=250,826
Collapsed=0 Collapsed=0
DockId=0x00000007,0 DockId=0x00000007,0
@@ -66,8 +66,8 @@ Collapsed=0
DockId=0x0000000C,0 DockId=0x0000000C,0
[Window][Log Window] [Window][Log Window]
Pos=8,627 Pos=8,37
Size=1568,226 Size=16,19
Collapsed=0 Collapsed=0
DockId=0x00000006,0 DockId=0x00000006,0

View File

@@ -46,19 +46,6 @@ public:
bool RenderCelShadingShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float); bool RenderCelShadingShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float);
bool RenderSunlightShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float); bool RenderSunlightShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float);
bool RenderSkyboxShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float); bool RenderSkyboxShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float);
// ID3D11DeviceContext* deviceContext,
// int indexCount,
// XMMATRIX worldMatrix,
// XMMATRIX viewMatrix,
// XMMATRIX projectionMatrix,
// ID3D11ShaderResourceView* front,
// ID3D11ShaderResourceView* back,
// ID3D11ShaderResourceView* left,
// ID3D11ShaderResourceView* right,
// ID3D11ShaderResourceView* top,
// ID3D11ShaderResourceView* bottom,
// XMFLOAT4 sunDiffuseColor
// );
private: private:
TextureShaderClass* m_TextureShader; TextureShaderClass* m_TextureShader;

View File

@@ -151,7 +151,7 @@ public:
// Save and load scene // Save and load scene
void SaveScene(); void SaveScene();
void LoadScene(); bool LoadScene();
void SetScenePath(std::string path) { m_scenePath = path; }; void SetScenePath(std::string path) { m_scenePath = path; };
std::wstring GetScenePath(); std::wstring GetScenePath();

View File

@@ -22,7 +22,128 @@ using namespace std;
/////////////////////// ///////////////////////
#include "textureclass.h" #include "textureclass.h"
enum class TextureType
{
Diffuse,
Normal,
Specular,
Alpha
};
struct TextureContainer
{
// Textures
std::vector<ID3D11ShaderResourceView*> diffuse;
std::vector<ID3D11ShaderResourceView*> normal;
std::vector<ID3D11ShaderResourceView*> specular;
std::vector<ID3D11ShaderResourceView*> alpha;
// Textures Paths
std::vector<std::wstring> diffusePaths;
std::vector<std::wstring> normalPaths;
std::vector<std::wstring> specularPaths;
std::vector<std::wstring> alphaPaths;
// Get the vector of textures based on the type
std::vector<ID3D11ShaderResourceView*>& Get(TextureType type) const {
switch (type) {
case TextureType::Diffuse: return const_cast<std::vector<ID3D11ShaderResourceView*>&>(diffuse);
case TextureType::Normal: return const_cast<std::vector<ID3D11ShaderResourceView*>&>(normal);
case TextureType::Specular: return const_cast<std::vector<ID3D11ShaderResourceView*>&>(specular);
case TextureType::Alpha: return const_cast<std::vector<ID3D11ShaderResourceView*>&>(alpha);
default: return const_cast<std::vector<ID3D11ShaderResourceView*>&>(diffuse);
}
}
// Get the vector of textures paths based on the type
std::vector<std::wstring> GetPaths(TextureType type) const {
switch (type)
{
case TextureType::Diffuse: return std::vector<std::wstring>(diffusePaths);
case TextureType::Normal: return std::vector<std::wstring>(normalPaths);
case TextureType::Specular: return std::vector<std::wstring>(specularPaths);
case TextureType::Alpha: return std::vector<std::wstring>(alphaPaths);
default: return std::vector<std::wstring>(diffusePaths);
}
}
// Get The texture based on the type and index
ID3D11ShaderResourceView* GetTexture(TextureType type, int index) const {
auto& vec = Get(type);
if (index >= 0 && index < vec.size())
return vec[index];
return nullptr;
}
// Get The texture path based on the type and index
std::wstring GetTexturePath(TextureType type, int index) const
{
std::vector<std::wstring> path = GetPaths(type);
if (index >= 0 && index < path.size())
return path[index];
return L"";
}
// Release all textures and textures paths
void ReleaseAll() {
ReleaseVector(diffuse);
ReleaseVector(normal);
ReleaseVector(specular);
ReleaseVector(alpha);
ReleaseVector(diffusePaths);
ReleaseVector(normalPaths);
ReleaseVector(specularPaths);
ReleaseVector(alphaPaths);
}
// Assign a texture and its path to the appropriate vector based on the index
void AssignTexture(TextureContainer& textContainer, ID3D11ShaderResourceView* texture , const std::wstring paths, int index)
{
switch (index)
{
case 0:
textContainer.diffuse.push_back(texture);
textContainer.diffusePaths.push_back(paths);
break;
case 1:
textContainer.normal.push_back(texture);
textContainer.normalPaths.push_back(paths);
break;
case 2:
textContainer.specular.push_back(texture);
textContainer.specularPaths.push_back(paths);
break;
case 3:
textContainer.alpha.push_back(texture);
textContainer.alphaPaths.push_back(paths);
break;
default:
textContainer.diffuse.push_back(texture);
textContainer.diffusePaths.push_back(paths);
break;
}
}
private:
void ReleaseVector(std::vector<ID3D11ShaderResourceView*>& vec) {
for (auto& tex : vec) {
if (tex) {
tex->Release();
tex = nullptr;
}
}
vec.clear();
}
void ReleaseVector(std::vector<std::wstring>& vec) {
vec.clear();
}
};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Class name: ModelClass // Class name: ModelClass
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -83,14 +204,29 @@ public:
ModelClass(const ModelClass&); ModelClass(const ModelClass&);
~ModelClass(); ~ModelClass();
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*, std::vector<ID3D11ShaderResourceView*>); //bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*, std::vector<ID3D11ShaderResourceView*>);
// Nouvelle surcharge avec TextureContainer
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*, const TextureContainer&);
// Nouvelle m<>thode - initialisation sans textures
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*);
void Shutdown(); void Shutdown();
void Render(ID3D11DeviceContext*); void Render(ID3D11DeviceContext*);
int GetIndexCount(); int GetIndexCount();
ID3D11ShaderResourceView* GetTexture(int index) const; //ID3D11ShaderResourceView* GetTexture(int index) const;
bool ChangeTexture(ID3D11Device*, ID3D11DeviceContext*, std::wstring filename, int index); ID3D11ShaderResourceView* GetTexture(TextureType type, int index) const;
//bool ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, std::wstring filename, int index);
bool ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext,std::wstring filename, TextureType type, int index);
// M<>thodes pour ajouter une nouvelle texture
bool AddTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext,std::wstring filename, TextureType type);
bool AddTexture(ID3D11ShaderResourceView* texture, TextureType type);
void SetTextureContainer (TextureContainer& texturesContainer) { m_Textures = texturesContainer; }
TextureContainer GetTextureContainer() const { return m_Textures; }
bool PreloadTextures(ID3D11Device* device, ID3D11DeviceContext* deviceContext, TextureContainer& textureContainer);
private: private:
bool InitializeBuffers(ID3D11Device*); bool InitializeBuffers(ID3D11Device*);
@@ -107,10 +243,9 @@ private:
void CalculateModelVectors(); void CalculateModelVectors();
void CalculateTangentBinormal(TempVertexType, TempVertexType, TempVertexType, VectorType&, VectorType&); void CalculateTangentBinormal(TempVertexType, TempVertexType, TempVertexType, VectorType&, VectorType&);
private:
ID3D11Buffer* m_vertexBuffer, * m_indexBuffer; ID3D11Buffer* m_vertexBuffer, * m_indexBuffer;
int m_vertexCount, m_indexCount; int m_vertexCount, m_indexCount;
std::vector<ID3D11ShaderResourceView*> m_Textures; TextureContainer m_Textures;
ModelType* m_model; ModelType* m_model;
}; };

View File

@@ -3,6 +3,8 @@
#include <WICTextureLoader.h> #include <WICTextureLoader.h>
#include <SimpleMath.h> #include <SimpleMath.h>
#include "d3dclass.h"
enum class ObjectType enum class ObjectType
{ {
Sphere, Sphere,
@@ -96,6 +98,8 @@ public:
std::string ObjectTypeToString(ObjectType objectType); std::string ObjectTypeToString(ObjectType objectType);
void LaunchObject(); void LaunchObject();
bool LoadTexturesFromPath(std::vector<std::wstring>& texturePaths, TextureContainer& texturesContainer,
D3DClass* m_Direct3D);
void SetAlpha(float alpha) { m_alpha = alpha; } void SetAlpha(float alpha) { m_alpha = alpha; }
float GetAlpha() const { return m_alpha; } float GetAlpha() const { return m_alpha; }
void SetInitialStretch(float initialStretch) { m_initialStretch = initialStretch; } void SetInitialStretch(float initialStretch) { m_initialStretch = initialStretch; }
@@ -127,12 +131,11 @@ private:
std::string m_name; std::string m_name;
ObjectType m_type = ObjectType::Unknown; ObjectType m_type = ObjectType::Unknown;
ShaderType m_activeShader = ShaderType::LIGHTING; ShaderType m_activeShader = ShaderType::LIGHTING;
float m_boundingRadius; float m_boundingRadius;
std::wstring m_modelPath; std::wstring m_modelPath;
TextureContainer m_texturesContainer;
float m_alpha = 0.0f; float m_alpha = 0.0f;
float m_initialStretch = 0.0f; float m_initialStretch = 0.0f;
float m_springConstant = 10.0f; float m_springConstant = 10.0f;

View File

@@ -30,11 +30,12 @@ Object* Skybox::ConstructSkybox()
char modelFilename[128]; char modelFilename[128];
strcpy_s(modelFilename, "assets/Model/OBJ/skysphere.obj"); strcpy_s(modelFilename, "assets/Model/OBJ/skysphere.obj");
textures.clear();
std::vector<std::wstring> skyboxTextures = { std::vector<std::wstring> skyboxTextures = {
L"assets/Skybox/skybox.png", L"assets/Skybox/skybox.png",
}; };
TextureContainer SkyboxTextures;
// Load the textures // Load the textures
for (const auto& textureFilename : skyboxTextures) for (const auto& textureFilename : skyboxTextures)
{ {
@@ -45,12 +46,13 @@ Object* Skybox::ConstructSkybox()
Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error); Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return nullptr; return nullptr;
} }
textures.push_back(texture); SkyboxTextures.diffuse.push_back(texture);
} }
// Create the model object // Create the model object
m_Skybox = new Object(); m_Skybox = new Object();
HRESULT result = m_Skybox->Initialize(m_d3dClassRef->GetDevice(), m_d3dClassRef->GetDeviceContext(), modelFilename, textures); HRESULT result = m_Skybox->Initialize(m_d3dClassRef->GetDevice(), m_d3dClassRef->GetDeviceContext(), modelFilename, SkyboxTextures);
if (!result) if (!result)
{ {
Logger::Get().Log("Could not initialize the skybox model object", __FILE__, __LINE__, Logger::LogLevel::Error); Logger::Get().Log("Could not initialize the skybox model object", __FILE__, __LINE__, Logger::LogLevel::Error);

View File

@@ -78,10 +78,10 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd,
bool result; bool result;
HRESULT Hresult; HRESULT Hresult;
m_RenderQueues.push_back(std::ref(m_Skybox)); // Skybox doit <20>tre rendu en premier pour <20>tre derri<72>re touts les autres objets
m_RenderQueues.push_back(std::ref(m_object)); m_RenderQueues.push_back(std::ref(m_object));
m_RenderQueues.push_back(std::ref(m_cubes)); m_RenderQueues.push_back(std::ref(m_cubes));
m_RenderQueues.push_back(std::ref(m_terrainChunk)); m_RenderQueues.push_back(std::ref(m_terrainChunk));
m_RenderQueues.push_back(std::ref(m_Skybox));
m_screenWidth = screenWidth; m_screenWidth = screenWidth;
m_screenHeight = screenHeight; m_screenHeight = screenHeight;
@@ -226,6 +226,8 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd,
L"assets/Texture/stone01.png" L"assets/Texture/stone01.png"
}; };
TextureContainer CubeTextures;
for (const auto& textureFilename : textureFilenames) for (const auto& textureFilename : textureFilenames)
{ {
ID3D11ShaderResourceView* texture = nullptr; ID3D11ShaderResourceView* texture = nullptr;
@@ -235,13 +237,14 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd,
Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error); Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
textures.push_back(texture); CubeTextures.diffuse.push_back(texture);
} }
// Create and initialize the model object. // Create and initialize the model object.
m_Model = new ModelClass; m_Model = new ModelClass;
result = m_Model->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textures);
result = m_Model->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, CubeTextures);
if (!result) if (!result)
{ {
Logger::Get().Log("Could not initialize the model object", __FILE__, __LINE__, Logger::LogLevel::Error); Logger::Get().Log("Could not initialize the model object", __FILE__, __LINE__, Logger::LogLevel::Error);
@@ -337,6 +340,8 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd,
L"assets/Texture/marble01.png" L"assets/Texture/marble01.png"
}; };
TextureContainer BathTextures;
textures.clear(); textures.clear();
for (const auto& textureFilename : bathTextures) for (const auto& textureFilename : bathTextures)
{ {
@@ -347,7 +352,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd,
Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error); Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
textures.push_back(texture); BathTextures.diffuse.push_back(texture);
} }
// Set the file name of the bath model. // Set the file name of the bath model.
@@ -356,7 +361,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd,
// Create and initialize the bath model object. // Create and initialize the bath model object.
m_BathModel = new ModelClass; m_BathModel = new ModelClass;
result = m_BathModel->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textures); result = m_BathModel->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, BathTextures);
if (!result) if (!result)
{ {
MessageBox(hwnd, L"Could not initialize the bath model object.", L"Error", MB_OK); MessageBox(hwnd, L"Could not initialize the bath model object.", L"Error", MB_OK);
@@ -370,6 +375,8 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd,
L"assets/Texture/water01.png" L"assets/Texture/water01.png"
}; };
TextureContainer WaterTextures;
textures.clear(); textures.clear();
for (const auto& textureFilename : waterTextures) for (const auto& textureFilename : waterTextures)
{ {
@@ -380,13 +387,13 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd,
Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error); Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
textures.push_back(texture); WaterTextures.diffuse.push_back(texture);
} }
// Create and initialize the water model object. // Create and initialize the water model object.
m_WaterModel = new ModelClass; m_WaterModel = new ModelClass;
result = m_WaterModel->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textures); result = m_WaterModel->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, WaterTextures);
if (!result) if (!result)
{ {
MessageBox(hwnd, L"Could not initialize the water model object.", L"Error", MB_OK); MessageBox(hwnd, L"Could not initialize the water model object.", L"Error", MB_OK);
@@ -890,7 +897,7 @@ bool ApplicationClass::RenderRefractionToTexture()
m_BathModel->Render(m_Direct3D->GetDeviceContext()); m_BathModel->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderRefractionShader(m_Direct3D->GetDeviceContext(), m_BathModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, result = m_ShaderManager->RenderRefractionShader(m_Direct3D->GetDeviceContext(), m_BathModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_BathModel->GetTexture(0), m_Lights[0]->GetDirection(), ambientColor, diffuseColor, lightPosition, clipPlane); m_BathModel->GetTexture(TextureType::Diffuse,0), m_Lights[0]->GetDirection(), ambientColor, diffuseColor, lightPosition, clipPlane);
if (!result) if (!result)
{ {
return false; return false;
@@ -946,7 +953,7 @@ bool ApplicationClass::RenderSceneToTexture(float rotation)
m_Model->Render(m_Direct3D->GetDeviceContext()); m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderTextureShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, result = m_ShaderManager->RenderTextureShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_Model->GetTexture(0)); m_Model->GetTexture(TextureType::Diffuse,0));
if (!result) if (!result)
{ {
return false; return false;
@@ -1026,7 +1033,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_Model->Render(m_Direct3D->GetDeviceContext()); m_Model->Render(m_Direct3D->GetDeviceContext());
// Render the model using the light shader. // Render the model using the light shader.
result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0), result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(TextureType::Diffuse,0),
diffuseColor, lightPosition, ambientColor); diffuseColor, lightPosition, ambientColor);
UpdateSkyboxPosition(); // Update the position of the skybox to match the camera position. UpdateSkyboxPosition(); // Update the position of the skybox to match the camera position.
@@ -1061,7 +1068,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
// Render the bath model using the light shader. // Render the bath model using the light shader.
result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), m_BathModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), m_BathModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_BathModel->GetTexture(0), diffuseColor, lightPosition, ambientColor); m_BathModel->GetTexture(TextureType::Diffuse,0), diffuseColor, lightPosition, ambientColor);
if (!result) if (!result)
{ {
return false; return false;
@@ -1081,7 +1088,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
// Render the water model using the water shader. // Render the water model using the water shader.
result = m_ShaderManager->RenderWaterShader(m_Direct3D->GetDeviceContext(), m_WaterModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, reflectionMatrix, result = m_ShaderManager->RenderWaterShader(m_Direct3D->GetDeviceContext(), m_WaterModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, reflectionMatrix,
m_ReflectionTexture->GetShaderResourceView(), m_RefractionTexture->GetShaderResourceView(), m_WaterModel->GetTexture(0), m_ReflectionTexture->GetShaderResourceView(), m_RefractionTexture->GetShaderResourceView(), m_WaterModel->GetTexture(TextureType::Diffuse,0),
m_waterTranslation, 0.01f); m_waterTranslation, 0.01f);
if (!result) if (!result)
{ {
@@ -1153,17 +1160,6 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
// turn on the Z buffer // turn on the Z buffer
m_Direct3D->TurnZBufferOn(); m_Direct3D->TurnZBufferOn();
// Render the model using the multitexture shader.
m_Model->Render(m_Direct3D->GetDeviceContext());
scaleMatrix = XMMatrixScaling(2.0f, 2.0f, 2.0f); // Build the scaling matrix.
rotateMatrix = XMMatrixRotationY(-rotation); // Build the rotation matrix.
translateMatrix = XMMatrixTranslation(-x, -y, -z); // Build the translation matrix.
// Multiply the scale, rotation, and translation matrices together to create the final world transformation matrix.
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
// Get the light properties. // Get the light properties.
for (i = 0; i < m_numLights; i++) for (i = 0; i < m_numLights; i++)
{ {
@@ -1173,156 +1169,8 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
// Create the light position array from the four light positions. // Create the light position array from the four light positions.
lightPosition[i] = m_Lights[i]->GetPosition(); lightPosition[i] = m_Lights[i]->GetPosition();
} }
// Setup matrices.
rotateMatrix = XMMatrixRotationY(rotation);
translateMatrix = XMMatrixTranslation(-5.0f, 1.0f, -20.0f);
worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix);
// Render the model using the alpha map shader.
m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderAlphaMapShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_Model->GetTexture(0), m_Model->GetTexture(5), m_Model->GetTexture(3));
if (!result)
{
Logger::Get().Log("Could not render the model using the alpha map shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Setup matrices.
rotateMatrix = XMMatrixRotationY(rotation);
translateMatrix = XMMatrixTranslation(-5.0f, -5.0f, -20.0f);
worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix);
// Render the model using the texture shader.
m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderTextureShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_Model->GetTexture(0));
if (!result)
{
Logger::Get().Log("Could not render the model using the texture shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Setup matrices.
rotateMatrix = XMMatrixRotationY(rotation);
translateMatrix = XMMatrixTranslation(0.0f, 1.0f, -20.0f);
worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix);
// Render the model using the render map shader.
m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderNormalMapShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_Model->GetTexture(0), m_Model->GetTexture(1), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor());
if (!result)
{
Logger::Get().Log("Could not render the model using the normal map shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Setup matrices.
rotateMatrix = XMMatrixRotationY(rotation);
translateMatrix = XMMatrixTranslation(0.0f, -2.0f, -20.0f);
worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix);
// Render the model using the multitexture shader.
m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderMultitextureShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_Model->GetTexture(0), m_Model->GetTexture(5));
if (!result)
{
Logger::Get().Log("Could not render the model using the multitexture shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Setup matrices.
rotateMatrix = XMMatrixRotationY(rotation);
translateMatrix = XMMatrixTranslation(0.0f, -5.0f, -20.0f);
worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix);
// Render the model using the translate shader.
m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderTranslateShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_Model->GetTexture(0), textureTranslation);
if (!result)
{
Logger::Get().Log("Could not render the model using the translate shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Setup matrices.
rotateMatrix = XMMatrixRotationY(rotation);
translateMatrix = XMMatrixTranslation(-5.0f, -2.0f, -20.0f);
worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix);
// Render the model using the specular map shader.
m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderSpecMapShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_Model->GetTexture(0), m_Model->GetTexture(1), m_Model->GetTexture(2), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor(),
m_Camera->GetPosition(), m_Lights[0]->GetSpecularColor(), m_Lights[0]->GetSpecularPower());
if (!result)
{
Logger::Get().Log("Could not render the model using the specular map shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Setup matrices.
rotateMatrix = XMMatrixRotationY(rotation);
translateMatrix = XMMatrixTranslation(-10.0f, -5.0f, -20.0f);
worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix);
// Render the model using the transparent shader.
m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderTransparentShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0), blendAmount);
if (!result)
{
Logger::Get().Log("Could not render the model using the transparent shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Setup matrices.
rotateMatrix = XMMatrixRotationY(rotation);
translateMatrix = XMMatrixTranslation(-10.0f, -2.0f, -20.0f);
worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix);
// Render the model using the transparent shader.
m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0), diffuseColor, lightPosition, ambientColor);
if (!result)
{
return false;
}
// Setup matrices.
rotateMatrix = XMMatrixRotationY(rotation);
translateMatrix = XMMatrixTranslation(-10.0f, 1.0f, -20.0f);
worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix);
// Render the model using the transparent shader.
m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderlightMapShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0), m_Model->GetTexture(4));
if (!result)
{
return false;
}
// Enable the Z buffer and disable alpha blending now that 2D rendering is complete.
// R<>initialiser la cible de rendu au back buffer. // R<>initialiser la cible de rendu au back buffer.
m_Direct3D->SetBackBufferRenderTarget(); m_Direct3D->SetBackBufferRenderTarget();
m_Direct3D->TurnZBufferOn();
m_Direct3D->DisableAlphaBlending();
return true; return true;
} }
@@ -1344,81 +1192,74 @@ int ApplicationClass::GetScreenHeight() const
void ApplicationClass::GenerateTerrain() void ApplicationClass::GenerateTerrain()
{ {
Logger::Get().Log("G<EFBFBD>n<EFBFBD>ration du terrain avec instanciation", __FILE__, __LINE__, Logger::LogLevel::Info);
Logger::Get().Log("Generating terrain", __FILE__, __LINE__); // Nettoyer les objets terrain existants pour <20>viter les fuites
for (auto* chunk : m_terrainChunk)
{
if (chunk)
{
chunk->Shutdown();
delete chunk;
}
}
m_terrainChunk.clear();
char modelFilename[128]; // Dimensions du terrain
float scaleX = 10.0f;
float scaleY = 1.0f;
float scaleZ = 10.0f;
int gridSizeX = 20;
int gridSizeZ = 20;
XMMATRIX scaleMatrix; // Cr<43>er un conteneur de textures partag<61>
float scaleX, scaleY, scaleZ; 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");
scaleX = 10.0f; // Pr<50>charger les textures une seule fois
scaleY = 1.0f; ModelClass* sharedModel = new ModelClass();
scaleZ = 10.0f; sharedModel->PreloadTextures(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), textureContainer);
scaleMatrix = XMMatrixScaling(scaleX, scaleY, scaleZ); char modelFilename[128];
strcpy_s(modelFilename, "assets/Model/OBJ/plane.obj");
// Set the file name of the model. // G<>n<EFBFBD>rer les tuiles de terrain
strcpy_s(modelFilename, "assets/Model/OBJ/plane.obj"); for (int i = 0; i < gridSizeX; i++)
{
for (int j = 0; j < gridSizeZ; j++)
{
// Cr<43>er un nouvel objet de terrain
Object* terrain = new Object();
// Liste des fichiers de texture // Initialiser avec le mod<6F>le et les textures pr<70>charg<72>es
std::vector<std::wstring> terrainTexture = { if (!terrain->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureContainer))
L"assets/Texture/Bricks2K.png", {
L"assets/Texture/BricksNRM2K.png", Logger::Get().Log("<EFBFBD>chec de l'initialisation d'une tuile de terrain", __FILE__, __LINE__, Logger::LogLevel::Error);
L"assets/Texture/BricksGLOSS2K.png" delete terrain;
}; continue;
}
// D<>finir la position dans la grille
XMFLOAT3 position(i * scaleX, -12.0f, j * scaleZ);
XMFLOAT3 scale(scaleX, scaleY, scaleZ);
textures.clear(); terrain->SetPosition(XMLoadFloat3(&position));
for (const auto& textureFilename : terrainTexture) terrain->SetScale(XMLoadFloat3(&scale));
{
ID3D11ShaderResourceView* texture = nullptr; // Configurer les propri<72>t<EFBFBD>s
HRESULT result = DirectX::CreateWICTextureFromFile(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), textureFilename.c_str(), nullptr, &texture); terrain->SetName("TerrainTile_" + std::to_string(i) + "_" + std::to_string(j));
if (FAILED(result)) terrain->SetType(ObjectType::Cube);
{ terrain->SetActiveShader(ShaderType::SUNLIGHT);
// Utiliser _com_error pour obtenir des informations d<>taill<6C>es sur l'erreur terrain->SetId(m_ObjectId++);
_com_error err(result);
LPCTSTR errMsg = err.ErrorMessage();
//convertie errMessage en std::wstring // Ajouter <20> la liste des chunks de terrain
std::wstring ws(errMsg); m_terrainChunk.push_back(terrain);
std::string str(ws.begin(), ws.end()); }
}
Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()) +
"\nError: " + std::to_string(result) +
"\nDescription: " + str,
__FILE__, __LINE__, Logger::LogLevel::Error);
return ; // Assurez-vous de retourner false ou de g<>rer l'erreur de mani<6E>re appropri<72>e
}
textures.push_back(texture);
// log success message
Logger::Get().Log("Texture loaded: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Initialize);
}
std::filesystem::path p(modelFilename);
std::string filenameWithoutExtension = p.stem().string();
// for loop to generate terrain chunks for a 10x10 grid
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 20; j++)
{
Object* newTerrain = new Object();
newTerrain->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textures);
newTerrain->SetScaleMatrix(scaleMatrix);
newTerrain->SetTranslateMatrix(XMMatrixTranslation(i / 2 * scaleX , -12.0f, j * scaleZ));
newTerrain->SetName(filenameWithoutExtension);
newTerrain->SetType(ObjectType::Cube);
newTerrain->SetActiveShader(ShaderType::SUNLIGHT);
m_terrainChunk.push_back(newTerrain);
}
}
Logger::Get().Log("Terrain g<>n<EFBFBD>r<EFBFBD> avec " + std::to_string(m_terrainChunk.size()) + " tuiles", __FILE__, __LINE__, Logger::LogLevel::Info);
} }
void ApplicationClass::AddKobject(std::wstring& filepath) void ApplicationClass::AddKobject(std::wstring& filepath)
@@ -1427,8 +1268,7 @@ void ApplicationClass::AddKobject(std::wstring& filepath)
char modelFilename[128]; char modelFilename[128];
vector<string> Filename; vector<string> Filename;
HRESULT result; TextureContainer KobjectsTextures;
filesystem::path p(filepath); filesystem::path p(filepath);
string filename = p.stem().string(); string filename = p.stem().string();
@@ -1441,23 +1281,12 @@ void ApplicationClass::AddKobject(std::wstring& filepath)
std::vector<std::wstring> kobjTexture = { std::vector<std::wstring> kobjTexture = {
L"assets/Texture/Bricks2K.png", L"assets/Texture/Bricks2K.png",
L"assets/Texture/BricksNRM2K.png", L"assets/Texture/BricksNRM2K.png",
L"assets/Texture/EmptyTexture.png" L"assets/Texture/BricksGLOSS2K.png"
}; };
textures.clear();
for (const auto& textureFilename : kobjTexture)
{
ID3D11ShaderResourceView* texture = nullptr;
result = DirectX::CreateWICTextureFromFile(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), textureFilename.c_str(), nullptr, &texture);
if (FAILED(result))
{
// Handle error
}
textures.push_back(texture);
}
Object* newObject = new Object(); Object* newObject = new Object();
newObject->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textures); newObject->LoadTexturesFromPath(kobjTexture,KobjectsTextures, m_Direct3D); // Load textures from the path
newObject->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, KobjectsTextures);
newObject->SetMass(1.0f); newObject->SetMass(1.0f);
newObject->SetTranslateMatrix(XMMatrixTranslation(0.0f, 50.0f, 0.0f)); newObject->SetTranslateMatrix(XMMatrixTranslation(0.0f, 50.0f, 0.0f));
newObject->SetName(filename); newObject->SetName(filename);
@@ -1469,7 +1298,7 @@ void ApplicationClass::AddKobject(std::wstring& filepath)
m_object.push_back(newObject); m_object.push_back(newObject);
// V<>rifiez que l'objet a bien re<72>u les textures // V<>rifiez que l'objet a bien re<72>u les textures
if (newObject->GetTexture(0) == nullptr) if (newObject->GetTexture(TextureType::Diffuse,0) == nullptr)
{ {
Logger::Get().Log("Object texture is null after initialization", __FILE__, __LINE__, Logger::LogLevel::Error); Logger::Get().Log("Object texture is null after initialization", __FILE__, __LINE__, Logger::LogLevel::Error);
} }
@@ -1477,12 +1306,10 @@ void ApplicationClass::AddKobject(std::wstring& filepath)
void ApplicationClass::AddCube() void ApplicationClass::AddCube()
{ {
Logger::Get().Log("Adding cube", __FILE__, __LINE__); Logger::Get().Log("Adding cube", __FILE__, __LINE__);
char modelFilename[128]; char modelFilename[128];
HRESULT result; TextureContainer CubeTexture;
// Set the file name of the model. // Set the file name of the model.
strcpy_s(modelFilename, "assets/Model/TXT/cube.txt"); strcpy_s(modelFilename, "assets/Model/TXT/cube.txt");
@@ -1491,25 +1318,11 @@ void ApplicationClass::AddCube()
L"assets/Texture/Bricks2K.png" L"assets/Texture/Bricks2K.png"
}; };
textures.clear();
for (const auto& textureFilename : cubeTexture)
{
ID3D11ShaderResourceView* texture = nullptr;
result = DirectX::CreateWICTextureFromFile(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), textureFilename.c_str(), nullptr, &texture);
if (FAILED(result))
{
Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return;
}
textures.push_back(texture);
}
static int cubeCount = 0; static int cubeCount = 0;
float position = cubeCount * 2.0f; float position = cubeCount * 2.0f;
Object* newCube = new Object(); Object* newCube = new Object();
newCube->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textures); newCube->LoadTexturesFromPath(cubeTexture, CubeTexture, m_Direct3D); // Load textures from the path
newCube->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, CubeTexture);
newCube->SetTranslateMatrix(XMMatrixTranslation(position, 0.0f, 0.0f)); newCube->SetTranslateMatrix(XMMatrixTranslation(position, 0.0f, 0.0f));
m_cubes.push_back(newCube); m_cubes.push_back(newCube);
@@ -1789,7 +1602,8 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
for (const auto& RenderQueue : RenderQueues) for (const auto& RenderQueue : RenderQueues)
{ {
// D<>sactiver le Z-buffer si la RenderQueue est m_Skybox // D<>sactiver le Z-buffer si la RenderQueue est m_Skybox
if (&RenderQueue.get() == &m_Skybox) bool isSkybox = (&RenderQueue.get() == &m_Skybox);
if (isSkybox)
{ {
m_Direct3D->TurnZBufferOff(); m_Direct3D->TurnZBufferOff();
} }
@@ -1846,9 +1660,9 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
worldMatrix, worldMatrix,
view, view,
projection, projection,
object->GetTexture(0), object->GetTexture(TextureType::Diffuse,0),
object->GetTexture(5), object->GetTexture(TextureType::Diffuse,1),
object->GetTexture(3) object->GetTexture(TextureType::Alpha,0)
); );
if (!result) if (!result)
{ {
@@ -1866,7 +1680,7 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
worldMatrix, worldMatrix,
view, view,
projection, projection,
object->GetTexture(0), object->GetTexture(TextureType::Diffuse,0),
m_SunLight->GetDiffuseColor(), m_SunLight->GetDiffuseColor(),
m_SunLight->GetAmbientColor(), m_SunLight->GetAmbientColor(),
m_SunLight->GetDirection(), m_SunLight->GetDirection(),
@@ -1886,8 +1700,8 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
worldMatrix, worldMatrix,
view, view,
projection, projection,
object->GetTexture(0), object->GetTexture(TextureType::Diffuse,0),
object->GetTexture(1), object->GetTexture(TextureType::Normal,0),
m_Lights[0]->GetDirection(), m_Lights[0]->GetDirection(),
m_Lights[0]->GetDiffuseColor() m_Lights[0]->GetDiffuseColor()
); );
@@ -1905,9 +1719,9 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
worldMatrix, worldMatrix,
view, view,
projection, projection,
object->GetTexture(0), object->GetTexture(TextureType::Diffuse,0),
object->GetTexture(1), object->GetTexture(TextureType::Normal,0),
object->GetTexture(2), object->GetTexture(TextureType::Specular,0),
m_Lights[0]->GetDirection(), m_Lights[0]->GetDirection(),
m_Lights[0]->GetDiffuseColor(), m_Lights[0]->GetDiffuseColor(),
m_Camera->GetPosition(), m_Camera->GetPosition(),
@@ -1920,6 +1734,7 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
return false; return false;
} }
break; break;
case ShaderType::TEXTURE: case ShaderType::TEXTURE:
result = m_ShaderManager->RenderTextureShader( result = m_ShaderManager->RenderTextureShader(
m_Direct3D->GetDeviceContext(), m_Direct3D->GetDeviceContext(),
@@ -1927,7 +1742,7 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
worldMatrix, worldMatrix,
view, view,
projection, projection,
object->GetTexture(0) object->GetTexture(TextureType::Diffuse,0)
); );
if (!result) if (!result)
{ {
@@ -1943,7 +1758,7 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
worldMatrix, worldMatrix,
view, view,
projection, projection,
object->GetTexture(0), object->GetTexture(TextureType::Diffuse,0),
diffuse, diffuse,
position, position,
ambient ambient
@@ -1962,26 +1777,12 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
worldMatrix, worldMatrix,
view, view,
projection, projection,
object->GetTexture(0), object->GetTexture(TextureType::Diffuse,0),
m_SunLight->GetDiffuseColor(), m_SunLight->GetDiffuseColor(),
m_SunLight->GetAmbientColor(), m_SunLight->GetAmbientColor(),
m_SunLight->GetDirection(), m_SunLight->GetDirection(),
m_SunLight->GetIntensity() m_SunLight->GetIntensity()
); );
// m_Direct3D->GetDeviceContext(),
// object->GetIndexCount(),
// worldMatrix,
// view,
// projection,
// object->GetTexture(0), // Front
// object->GetTexture(1), // Back
// object->GetTexture(2), // Left
// object->GetTexture(3), // Right
// object->GetTexture(4), // Top
// object->GetTexture(5), // Bottom
// m_SunLight->GetDiffuseColor() // Sunlight color to tint the skybox
// );
if (!result) if (!result)
{ {
Logger::Get().Log("Could not render the object model using the skybox shader", __FILE__, __LINE__, Logger::LogLevel::Error); Logger::Get().Log("Could not render the object model using the skybox shader", __FILE__, __LINE__, Logger::LogLevel::Error);
@@ -1996,7 +1797,7 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
worldMatrix, worldMatrix,
view, view,
projection, projection,
object->GetTexture(0), object->GetTexture(TextureType::Diffuse,0),
m_SunLight->GetDiffuseColor(), m_SunLight->GetDiffuseColor(),
m_SunLight->GetAmbientColor(), m_SunLight->GetAmbientColor(),
m_SunLight->GetDirection(), m_SunLight->GetDirection(),
@@ -2015,7 +1816,7 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
worldMatrix, worldMatrix,
view, view,
projection, projection,
object->GetTexture(0), object->GetTexture(TextureType::Diffuse,0),
diffuse, diffuse,
position, position,
ambient ambient
@@ -2028,8 +1829,14 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
break; break;
} }
} }
if (isSkybox)
{
m_Direct3D->TurnZBufferOn();
}
} }
SetRenderCount(renderCount); SetRenderCount(renderCount);
return true; return true;
@@ -2193,6 +2000,7 @@ void ApplicationClass::SaveScene() {
XMStoreFloat3(&scale, object->GetScale()); XMStoreFloat3(&scale, object->GetScale());
XMStoreFloat3(&rotation, object->GetRotation()); XMStoreFloat3(&rotation, object->GetRotation());
// <20>crire les donn<6E>es de base de l'objet
outFile << object->GetId() << " " outFile << object->GetId() << " "
<< object->GetName() << " " << object->GetName() << " "
<< position.x << " " << position.y << " " << position.z << " " << position.x << " " << position.y << " " << position.z << " "
@@ -2203,14 +2011,51 @@ void ApplicationClass::SaveScene() {
<< object->GetBoundingRadius() << " " << object->GetBoundingRadius() << " "
<< object->ObjectTypeToString(object->GetType()) << " " << object->ObjectTypeToString(object->GetType()) << " "
<< object->GetMass() << " " << object->GetMass() << " "
<< object->IsPhysicsEnabled() << std::endl; << object->IsPhysicsEnabled();
// Sauvegarder les chemins des textures
// Format: nombre de textures diffuses, puis les chemins
// M<>me chose pour les autres types de textures
// Textures diffuses
const auto& diffusePaths = object->GetTextureContainer().GetPaths(TextureType::Diffuse);
outFile << " " << diffusePaths.size();
for (const auto& path : diffusePaths) {
outFile << " " << ConvertWStringToString(path);
}
// Textures normales
const auto& normalPaths = object->GetTextureContainer().GetPaths(TextureType::Normal);
outFile << " " << normalPaths.size();
for (const auto& path : normalPaths) {
outFile << " " << ConvertWStringToString(path);
}
// Textures sp<73>culaires
const auto& specularPaths = object->GetTextureContainer().GetPaths(TextureType::Specular);
outFile << " " << specularPaths.size();
for (const auto& path : specularPaths) {
outFile << " " << ConvertWStringToString(path);
}
// Textures alpha
const auto& alphaPaths = object->GetTextureContainer().GetPaths(TextureType::Alpha);
outFile << " " << alphaPaths.size();
for (const auto& path : alphaPaths) {
outFile << " " << ConvertWStringToString(path);
}
outFile << std::endl;
} }
outFile.close(); outFile.close();
Logger::Get().Log("Scene saved successfully", __FILE__, __LINE__, Logger::LogLevel::Info); Logger::Get().Log("Scene saved successfully to " + m_scenePath, __FILE__, __LINE__, Logger::LogLevel::Info);
} }
void ApplicationClass::LoadScene() {
bool ApplicationClass::LoadScene() {
Logger::Get().Log("Loading scene from " , __FILE__, __LINE__, Logger::LogLevel::Info);
std::wstring scenePath = GetScenePath(); std::wstring scenePath = GetScenePath();
if (!scenePath.empty()) if (!scenePath.empty())
@@ -2218,53 +2063,169 @@ void ApplicationClass::LoadScene() {
SetScenePath(ConvertWStringToString(scenePath)); SetScenePath(ConvertWStringToString(scenePath));
} }
if (m_scenePath.empty()) { if (m_scenePath.empty()) {
Logger::Get().Log("Scene path is empty. Cannot load scene.", __FILE__, __LINE__, Logger::LogLevel::Error); Logger::Get().Log("Scene path is empty. Cannot load scene.", __FILE__, __LINE__, Logger::LogLevel::Error);
return; return false;
} }
std::ifstream inFile(m_scenePath); std::ifstream inFile(scenePath);
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: ", __FILE__, __LINE__, Logger::LogLevel::Error);
return; return false;
} }
// Nettoyer les objets existants
for (auto& obj : m_object) {
if (obj) {
obj->Shutdown();
delete obj;
}
}
m_object.clear(); m_object.clear();
m_ObjectId = 0;
int id; // Sauvegarder le r<>pertoire de travail actuel
std::string name; std::wstring currentDirectory = m_WFolder;
float posX, posY, posZ;
float rotX, rotY, rotZ;
float scaleX, scaleY, scaleZ;
std::string modelPath;
std::string shaderTypeStr;
float boundingRadius;
std::string objectTypeStr;
float mass;
bool physicsEnabled;
while (inFile >> id >> name >> posX >> posY >> posZ >> rotX >> rotY >> rotZ >> scaleX >> scaleY >> scaleZ >> modelPath >> shaderTypeStr >> boundingRadius >> objectTypeStr >> mass >> physicsEnabled) { std::string line;
int size_needed = MultiByteToWideChar(CP_UTF8, 0, modelPath.c_str(), (int)modelPath.size(), NULL, 0); while (std::getline(inFile, line)) {
std::wstring wModelPath(size_needed, 0); std::istringstream iss(line);
MultiByteToWideChar(CP_UTF8, 0, modelPath.c_str(), (int)modelPath.size(), &wModelPath[0], size_needed); int id;
std::string name;
XMFLOAT3 position, rotation, scale;
std::string modelPath;
std::string shaderTypeStr;
float boundingRadius;
std::string objectTypeStr;
float mass;
bool physicsEnabled;
AddKobject(wModelPath); // Lire les donn<6E>es de base de l'objet
iss >> id >> name
>> position.x >> position.y >> position.z
>> rotation.x >> rotation.y >> rotation.z
>> scale.x >> scale.y >> scale.z
>> modelPath >> shaderTypeStr
>> boundingRadius >> objectTypeStr
>> mass >> physicsEnabled;
Object* newObject = m_object.back(); if (iss.fail()) {
Logger::Get().Log("Failed to parse object data", __FILE__, __LINE__, Logger::LogLevel::Error);
continue;
}
// Cr<43>er un nouvel objet
Object* newObject = new Object();
// Convertir le chemin du mod<6F>le en wstring
std::wstring wModelPath(modelPath.begin(), modelPath.end());
// V<>rifier si le chemin est relatif (ne commence pas par un disque comme C:)
if (modelPath.length() > 1 && modelPath[1] != ':') {
// C'est un chemin relatif, pr<70>fixer avec le r<>pertoire de travail
if (currentDirectory.back() != L'/' && currentDirectory.back() != L'\\') {
// Ajouter un s<>parateur si n<>cessaire
wModelPath = currentDirectory + L"\\" + wModelPath;
} else {
wModelPath = currentDirectory + wModelPath;
}
}
// Cr<43>er le conteneur de textures pour stocker les chemins
TextureContainer objectTextures;
// IMPORTANT: Vider les conteneurs de chemins de textures
objectTextures.diffusePaths.clear();
objectTextures.normalPaths.clear();
objectTextures.specularPaths.clear();
objectTextures.alphaPaths.clear();
// Lire les chemins des textures diffuses
int diffuseTextureCount;
iss >> diffuseTextureCount;
for (int i = 0; i < diffuseTextureCount; i++) {
std::string texturePath;
iss >> texturePath;
std::wstring wTexturePath(texturePath.begin(), texturePath.end());
objectTextures.diffusePaths.push_back(wTexturePath);
}
// Lire les chemins des textures normales
int normalTextureCount;
iss >> normalTextureCount;
for (int i = 0; i < normalTextureCount; i++) {
std::string texturePath;
iss >> texturePath;
std::wstring wTexturePath(texturePath.begin(), texturePath.end());
objectTextures.normalPaths.push_back(wTexturePath);
}
// Lire les chemins des textures sp<73>culaires
int specularTextureCount;
iss >> specularTextureCount;
for (int i = 0; i < specularTextureCount; i++) {
std::string texturePath;
iss >> texturePath;
std::wstring wTexturePath(texturePath.begin(), texturePath.end());
objectTextures.specularPaths.push_back(wTexturePath);
}
// Lire les chemins des textures alpha
int alphaTextureCount;
iss >> alphaTextureCount;
for (int i = 0; i < alphaTextureCount; i++) {
std::string texturePath;
iss >> texturePath;
std::wstring wTexturePath(texturePath.begin(), texturePath.end());
objectTextures.alphaPaths.push_back(wTexturePath);
}
// preload texture
if (!newObject->PreloadTextures(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), objectTextures))
{
// 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(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, objectTextures)) {
Logger::Get().Log("Failed to initialize object: " + name, __FILE__, __LINE__, Logger::LogLevel::Error);
delete newObject;
continue;
}
// D<>finir les propri<72>t<EFBFBD>s de l'objet
newObject->SetId(id); newObject->SetId(id);
newObject->SetName(name); newObject->SetName(name);
newObject->SetPosition(XMVectorSet(posX, posY, posZ, 0.0f)); newObject->SetPosition(XMLoadFloat3(&position));
newObject->SetRotation(XMVectorSet(rotX, rotY, rotZ, 0.0f)); newObject->SetRotation(XMLoadFloat3(&rotation));
newObject->SetScale(XMVectorSet(scaleX, scaleY, scaleZ, 0.0f)); newObject->SetScale(XMLoadFloat3(&scale));
newObject->SetModelPath(wModelPath);
newObject->SetActiveShader(newObject->StringToShaderType(shaderTypeStr)); newObject->SetActiveShader(newObject->StringToShaderType(shaderTypeStr));
newObject->SetBoundingRadius(boundingRadius); newObject->SetBoundingRadius(boundingRadius);
newObject->SetType(newObject->StringToObjectType(objectTypeStr)); newObject->SetType(newObject->StringToObjectType(objectTypeStr));
newObject->SetMass(mass); newObject->SetMass(mass);
newObject->SetPhysicsEnabled(physicsEnabled); newObject->SetPhysicsEnabled(physicsEnabled);
// Mettre <20> jour l'ID global si n<>cessaire
if (id >= m_ObjectId) {
m_ObjectId = id + 1;
}
m_object.push_back(newObject);
Logger::Get().Log("Loaded object: " + name, __FILE__, __LINE__, Logger::LogLevel::Info);
} }
inFile.close(); Logger::Get().Log("Scene loaded successfully from ", __FILE__, __LINE__, Logger::LogLevel::Info);
Logger::Get().Log("Scene loaded successfully", __FILE__, __LINE__, Logger::LogLevel::Info); return true;
} }
std::wstring ApplicationClass::GetScenePath() std::wstring ApplicationClass::GetScenePath()

View File

@@ -92,7 +92,6 @@ void imguiManager::SetupDockspace(ApplicationClass* app) {
ImGui::MenuItem("Object Window", NULL, &showObjectWindow); ImGui::MenuItem("Object Window", NULL, &showObjectWindow);
ImGui::MenuItem("Terrain Window", NULL, &showTerrainWindow); ImGui::MenuItem("Terrain Window", NULL, &showTerrainWindow);
ImGui::MenuItem("Light Window", NULL, &showLightWindow); ImGui::MenuItem("Light Window", NULL, &showLightWindow);
ImGui::MenuItem("Old Scene Window", NULL, &showOldSceneWindow);
ImGui::MenuItem("Engine Settings Window", NULL, &showEngineSettingsWindow); ImGui::MenuItem("Engine Settings Window", NULL, &showEngineSettingsWindow);
ImGui::MenuItem("Log Window", NULL, &showLogWindow); ImGui::MenuItem("Log Window", NULL, &showLogWindow);
ImGui::EndMenu(); ImGui::EndMenu();
@@ -272,69 +271,116 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app)
object->SetScale(XMVectorSet(scl[0], scl[1], scl[2], 0.0f)); object->SetScale(XMVectorSet(scl[0], scl[1], scl[2], 0.0f));
} }
ImGui::Separator(); ImGui::Separator();
// Texture // D<>finir les types de textures
// add all texture category names to a vector std::vector<std::string> textureCategories = {
std::vector<std::string> textureCategories = { "Diffuse", "Normal", "Specular", "Alpha"
"Diffuse", };
"Normal",
"Specular",
"Reflection",
"Refraction"
};
// Display all images std::vector<TextureType> textureTypes = {
ImGui::BeginChild("TextureChild", ImVec2(0, 100), false, ImGuiWindowFlags_HorizontalScrollbar); TextureType::Diffuse, TextureType::Normal,
for (int count = 0; count < textureCategories.size(); count++) TextureType::Specular, TextureType::Alpha
{ };
std::string textureLabel = "Texture##" + std::to_string(index) + "##" + std::to_string(count);
ID3D11ShaderResourceView* texture = object->GetTexture(count);
if (texture != nullptr)
{
ImGui::Text(textureCategories[count].c_str());
ImGui::SameLine();
std::string buttonLabel = "button " + std::to_string(count); // Cr<43>er un espace pour afficher les textures avec d<>filement
if (ImGui::ImageButton(buttonLabel.c_str(), (ImTextureID)texture, ImVec2(64, 64))) ImGui::BeginChild("TextureChild", ImVec2(0, 200), true, ImGuiWindowFlags_HorizontalScrollbar);
{
// Open file dialog
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\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn)) // Pour chaque type de texture
{ for (int typeIndex = 0; typeIndex < textureCategories.size(); typeIndex++)
// Load the selected texture {
object->ChangeTexture(m_device, m_deviceContext, ofn.lpstrFile, count); TextureType type = textureTypes[typeIndex];
} std::string typeName = textureCategories[typeIndex];
}
if (ImGui::IsItemHovered()) // Afficher le titre de la cat<61>gorie
{ ImGui::Text("%s:", typeName.c_str());
ImGui::BeginTooltip(); ImGui::SameLine();
ImGui::Image((ImTextureID)texture, ImVec2(256, 256));
ImGui::EndTooltip();
}
if (count < textureCategories.size() - 1) // Compter combien de textures de ce type existent
{ int textureCount = 0;
ImGui::SameLine(); while (object->GetTexture(type, textureCount) != nullptr)
} {
} textureCount++;
} }
ImGui::EndChild();
// Afficher toutes les textures existantes
ImGui::BeginGroup();
for (int texIndex = 0; texIndex < textureCount; texIndex++)
{
ID3D11ShaderResourceView* texture = object->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->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->AddTexture(m_device, m_deviceContext, ofn.lpstrFile, type);
}
}
ImGui::EndGroup();
ImGui::Separator();
}
ImGui::EndChild();
ImGui::Separator(); ImGui::Separator();

View File

@@ -18,8 +18,37 @@ ModelClass::~ModelClass()
{ {
} }
bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* modelFilename, std::vector<ID3D11ShaderResourceView*> textures) { // bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* modelFilename, std::vector<ID3D11ShaderResourceView*> textures) {
Logger::Get().Log("Initializing model class with preloaded textures", __FILE__, __LINE__, Logger::LogLevel::Initialize); // Logger::Get().Log("Initializing model class with preloaded textures (vector)", __FILE__, __LINE__, Logger::LogLevel::Initialize);
//
// bool result = Initialize(device, deviceContext, modelFilename);
// if (!result) {
// return false;
// }
//
// // Ajouter toutes les textures au container comme textures diffuses
// for (auto& tex : textures) {
// m_Textures.diffuse.push_back(tex);
// }
//
// return true;
// }
bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* modelFilename, const TextureContainer& textures) {
Logger::Get().Log("Initializing model class with preloaded texture container", __FILE__, __LINE__, Logger::LogLevel::Initialize);
bool result = Initialize(device, deviceContext, modelFilename);
if (!result) {
return false;
}
m_Textures = textures; // Copie de la structure de textures
return true;
}
bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* modelFilename) {
Logger::Get().Log("Initializing model class without textures", __FILE__, __LINE__, Logger::LogLevel::Initialize);
bool result; bool result;
@@ -40,14 +69,11 @@ bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCon
return false; return false;
} }
m_Textures = textures; Logger::Get().Log("Model class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
Logger::Get().Log("Model class initialized with preloaded textures", __FILE__, __LINE__, Logger::LogLevel::Initialize);
return true; return true;
} }
void ModelClass::Shutdown() void ModelClass::Shutdown()
{ {
// Release the model textures. // Release the model textures.
@@ -77,11 +103,13 @@ int ModelClass::GetIndexCount()
return m_indexCount; return m_indexCount;
} }
ID3D11ShaderResourceView* ModelClass::GetTexture(int index) const { // ID3D11ShaderResourceView* ModelClass::GetTexture(int index) const {
if (index >= 0 && index < m_Textures.size()) { // // Pour compatibilit<69>, utilise la texture diffuse par d<>faut
return m_Textures[index]; // return m_Textures.GetTexture(TextureType::Diffuse, index);
} // }
return nullptr; // Retourne nullptr si l'index est hors limites
ID3D11ShaderResourceView* ModelClass::GetTexture(TextureType type, int index) const {
return m_Textures.GetTexture(type, index);
} }
bool ModelClass::InitializeBuffers(ID3D11Device* device) bool ModelClass::InitializeBuffers(ID3D11Device* device)
@@ -217,17 +245,8 @@ void ModelClass::ReleaseTextures()
{ {
Logger::Get().Log("Releasing textures", __FILE__, __LINE__); Logger::Get().Log("Releasing textures", __FILE__, __LINE__);
// Release the texture object array. // Utilise la m<>thode ReleaseAll de TextureContainer
for (auto& texture : m_Textures) m_Textures.ReleaseAll();
{
if (texture)
{
texture->Release();
texture = nullptr;
}
}
m_Textures.clear();
Logger::Get().Log("Textures released", __FILE__, __LINE__); Logger::Get().Log("Textures released", __FILE__, __LINE__);
} }
@@ -551,41 +570,193 @@ void ModelClass::ReleaseModel()
return; return;
} }
bool ModelClass::ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, std::wstring filename, int index) // bool ModelClass::ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, std::wstring filename, int index) {
// // Pour compatibilit<69>, utilise la texture diffuse par d<>faut
// return ChangeTexture(device, deviceContext, filename, TextureType::Diffuse, index);
// }
bool ModelClass::PreloadTextures(ID3D11Device* device, ID3D11DeviceContext* deviceContext, TextureContainer& textureContainer)
{ {
HRESULT hResult;
// Charger les textures diffuses
for (const auto& texturePath : textureContainer.diffusePaths)
{
ID3D11ShaderResourceView* texture = nullptr;
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
if (FAILED(hResult))
{
Logger::Get().Log("<EFBFBD>chec du chargement de la texture diffuse: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
textureContainer.diffuse.push_back(texture);
}
// Charger les textures normales
for (const auto& texturePath : textureContainer.normalPaths)
{
ID3D11ShaderResourceView* texture = nullptr;
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
if (FAILED(hResult))
{
Logger::Get().Log("<EFBFBD>chec du chargement de la texture normale: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
textureContainer.normal.push_back(texture);
}
// Charger les textures sp<73>culaires
for (const auto& texturePath : textureContainer.specularPaths)
{
ID3D11ShaderResourceView* texture = nullptr;
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
if (FAILED(hResult))
{
Logger::Get().Log("<EFBFBD>chec du chargement de la texture sp<73>culaire: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
textureContainer.specular.push_back(texture);
}
// Charger les textures alpha
for (const auto& texturePath : textureContainer.alphaPaths)
{
ID3D11ShaderResourceView* texture = nullptr;
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
if (FAILED(hResult))
{
Logger::Get().Log("<EFBFBD>chec du chargement de la texture alpha: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
textureContainer.alpha.push_back(texture);
}
return true;
}
bool ModelClass::ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, std::wstring filename, TextureType type, int index) {
Logger::Get().Log("Changing texture", __FILE__, __LINE__, Logger::LogLevel::Initialize); Logger::Get().Log("Changing texture", __FILE__, __LINE__, Logger::LogLevel::Initialize);
HRESULT result; HRESULT result;
ID3D11ShaderResourceView* newTexture = nullptr; ID3D11ShaderResourceView* newTexture = nullptr;
// Load the new texture using WICTextureLoader. // Charger la nouvelle texture
result = DirectX::CreateWICTextureFromFile(device, deviceContext, filename.c_str(), nullptr, &newTexture); result = DirectX::CreateWICTextureFromFile(device, deviceContext, filename.c_str(), nullptr, &newTexture);
if (FAILED(result)) if (FAILED(result)) {
{ Logger::Get().Log("Failed to load texture: " + std::string(filename.begin(), filename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
Logger::Get().Log("Failed to load new texture", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
// Release the old texture if it exists. // R<EFBFBD>cup<EFBFBD>rer le vecteur correspondant au type de texture
if (index >= 0 && index < m_Textures.size() && m_Textures[index]) auto& textureVector = m_Textures.Get(type);
{
m_Textures[index]->Release(); // Si l'index est hors limites, redimensionner le vecteur
m_Textures[index] = nullptr; if (index >= textureVector.size()) {
textureVector.resize(index + 1, nullptr);
} }
// Assign the new texture to the specified index. // Lib<EFBFBD>rer l'ancienne texture si elle existe
if (index >= 0 && index < m_Textures.size()) if (textureVector[index]) {
{ textureVector[index]->Release();
m_Textures[index] = newTexture;
} }
else
{ // Assigner la nouvelle texture
// If the index is out of range, log an error and release the new texture. textureVector[index] = newTexture;
Logger::Get().Log("Texture index out of range", __FILE__, __LINE__, Logger::LogLevel::Error);
newTexture->Release(); // Mettre <20> jour le chemin dans le conteneur appropri<72> selon le type
return false; switch (type) {
case TextureType::Diffuse:
if (index >= m_Textures.diffusePaths.size()) {
m_Textures.diffusePaths.resize(index + 1, L"");
}
m_Textures.diffusePaths[index] = filename;
break;
case TextureType::Normal:
if (index >= m_Textures.normalPaths.size()) {
m_Textures.normalPaths.resize(index + 1, L"");
}
m_Textures.normalPaths[index] = filename;
break;
case TextureType::Specular:
if (index >= m_Textures.specularPaths.size()) {
m_Textures.specularPaths.resize(index + 1, L"");
}
m_Textures.specularPaths[index] = filename;
break;
case TextureType::Alpha:
if (index >= m_Textures.alphaPaths.size()) {
m_Textures.alphaPaths.resize(index + 1, L"");
}
m_Textures.alphaPaths[index] = filename;
break;
} }
Logger::Get().Log("Texture changed successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize); Logger::Get().Log("Texture changed successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize);
return true; return true;
} }
bool ModelClass::AddTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, std::wstring filename, TextureType type) {
Logger::Get().Log("Adding texture", __FILE__, __LINE__, Logger::LogLevel::Initialize);
HRESULT result;
ID3D11ShaderResourceView* newTexture = nullptr;
// Charger la nouvelle texture
result = DirectX::CreateWICTextureFromFile(device, deviceContext, filename.c_str(), nullptr, &newTexture);
if (FAILED(result)) {
Logger::Get().Log("Failed to load texture: " + std::string(filename.begin(), filename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Ajouter la texture au vecteur appropri<72> selon le type
auto& textureVector = m_Textures.Get(type);
textureVector.push_back(newTexture);
// Ajouter le chemin de la texture au vecteur appropri<72> selon le type
switch (type) {
case TextureType::Diffuse:
m_Textures.diffusePaths.push_back(filename);
break;
case TextureType::Normal:
m_Textures.normalPaths.push_back(filename);
break;
case TextureType::Specular:
m_Textures.specularPaths.push_back(filename);
break;
case TextureType::Alpha:
m_Textures.alphaPaths.push_back(filename);
break;
}
Logger::Get().Log("Texture added successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize);
return true;
}
bool ModelClass::AddTexture(ID3D11ShaderResourceView* texture, TextureType type) {
if (!texture) {
Logger::Get().Log("Cannot add null texture", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Ajouter la texture au vecteur appropri<72>
auto& textureVector = m_Textures.Get(type);
textureVector.push_back(texture);
// Ajouter un chemin vide ou g<>n<EFBFBD>rique pour maintenir la synchronisation
switch (type) {
case TextureType::Diffuse:
m_Textures.diffusePaths.push_back(L"[texture pr<70>charg<72>e]");
break;
case TextureType::Normal:
m_Textures.normalPaths.push_back(L"[texture pr<70>charg<72>e]");
break;
case TextureType::Specular:
m_Textures.specularPaths.push_back(L"[texture pr<70>charg<72>e]");
break;
case TextureType::Alpha:
m_Textures.alphaPaths.push_back(L"[texture pr<70>charg<72>e]");
break;
}
return true;
}

View File

@@ -1,5 +1,9 @@
#include "object.h" #include "object.h"
#include <comdef.h>
#include "d3dclass.h"
Object::Object()// Initialize the reference here Object::Object()// Initialize the reference here
{ {
m_scaleMatrix = XMMatrixIdentity(); m_scaleMatrix = XMMatrixIdentity();
@@ -349,3 +353,40 @@ void Object::LaunchObject()
sprintf_s(buffer, "Launch velocity: %f m/s at angle %f degrees", XMVectorGetX(XMVector3Length(velocity)), m_alpha); sprintf_s(buffer, "Launch velocity: %f m/s at angle %f degrees", XMVectorGetX(XMVector3Length(velocity)), m_alpha);
OutputDebugStringA(buffer); OutputDebugStringA(buffer);
} }
bool Object::LoadTexturesFromPath(std::vector<std::wstring>& texturePaths, TextureContainer& texturesContainer,
D3DClass* m_Direct3D)
{
HRESULT result;
int i = 0;
TextureType type;
for (const auto& texturePath : texturePaths)
{
ID3D11ShaderResourceView* texture = nullptr;
result = DirectX::CreateWICTextureFromFile(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), texturePath.c_str(), nullptr, &texture);
if (FAILED(result))
{
// Utiliser _com_error pour obtenir des informations d<>taill<6C>es sur l'erreur
_com_error err(result);
LPCTSTR errMsg = err.ErrorMessage();
//convertie errMessage en std::wstring
std::wstring ws(errMsg);
std::string str(ws.begin(), ws.end());
Logger::Get().Log("Failed to load texture: " + std::string(texturePath.begin(), texturePath.end()) +
"\nError: " + std::to_string(result) +
"\nDescription: " + str,
__FILE__, __LINE__, Logger::LogLevel::Error);
return false; // Assurez-vous de retourner false ou de g<>rer l'erreur de mani<6E>re appropri<72>e
}
texturesContainer.AssignTexture(texturesContainer, texture,texturePath , i);
i++;
}
return true;
}