Patch Update - Fix the loading and saving of the texture - V10.1.1
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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();
|
||||
|
@@ -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*);
|
||||
|
@@ -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<6E>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<6F>le en wstring pour Windows
|
||||
std::wstring wModelPath(modelPath.begin(), modelPath.end());
|
||||
|
||||
|
||||
// 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;
|
||||
|
||||
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;
|
||||
|
||||
// Lire les chemins de textures
|
||||
TextureContainer textures;
|
||||
|
||||
// Textures diffuses
|
||||
int diffuseCount;
|
||||
iss >> diffuseCount;
|
||||
std::vector<std::wstring> 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<std::wstring> 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<73>culaires
|
||||
int specularCount;
|
||||
iss >> specularCount;
|
||||
std::vector<std::wstring> 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<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);
|
||||
}
|
||||
|
||||
// Textures alpha
|
||||
int alphaCount;
|
||||
iss >> alphaCount;
|
||||
std::vector<std::wstring> 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<std::wstring> 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<6F>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<6F>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<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->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 <20> jour les matrices de l'objet
|
||||
newObject->Update();
|
||||
|
||||
// Ajouter l'objet <20> la liste
|
||||
m_object.push_back(newObject);
|
||||
|
||||
// Mettre <20> jour l'ID global
|
||||
|
||||
// Mettre <20> jour l'ID global si n<>cessaire
|
||||
if (id >= m_ObjectId) {
|
||||
m_ObjectId = id + 1;
|
||||
}
|
||||
|
||||
m_object.push_back(newObject);
|
||||
Logger::Get().Log("Loaded object: " + name, __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
}
|
||||
|
||||
inFile.close();
|
||||
|
||||
Logger::Get().Log("Scene loaded successfully from ", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::wstring ApplicationClass::GetScenePath()
|
||||
|
@@ -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();
|
||||
|
@@ -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("<EFBFBD>chec du chargement de la texture diffuse: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
textureContainer.diffuse.push_back(texture);
|
||||
}
|
||||
|
||||
// Charger les textures normales
|
||||
for (const auto& texturePath : textureContainer.normalPaths)
|
||||
{
|
||||
ID3D11ShaderResourceView* texture = nullptr;
|
||||
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
|
||||
if (FAILED(hResult))
|
||||
{
|
||||
Logger::Get().Log("<EFBFBD>chec du chargement de la texture normale: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
textureContainer.normal.push_back(texture);
|
||||
}
|
||||
|
||||
// Charger les textures sp<73>culaires
|
||||
for (const auto& texturePath : textureContainer.specularPaths)
|
||||
{
|
||||
ID3D11ShaderResourceView* texture = nullptr;
|
||||
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
|
||||
if (FAILED(hResult))
|
||||
{
|
||||
Logger::Get().Log("<EFBFBD>chec du chargement de la texture sp<73>culaire: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
textureContainer.specular.push_back(texture);
|
||||
}
|
||||
|
||||
// Charger les textures alpha
|
||||
for (const auto& texturePath : textureContainer.alphaPaths)
|
||||
{
|
||||
ID3D11ShaderResourceView* texture = nullptr;
|
||||
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
|
||||
if (FAILED(hResult))
|
||||
{
|
||||
Logger::Get().Log("<EFBFBD>chec du chargement de la texture alpha: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
textureContainer.alpha.push_back(texture);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ModelClass::ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, std::wstring filename, TextureType type, int index) {
|
||||
Logger::Get().Log("Changing texture", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||
|
||||
@@ -705,4 +758,5 @@ bool ModelClass::AddTexture(ID3D11ShaderResourceView* texture, TextureType type)
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user