Minor Update - V.9.2.0
[FEAT] : - Add More Object Property to the save and load
This commit is contained in:
@@ -10,6 +10,20 @@ enum class ObjectType
|
||||
Unknown
|
||||
};
|
||||
|
||||
enum class ShaderType
|
||||
{
|
||||
CEL_SHADING,
|
||||
LIGHTING,
|
||||
NORMAL_MAPPING,
|
||||
SPECULAR_MAPPING,
|
||||
REFLECTION,
|
||||
REFRACTION,
|
||||
TEXTURE,
|
||||
SKYBOX,
|
||||
SUNLIGHT,
|
||||
ALPHA_MAPPING
|
||||
};
|
||||
|
||||
class Object : public ModelClass
|
||||
{
|
||||
public:
|
||||
@@ -63,32 +77,24 @@ public:
|
||||
void SetName(std::string name);
|
||||
int SetId(int id);
|
||||
int GetId() const;
|
||||
void SetType(ObjectType type) { m_type = type; };
|
||||
void SetType(ObjectType type);
|
||||
ObjectType GetType() const { return m_type; };
|
||||
|
||||
|
||||
enum ShaderType
|
||||
{
|
||||
CEL_SHADING,
|
||||
LIGHTING,
|
||||
NORMAL_MAPPING,
|
||||
SPECULAR_MAPPING,
|
||||
REFLECTION,
|
||||
REFRACTION,
|
||||
TEXTURE,
|
||||
SKYBOX,
|
||||
SUNLIGHT,
|
||||
ALPHA_MAPPING
|
||||
};
|
||||
|
||||
ShaderType GetActiveShader() const { return m_activeShader; };
|
||||
void SetActiveShader(ShaderType activeShader) { m_activeShader = activeShader; };
|
||||
|
||||
float GetBoundingRadius() const;
|
||||
void SetBoundingRadius(float radius) { m_boundingRadius = radius; }
|
||||
|
||||
void SetModelPath(std::wstring& path) { m_modelPath = path; }
|
||||
std::wstring& GetModelPath() { return m_modelPath; }
|
||||
|
||||
ShaderType StringToShaderType(const std::string& shaderType);
|
||||
std::string ShaderTypeToString(ShaderType shaderType);
|
||||
|
||||
ObjectType StringToObjectType(const std::string& objectType);
|
||||
std::string ObjectTypeToString(ObjectType objectType);
|
||||
|
||||
public :
|
||||
bool m_demoSpinning = false;
|
||||
XMVECTOR m_previousPosition;
|
||||
@@ -109,8 +115,9 @@ private:
|
||||
|
||||
std::string m_name;
|
||||
ObjectType m_type = ObjectType::Unknown;
|
||||
|
||||
|
||||
ShaderType m_activeShader = LIGHTING;
|
||||
ShaderType m_activeShader = ShaderType::LIGHTING;
|
||||
|
||||
float m_boundingRadius;
|
||||
std::wstring m_modelPath;
|
||||
|
@@ -1421,7 +1421,7 @@ void ApplicationClass::GenerateTerrain()
|
||||
newTerrain->SetTranslateMatrix(XMMatrixTranslation(i / 2 * scaleX , -12.0f, j * scaleZ));
|
||||
newTerrain->SetName(filenameWithoutExtension);
|
||||
newTerrain->SetType(ObjectType::Cube);
|
||||
newTerrain->SetActiveShader(Object::SUNLIGHT);
|
||||
newTerrain->SetActiveShader(ShaderType::SUNLIGHT);
|
||||
m_terrainChunk.push_back(newTerrain);
|
||||
|
||||
}
|
||||
@@ -1843,7 +1843,7 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
|
||||
switch (object->GetActiveShader())
|
||||
{
|
||||
|
||||
case Object::ALPHA_MAPPING:
|
||||
case ShaderType::ALPHA_MAPPING:
|
||||
|
||||
// Enable alpha blending for transparency.
|
||||
m_Direct3D->EnableAlphaBlending();
|
||||
@@ -1867,7 +1867,7 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
|
||||
m_Direct3D->DisableAlphaBlending();
|
||||
break;
|
||||
|
||||
case Object::CEL_SHADING:
|
||||
case ShaderType::CEL_SHADING:
|
||||
result = m_ShaderManager->RenderCelShadingShader(
|
||||
m_Direct3D->GetDeviceContext(),
|
||||
object->GetIndexCount(),
|
||||
@@ -1887,7 +1887,7 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
|
||||
}
|
||||
break;
|
||||
|
||||
case Object::NORMAL_MAPPING:
|
||||
case ShaderType::NORMAL_MAPPING:
|
||||
result = m_ShaderManager->RenderNormalMapShader(
|
||||
m_Direct3D->GetDeviceContext(),
|
||||
object->GetIndexCount(),
|
||||
@@ -1906,7 +1906,7 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
|
||||
}
|
||||
break;
|
||||
|
||||
case Object::SPECULAR_MAPPING:
|
||||
case ShaderType::SPECULAR_MAPPING:
|
||||
result = m_ShaderManager->RenderSpecMapShader(
|
||||
m_Direct3D->GetDeviceContext(),
|
||||
object->GetIndexCount(),
|
||||
@@ -1928,7 +1928,7 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case Object::TEXTURE:
|
||||
case ShaderType::TEXTURE:
|
||||
result = m_ShaderManager->RenderTextureShader(
|
||||
m_Direct3D->GetDeviceContext(),
|
||||
object->GetIndexCount(),
|
||||
@@ -1944,7 +1944,7 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
|
||||
}
|
||||
break;
|
||||
|
||||
case Object::LIGHTING:
|
||||
case ShaderType::LIGHTING:
|
||||
result = m_ShaderManager->RenderlightShader(
|
||||
m_Direct3D->GetDeviceContext(),
|
||||
object->GetIndexCount(),
|
||||
@@ -1963,7 +1963,7 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
|
||||
}
|
||||
break;
|
||||
|
||||
case Object::SUNLIGHT:
|
||||
case ShaderType::SUNLIGHT:
|
||||
result = m_ShaderManager->RenderSunlightShader(
|
||||
m_Direct3D->GetDeviceContext(),
|
||||
object->GetIndexCount(),
|
||||
@@ -2065,7 +2065,7 @@ void ApplicationClass::ConstructSkybox() {
|
||||
face->SetScaleMatrix(XMMatrixScaling(2.01f, 2.01f, 2.01f));
|
||||
face->SetRotateMatrix(rotations[i]);
|
||||
face->SetTranslateMatrix(translations[i]);
|
||||
face->SetActiveShader(Object::SKYBOX);
|
||||
face->SetActiveShader(ShaderType::SKYBOX);
|
||||
m_Skybox.push_back(face);
|
||||
m_SkyboxInitialTranslations.push_back(translations[i]);
|
||||
}
|
||||
@@ -2238,82 +2238,96 @@ std::string ApplicationClass::ConvertWStringToString(const std::wstring& wstr)
|
||||
return str;
|
||||
}
|
||||
|
||||
void ApplicationClass::SaveScene()
|
||||
{
|
||||
if (m_scenePath.empty())
|
||||
{
|
||||
Logger::Get().Log("Scene path is empty. Cannot save scene.", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return;
|
||||
}
|
||||
void ApplicationClass::SaveScene() {
|
||||
if (m_scenePath.empty()) {
|
||||
Logger::Get().Log("Scene path is empty. Cannot save scene.", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
std::ofstream outFile(m_scenePath);
|
||||
if (!outFile.is_open())
|
||||
{
|
||||
Logger::Get().Log("Failed to open file for saving scene", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return;
|
||||
}
|
||||
std::ofstream outFile(m_scenePath);
|
||||
if (!outFile.is_open()) {
|
||||
Logger::Get().Log("Failed to open file for saving scene", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& object : m_object)
|
||||
{
|
||||
XMFLOAT3 position, scale;
|
||||
XMStoreFloat3(&position, object->GetPosition());
|
||||
XMStoreFloat3(&scale, object->GetScale());
|
||||
outFile << object->GetId() << " " << object->GetName() << " "
|
||||
<< position.x << " " << position.y << " " << position.z << " "
|
||||
<< scale.x << " " << scale.y << " " << scale.z << " "
|
||||
<< ConvertWStringToString(object->GetModelPath()) << std::endl; // Convert model path to std::string
|
||||
}
|
||||
for (const auto& object : m_object) {
|
||||
XMFLOAT3 position, scale, rotation;
|
||||
XMStoreFloat3(&position, object->GetPosition());
|
||||
XMStoreFloat3(&scale, object->GetScale());
|
||||
XMStoreFloat3(&rotation, object->GetRotation());
|
||||
|
||||
outFile.close();
|
||||
Logger::Get().Log("Scene saved successfully", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
outFile << object->GetId() << " "
|
||||
<< object->GetName() << " "
|
||||
<< position.x << " " << position.y << " " << position.z << " "
|
||||
<< rotation.x << " " << rotation.y << " " << rotation.z << " "
|
||||
<< scale.x << " " << scale.y << " " << scale.z << " "
|
||||
<< ConvertWStringToString(object->GetModelPath()) << " "
|
||||
<< object->ShaderTypeToString(object->GetActiveShader()) << " "
|
||||
<< object->GetBoundingRadius() << " "
|
||||
<< object->ObjectTypeToString(object->GetType()) << " "
|
||||
<< object->GetMass() << " "
|
||||
<< object->IsPhysicsEnabled() << std::endl;
|
||||
}
|
||||
|
||||
outFile.close();
|
||||
Logger::Get().Log("Scene saved successfully", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
}
|
||||
|
||||
void ApplicationClass::LoadScene()
|
||||
{
|
||||
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;
|
||||
}
|
||||
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 (!inFile.is_open())
|
||||
{
|
||||
Logger::Get().Log("Failed to open file for loading scene", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return;
|
||||
}
|
||||
std::ifstream inFile(m_scenePath);
|
||||
if (!inFile.is_open()) {
|
||||
Logger::Get().Log("Failed to open file for loading scene", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
m_object.clear();
|
||||
m_object.clear();
|
||||
|
||||
int id;
|
||||
std::string name;
|
||||
float posX, posY, posZ;
|
||||
float scaleX, scaleY, scaleZ;
|
||||
std::string modelPath;
|
||||
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 >> scaleX >> scaleY >> scaleZ >> modelPath)
|
||||
{
|
||||
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);
|
||||
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);
|
||||
AddKobject(wModelPath);
|
||||
|
||||
Object* newObject = m_object.back();
|
||||
newObject->SetId(id);
|
||||
newObject->SetName(name);
|
||||
newObject->SetPosition(XMVectorSet(posX, posY, posZ, 0.0f));
|
||||
newObject->SetScale(XMVectorSet(scaleX, scaleY, scaleZ, 0.0f));
|
||||
}
|
||||
Object* newObject = m_object.back();
|
||||
newObject->SetId(id);
|
||||
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->SetActiveShader(newObject->StringToShaderType(shaderTypeStr));
|
||||
newObject->SetBoundingRadius(boundingRadius);
|
||||
newObject->SetType(newObject->StringToObjectType(objectTypeStr));
|
||||
newObject->SetMass(mass);
|
||||
newObject->SetPhysicsEnabled(physicsEnabled);
|
||||
}
|
||||
|
||||
inFile.close();
|
||||
Logger::Get().Log("Scene loaded successfully", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
inFile.close();
|
||||
Logger::Get().Log("Scene loaded successfully", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
}
|
||||
|
||||
std::wstring ApplicationClass::GetScenePath()
|
||||
|
@@ -359,13 +359,13 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app)
|
||||
"Enable Alpha Mapping"
|
||||
};
|
||||
|
||||
Object::ShaderType shaderTypes[] = {
|
||||
Object::SUNLIGHT,
|
||||
Object::LIGHTING,
|
||||
Object::CEL_SHADING,
|
||||
Object::NORMAL_MAPPING,
|
||||
Object::SPECULAR_MAPPING,
|
||||
Object::ALPHA_MAPPING
|
||||
ShaderType shaderTypes[] = {
|
||||
ShaderType::SUNLIGHT,
|
||||
ShaderType::LIGHTING,
|
||||
ShaderType::CEL_SHADING,
|
||||
ShaderType::NORMAL_MAPPING,
|
||||
ShaderType::SPECULAR_MAPPING,
|
||||
ShaderType::ALPHA_MAPPING
|
||||
};
|
||||
|
||||
// Variable pour stocker l'option s<>lectionn<6E>e
|
||||
|
@@ -259,4 +259,51 @@ void Object::UpdatePosition(float deltaTime)
|
||||
XMVECTOR position = GetPosition();
|
||||
position = position + GetVelocity() * deltaTime;
|
||||
SetPosition(position);
|
||||
}
|
||||
|
||||
void Object::SetType(ObjectType type)
|
||||
{
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
std::string Object::ObjectTypeToString(ObjectType type) {
|
||||
switch (type) {
|
||||
case ObjectType::Cube: return "Cube";
|
||||
case ObjectType::Sphere: return "Sphere";
|
||||
// Ajoutez d'autres cas si n<>cessaire
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
ObjectType Object::StringToObjectType(const std::string& str) {
|
||||
if (str == "Cube") return ObjectType::Cube;
|
||||
if (str == "Sphere") return ObjectType::Sphere;
|
||||
// Add other cases as needed
|
||||
return ObjectType::Unknown;
|
||||
}
|
||||
|
||||
std::string Object::ShaderTypeToString(ShaderType type) {
|
||||
switch (type) {
|
||||
case ShaderType::ALPHA_MAPPING: return "ALPHA_MAPPING";
|
||||
case ShaderType::CEL_SHADING: return "CEL_SHADING";
|
||||
case ShaderType::NORMAL_MAPPING: return "NORMAL_MAPPING";
|
||||
case ShaderType::SPECULAR_MAPPING: return "SPECULAR_MAPPING";
|
||||
case ShaderType::TEXTURE: return "TEXTURE";
|
||||
case ShaderType::LIGHTING: return "LIGHTING";
|
||||
case ShaderType::SUNLIGHT: return "SUNLIGHT";
|
||||
// Ajoutez d'autres cas si n<>cessaire
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
ShaderType Object::StringToShaderType(const std::string& str) {
|
||||
if (str == "ALPHA_MAPPING") return ShaderType::ALPHA_MAPPING;
|
||||
if (str == "CEL_SHADING") return ShaderType::CEL_SHADING;
|
||||
if (str == "NORMAL_MAPPING") return ShaderType::NORMAL_MAPPING;
|
||||
if (str == "SPECULAR_MAPPING") return ShaderType::SPECULAR_MAPPING;
|
||||
if (str == "TEXTURE") return ShaderType::TEXTURE;
|
||||
if (str == "LIGHTING") return ShaderType::LIGHTING;
|
||||
if (str == "SUNLIGHT") return ShaderType::SUNLIGHT;
|
||||
// Add other cases as needed
|
||||
return ShaderType::TEXTURE;
|
||||
}
|
Reference in New Issue
Block a user