Patch Update - LoadTexture Tweak - V10.0.1
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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;
|
||||
|
@@ -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<6C>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<6E>re appropri<72>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);
|
||||
|
@@ -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<6C>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<6E>re appropri<72>e
|
||||
}
|
||||
texturesContainer.AssignTexture(texturesContainer, texture, i);
|
||||
i++;
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user