Add Instanced Rendering / 2 more scenes
This commit is contained in:
@@ -10,48 +10,45 @@
|
||||
#include <iostream>
|
||||
|
||||
|
||||
void DioramaScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr) {
|
||||
|
||||
void DioramaScene::Initialize(ID3D11Device *DevicePtr) {
|
||||
std::vector<std::unique_ptr<Utils::MaterialMesh>> materialMeshes;
|
||||
Utils::LoadObjWithMaterials("resources/scene.obj", materialMeshes, true, DevicePtr);
|
||||
for (const auto &mesh: materialMeshes) {
|
||||
if (mesh->vertices.size() > 0) {
|
||||
std::shared_ptr<Material> material = std::make_shared<Material>();
|
||||
BaseEffect *effect{nullptr};
|
||||
|
||||
std::vector<std::unique_ptr<Utils::MaterialMesh>> materialMeshes;
|
||||
Utils::LoadObjWithMaterials("resources/scene.obj", materialMeshes, true, DevicePtr);
|
||||
for (const auto &mesh: materialMeshes) {
|
||||
if(mesh->vertices.size() > 0) {
|
||||
std::shared_ptr<Material> material = std::make_shared<Material>();
|
||||
BaseEffect *effect{ nullptr };
|
||||
|
||||
if(mesh->opacity_map != ""){
|
||||
// std::cout << "Opacity map found" << mesh->opacity_map << std::endl;
|
||||
effect = new FireEffect(DevicePtr, L"resources/Fire.fx");
|
||||
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/diorama/" + mesh->diffuse_texture, DevicePtr);
|
||||
// material-> = Texture::LoadFromFile("./resources/" + mesh->opacity_map, DevicePtr);
|
||||
} else {
|
||||
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/diorama/" + mesh->diffuse_texture, DevicePtr);
|
||||
effect = new Effect(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||
}
|
||||
|
||||
|
||||
m_meshes.push_back(new Mesh(DevicePtr, mesh->vertices, mesh->indices, material, effect));
|
||||
|
||||
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||
worldMatrix *= Matrix::CreateScale(2.f, 2.f, 2.f);
|
||||
worldMatrix *= Matrix::CreateScale(-1.f, 1.f, 1.f);
|
||||
m_meshes.back()->SetWorldMatrix(worldMatrix);
|
||||
if (mesh->opacity_map != "") {
|
||||
effect = new FireEffect(DevicePtr, L"resources/Fire.fx");
|
||||
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/diorama/" + mesh->diffuse_texture, DevicePtr);
|
||||
} else {
|
||||
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/diorama/" + mesh->diffuse_texture, DevicePtr);
|
||||
effect = new Effect(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||
}
|
||||
}
|
||||
|
||||
m_meshes.push_back(new Mesh(DevicePtr, mesh->vertices, mesh->indices, material, effect));
|
||||
|
||||
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||
worldMatrix *= Matrix::CreateScale(2.f, 2.f, 2.f);
|
||||
worldMatrix *= Matrix::CreateScale(-1.f, 1.f, 1.f); // Mirror the model (Possible loading fault)
|
||||
m_meshes.back()->SetWorldMatrix(worldMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
//Load brok
|
||||
materialMeshes.clear();
|
||||
Utils::LoadObjWithMaterials("resources/brok/brok.obj", materialMeshes, true, DevicePtr);
|
||||
for (const auto &mesh: materialMeshes) {
|
||||
if(mesh->vertices.size() > 0) {
|
||||
if (!mesh->vertices.empty()) {
|
||||
std::shared_ptr<Material> material = std::make_shared<Material>();
|
||||
BaseEffect *effect{ nullptr };
|
||||
BaseEffect *effect{nullptr};
|
||||
|
||||
effect = new Effect(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/brok/" + mesh->diffuse_texture, DevicePtr);
|
||||
|
||||
|
||||
m_meshes.push_back(new Mesh(DevicePtr, mesh->vertices, mesh->indices, material, effect));
|
||||
m_brokMeshses.push_back(m_meshes.back());
|
||||
|
||||
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||
worldMatrix *= Matrix::CreateRotationY(3.14f / 2.f);
|
||||
@@ -63,6 +60,27 @@ void DioramaScene::Initialize(ID3D11Device *DevicePtr) {
|
||||
}
|
||||
}
|
||||
|
||||
void DioramaScene::Update() {
|
||||
m_brokTimer += 0.01f;
|
||||
for(auto* mesh : m_brokMeshses){
|
||||
if(mesh == nullptr)
|
||||
continue;
|
||||
Matrix worldMatrix = mesh->GetWorldMatrix();
|
||||
|
||||
float YOffset = sin(m_brokTimer) / 2000.f;
|
||||
|
||||
worldMatrix *= Matrix::CreateTranslation(0.f, YOffset, 0.f);
|
||||
|
||||
mesh->SetWorldMatrix(worldMatrix);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DioramaScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView *renderTargetViewPtr,
|
||||
ID3D11DepthStencilView *depthStencilViewPtr, const Camera &camera) {
|
||||
|
||||
}
|
||||
|
||||
std::vector<Mesh *> &DioramaScene::GetMeshes() {
|
||||
return m_meshes;
|
||||
}
|
||||
@@ -72,7 +90,7 @@ std::vector<std::shared_ptr<Material>> &DioramaScene::GetMaterials() {
|
||||
}
|
||||
|
||||
void DioramaScene::Cleanup() {
|
||||
for (Mesh *mesh : m_meshes) {
|
||||
for (Mesh *mesh: m_meshes) {
|
||||
delete mesh;
|
||||
}
|
||||
m_meshes.clear();
|
||||
|
||||
Reference in New Issue
Block a user