diff --git a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
index 42a91e4..60ff8bd 100644
--- a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
+++ b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
@@ -4,7 +4,16 @@
-
+
+
+
+
+
+
+
+
+
+
@@ -17,14 +26,6 @@
-
-
-
-
-
-
-
-
@@ -181,6 +182,10 @@
+
+
+
+
@@ -238,6 +243,11 @@
+
+ file://$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp
+ 1997
+
+
diff --git a/enginecustom/demo.ker b/enginecustom/demo.ker
index ddae704..c9181a6 100644
--- a/enginecustom/demo.ker
+++ b/enginecustom/demo.ker
@@ -1,2 +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
+0 isosphere 0 10 0 0 -0 0 1 1 1 Content/Assets/Kobject/isosphere.obj ALPHA_MAPPING 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\moss01.png 1 F:\Github_Repo\khaotic-engine-Reborn\enginecustom\assets\Texture\normal01.png 1 F:\Github_Repo\khaotic-engine-Reborn\enginecustom\assets\Texture\spec02.png 1 F:\Github_Repo\khaotic-engine-Reborn\enginecustom\assets\Texture\light01.png
diff --git a/enginecustom/src/inc/system/modelclass.h b/enginecustom/src/inc/system/modelclass.h
index a90079b..6d78c43 100644
--- a/enginecustom/src/inc/system/modelclass.h
+++ b/enginecustom/src/inc/system/modelclass.h
@@ -32,11 +32,21 @@ enum class TextureType
struct TextureContainer
{
+
+ // Textures
std::vector diffuse;
std::vector normal;
std::vector specular;
std::vector alpha;
+ // Textures Paths
+ std::vector diffusePaths;
+ std::vector normalPaths;
+ std::vector specularPaths;
+ std::vector alphaPaths;
+
+
+ // Get the vector of textures based on the type
std::vector& Get(TextureType type) const {
switch (type) {
case TextureType::Diffuse: return const_cast&>(diffuse);
@@ -47,6 +57,20 @@ struct TextureContainer
}
}
+ // Get the vector of textures paths based on the type
+ std::vector GetPaths(TextureType type) const {
+ switch (type)
+ {
+ case TextureType::Diffuse: return std::vector(diffusePaths);
+ case TextureType::Normal: return std::vector(normalPaths);
+ case TextureType::Specular: return std::vector(specularPaths);
+ case TextureType::Alpha: return std::vector(alphaPaths);
+ default: return std::vector(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())
@@ -54,31 +78,53 @@ struct TextureContainer
return nullptr;
}
+ // Get The texture path based on the type and index
+ std::wstring GetTexturePath(TextureType type, int index) const
+ {
+ std::vector 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);
}
- 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)
{
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;
}
}
@@ -93,6 +139,10 @@ private:
}
vec.clear();
}
+
+ void ReleaseVector(std::vector& vec) {
+ vec.clear();
+ }
};
////////////////////////////////////////////////////////////////////////////////
// Class name: ModelClass
@@ -172,6 +222,9 @@ public:
// 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; }
private:
bool InitializeBuffers(ID3D11Device*);
diff --git a/enginecustom/src/inc/system/object.h b/enginecustom/src/inc/system/object.h
index 05e1867..e181046 100644
--- a/enginecustom/src/inc/system/object.h
+++ b/enginecustom/src/inc/system/object.h
@@ -98,7 +98,7 @@ public:
std::string ObjectTypeToString(ObjectType objectType);
void LaunchObject();
- void LoadTexturesFromPath(std::vector& texturePaths, TextureContainer& texturesContainer,D3DClass* m_Direct3D);
+ 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; }
@@ -134,6 +134,7 @@ private:
float m_boundingRadius;
std::wstring m_modelPath;
+ TextureContainer m_texturesContainer;
float m_alpha = 0.0f;
float m_initialStretch = 0.0f;
float m_springConstant = 10.0f;
diff --git a/enginecustom/src/src/system/Skybox.cpp b/enginecustom/src/src/system/Skybox.cpp
index 3e88ab5..e6e3112 100644
--- a/enginecustom/src/src/system/Skybox.cpp
+++ b/enginecustom/src/src/system/Skybox.cpp
@@ -48,7 +48,6 @@ Object* Skybox::ConstructSkybox()
}
SkyboxTextures.diffuse.push_back(texture);
-
}
// Create the model object
diff --git a/enginecustom/src/src/system/applicationclass.cpp b/enginecustom/src/src/system/applicationclass.cpp
index 1e60544..cca68f3 100644
--- a/enginecustom/src/src/system/applicationclass.cpp
+++ b/enginecustom/src/src/system/applicationclass.cpp
@@ -1975,7 +1975,8 @@ void ApplicationClass::SaveScene() {
XMStoreFloat3(&position, object->GetPosition());
XMStoreFloat3(&scale, object->GetScale());
XMStoreFloat3(&rotation, object->GetRotation());
-
+
+ // Écrire les données de base de l'objet
outFile << object->GetId() << " "
<< object->GetName() << " "
<< position.x << " " << position.y << " " << position.z << " "
@@ -1986,68 +1987,187 @@ void ApplicationClass::SaveScene() {
<< object->GetBoundingRadius() << " "
<< object->ObjectTypeToString(object->GetType()) << " "
<< 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é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();
- 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() {
-
+
std::wstring scenePath = GetScenePath();
if (!scenePath.empty())
{
SetScenePath(ConvertWStringToString(scenePath));
}
- if (m_scenePath.empty()) {
- Logger::Get().Log("Scene path is empty. Cannot load scene.", __FILE__, __LINE__, Logger::LogLevel::Error);
- return;
- }
-
- std::ifstream inFile(m_scenePath);
+ if (m_scenePath.empty()) {
+ Logger::Get().Log("Scene path is empty. Cannot load scene.", __FILE__, __LINE__, Logger::LogLevel::Error);
+ return;
+ }
+
+ std::ifstream inFile(scenePath);
if (!inFile.is_open()) {
- Logger::Get().Log("Failed to open file for loading scene", __FILE__, __LINE__, Logger::LogLevel::Error);
- return;
+ Logger::Get().Log("Failed to open file for loading scene: ", __FILE__, __LINE__, Logger::LogLevel::Error);
+ }
+
+ // Nettoyer les objets existants
+ for (auto& obj : m_object) {
+ if (obj) {
+ obj->Shutdown();
+ delete obj;
+ }
}
-
m_object.clear();
-
- int id;
- std::string name;
- 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) {
- int size_needed = MultiByteToWideChar(CP_UTF8, 0, modelPath.c_str(), (int)modelPath.size(), NULL, 0);
- std::wstring wModelPath(size_needed, 0);
- MultiByteToWideChar(CP_UTF8, 0, modelPath.c_str(), (int)modelPath.size(), &wModelPath[0], size_needed);
-
- AddKobject(wModelPath);
-
- Object* newObject = m_object.back();
- newObject->SetId(id);
+ m_ObjectId = 0;
+
+ std::string line;
+ while (std::getline(inFile, line)) {
+ std::istringstream iss(line);
+
+ int id;
+ std::string name;
+ float posX, posY, posZ, rotX, rotY, rotZ, scaleX, scaleY, scaleZ;
+ std::string modelPath, shaderTypeStr, objectTypeStr;
+ float boundingRadius, mass;
+ bool physicsEnabled;
+
+ // Lire les données de base
+ iss >> id >> name >> posX >> posY >> posZ >> rotX >> rotY >> rotZ
+ >> scaleX >> scaleY >> scaleZ >> modelPath >> shaderTypeStr
+ >> boundingRadius >> objectTypeStr >> mass >> physicsEnabled;
+
+ // Convertir les chemins de modèle en wstring pour Windows
+ std::wstring wModelPath(modelPath.begin(), modelPath.end());
+
+ // Créer un nouvel objet
+ Object* newObject = new Object();
+
+ // Lire les chemins de textures
+ TextureContainer textures;
+
+ // Textures diffuses
+ int diffuseCount;
+ iss >> diffuseCount;
+ std::vector diffusePaths;
+ for (int i = 0; i < diffuseCount; i++) {
+ std::string path;
+ iss >> path;
+ diffusePaths.push_back(std::wstring(path.begin(), path.end()));
+ }
+
+ // Textures normales
+ int normalCount;
+ iss >> normalCount;
+ std::vector normalPaths;
+ for (int i = 0; i < normalCount; i++) {
+ std::string path;
+ iss >> path;
+ normalPaths.push_back(std::wstring(path.begin(), path.end()));
+ }
+
+ // Textures spéculaires
+ int specularCount;
+ iss >> specularCount;
+ std::vector specularPaths;
+ for (int i = 0; i < specularCount; i++) {
+ std::string path;
+ iss >> path;
+ specularPaths.push_back(std::wstring(path.begin(), path.end()));
+ }
+
+ // Textures alpha
+ int alphaCount;
+ iss >> alphaCount;
+ std::vector alphaPaths;
+ for (int i = 0; i < alphaCount; i++) {
+ std::string path;
+ iss >> path;
+ alphaPaths.push_back(std::wstring(path.begin(), path.end()));
+ }
+
+ // Combiner tous les chemins de textures
+ std::vector allTextures;
+ allTextures.insert(allTextures.end(), diffusePaths.begin(), diffusePaths.end());
+ allTextures.insert(allTextures.end(), normalPaths.begin(), normalPaths.end());
+ allTextures.insert(allTextures.end(), specularPaths.begin(), specularPaths.end());
+ allTextures.insert(allTextures.end(), alphaPaths.begin(), alphaPaths.end());
+
+ // Charger les textures
+ newObject->LoadTexturesFromPath(allTextures, textures, m_Direct3D);
+
+ // Convertir le chemin du modèle en char* pour l'initialisation
+ char modelFilename[128];
+ wcstombs_s(nullptr, modelFilename, sizeof(modelFilename), wModelPath.c_str(), _TRUNCATE);
+
+ // Initialiser l'objet avec le modèle et les textures
+ if (!newObject->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textures)) {
+ Logger::Get().Log("Failed to initialize object from scene file", __FILE__, __LINE__, Logger::LogLevel::Error);
+ delete newObject;
+ continue;
+ }
+
+ // Définir les propriétés de l'objet
+ newObject->SetPosition(XMVectorSet(posX, posY, posZ, 1.0f));
+ newObject->SetRotation(XMVectorSet(rotX, rotY, rotZ, 1.0f));
+ newObject->SetScale(XMVectorSet(scaleX, scaleY, scaleZ, 1.0f));
newObject->SetName(name);
- newObject->SetPosition(XMVectorSet(posX, posY, posZ, 0.0f));
- newObject->SetRotation(XMVectorSet(rotX, rotY, rotZ, 0.0f));
- newObject->SetScale(XMVectorSet(scaleX, scaleY, scaleZ, 0.0f));
+ newObject->SetId(id);
+ newObject->SetModelPath(wModelPath);
newObject->SetActiveShader(newObject->StringToShaderType(shaderTypeStr));
- newObject->SetBoundingRadius(boundingRadius);
newObject->SetType(newObject->StringToObjectType(objectTypeStr));
newObject->SetMass(mass);
newObject->SetPhysicsEnabled(physicsEnabled);
+
+ // Mettre à jour les matrices de l'objet
+ newObject->Update();
+
+ // Ajouter l'objet à la liste
+ m_object.push_back(newObject);
+
+ // Mettre à jour l'ID global
+ if (id >= m_ObjectId) {
+ m_ObjectId = id + 1;
+ }
}
-
+
inFile.close();
- Logger::Get().Log("Scene loaded successfully", __FILE__, __LINE__, Logger::LogLevel::Info);
+ Logger::Get().Log("Scene loaded successfully from ", __FILE__, __LINE__, Logger::LogLevel::Info);
}
std::wstring ApplicationClass::GetScenePath()
diff --git a/enginecustom/src/src/system/modelclass.cpp b/enginecustom/src/src/system/modelclass.cpp
index 38c231a..5bdaba3 100644
--- a/enginecustom/src/src/system/modelclass.cpp
+++ b/enginecustom/src/src/system/modelclass.cpp
@@ -42,11 +42,13 @@ bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCon
return false;
}
- // Copie de toutes les textures de la structure
- 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);
+ m_Textures = textures; // Copie de la structure de textures
+
+ // // Copie de toutes les textures de la structure
+ // 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;
}
@@ -608,6 +610,34 @@ bool ModelClass::ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* device
// Assigner la nouvelle texture
textureVector[index] = newTexture;
+ // Mettre à jour le chemin dans le conteneur approprié 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);
return true;
}
@@ -625,8 +655,25 @@ bool ModelClass::AddTexture(ID3D11Device* device, ID3D11DeviceContext* deviceCon
return false;
}
- // Ajouter la texture au vecteur correspondant
- m_Textures.Get(type).push_back(newTexture);
+ // Ajouter la texture au vecteur approprié selon le type
+ auto& textureVector = m_Textures.Get(type);
+ textureVector.push_back(newTexture);
+
+ // Ajouter le chemin de la texture au vecteur approprié 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;
@@ -638,7 +685,24 @@ bool ModelClass::AddTexture(ID3D11ShaderResourceView* texture, TextureType type)
return false;
}
- // Ajouter la texture au vecteur correspondant
- m_Textures.Get(type).push_back(texture);
+ // Ajouter la texture au vecteur approprié
+ auto& textureVector = m_Textures.Get(type);
+ textureVector.push_back(texture);
+
+ // Ajouter un chemin vide ou générique pour maintenir la synchronisation
+ switch (type) {
+ case TextureType::Diffuse:
+ m_Textures.diffusePaths.push_back(L"[texture préchargée]");
+ break;
+ case TextureType::Normal:
+ m_Textures.normalPaths.push_back(L"[texture préchargée]");
+ break;
+ case TextureType::Specular:
+ m_Textures.specularPaths.push_back(L"[texture préchargée]");
+ break;
+ case TextureType::Alpha:
+ m_Textures.alphaPaths.push_back(L"[texture préchargée]");
+ break;
+ }
return true;
}
\ No newline at end of file
diff --git a/enginecustom/src/src/system/object.cpp b/enginecustom/src/src/system/object.cpp
index 87a2c95..0a2ae04 100644
--- a/enginecustom/src/src/system/object.cpp
+++ b/enginecustom/src/src/system/object.cpp
@@ -382,7 +382,7 @@ void Object::LoadTexturesFromPath(std::vector& texturePaths, Textu
__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);
+ texturesContainer.AssignTexture(texturesContainer, texture,texturePath , i);
i++;
}