Skip to content

Commit e985399

Browse files
committed
Finished modelc and loader function
1 parent e93dbdf commit e985399

File tree

15 files changed

+331
-5519
lines changed

15 files changed

+331
-5519
lines changed

dependencies/assimp

Submodule assimp updated 1124 files

dependencies/versions.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
assimp 4.1.0
1+
assimp 5.0.0.rc1
22
bullet 2.87
33
entt 3.0.0
44
glfw 3.3

igneous/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ set(INCLUDES
4444
include/igneous/renderer/fpsCamera.hpp
4545
include/igneous/renderer/model.hpp
4646
include/igneous/renderer/renderer.hpp
47-
include/igneous/renderer/renderer.inl
48-
include/igneous/renderer/vertex.hpp
4947
)
5048

5149
set(AMALGAMATED_INCLUDES

igneous/include/igneous/renderer.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,3 @@
77
#include "igneous/renderer/fpsCamera.hpp"
88
#include "igneous/renderer/model.hpp"
99
#include "igneous/renderer/renderer.hpp"
10-
#include "igneous/renderer/renderer.inl"
11-
#include "igneous/renderer/vertex.hpp"

igneous/include/igneous/renderer/renderer.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ namespace renderer
2020
bgfx::ShaderHandle loadShader(const char* shader);
2121
bgfx::ProgramHandle loadProgram(const char* vs, const char* fs);
2222

23-
template<typename VertexType>
24-
Model* loadModel(std::string path, bgfx::ProgramHandle program = BGFX_INVALID_HANDLE);
23+
ModelHandle loadModel(std::string path, bgfx::ProgramHandle program);
2524

2625
void render();
2726
void screenshot();
@@ -41,5 +40,3 @@ namespace renderer
4140
extern std::map<std::string, Model*> models;
4241
}
4342
} // end namespace igneous
44-
45-
#include "igneous/renderer/renderer.inl"

igneous/include/igneous/renderer/renderer.inl

Lines changed: 0 additions & 152 deletions
This file was deleted.

igneous/include/igneous/renderer/vertex.hpp

Lines changed: 0 additions & 62 deletions
This file was deleted.

igneous/src/physics/debugRenderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace physics
7676
bgfx::setVertexBuffer(0, vb);
7777
bgfx::IndexBufferHandle ib = bgfx::createIndexBuffer(bgfx::makeRef(debugIndicies.data(), (uint32_t)debugIndicies.size() * sizeof(uint16_t)));
7878
bgfx::setIndexBuffer(ib);
79-
bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_PT_LINES | BGFX_STATE_LINEAA);
79+
bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_PT_LINES | BGFX_STATE_LINEAA | BGFX_STATE_POINT_SIZE(3));
8080
bgfx::setViewRect(100, 0, 0, input::width, input::height);
8181
bgfx::submit(100, debugProgram);
8282
bgfx::destroy(vb);

igneous/src/physics/physics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace physics
3838

3939
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
4040

41-
dynamicsWorld->setGravity(btVector3(0, -10.0f, 0));
41+
dynamicsWorld->setGravity(btVector3(0, 0.0f, 0));
4242
dynamicsWorld->debugDrawWorld();
4343

4444
identityTransform.setFromOpenGLMatrix(glm::value_ptr(glm::identity<glm::mat4>()));

igneous/src/renderer/renderer.cpp

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <bgfx/platform.h>
99

1010
#include "igneous/core/log.hpp"
11-
#include "igneous/renderer/vertex.hpp"
1211
#include "splash_assets.h"
1312
#include "igneous/ecs/components/transformationComponent.hpp"
1413
#include "igneous/console/console.hpp"
@@ -119,9 +118,6 @@ namespace renderer
119118
bgfx::destroy(s_splash);
120119
bgfx::destroy(splashProgram);
121120

122-
Vertex::init();
123-
GenericVertex::init();
124-
125121
console::command("screenshot", screenshotCallback);
126122
console::bind(IG_KEY_F2, "screenshot");
127123
recording = &console::variable("recording", false, recordingCallback);
@@ -277,6 +273,97 @@ namespace renderer
277273
return bgfx::createProgram(loadShader(vsPath), loadShader(fsPath), true);
278274
}
279275

