tutorial 04

This commit is contained in:
h4570
2022-08-22 23:23:51 +02:00
parent 4fa65fc535
commit d469e78747
26 changed files with 400 additions and 96 deletions
+45 -6
View File
@@ -13,25 +13,64 @@
namespace Tyra {
Tutorial04::Tutorial04(Engine* t_engine) : engine(t_engine) {}
Tutorial04::Tutorial04(Engine* t_engine)
: engine(t_engine), camera(&t_engine->pad) {}
Tutorial04::~Tutorial04() {
engine->renderer.getTextureRepository().freeByMesh(mesh.get());
}
void Tutorial04::init() { loadMesh(); }
void Tutorial04::init() {
stapip.setRenderer(&engine->renderer.core);
loadMesh();
}
void Tutorial04::loop() {}
void Tutorial04::loop() {
/** Update camera's lookAt and position */
camera.update();
engine->renderer.beginFrame(camera.getCameraInfo());
{
/** Upload static pipeline's VU1 programs */
engine->renderer.renderer3D.usePipeline(stapip);
/**
* Render de_dust2.
*
* As you see there are clipping issues (visual glitches).
* If you want to know how to fix it, please
* watch video tutorial.
*/
stapip.render(mesh.get(), renderOptions);
}
engine->renderer.endFrame();
}
void Tutorial04::loadMesh() {
ObjLoader loader;
ObjLoaderOptions options;
options.flipUVs = true;
options.scale = 200.0F;
auto data = loader.load(FileUtils::fromCwd("de_dust2/de_dust2.obj"), options);
/**
* Load mesh data
* Texture names are the material names "usemtl <material name>"
*/
auto data =
ObjLoader::load(FileUtils::fromCwd("de_dust2/de_dust2.obj"), options);
/** Create mesh with loaded data */
mesh = std::make_unique<StaticMesh>(data.get());
/**
* Disable frustum culling in render options,
* because it not make sense to perform
* frustum check on entire map (which will be always visible)
*/
renderOptions.frustumCulling = Tyra::PipelineFrustumCulling_None;
/**
* Function which load all textures into texture repository,
* based on material names.
*/
engine->renderer.getTextureRepository().addByMesh(
mesh.get(), FileUtils::fromCwd("de_dust2/"), "png");
}