diff --git a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
index 1a8481b..cf808b5 100644
--- a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
+++ b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
@@ -5,15 +5,13 @@
-
-
+
-
+
-
-
+
@@ -58,25 +56,25 @@
- {
+ "keyToString": {
+ "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "C++ Project.enginecustom.executor": "Run",
+ "C/C++ Project.enginecustom.executor": "Run",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "RunOnceActivity.git.unshallow": "true",
+ "SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "git-widget-placeholder": "main",
+ "ignore.virus.scanning.warn.message": "true",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "settings.editor.selected.configurable": "preferences.build.unityPlugin",
+ "vue.rearranger.settings.migration": "true"
}
-}]]>
+}
@@ -190,6 +188,7 @@
+
diff --git a/enginecustom/assets/Texture/imgui.ini b/enginecustom/assets/Texture/imgui.ini
index 1ef1a97..cbe9131 100644
--- a/enginecustom/assets/Texture/imgui.ini
+++ b/enginecustom/assets/Texture/imgui.ini
@@ -16,7 +16,7 @@ Collapsed=0
DockId=0x00000009,0
[Window][Terrain]
-Pos=299,27
+Pos=8,27
Size=250,826
Collapsed=0
DockId=0x00000007,0
diff --git a/enginecustom/demo.ker b/enginecustom/demo.ker
index 33afb2a..ddae704 100644
--- a/enginecustom/demo.ker
+++ b/enginecustom/demo.ker
@@ -1 +1,2 @@
-0 86 111.063 12.7056 0 0 -0 0 1 1 1 Content/Assets/Kobject/86.obj CEL_SHADING 1 Cube 1 1
+0 isosphere 0 10 0 0 -0 0 1 1 1 Content/Assets/Kobject/isosphere.obj SPECULAR_MAPPING 1 Unknown 1 0
+ 3 assets/Texture/Bricks2K.png assets/Texture/BricksNRM2K.png assets/Texture/BricksGLOSS2K.png
diff --git a/enginecustom/src/inc/system/modelclass.h b/enginecustom/src/inc/system/modelclass.h
index 457db5e..a90079b 100644
--- a/enginecustom/src/inc/system/modelclass.h
+++ b/enginecustom/src/inc/system/modelclass.h
@@ -61,7 +61,7 @@ struct TextureContainer
ReleaseVector(alpha);
}
- void AssignTexture(TextureContainer& textContainer, ID3D11ShaderResourceView* texture, int index)
+ void AssignTexture(TextureContainer& textContainer, ID3D11ShaderResourceView* texture , int index)
{
switch (index)
{
diff --git a/enginecustom/src/inc/system/object.h b/enginecustom/src/inc/system/object.h
index e12eb06..05e1867 100644
--- a/enginecustom/src/inc/system/object.h
+++ b/enginecustom/src/inc/system/object.h
@@ -3,6 +3,8 @@
#include
#include
+#include "d3dclass.h"
+
enum class ObjectType
{
Sphere,
@@ -96,6 +98,7 @@ public:
std::string ObjectTypeToString(ObjectType objectType);
void LaunchObject();
+ void LoadTexturesFromPath(std::vector& texturePaths, TextureContainer& texturesContainer,D3DClass* m_Direct3D);
void SetAlpha(float alpha) { m_alpha = alpha; }
float GetAlpha() const { return m_alpha; }
void SetInitialStretch(float initialStretch) { m_initialStretch = initialStretch; }
@@ -127,8 +130,6 @@ private:
std::string m_name;
ObjectType m_type = ObjectType::Unknown;
-
-
ShaderType m_activeShader = ShaderType::LIGHTING;
float m_boundingRadius;
diff --git a/enginecustom/src/src/system/applicationclass.cpp b/enginecustom/src/src/system/applicationclass.cpp
index f0959c7..1e60544 100644
--- a/enginecustom/src/src/system/applicationclass.cpp
+++ b/enginecustom/src/src/system/applicationclass.cpp
@@ -1192,11 +1192,10 @@ int ApplicationClass::GetScreenHeight() const
void ApplicationClass::GenerateTerrain()
{
-
Logger::Get().Log("Generating terrain", __FILE__, __LINE__);
char modelFilename[128];
-
+ TextureContainer TerrainTextures;
XMMATRIX scaleMatrix;
float scaleX, scaleY, scaleZ;
@@ -1216,47 +1215,16 @@ void ApplicationClass::GenerateTerrain()
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é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ère approprié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::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->LoadTexturesFromPath(terrainTexture, TerrainTextures, m_Direct3D); // Load textures from the path
newTerrain->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, TerrainTextures);
newTerrain->SetScaleMatrix(scaleMatrix);
newTerrain->SetTranslateMatrix(XMMatrixTranslation(i / 2 * scaleX , -12.0f, j * scaleZ));
@@ -1276,8 +1244,7 @@ void ApplicationClass::AddKobject(std::wstring& filepath)
char modelFilename[128];
vector Filename;
- HRESULT result;
-
+ TextureContainer KobjectsTextures;
filesystem::path p(filepath);
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);
filesystem::current_path(m_WFolder);
-
- TextureContainer KobjectsTextures;
// Liste des fichiers de texture
std::vector kobjTexture = {
@@ -1295,21 +1260,8 @@ void ApplicationClass::AddKobject(std::wstring& filepath)
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();
+ 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->SetTranslateMatrix(XMMatrixTranslation(0.0f, 50.0f, 0.0f));
@@ -1330,12 +1282,10 @@ void ApplicationClass::AddKobject(std::wstring& filepath)
void ApplicationClass::AddCube()
{
-
Logger::Get().Log("Adding cube", __FILE__, __LINE__);
char modelFilename[128];
- HRESULT result;
-
+ TextureContainer CubeTexture;
// Set the file name of the model.
strcpy_s(modelFilename, "assets/Model/TXT/cube.txt");
@@ -1344,27 +1294,11 @@ void ApplicationClass::AddCube()
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;
float position = cubeCount * 2.0f;
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->SetTranslateMatrix(XMMatrixTranslation(position, 0.0f, 0.0f));
m_cubes.push_back(newCube);
diff --git a/enginecustom/src/src/system/object.cpp b/enginecustom/src/src/system/object.cpp
index eff3c1a..87a2c95 100644
--- a/enginecustom/src/src/system/object.cpp
+++ b/enginecustom/src/src/system/object.cpp
@@ -1,5 +1,9 @@
#include "object.h"
+#include
+
+#include "d3dclass.h"
+
Object::Object()// Initialize the reference here
{
m_scaleMatrix = XMMatrixIdentity();
@@ -348,4 +352,38 @@ void Object::LaunchObject()
char buffer[256];
sprintf_s(buffer, "Launch velocity: %f m/s at angle %f degrees", XMVectorGetX(XMVector3Length(velocity)), m_alpha);
OutputDebugStringA(buffer);
+}
+
+void Object::LoadTexturesFromPath(std::vector& 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é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ère appropriée
+ }
+ texturesContainer.AssignTexture(texturesContainer, texture, i);
+ i++;
+
+ }
}
\ No newline at end of file