응애맘마조

230614 강의 본문

공부/3D강의

230614 강의

TH.Wert 2023. 6. 14. 20:49

머터리얼에 대해 추가적인 설명이 있었습니다. 어제 너무 급해서 설명을 잘하지 못하고 넘어간 부분이 있었습니다.

#include "stdafx.h"
#include "Main.h"

#include <shlwapi.h>
#pragma comment(lib, "shlwapi.lib")

Main.cpp의 첫 부분입니다. shlwapi인데 경로를 조작할 때 사용하는 API입니다. 백슬래시나 확장자를 덧붙이면서 경로가 없으면 만들거나 이미 있으면 그 경로에 저장하는 API입니다.

size_t tok = file.find_last_of(".");
string filename = file.substr(0, tok);
string checkPath = "../Contents/Texture/" + filename;
    
if (!PathFileExistsA(checkPath.c_str()))
{
	CreateDirectoryA(checkPath.c_str(), NULL);
}
	
string orgin = "../Assets/" + TexName;
string copy = "../Contents/Texture/" + file.substr(0, tok) + "/" + TexName;
bool isCheck = true;
CopyFileA(orgin.c_str(), copy.c_str(), isCheck);
mtlList[name]->diffuseMap = make_shared<Texture>();
mtlList[name]->diffuseMap->LoadFile(filename + "/" + TexName);

size_t tok = file.find_last_of(".");
string filename = file.substr(0, tok);
string checkPath = "../Contents/Material/" + filename;

if (!PathFileExistsA(checkPath.c_str()))
{
	CreateDirectoryA(checkPath.c_str(), NULL);
}

mtlList[name]->SaveFile(filename + "/" + name + ".mtl");

그래서 위의 코드처럼 경로를 설정하였기 때문에 솔루션 파일에서 Asset이나 Contents파일이나 Shader파일에 접근할 수 있었습니다. 크게 중요한 부분은 아니라서 길게 설명하지는 않았었습니다. 이후로도 밑의 코드로도 GUI로 접근하는 코드도 이렇게 경로를 설정하여 세이브나 로드할 수 있도록 되어 있었던 이유입니다. 사실 강의나 과제를 하면서 GUI에 의존성이 굉장히 높기 때문에 작성할 수밖에 없는 코드였습니다.

#pragma once

class MaterialBuffer
{
public:
	Color	ambient;
	Color	diffuse;
	Color	specular;
	Color	emissive;
	float	shininess;
	float	opacity;
	float   environment;
	float	shadow;
};
class Material : public MaterialBuffer
{
	static ID3D11Buffer* materialBuffer;
public:
	static void CreateStaticMember();
	static void DeleteStaticMember();
public:
	shared_ptr<Texture>			normalMap;
	shared_ptr<Texture>			diffuseMap;
	shared_ptr<Texture>			specularMap;
	shared_ptr<Texture>			emissiveMap;
	string					file;
public:
	Material();
	~Material();

	void RenderDetail();
	virtual void Set();
	void LoadFile(string file);
	void SaveFile(string file);
};

다음은 Material의 헤더 파일입니다. 미리 버퍼로 public으로 선언하고 밑의 Material 클래스에서 버퍼를 상속받는 식으로 작성했습니다. shared_ptr로 몇 가지 적었습니다. 사실 위의 public으로는 여러 개 만들어져도 상관이 없습니다. 텍스쳐에 용량이나 연산량이 많아지기 때문에 줄일 수 있으면 줄이는 것이 속도나 효율이 좋다고 볼 수 있습니다.
 
학원 내부의 일정에 따라 6월 15일 목요일과 19일 월요일은 휴무입니다.
읽어주셔서 감사합니다.

'공부 > 3D강의' 카테고리의 다른 글

230620 강의  (0) 2023.06.20
230616 강의  (0) 2023.06.20
230613 강의  (0) 2023.06.13
230612 강의  (0) 2023.06.12
230609 강의  (1) 2023.06.11