276+
ModelHandle loadModel(std::string path, bgfx::ProgramHandle program)
277+
{
278+
std::ifstream file(path, std::ios::in | std::ios::binary);
279+
if (file.fail())
280+
{
281+
IG_CORE_CRITICAL("Could not open model file: {}", path);
282+
}
283+
284+
file.seekg(sizeof(uint64_t), std::ios::beg);
285+
uint8_t numAttributes;
286+
file.read((char*)&numAttributes, sizeof(uint8_t));
287+
bgfx::VertexDecl vertexDecl;
288+
vertexDecl.begin();
289+
for (int i = 0; i < numAttributes; i++)
290+
{
291+
uint8_t attribute;
292+
file.read((char*)&attribute, sizeof(uint8_t));
293+
294+
if (attribute == bgfx::Attrib::Position)
295+
{
296+
vertexDecl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
297+
}
298+
else if (attribute == bgfx::Attrib::Normal)
299+
{
300+
vertexDecl.add(bgfx::Attrib::Normal, 3, bgfx::AttribType::Float);
301+
}
302+
else if (attribute == bgfx::Attrib::Tangent)
303+
{
304+
vertexDecl.add(bgfx::Attrib::Tangent, 3, bgfx::AttribType::Float);
305+
}
306+
else if (attribute == bgfx::Attrib::Bitangent)
307+
{
308+
vertexDecl.add(bgfx::Attrib::Bitangent, 3, bgfx::AttribType::Float);
309+
}
310+
else if (attribute >= bgfx::Attrib::TexCoord0 && attribute <= bgfx::Attrib::TexCoord7)
311+
{
312+
vertexDecl.add((bgfx::Attrib::Enum)attribute, 2, bgfx::AttribType::Float);
313+
}
314+
else if (attribute >= bgfx::Attrib::Color0 && attribute <= bgfx::Attrib::Color3)
315+
{
316+
vertexDecl.add((bgfx::Attrib::Enum)attribute, 4, bgfx::AttribType::Uint8, true);
317+
}
318+
}
319+
vertexDecl.end();
320+
321+
unsigned int numMeshes;
322+
file.read((char*)&numMeshes, sizeof(unsigned int));
323+
324+
int pos = file.tellg();
325+
326+
uint32_t modelSize = 0;
327+
for (int i = 0; i < numMeshes; i++)
328+
{
329+
unsigned int numVerticies;
330+
unsigned int numIndicies;
331+
file.read((char*)&numVerticies, sizeof(unsigned int));
332+
file.read((char*)&numIndicies, sizeof(unsigned int));
333+
modelSize += (uint32_t)numVerticies * (uint32_t)vertexDecl.getStride() + (uint32_t)numIndicies * sizeof(uint16_t);
334+
}
335+
336+
const void* modelData = malloc(modelSize);
337+
file.read((char*)modelData, modelSize);
338+
339+
file.seekg(pos, std::ios::beg);
340+
341+
std::vector<Mesh> meshes;
342+
uint32_t amountRead = 0;
343+
for (int i = 0; i < numMeshes; i++)
344+
{
345+
unsigned int numVerticies;
346+
unsigned int numIndicies;
347+
file.read((char*)&numVerticies, sizeof(unsigned int));
348+
file.read((char*)&numIndicies, sizeof(unsigned int));
349+
uint32_t verticiesSize = (uint32_t)numVerticies * (uint32_t)vertexDecl.getStride();
350+
uint32_t indiciesSize = (uint32_t)numIndicies * sizeof(uint16_t);
351+
Mesh mesh;
352+
mesh.vbh = bgfx::createVertexBuffer(bgfx::makeRef((uint8_t*)modelData + amountRead, verticiesSize), vertexDecl);
353+
amountRead += verticiesSize;
354+
mesh.ibh = bgfx::createIndexBuffer(bgfx::makeRef((uint8_t*)modelData + amountRead, indiciesSize));
355+
amountRead += indiciesSize;
356+
357+
meshes.push_back(mesh);
358+
}
359+
360+
Model* model = new Model;
361+
model->meshes = meshes;
362+
model->program = program;
363+
364+
return model;
365+
}
366+
280367
void reset()
281368
{
282369
bgfx::reset(input::width, input::height, flags);
@@ -379,6 +466,4 @@ namespace renderer
379466
IG_CORE_INFO("Renderer Shutdown");
380467
}
381468
}
382-
383-
bgfx::VertexDecl Vertex::ms_decl;
384469
} // end namespace igneous

0 commit comments

Comments
 (0)