finish 8 tutorial

This commit is contained in:
h4570
2022-08-24 18:51:46 +02:00
parent b5147bba3a
commit 5c375dd24f
5 changed files with 108 additions and 8 deletions
+1 -3
View File
@@ -1,7 +1,5 @@
------------ Tyra's v2.0 roadmap to publish on GitHub ------------ ------------ Tyra's v2.0 roadmap to publish on GitHub ------------
- [Renderer] Add decimate to de_dust2
- [Tutorials] 8
- [Tutorials] 9. - [Tutorials] 9.
- [General] Check all left TODOs -> Github issues - [General] Check all left TODOs -> Github issues
@@ -22,7 +20,7 @@
- [General] CI in Github via docker image - [General] CI in Github via docker image
- [MD2] Refactor - [MD2] Refactor
- [2D] Add zbuffer support (z-index) - [2D] Add zbuffer support (z-index)
- [3DUtility] Add zbuffer support (z-index) - [3DUtility] Add zbuffer support (z-index), cupMesh->translation.translateZ(10.0F) - wylaczyc zeby widziec problem
- [2D] Fixed font support - [2D] Fixed font support
- [File] Async file loading - [File] Async file loading
- [tyrdat] Custom 3D data file with precalculated bboxes with support of async loading - [tyrdat] Custom 3D data file with precalculated bboxes with support of async loading
+4 -1
View File
@@ -15,7 +15,10 @@ namespace Tyra {
Tutorial05::Tutorial05(Engine* t_engine) : engine(t_engine) {} Tutorial05::Tutorial05(Engine* t_engine) : engine(t_engine) {}
Tutorial05::~Tutorial05() {} Tutorial05::~Tutorial05() {
engine->renderer.getTextureRepository().freeByMesh(zombieMesh.get());
engine->renderer.getTextureRepository().freeByMesh(warriorMesh.get());
}
void Tutorial05::init() { void Tutorial05::init() {
dynpip.setRenderer(&engine->renderer.core); dynpip.setRenderer(&engine->renderer.core);
@@ -65,6 +65,14 @@ void Tutorial07::loadMeshWithLightmap() {
ObjLoaderOptions options; ObjLoaderOptions options;
options.scale = 2.0F; options.scale = 2.0F;
/**
* Material colors are automatically fetched from .mtl file
* (Kd field)
*
* If you want to change it manually, just try to change
* mesh.materials[].ambient
*/
auto data = ObjLoader::load(FileUtils::fromCwd("cup.obj"), options); auto data = ObjLoader::load(FileUtils::fromCwd("cup.obj"), options);
/** /**
@@ -23,7 +23,20 @@ class Tutorial08 : public Game {
void loop(); void loop();
private: private:
void loadCupMesh();
void loadSkyboxMesh();
Vec4 cameraPosition, cameraLookAt;
Engine* engine; Engine* engine;
u8 fpsCounter;
StaticPipeline stapip;
StaPipOptions skyboxRenderOptions;
StaPipOptions cupRenderOptions;
std::unique_ptr<StaticMesh> skyboxMesh;
std::unique_ptr<StaticMesh> cupMesh;
}; };
} // namespace Tyra } // namespace Tyra
+82 -4
View File
@@ -13,12 +13,90 @@
namespace Tyra { namespace Tyra {
Tutorial08::Tutorial08(Engine* t_engine) : engine(t_engine) {} Tutorial08::Tutorial08(Engine* t_engine) : engine(t_engine), fpsCounter(0) {}
Tutorial08::~Tutorial08() {} Tutorial08::~Tutorial08() {
engine->renderer.getTextureRepository().freeByMesh(skyboxMesh.get());
}
void Tutorial08::init() {} void Tutorial08::init() {
stapip.setRenderer(&engine->renderer.core);
void Tutorial08::loop() {} cameraPosition = Vec4(0.0F, 0.0F, -10.0F);
cameraLookAt.unit();
loadSkyboxMesh();
loadCupMesh();
/** Uncomment this, to disable vsync */
// engine->renderer.setFrameLimit(false);
}
void Tutorial08::loop() {
if (fpsCounter++ > 50) {
fpsCounter = 0;
TYRA_LOG("FPS: ", engine->info.getFps(),
" RAM: ", engine->info.getAvailableRAM());
}
cupMesh->rotation.rotate(Vec4(0.03F, 0.03F, 0.03F));
auto& utilityTools = engine->renderer.renderer3D.utility;
engine->renderer.beginFrame(CameraInfo3D(&cameraPosition, &cameraLookAt));
{
engine->renderer.renderer3D.usePipeline(stapip);
stapip.render(skyboxMesh.get(), skyboxRenderOptions);
stapip.render(cupMesh.get(), cupRenderOptions);
/** Utility drawing should be done AFTER pipeline rendering */
/** Draw cup bbox */
utilityTools.drawBBox(
cupMesh->frame->bbox->getTransformed(cupMesh->getModelMatrix()));
/** Draw line */
utilityTools.drawLine(Vec4(50.0F, 50.0F, 50.0F), *cupMesh->getPosition(),
Color(0.0F, 128.0F, 0.0F));
/** Draw box at origin */
utilityTools.drawBox(Vec4(0.0F, 0.0F, 0.0F), 0.2F,
Color(0.0F, 0.0F, 255.0F));
}
engine->renderer.endFrame();
}
void Tutorial08::loadSkyboxMesh() {
ObjLoaderOptions options;
options.scale = 200.0F;
options.flipUVs = true;
auto data = ObjLoader::load(FileUtils::fromCwd("skybox/skybox.obj"), options);
skyboxMesh = std::make_unique<StaticMesh>(data.get());
skyboxRenderOptions.frustumCulling = Tyra::PipelineFrustumCulling_None;
/**
* We need to put the skybox at infinite Z, so this options
* will help us to do that.
*/
skyboxRenderOptions.zTestType = Tyra::PipelineZTest_AllPass;
engine->renderer.getTextureRepository().addByMesh(
skyboxMesh.get(), FileUtils::fromCwd("skybox/"), "png");
}
void Tutorial08::loadCupMesh() {
ObjLoaderOptions options;
options.scale = 3.0F;
auto data = ObjLoader::load(FileUtils::fromCwd("cup/cup.obj"), options);
data->textureCoordsEnabled = false;
cupMesh = std::make_unique<StaticMesh>(data.get());
cupMesh->translation.translateZ(10.0F);
}
} // namespace Tyra } // namespace Tyra