tutorial 04
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "../../loader.hpp"
|
||||
#include "../builder/mesh_builder_data.hpp"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
@@ -24,13 +25,12 @@ struct MD2LoaderOptions {
|
||||
/** Class responsible for loading & parsing Quake's II ".md2" 3D files */
|
||||
class MD2Loader : public Loader {
|
||||
public:
|
||||
MD2Loader();
|
||||
~MD2Loader();
|
||||
|
||||
MeshBuilderData* load(const char* fullpath);
|
||||
MeshBuilderData* load(const char* fullpath, MD2LoaderOptions options);
|
||||
MeshBuilderData* load(const std::string& fullpath);
|
||||
MeshBuilderData* load(const std::string& fullpath, MD2LoaderOptions options);
|
||||
static std::unique_ptr<MeshBuilderData> load(const char* fullpath);
|
||||
static std::unique_ptr<MeshBuilderData> load(const char* fullpath,
|
||||
MD2LoaderOptions options);
|
||||
static std::unique_ptr<MeshBuilderData> load(const std::string& fullpath);
|
||||
static std::unique_ptr<MeshBuilderData> load(const std::string& fullpath,
|
||||
MD2LoaderOptions options);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
|
||||
@@ -38,32 +38,30 @@ struct MaterialVertexCount {
|
||||
/** Class responsible for loading & parsing obj files */
|
||||
class ObjLoader : public Loader {
|
||||
public:
|
||||
ObjLoader();
|
||||
~ObjLoader();
|
||||
|
||||
std::unique_ptr<MeshBuilderData> load(const char* fullpath);
|
||||
std::unique_ptr<MeshBuilderData> load(const char* fullpath,
|
||||
const ObjLoaderOptions& options);
|
||||
std::unique_ptr<MeshBuilderData> load(const std::string& fullpath);
|
||||
std::unique_ptr<MeshBuilderData> load(const std::string& fullpath,
|
||||
const ObjLoaderOptions& options);
|
||||
static std::unique_ptr<MeshBuilderData> load(const char* fullpath);
|
||||
static std::unique_ptr<MeshBuilderData> load(const char* fullpath,
|
||||
const ObjLoaderOptions& options);
|
||||
static std::unique_ptr<MeshBuilderData> load(const std::string& fullpath);
|
||||
static std::unique_ptr<MeshBuilderData> load(const std::string& fullpath,
|
||||
const ObjLoaderOptions& options);
|
||||
|
||||
private:
|
||||
void addOutputMaterialsAndFrames(
|
||||
static void addOutputMaterialsAndFrames(
|
||||
MeshBuilderData* output, const tinyobj::attrib_t& attrib,
|
||||
const std::vector<tinyobj::shape_t>& shapes,
|
||||
const std::vector<tinyobj::material_t>& materials, const u16& framesCount,
|
||||
std::vector<MaterialVertexCount>& materialVertexCounts);
|
||||
|
||||
std::vector<MaterialVertexCount> scan(
|
||||
static std::vector<MaterialVertexCount> scan(
|
||||
const std::vector<tinyobj::shape_t>& shapes,
|
||||
const std::vector<tinyobj::material_t>& materials);
|
||||
|
||||
void importFrame(MeshBuilderData* output, const tinyobj::attrib_t& attrib,
|
||||
const std::vector<tinyobj::shape_t>& shapes,
|
||||
const std::vector<tinyobj::material_t>& materials,
|
||||
const u16& frameIndex, const float& scale,
|
||||
const bool& invertY, const u16& count);
|
||||
static void importFrame(MeshBuilderData* output,
|
||||
const tinyobj::attrib_t& attrib,
|
||||
const std::vector<tinyobj::shape_t>& shapes,
|
||||
const std::vector<tinyobj::material_t>& materials,
|
||||
const u16& frameIndex, const float& scale,
|
||||
const bool& invertY, const u16& count);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
|
||||
@@ -16,10 +16,10 @@ namespace Tyra {
|
||||
|
||||
class Loader {
|
||||
protected:
|
||||
std::string getFilenameFromPath(const std::string& path);
|
||||
std::string getPathFromFilename(const std::string& path);
|
||||
std::string getFilenameWithoutExtension(const std::string& filename);
|
||||
std::string getExtensionOfFilename(const std::string& filename);
|
||||
static std::string getFilenameFromPath(const std::string& path);
|
||||
static std::string getPathFromFilename(const std::string& path);
|
||||
static std::string getFilenameWithoutExtension(const std::string& filename);
|
||||
static std::string getExtensionOfFilename(const std::string& filename);
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
|
||||
@@ -39,13 +39,16 @@ class DynamicPipeline : public Renderer3DPipeline {
|
||||
|
||||
void onUse();
|
||||
|
||||
void onFrameEnd();
|
||||
|
||||
void onUseEnd();
|
||||
|
||||
/**
|
||||
* Render dynamic model.
|
||||
* This render() method is a bridge to core.render() method.
|
||||
*/
|
||||
void render(const DynamicMesh& mesh, const DynPipOptions* options = nullptr);
|
||||
void render(const DynamicMesh* mesh);
|
||||
void render(const DynamicMesh* mesh, const DynPipOptions& options);
|
||||
void render(const DynamicMesh* mesh, const DynPipOptions* options = nullptr);
|
||||
|
||||
private:
|
||||
|
||||
@@ -33,6 +33,7 @@ class MinecraftPipeline : public Renderer3DPipeline {
|
||||
|
||||
void onUse();
|
||||
void onUseEnd();
|
||||
void onFrameEnd();
|
||||
|
||||
/**
|
||||
* @brief Render voxels
|
||||
|
||||
@@ -21,6 +21,7 @@ class Renderer3DPipeline {
|
||||
|
||||
virtual void setRenderer(RendererCore* core) = 0;
|
||||
virtual void onUse() = 0;
|
||||
virtual void onFrameEnd() = 0;
|
||||
virtual void onUseEnd() = 0;
|
||||
std::function<void(Renderer3DPipeline*)> onDestroy;
|
||||
};
|
||||
|
||||
@@ -28,7 +28,8 @@ class StaPipCore {
|
||||
void init(RendererCore* t_core);
|
||||
|
||||
/** Render 3D via "bags" */
|
||||
void render(StaPipBag* bag, StaPipBagPackagesBBox* bbox = nullptr);
|
||||
void render(StaPipBag* bag, StaPipBagPackagesBBox* bbox,
|
||||
const u32& maxVertCount);
|
||||
|
||||
/** Get max vert count of VU1 qbuffer (for optimizations) */
|
||||
u32 getMaxVertCountByParams(const bool& isSingleColor,
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
# _____ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licensed under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include "core/bag/packaging/stapip_bag_packages_bbox.hpp"
|
||||
#include "renderer/3d/mesh/mesh.hpp"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
struct StapipBagBBoxesCacheItem {
|
||||
u32 vu1MaxVertCount;
|
||||
u32 frameId;
|
||||
std::unique_ptr<StaPipBagPackagesBBox> bboxes;
|
||||
int framesLeftToDestroy;
|
||||
};
|
||||
|
||||
class StapipBagBBoxesCacher {
|
||||
public:
|
||||
StapipBagBBoxesCacher();
|
||||
~StapipBagBBoxesCacher();
|
||||
|
||||
const int cacheFramesCount = 50;
|
||||
const int cacheSecondsCount = 5;
|
||||
|
||||
void onFrameEnd();
|
||||
|
||||
StaPipBagPackagesBBox* getBBoxesByMesh(const MeshMaterialFrame* frame,
|
||||
const u32& maxVertCount);
|
||||
|
||||
private:
|
||||
StapipBagBBoxesCacheItem* getCache(const u32& maxVertCount,
|
||||
const u32& frameId);
|
||||
|
||||
std::vector<StapipBagBBoxesCacheItem> storage;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "renderer/3d/mesh/static/static_mesh.hpp"
|
||||
#include "./core/stapip_core.hpp"
|
||||
#include "./stapip_options.hpp"
|
||||
#include "./stapip_bag_bboxes_cacher.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
@@ -38,17 +39,19 @@ class StaticPipeline : public Renderer3DPipeline {
|
||||
void setRenderer(RendererCore* core);
|
||||
|
||||
void onUse();
|
||||
|
||||
void onUseEnd();
|
||||
void onFrameEnd();
|
||||
|
||||
/**
|
||||
* Render static model
|
||||
* This render() method is a bridge to core.render() method.
|
||||
*/
|
||||
void render(const StaticMesh& mesh, const StaPipOptions* options = nullptr);
|
||||
void render(const StaticMesh* mesh);
|
||||
void render(const StaticMesh* mesh, const StaPipOptions& options);
|
||||
void render(const StaticMesh* mesh, const StaPipOptions* options = nullptr);
|
||||
|
||||
private:
|
||||
StapipBagBBoxesCacher cacher;
|
||||
RendererCore* rendererCore;
|
||||
Vec4* colorsCache;
|
||||
|
||||
@@ -65,6 +68,7 @@ class StaticPipeline : public Renderer3DPipeline {
|
||||
const MeshMaterialFrame* materialFrame);
|
||||
|
||||
StaPipLightingBag* getLightingBag(const MeshMaterialFrame* materialFrame,
|
||||
PipelineDirLightsBag* dirLightsBag,
|
||||
M4x4* model,
|
||||
const StaPipOptions* options) const;
|
||||
|
||||
|
||||
@@ -23,12 +23,16 @@ class Renderer3D {
|
||||
|
||||
Renderer3DUtility utility;
|
||||
|
||||
void init(RendererCore* core);
|
||||
|
||||
/** Deinitialize previous pipeline and initialize new pipeline */
|
||||
void usePipeline(Renderer3DPipeline* pipeline);
|
||||
void usePipeline(Renderer3DPipeline& pipeline);
|
||||
|
||||
/** Called by engine */
|
||||
void init(RendererCore* core);
|
||||
|
||||
/** Called by engine */
|
||||
void onFrameEnd();
|
||||
|
||||
private:
|
||||
Renderer3DPipeline* currentPipeline;
|
||||
void onDestroy(Renderer3DPipeline* pipeline);
|
||||
|
||||
@@ -22,8 +22,8 @@ class RendererSettings {
|
||||
height(448.0F),
|
||||
interlacedHeightF(height / 2),
|
||||
near(0.1F),
|
||||
far(4096.0F),
|
||||
projectionScale(4096.0F),
|
||||
far(8192.0F),
|
||||
projectionScale(8192.0F),
|
||||
aspectRatio(width / height),
|
||||
interlacedHeightUI(static_cast<unsigned int>(interlacedHeightF)) {}
|
||||
~RendererSettings();
|
||||
|
||||
Reference in New Issue
Block a user