Compare commits
7 Commits
V10.0.0
...
2b1e64ffbd
Author | SHA1 | Date | |
---|---|---|---|
2b1e64ffbd | |||
96aa41f649 | |||
00e6749d01 | |||
5a3a4f73a8 | |||
c442a87883 | |||
e681943aa8 | |||
e68f1d5dd0 |
42
.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
generated
42
.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
generated
@@ -4,17 +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/projectSettingsUpdater.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.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/Texture/imgui.ini" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/assets/Texture/imgui.ini" 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/modelclass.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/modelclass.h" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/Skybox.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/Skybox.cpp" 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/imguiManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/imguiManager.cpp" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/modelclass.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/modelclass.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" />
|
||||||
@@ -41,7 +31,29 @@
|
|||||||
<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://0" root0="FORCE_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://6" 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" />
|
||||||
@@ -190,6 +202,12 @@
|
|||||||
<workItem from="1746188920194" duration="1870000" />
|
<workItem from="1746188920194" duration="1870000" />
|
||||||
<workItem from="1746274246641" duration="89000" />
|
<workItem from="1746274246641" duration="89000" />
|
||||||
<workItem from="1746274352144" duration="8039000" />
|
<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" />
|
||||||
</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" />
|
||||||
|
10
README.md
10
README.md
@@ -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 :
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@ Collapsed=0
|
|||||||
DockId=0x00000009,0
|
DockId=0x00000009,0
|
||||||
|
|
||||||
[Window][Terrain]
|
[Window][Terrain]
|
||||||
Pos=299,27
|
Pos=8,27
|
||||||
Size=250,826
|
Size=250,826
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000007,0
|
DockId=0x00000007,0
|
||||||
|
@@ -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
|
||||||
|
@@ -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
|
||||||
|
|
||||||
|
@@ -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();
|
||||||
|
@@ -32,11 +32,21 @@ enum class TextureType
|
|||||||
|
|
||||||
struct TextureContainer
|
struct TextureContainer
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Textures
|
||||||
std::vector<ID3D11ShaderResourceView*> diffuse;
|
std::vector<ID3D11ShaderResourceView*> diffuse;
|
||||||
std::vector<ID3D11ShaderResourceView*> normal;
|
std::vector<ID3D11ShaderResourceView*> normal;
|
||||||
std::vector<ID3D11ShaderResourceView*> specular;
|
std::vector<ID3D11ShaderResourceView*> specular;
|
||||||
std::vector<ID3D11ShaderResourceView*> alpha;
|
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 {
|
std::vector<ID3D11ShaderResourceView*>& Get(TextureType type) const {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TextureType::Diffuse: return const_cast<std::vector<ID3D11ShaderResourceView*>&>(diffuse);
|
case TextureType::Diffuse: return const_cast<std::vector<ID3D11ShaderResourceView*>&>(diffuse);
|
||||||
@@ -47,6 +57,20 @@ struct TextureContainer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 {
|
ID3D11ShaderResourceView* GetTexture(TextureType type, int index) const {
|
||||||
auto& vec = Get(type);
|
auto& vec = Get(type);
|
||||||
if (index >= 0 && index < vec.size())
|
if (index >= 0 && index < vec.size())
|
||||||
@@ -54,31 +78,53 @@ struct TextureContainer
|
|||||||
return nullptr;
|
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() {
|
void ReleaseAll() {
|
||||||
ReleaseVector(diffuse);
|
ReleaseVector(diffuse);
|
||||||
ReleaseVector(normal);
|
ReleaseVector(normal);
|
||||||
ReleaseVector(specular);
|
ReleaseVector(specular);
|
||||||
ReleaseVector(alpha);
|
ReleaseVector(alpha);
|
||||||
|
|
||||||
|
ReleaseVector(diffusePaths);
|
||||||
|
ReleaseVector(normalPaths);
|
||||||
|
ReleaseVector(specularPaths);
|
||||||
|
ReleaseVector(alphaPaths);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssignTexture(TextureContainer& textContainer, ID3D11ShaderResourceView* texture, int index)
|
// 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)
|
switch (index)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
textContainer.diffuse.push_back(texture);
|
textContainer.diffuse.push_back(texture);
|
||||||
|
textContainer.diffusePaths.push_back(paths);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
textContainer.normal.push_back(texture);
|
textContainer.normal.push_back(texture);
|
||||||
|
textContainer.normalPaths.push_back(paths);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
textContainer.specular.push_back(texture);
|
textContainer.specular.push_back(texture);
|
||||||
|
textContainer.specularPaths.push_back(paths);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
textContainer.alpha.push_back(texture);
|
textContainer.alpha.push_back(texture);
|
||||||
|
textContainer.alphaPaths.push_back(paths);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
textContainer.diffuse.push_back(texture);
|
textContainer.diffuse.push_back(texture);
|
||||||
|
textContainer.diffusePaths.push_back(paths);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,6 +139,10 @@ private:
|
|||||||
}
|
}
|
||||||
vec.clear();
|
vec.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReleaseVector(std::vector<std::wstring>& vec) {
|
||||||
|
vec.clear();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Class name: ModelClass
|
// Class name: ModelClass
|
||||||
@@ -172,6 +222,11 @@ public:
|
|||||||
// M<>thodes pour ajouter une nouvelle texture
|
// M<>thodes pour ajouter une nouvelle texture
|
||||||
bool AddTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext,std::wstring filename, TextureType type);
|
bool AddTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext,std::wstring filename, TextureType type);
|
||||||
bool AddTexture(ID3D11ShaderResourceView* texture, 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*);
|
||||||
|
@@ -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,7 @@ public:
|
|||||||
std::string ObjectTypeToString(ObjectType objectType);
|
std::string ObjectTypeToString(ObjectType objectType);
|
||||||
|
|
||||||
void LaunchObject();
|
void LaunchObject();
|
||||||
|
void 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 +130,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;
|
||||||
|
@@ -48,7 +48,6 @@ Object* Skybox::ConstructSkybox()
|
|||||||
}
|
}
|
||||||
SkyboxTextures.diffuse.push_back(texture);
|
SkyboxTextures.diffuse.push_back(texture);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the model object
|
// Create the model object
|
||||||
|
@@ -1192,11 +1192,10 @@ int ApplicationClass::GetScreenHeight() const
|
|||||||
|
|
||||||
void ApplicationClass::GenerateTerrain()
|
void ApplicationClass::GenerateTerrain()
|
||||||
{
|
{
|
||||||
|
|
||||||
Logger::Get().Log("Generating terrain", __FILE__, __LINE__);
|
Logger::Get().Log("Generating terrain", __FILE__, __LINE__);
|
||||||
|
|
||||||
char modelFilename[128];
|
char modelFilename[128];
|
||||||
|
TextureContainer TerrainTextures;
|
||||||
XMMATRIX scaleMatrix;
|
XMMATRIX scaleMatrix;
|
||||||
float scaleX, scaleY, scaleZ;
|
float scaleX, scaleY, scaleZ;
|
||||||
|
|
||||||
@@ -1216,47 +1215,16 @@ void ApplicationClass::GenerateTerrain()
|
|||||||
L"assets/Texture/BricksGLOSS2K.png"
|
L"assets/Texture/BricksGLOSS2K.png"
|
||||||
};
|
};
|
||||||
|
|
||||||
TextureContainer TerrainTextures;
|
|
||||||
int i = 0;
|
|
||||||
for (const auto& textureFilename : terrainTexture)
|
|
||||||
{
|
|
||||||
ID3D11ShaderResourceView* texture = nullptr;
|
|
||||||
HRESULT result = DirectX::CreateWICTextureFromFile(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), textureFilename.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(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
|
|
||||||
}
|
|
||||||
TerrainTextures.AssignTexture(TerrainTextures, texture, i);
|
|
||||||
i++;
|
|
||||||
|
|
||||||
|
|
||||||
// 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::filesystem::path p(modelFilename);
|
||||||
std::string filenameWithoutExtension = p.stem().string();
|
std::string filenameWithoutExtension = p.stem().string();
|
||||||
|
|
||||||
|
|
||||||
// for loop to generate terrain chunks for a 10x10 grid
|
// for loop to generate terrain chunks for a 10x10 grid
|
||||||
for (int i = 0; i < 20; i++)
|
for (int i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 20; j++)
|
for (int j = 0; j < 20; j++)
|
||||||
{
|
{
|
||||||
Object* newTerrain = new Object();
|
Object* newTerrain = new Object();
|
||||||
|
newTerrain->LoadTexturesFromPath(terrainTexture, TerrainTextures, m_Direct3D); // Load textures from the path
|
||||||
newTerrain->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, TerrainTextures);
|
newTerrain->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, TerrainTextures);
|
||||||
newTerrain->SetScaleMatrix(scaleMatrix);
|
newTerrain->SetScaleMatrix(scaleMatrix);
|
||||||
newTerrain->SetTranslateMatrix(XMMatrixTranslation(i / 2 * scaleX , -12.0f, j * scaleZ));
|
newTerrain->SetTranslateMatrix(XMMatrixTranslation(i / 2 * scaleX , -12.0f, j * scaleZ));
|
||||||
@@ -1276,8 +1244,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();
|
||||||
|
|
||||||
@@ -1285,8 +1252,6 @@ void ApplicationClass::AddKobject(std::wstring& filepath)
|
|||||||
wcstombs_s(&convertedChars, modelFilename, sizeof(modelFilename), filepath.c_str(), _TRUNCATE);
|
wcstombs_s(&convertedChars, modelFilename, sizeof(modelFilename), filepath.c_str(), _TRUNCATE);
|
||||||
|
|
||||||
filesystem::current_path(m_WFolder);
|
filesystem::current_path(m_WFolder);
|
||||||
|
|
||||||
TextureContainer KobjectsTextures;
|
|
||||||
|
|
||||||
// Liste des fichiers de texture
|
// Liste des fichiers de texture
|
||||||
std::vector<std::wstring> kobjTexture = {
|
std::vector<std::wstring> kobjTexture = {
|
||||||
@@ -1295,21 +1260,8 @@ void ApplicationClass::AddKobject(std::wstring& filepath)
|
|||||||
L"assets/Texture/BricksGLOSS2K.png"
|
L"assets/Texture/BricksGLOSS2K.png"
|
||||||
};
|
};
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
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
|
|
||||||
}
|
|
||||||
KobjectsTextures.AssignTexture(KobjectsTextures, texture, i);
|
|
||||||
i++;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Object* newObject = new Object();
|
Object* newObject = new Object();
|
||||||
|
newObject->LoadTexturesFromPath(kobjTexture,KobjectsTextures, m_Direct3D); // Load textures from the path
|
||||||
newObject->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, KobjectsTextures);
|
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));
|
||||||
@@ -1330,12 +1282,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");
|
||||||
|
|
||||||
@@ -1344,27 +1294,11 @@ void ApplicationClass::AddCube()
|
|||||||
L"assets/Texture/Bricks2K.png"
|
L"assets/Texture/Bricks2K.png"
|
||||||
};
|
};
|
||||||
|
|
||||||
TextureContainer CubeTexture;
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
CubeTexture.AssignTexture(CubeTexture, texture, i);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
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->LoadTexturesFromPath(cubeTexture, CubeTexture, m_Direct3D); // Load textures from the path
|
||||||
newCube->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, CubeTexture);
|
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);
|
||||||
@@ -2041,7 +1975,8 @@ void ApplicationClass::SaveScene() {
|
|||||||
XMStoreFloat3(&position, object->GetPosition());
|
XMStoreFloat3(&position, object->GetPosition());
|
||||||
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 << " "
|
||||||
@@ -2052,14 +1987,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())
|
||||||
@@ -2067,53 +2039,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(scenePath);
|
||||||
|
if (!inFile.is_open()) {
|
||||||
|
Logger::Get().Log("Failed to open file for loading scene: ", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
std::ifstream inFile(m_scenePath);
|
// Nettoyer les objets existants
|
||||||
if (!inFile.is_open()) {
|
for (auto& obj : m_object) {
|
||||||
Logger::Get().Log("Failed to open file for loading scene", __FILE__, __LINE__, Logger::LogLevel::Error);
|
if (obj) {
|
||||||
return;
|
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);
|
||||||
}
|
|
||||||
|
|
||||||
inFile.close();
|
// Mettre <20> jour l'ID global si n<>cessaire
|
||||||
Logger::Get().Log("Scene loaded successfully", __FILE__, __LINE__, Logger::LogLevel::Info);
|
if (id >= m_ObjectId) {
|
||||||
|
m_ObjectId = id + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_object.push_back(newObject);
|
||||||
|
Logger::Get().Log("Loaded object: " + name, __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::Get().Log("Scene loaded successfully from ", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring ApplicationClass::GetScenePath()
|
std::wstring ApplicationClass::GetScenePath()
|
||||||
|
@@ -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();
|
||||||
|
@@ -42,11 +42,7 @@ bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCon
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copie de toutes les textures de la structure
|
m_Textures = textures; // Copie de la structure de textures
|
||||||
for (auto& tex : textures.diffuse) m_Textures.diffuse.push_back(tex);
|
|
||||||
for (auto& tex : textures.normal) m_Textures.normal.push_back(tex);
|
|
||||||
for (auto& tex : textures.specular) m_Textures.specular.push_back(tex);
|
|
||||||
for (auto& tex : textures.alpha) m_Textures.alpha.push_back(tex);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -579,6 +575,65 @@ void ModelClass::ReleaseModel()
|
|||||||
// return ChangeTexture(device, deviceContext, filename, TextureType::Diffuse, index);
|
// 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) {
|
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);
|
||||||
|
|
||||||
@@ -608,6 +663,34 @@ bool ModelClass::ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* device
|
|||||||
// Assigner la nouvelle texture
|
// Assigner la nouvelle texture
|
||||||
textureVector[index] = newTexture;
|
textureVector[index] = newTexture;
|
||||||
|
|
||||||
|
// Mettre <20> jour le chemin dans le conteneur appropri<72> selon le type
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
@@ -625,8 +708,25 @@ bool ModelClass::AddTexture(ID3D11Device* device, ID3D11DeviceContext* deviceCon
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajouter la texture au vecteur correspondant
|
// Ajouter la texture au vecteur appropri<EFBFBD> selon le type
|
||||||
m_Textures.Get(type).push_back(newTexture);
|
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);
|
Logger::Get().Log("Texture added successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||||
return true;
|
return true;
|
||||||
@@ -638,7 +738,25 @@ bool ModelClass::AddTexture(ID3D11ShaderResourceView* texture, TextureType type)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajouter la texture au vecteur correspondant
|
// Ajouter la texture au vecteur appropri<EFBFBD>
|
||||||
m_Textures.Get(type).push_back(texture);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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();
|
||||||
@@ -348,4 +352,38 @@ void Object::LaunchObject()
|
|||||||
char buffer[256];
|
char buffer[256];
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void 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 ; // 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++;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user