diff --git a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
index 60ff8bd..b4f220a 100644
--- a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
+++ b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
@@ -7,12 +7,12 @@
+
+
-
-
+
-
@@ -32,7 +32,37 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -49,25 +79,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"
+
+}]]>
@@ -185,7 +215,8 @@
-
+
+
@@ -243,11 +274,6 @@
-
- file://$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp
- 1997
-
-
diff --git a/enginecustom/demo.ker b/enginecustom/demo.ker
index c9181a6..661d607 100644
--- a/enginecustom/demo.ker
+++ b/enginecustom/demo.ker
@@ -1 +1 @@
-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
+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
diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini
index cbe9131..bb5e10d 100644
--- a/enginecustom/imgui.ini
+++ b/enginecustom/imgui.ini
@@ -66,8 +66,8 @@ Collapsed=0
DockId=0x0000000C,0
[Window][Log Window]
-Pos=8,627
-Size=1568,226
+Pos=8,37
+Size=16,19
Collapsed=0
DockId=0x00000006,0
diff --git a/enginecustom/src/inc/system/applicationclass.h b/enginecustom/src/inc/system/applicationclass.h
index bbb5597..276a442 100644
--- a/enginecustom/src/inc/system/applicationclass.h
+++ b/enginecustom/src/inc/system/applicationclass.h
@@ -151,7 +151,7 @@ public:
// Save and load scene
void SaveScene();
- void LoadScene();
+ bool LoadScene();
void SetScenePath(std::string path) { m_scenePath = path; };
std::wstring GetScenePath();
diff --git a/enginecustom/src/inc/system/modelclass.h b/enginecustom/src/inc/system/modelclass.h
index 6d78c43..c9723e6 100644
--- a/enginecustom/src/inc/system/modelclass.h
+++ b/enginecustom/src/inc/system/modelclass.h
@@ -225,6 +225,8 @@ public:
void SetTextureContainer (TextureContainer& texturesContainer) { m_Textures = texturesContainer; }
TextureContainer GetTextureContainer() const { return m_Textures; }
+
+ bool PreloadTextures(ID3D11Device* device, ID3D11DeviceContext* deviceContext, TextureContainer& textureContainer);
private:
bool InitializeBuffers(ID3D11Device*);
diff --git a/enginecustom/src/src/system/applicationclass.cpp b/enginecustom/src/src/system/applicationclass.cpp
index cca68f3..3455309 100644
--- a/enginecustom/src/src/system/applicationclass.cpp
+++ b/enginecustom/src/src/system/applicationclass.cpp
@@ -2028,8 +2028,11 @@ void ApplicationClass::SaveScene() {
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();
if (!scenePath.empty())
{
@@ -2038,14 +2041,15 @@ void ApplicationClass::LoadScene() {
if (m_scenePath.empty()) {
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);
- }
-
+
+ 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;
+ }
+
// Nettoyer les objets existants
for (auto& obj : m_object) {
if (obj) {
@@ -2055,119 +2059,149 @@ void ApplicationClass::LoadScene() {
}
m_object.clear();
m_ObjectId = 0;
-
+
+ // Sauvegarder le répertoire de travail actuel
+ std::wstring currentDirectory = m_WFolder;
+
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;
+ XMFLOAT3 position, rotation, scale;
+ std::string modelPath;
+ std::string shaderTypeStr;
+ float boundingRadius;
+ std::string objectTypeStr;
+ float 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());
-
+
+ // Lire les donné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;
+
+ if (iss.fail()) {
+ Logger::Get().Log("Failed to parse object data", __FILE__, __LINE__, Logger::LogLevel::Error);
+ continue;
+ }
+
// Créer un nouvel objet
Object* newObject = new Object();
+
+ // Convertir le chemin du modè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é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éer le conteneur de textures pour stocker les chemins
+ TextureContainer objectTextures;
- // 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()));
+ // 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);
}
-
- // 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()));
+
+ // 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);
}
-
- // 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()));
+
+ // Lire les chemins des textures spé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);
}
-
- // 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()));
+
+ // 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);
}
-
- // 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);
+
+ // preload texture
+ if (!newObject->PreloadTextures(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), objectTextures))
+ {
+ // Gérer l'erreur
+ return false;
+ }
+
+ // Initialiser l'objet avec le modè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 à 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é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->SetId(id);
+ newObject->SetName(name);
+ newObject->SetPosition(XMLoadFloat3(&position));
+ newObject->SetRotation(XMLoadFloat3(&rotation));
+ newObject->SetScale(XMLoadFloat3(&scale));
newObject->SetModelPath(wModelPath);
newObject->SetActiveShader(newObject->StringToShaderType(shaderTypeStr));
+ newObject->SetBoundingRadius(boundingRadius);
newObject->SetType(newObject->StringToObjectType(objectTypeStr));
newObject->SetMass(mass);
newObject->SetPhysicsEnabled(physicsEnabled);
-
- // Mettre à jour les matrices de l'objet
- newObject->Update();
-
- // Ajouter l'objet à la liste
- m_object.push_back(newObject);
-
- // Mettre à jour l'ID global
+
+ // Mettre à 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);
+ return true;
}
std::wstring ApplicationClass::GetScenePath()
diff --git a/enginecustom/src/src/system/imguiManager.cpp b/enginecustom/src/src/system/imguiManager.cpp
index 31535eb..ac79a8c 100644
--- a/enginecustom/src/src/system/imguiManager.cpp
+++ b/enginecustom/src/src/system/imguiManager.cpp
@@ -92,7 +92,6 @@ void imguiManager::SetupDockspace(ApplicationClass* app) {
ImGui::MenuItem("Object Window", NULL, &showObjectWindow);
ImGui::MenuItem("Terrain Window", NULL, &showTerrainWindow);
ImGui::MenuItem("Light Window", NULL, &showLightWindow);
- ImGui::MenuItem("Old Scene Window", NULL, &showOldSceneWindow);
ImGui::MenuItem("Engine Settings Window", NULL, &showEngineSettingsWindow);
ImGui::MenuItem("Log Window", NULL, &showLogWindow);
ImGui::EndMenu();
diff --git a/enginecustom/src/src/system/modelclass.cpp b/enginecustom/src/src/system/modelclass.cpp
index 5bdaba3..a201701 100644
--- a/enginecustom/src/src/system/modelclass.cpp
+++ b/enginecustom/src/src/system/modelclass.cpp
@@ -44,12 +44,6 @@ bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCon
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;
}
@@ -581,6 +575,65 @@ void ModelClass::ReleaseModel()
// 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("É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("É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é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("Échec du chargement de la texture spé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("É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);
@@ -705,4 +758,5 @@ bool ModelClass::AddTexture(ID3D11ShaderResourceView* texture, TextureType type)
break;
}
return true;
-}
\ No newline at end of file
+}
+