Patch Update - LoadTexture Tweak - V10.0.1

This commit is contained in:
CatChow0 2025-05-05 16:12:38 +02:00
parent 8e6b7409d9
commit e68f1d5dd0
7 changed files with 74 additions and 101 deletions

View File

@ -5,15 +5,13 @@
</component>
<component name="ChangeListManager">
<list default="true" id="e81d6e08-efc7-40a0-909d-ec4943d948e9" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml" afterDir="false" />
<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/assets/Texture/imgui.ini" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/assets/Texture/imgui.ini" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/imgui.ini" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/imgui.ini" 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/src/system/Skybox.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/Skybox.cpp" 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/applicationclass.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/imguiManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/imguiManager.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" />
@ -58,25 +56,25 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"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"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;C++ Project.enginecustom.executor&quot;: &quot;Run&quot;,
&quot;C/C++ Project.enginecustom.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.build.unityPlugin&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<component name="RunManager" selected="C/C++ Project.enginecustom">
<configuration name="KhaoticDemo" type="CppProject" factoryName="C++ Project">
<configuration_1 setup="1">
@ -190,6 +188,7 @@
<workItem from="1746188920194" duration="1870000" />
<workItem from="1746274246641" duration="89000" />
<workItem from="1746274352144" duration="8039000" />
<workItem from="1746444660572" duration="7678000" />
</task>
<task id="LOCAL-00001" summary="Minor update - viewport window tweak">
<option name="closed" value="true" />

View File

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

View File

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

View File

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

View File

@ -3,6 +3,8 @@
#include <WICTextureLoader.h>
#include <SimpleMath.h>
#include "d3dclass.h"
enum class ObjectType
{
Sphere,
@ -96,6 +98,7 @@ public:
std::string ObjectTypeToString(ObjectType objectType);
void LaunchObject();
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; }
@ -127,8 +130,6 @@ private:
std::string m_name;
ObjectType m_type = ObjectType::Unknown;
ShaderType m_activeShader = ShaderType::LIGHTING;
float m_boundingRadius;

View File

@ -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<string> 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<std::wstring> 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);

View File

@ -1,5 +1,9 @@
#include "object.h"
#include <comdef.h>
#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<std::wstring>& 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++;
}
}