Can now load gltf models (but not display them yet)
parent
8b2dc08ec3
commit
a51c1936f2
|
@ -732,7 +732,7 @@ typedef bool (*LoadImageDataFunction)(Image *, std::string *, int, int,
|
||||||
|
|
||||||
#ifndef TINYGLTF_NO_STB_IMAGE
|
#ifndef TINYGLTF_NO_STB_IMAGE
|
||||||
// Declaration of default image loader callback
|
// Declaration of default image loader callback
|
||||||
static bool LoadImageData(Image *image, std::string *err, int req_width,
|
bool LoadImageData(Image *image, std::string *err, int req_width,
|
||||||
int req_height, const unsigned char *bytes, int size,
|
int req_height, const unsigned char *bytes, int size,
|
||||||
void *);
|
void *);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1197,7 +1197,7 @@ void TinyGLTF::SetImageLoader(LoadImageDataFunction func, void *user_data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TINYGLTF_NO_STB_IMAGE
|
#ifndef TINYGLTF_NO_STB_IMAGE
|
||||||
static bool LoadImageData(Image *image, std::string *err, int req_width,
|
bool LoadImageData(Image *image, std::string *err, int req_width,
|
||||||
int req_height, const unsigned char *bytes, int size,
|
int req_height, const unsigned char *bytes, int size,
|
||||||
void *) {
|
void *) {
|
||||||
int w, h, comp;
|
int w, h, comp;
|
||||||
|
|
|
@ -5,6 +5,7 @@ INCLUDE_DIRECTORIES (
|
||||||
ADD_LIBRARY (RenderModule SHARED
|
ADD_LIBRARY (RenderModule SHARED
|
||||||
RenderModule.cc
|
RenderModule.cc
|
||||||
RenderUtils.cc
|
RenderUtils.cc
|
||||||
|
gltf_implementation.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
ADD_LIBRARY (TestModule SHARED
|
ADD_LIBRARY (TestModule SHARED
|
||||||
|
|
|
@ -10,8 +10,13 @@
|
||||||
|
|
||||||
using namespace SimpleMath::GL;
|
using namespace SimpleMath::GL;
|
||||||
|
|
||||||
|
typedef tinygltf::Model Model;
|
||||||
|
typedef tinygltf::TinyGLTF GLTFLoader;
|
||||||
|
|
||||||
struct Renderer;
|
struct Renderer;
|
||||||
|
|
||||||
|
float moving_factor = 1.0f;
|
||||||
|
|
||||||
struct RendererSettings {
|
struct RendererSettings {
|
||||||
bool DrawDepth = false;
|
bool DrawDepth = false;
|
||||||
bool DrawLightDepth = false;
|
bool DrawLightDepth = false;
|
||||||
|
@ -59,6 +64,9 @@ VertexArrayMesh gXZPlaneMesh;
|
||||||
VertexArrayMesh gUnitCubeMesh;
|
VertexArrayMesh gUnitCubeMesh;
|
||||||
VertexArrayMesh gScreenQuad;
|
VertexArrayMesh gScreenQuad;
|
||||||
|
|
||||||
|
Model gModel;
|
||||||
|
GLTFLoader gLoader;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Module
|
// Module
|
||||||
//
|
//
|
||||||
|
@ -386,6 +394,16 @@ void Renderer::Initialize(int width, int height) {
|
||||||
mLight.mShadowMapTarget.mQuadMesh = &gScreenQuad;
|
mLight.mShadowMapTarget.mQuadMesh = &gScreenQuad;
|
||||||
mLight.mShadowMapTarget.mLinearizeDepthProgram = mRenderQuadProgramDepth;
|
mLight.mShadowMapTarget.mLinearizeDepthProgram = mRenderQuadProgramDepth;
|
||||||
mLight.mShadowMapTarget.mLinearizeDepthProgram.RegisterFileModification();
|
mLight.mShadowMapTarget.mLinearizeDepthProgram.RegisterFileModification();
|
||||||
|
|
||||||
|
// Model
|
||||||
|
std::string model_file = "data/models/Cube/Cube.gltf";
|
||||||
|
std::string err;
|
||||||
|
bool result = gLoader.LoadASCIIFromFile(&gModel, &err, model_file.c_str());
|
||||||
|
if (!err.empty()) {
|
||||||
|
gLog("Error loading model '%s': %s", model_file.c_str(), err.c_str());
|
||||||
|
} else {
|
||||||
|
gLog("Successfully loaded model '%s'", model_file.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::Shutdown() {
|
void Renderer::Shutdown() {
|
||||||
|
@ -539,7 +557,7 @@ void Renderer::RenderScene(RenderProgram &program, const Camera& camera) {
|
||||||
|
|
||||||
program.SetMat44("uModelMatrix",
|
program.SetMat44("uModelMatrix",
|
||||||
RotateMat44(200.0f, 0.0f, 1.0f, 0.0f)
|
RotateMat44(200.0f, 0.0f, 1.0f, 0.0f)
|
||||||
* TranslateMat44(-2.0f, 1.0f, -8.0f)
|
* TranslateMat44(moving_factor * sin(gTimer->mCurrentTime), 1.0f, 0.0f)
|
||||||
* ScaleMat44(0.5f, 0.5f, 0.5f));
|
* ScaleMat44(0.5f, 0.5f, 0.5f));
|
||||||
|
|
||||||
program.SetVec4("uColor", Vector4f (1.0f, 1.0f, 1.0f, 1.0f));
|
program.SetVec4("uColor", Vector4f (1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
|
@ -582,6 +600,9 @@ void Renderer::RenderGui() {
|
||||||
ImGui::EndDock();
|
ImGui::EndDock();
|
||||||
|
|
||||||
if (ImGui::BeginDock("Render Settings")) {
|
if (ImGui::BeginDock("Render Settings")) {
|
||||||
|
ImGui::Text("Scene");
|
||||||
|
ImGui::SliderFloat("Moving Factor", &moving_factor, -10.0f, 10.0f);
|
||||||
|
|
||||||
ImGui::Text("Camera");
|
ImGui::Text("Camera");
|
||||||
mCamera.DrawGui();
|
mCamera.DrawGui();
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,6 @@
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
#include "imgui_dock.h"
|
#include "imgui_dock.h"
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
|
||||||
|
|
||||||
#include "stb/stb_image.h"
|
|
||||||
|
|
||||||
using namespace SimpleMath;
|
using namespace SimpleMath;
|
||||||
using namespace SimpleMath::GL;
|
using namespace SimpleMath::GL;
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
#include "FileModificationObserver.h"
|
#include "FileModificationObserver.h"
|
||||||
|
|
||||||
|
#include "tinygltf/tiny_gltf.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
|
@ -288,7 +290,7 @@ struct Texture {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Multiple VertexArrayMeshes can be stored in a single VertexArray.
|
* Storage for (multiple) VertexArrayMeshes
|
||||||
* Storage order is:
|
* Storage order is:
|
||||||
* (VVVV)(NNNN)(UV)(CCCC)
|
* (VVVV)(NNNN)(UV)(CCCC)
|
||||||
*/
|
*/
|
||||||
|
@ -413,4 +415,17 @@ struct VertexArrayMesh {
|
||||||
void Draw(GLenum mode);
|
void Draw(GLenum mode);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct RenderCommand {
|
||||||
|
typedef enum {
|
||||||
|
EnableShadowPass = 1
|
||||||
|
} Flags;
|
||||||
|
|
||||||
|
int mFlags;
|
||||||
|
GLenum mDrawMode;
|
||||||
|
Vector4f mColor = Vector4f (1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
|
Matrix44f mTransform;
|
||||||
|
VertexArrayMesh *mMesh;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
#define TINYGLTF_IMPLEMENTATION
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
//#include "stb/stb_image.h"
|
||||||
|
#include "tinygltf/tiny_gltf.h"
|
Loading…
Reference in New Issue