Minor Update - Texture Are Saved - V10.1.0

This commit is contained in:
CatChow0 2025-05-06 15:29:23 +02:00
parent e681943aa8
commit c442a87883
8 changed files with 311 additions and 65 deletions

View File

@ -4,7 +4,16 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<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/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/demo.ker" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/demo.ker" 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/inc/system/object.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/object.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/modelclass.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/modelclass.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/object.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/object.cpp" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -17,14 +26,6 @@
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="HighlightingSettingsPerFile">
<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" />
@ -181,6 +182,10 @@
<workItem from="1746274246641" duration="89000" />
<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="1831000" />
</task>
<task id="LOCAL-00001" summary="Minor update - viewport window tweak">
<option name="closed" value="true" />
@ -238,6 +243,11 @@
<properties exception="System.Threading.ThreadAbortException" breakIfHandledByOtherCode="false" displayValue="System.Threading.ThreadAbortException" />
<option name="timeStamp" value="3" />
</breakpoint>
<line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
<url>file://$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp</url>
<line>1997</line>
<option name="timeStamp" value="5" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
<watches-manager>

View File

@ -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

View File

@ -32,11 +32,21 @@ enum class TextureType
struct TextureContainer
{
// Textures
std::vector<ID3D11ShaderResourceView*> diffuse;
std::vector<ID3D11ShaderResourceView*> normal;
std::vector<ID3D11ShaderResourceView*> specular;
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 {
switch (type) {
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 {
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<std::wstring> 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<std::wstring>& 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*);

View File

@ -98,7 +98,7 @@ public:
std::string ObjectTypeToString(ObjectType objectType);
void LaunchObject();
void LoadTexturesFromPath(std::vector<std::wstring>& texturePaths, TextureContainer& texturesContainer,D3DClass* m_Direct3D);
void LoadTexturesFromPath(std::vector<std::wstring>& 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;

View File

@ -48,7 +48,6 @@ Object* Skybox::ConstructSkybox()
}
SkyboxTextures.diffuse.push_back(texture);
}
// Create the model object

View File

@ -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<std::wstring> 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<std::wstring> 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<std::wstring> 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<std::wstring> 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<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è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()

View File

@ -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;
}

View File

@ -382,7 +382,7 @@ void Object::LoadTexturesFromPath(std::vector<std::wstring>& 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++;
}