1. ModelObject class
더보기
#pragma once
class ModelObject : public Model, public Transform
{
public:
string name;
public:
ModelObject(string file);
~ModelObject();
////////////////////////////////////
void Update();
void Render();
};
////////////////////////////////////////////////////////////////////////
#include "Framework.h"
#include "ModelObject.h"
ModelObject::ModelObject(string file)
:Model(file), name(file)
{
SetShader(L"NormalMapping");
scale = { 0.1f, 0.1f, 0.1f };
}
ModelObject::~ModelObject()
{
}
void ModelObject::Update()
{
UpdateWorld();
}
void ModelObject::Render()
{
SetWorldBuffer();
Model::Render();
}
2. ModelEditor class
더보기
#pragma once
class ModelEditor
{
public:
struct ModelTransformData
{
int modelNum;
Vector3 position;
Vector3 rotation;
Vector3 scale;
};
//
private:
vector<ModelObject*> objs;
ModelObject* test[2];
//
Vector3 pickingPos;
//
int currentModel = 0;
string modelNames[2]{ "amy", "xbot" };
public:
bool createModel;
public:
ModelEditor();
~ModelEditor();
//
void Update();
void Render();
void PostRender();
//
void Control();
void CreateModel();
//
void SetPickingPos(Vector3 pos) { pickingPos = pos; }
//
void SaveModels();
void LoadModels();
void ClearModels();
};
////////////////////////////////////////////////////////////////////////
#include "Framework.h"
#include "ModelEditor.h"
ModelEditor::ModelEditor()
{
test[0] = new ModelObject("amy");
test[1] = new ModelObject("xbot");
}
ModelEditor::~ModelEditor()
{
for (ModelObject* obj : objs)
delete obj;
//
delete test[0];
delete test[1];
}
void ModelEditor::Update()
{
Control();
//
test[currentModel]->Update();
//
for (ModelObject* obj : objs)
obj->Update();
}
void ModelEditor::Render()
{
test[currentModel]->Render();
//
for (ModelObject* obj : objs)
obj->Render();
}
void ModelEditor::PostRender()
{
ImGui::Spacing();
ImGui::Text("[ModelEditor]");
ImGui::Checkbox("CreateModel", &createModel);
ImGui::RadioButton("amy", ¤tModel, 0); ImGui::SameLine();
ImGui::RadioButton("xbot", ¤tModel, 1);
ImGui::Text("objCount : %d", objs.size());
ImGui::Text("- Model Transform -");
//ImGui::SliderFloat3("position", (float*)&(test[currentModel]->position), 0.0f, 100.0f);
ImGui::SliderFloat3("rotation", (float*)&(test[currentModel]->rotation), 0, 2.0f * XM_PI);
ImGui::SliderFloat3("scale", (float*)&(test[currentModel]->scale), 0.0f, 0.1f);
//
if (ImGui::Button("ClearModels", { 128.0f, 32.0f }))
ClearModels();
if (ImGui::Button("SaveModels", { 128.0f, 32.0f }))
SaveModels();
if (ImGui::Button("LoadModels", { 128.0f, 32.0f }))
LoadModels();
}
void ModelEditor::Control()
{
if (ImGui::GetIO().WantCaptureMouse == false)
if(createModel)
if (KEY_UP(VK_LBUTTON))
CreateModel();
}
void ModelEditor::CreateModel()
{
ModelObject* obj = new ModelObject(modelNames[currentModel]);
obj->name = modelNames[currentModel];
obj->position = pickingPos;
obj->rotation = test[currentModel]->rotation;
obj->scale = test[currentModel]->scale;
objs.emplace_back(obj);
}
void ModelEditor::SaveModels()
{
// Create Binary File
HANDLE file;
DWORD write; // unsigned long
file = CreateFile(L"MapFiles/modelData.map", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
{
int count = objs.size();
V(WriteFile(file, &count, sizeof(int), &write, nullptr));
ModelTransformData data{};
for (int i = 0; i < count; ++i)
{
if(objs[i]->name == "amy")
data.modelNum = 0;
else if(objs[i]->name == "xbot")
data.modelNum = 1;
data.position = objs[i]->position;
data.rotation = objs[i]->rotation;
data.scale = objs[i]->scale;
V(WriteFile(file, &data, sizeof(ModelTransformData), &write, nullptr));
}
}
// Save End
CloseHandle(file);
}
void ModelEditor::LoadModels()
{
ClearModels();
// Create Binary File
HANDLE file{};
DWORD read{}; // unsigned long
file = CreateFile(L"MapFiles/modelData.map", GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
{
int count{};
V(ReadFile(file, &count, sizeof(int), &read, nullptr));
//
ModelTransformData data{};
for (int i = 0; i < count; ++i)
{
V(ReadFile(file, &data, sizeof(ModelTransformData), &read, nullptr));
ModelObject* obj = new ModelObject(modelNames[data.modelNum]);
obj->position = data.position;
obj->rotation = data.rotation;
obj->scale = data.scale;
objs.emplace_back(obj);
}
}
// Load End
CloseHandle(file);
}
void ModelEditor::ClearModels()
{
for (ModelObject* obj : objs)
delete obj;
objs.clear();
}
'DX11 3D Game Programming' 카테고리의 다른 글
2020_1102 Model Anim(Jump) & Camera Move(Follow Target) (0) | 2020.11.01 |
---|---|
2020_1029 Model Animation (0) | 2020.10.29 |
2020_1021 Terrain Edit ( Texture Splatting ) (0) | 2020.10.21 |
2020_1020 Terrain Edit ( Terrain Brush ) (0) | 2020.10.20 |
2020_1019 Terrain Edit ( Save & Load ) (0) | 2020.10.19 |