Skip to content

Commit

Permalink
refine
Browse files Browse the repository at this point in the history
Former-commit-id: 4fc0b09
  • Loading branch information
Xayah-Hina committed Jun 5, 2022
1 parent 88194bd commit a19286c
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 27 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.15)
project(HinaGUI)

set(CMAKE_CXX_STANDARD 17)

include(cmake/mymacros.cmake)
Expand Down
2 changes: 1 addition & 1 deletion HinaGUI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
find_package(Assimp REQUIRED)

set(DEPENDENCY_LIB libimgui libglad ${ASSIMP_LIBRARIES})
file(GLOB_RECURSE HINA_GUI_SRC *.h *.cpp)
file(GLOB_RECURSE HINA_GUI_SRC CONFIGURE_DEPENDS *.h *.cpp)
add_library(HinaGUI ${HINA_GUI_SRC})
target_include_directories(HinaGUI PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(HinaGUI PRIVATE ${DEPENDENCY_LIB})
Expand Down
13 changes: 11 additions & 2 deletions HinaGUI/core/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ struct Face
class Mesh
{
public:
HINA_INLINE void init(unsigned int *data, size_t size, unsigned int vertices_per_face = 3)
HINA_INLINE void init(unsigned int *data, size_t size, const std::vector<unsigned int> &textures_id, unsigned int vertices_per_face = 3)
{
indices_.resize(size);
for (size_t i = 0; i < size; ++i, ++data)
indices_[i] = *data;
textures_id_ = textures_id;
}

HINA_INLINE void del()
HINA_INLINE void clear()
{
indices_.clear();
vertices_.clear();
Expand All @@ -59,6 +60,14 @@ class Mesh
std::vector<Vertex> vertices_;
std::vector<Edge> edges_;
std::vector<Face> faces_;

std::vector<unsigned int> textures_id_;
};

#endif //HINAGUI_MESH_H






19 changes: 13 additions & 6 deletions HinaGUI/core/particles.h → HinaGUI/core/particles_pool.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef HINAGUI_PARTICLES_H
#define HINAGUI_PARTICLES_H
#ifndef HINAGUI_PARTICLES_POOL_H
#define HINAGUI_PARTICLES_POOL_H

#include "defines.h"

#include <vector>

class Particles
class ParticlesPool
{
public:
HINA_INLINE size_t init(Vector3r *data, size_t size)
Expand All @@ -20,13 +20,16 @@ class Particles
return start;
}

HINA_INLINE void del(unsigned int vertices_start_offset, unsigned int vertices_size)
HINA_INLINE void emplace_back(const Vector3r &particle)
{ particles_.emplace_back(particle); }

HINA_INLINE void clear(unsigned int vertices_start_offset, unsigned int vertices_size)
{
for (unsigned int i = 0u; i < vertices_size; ++i)
particles_[i + vertices_start_offset] = Vector3r(REAL_MAX, REAL_MAX, REAL_MAX);
}

HINA_INLINE void del()
HINA_INLINE void clear()
{ particles_.clear(); }

public:
Expand All @@ -47,6 +50,10 @@ class Particles

protected:
std::vector<Vector3r> particles_;
std::vector<Vector3r> normals_;
std::vector<Vector2r> tex_coords_;
std::vector<Vector3r> tangent_;
std::vector<Vector3r> bi_tangent_;
};

#endif //HINAGUI_PARTICLES_H
#endif //HINAGUI_PARTICLES_POOL_H
17 changes: 8 additions & 9 deletions HinaGUI/core/renderable.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@

#include "defines.h"

#include "particles.h"
#include "particles_pool.h"
#include "mesh.h"
#include "texture.h"

class Renderable
{
public: // STATIC
static Particles &particles()
static ParticlesPool &particles()
{ return particles_; };

public:
virtual unsigned int load_from_model() = 0;
virtual unsigned int register_to_renderer() = 0;

public:
HINA_INLINE void init(unsigned int vertices_start_offset, unsigned int vertices_size, Mesh *mesh, const std::vector<unsigned int> &textures_id)
HINA_INLINE void init(unsigned int vertices_size, Mesh *mesh)
{
vertices_start_offset_ = vertices_start_offset;
vertices_start_offset_ = particles().size();
vertices_size_ = vertices_size;
mesh_ = mesh;
textures_id_ = textures_id;
}

HINA_INLINE void del()
{
mesh_->del();
textures_id_.clear();
mesh_->clear();
delete mesh_;
}

protected:
Expand All @@ -39,11 +39,10 @@ class Renderable
DONT_RENDER = 1 << 2
} RENDERING_MODE = FILL;

static Particles particles_;
static ParticlesPool particles_;
unsigned int vertices_start_offset_;
unsigned int vertices_size_;
Mesh *mesh_;
std::vector<unsigned int> textures_id_;
};

#endif //HINAGUI_RENDERABLE_H
16 changes: 10 additions & 6 deletions HinaGUI/core/shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

class Shader
{
public:
Shader(Shader const &) = delete;
Shader &operator=(Shader const &) = delete;

public:
virtual void init(const std::string &vertex_shader, const std::string &fragment_shader, const std::string &geometry_shader) = 0;
virtual void use() = 0;
Expand All @@ -14,12 +18,12 @@ class Shader
virtual void set_shader_var_bool(const std::string &name, bool value) = 0;
virtual void set_shader_var_int(const std::string &name, int value) = 0;
virtual void set_shader_var_float(const std::string &name, float value) = 0;
virtual void set_shader_var_vec2(const std::string &name, const Vector2r& value) = 0;
virtual void set_shader_var_vec3(const std::string &name, const Vector3r& value) = 0;
virtual void set_shader_var_vec4(const std::string &name, const Vector4r& value) = 0;
virtual void set_shader_var_mat2(const std::string &name, const Matrix2r& value) = 0;
virtual void set_shader_var_mat3(const std::string &name, const Matrix3r& value) = 0;
virtual void set_shader_var_mat4(const std::string &name, const Matrix4r& value) = 0;
virtual void set_shader_var_vec2(const std::string &name, const Vector2r &value) = 0;
virtual void set_shader_var_vec3(const std::string &name, const Vector3r &value) = 0;
virtual void set_shader_var_vec4(const std::string &name, const Vector4r &value) = 0;
virtual void set_shader_var_mat2(const std::string &name, const Matrix2r &value) = 0;
virtual void set_shader_var_mat3(const std::string &name, const Matrix3r &value) = 0;
virtual void set_shader_var_mat4(const std::string &name, const Matrix4r &value) = 0;
};

#endif //HINAGUI_SHADER_H
42 changes: 42 additions & 0 deletions HinaGUI/util/model_loader.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,43 @@
#include "model_loader.h"

#ifndef HINA_USE_ASSIMP

#include "assimp/Importer.hpp"
#include "assimp/scene.h"
#include "assimp/postprocess.h"

#include <iostream>

Mesh processMesh(aiMesh *mesh, const aiScene *scene)
{
for (unsigned int i = 0; i < mesh->mNumVertices; ++i)
{

}
return Mesh();
}

void process_node(aiNode *node, const aiScene *scene)
{
std::vector<Mesh> meshes;
for (unsigned int i = 0; i < node->mNumMeshes; i++)
meshes.push_back(processMesh(scene->mMeshes[node->mMeshes[i]], scene));

for (unsigned int i = 0; i < node->mNumChildren; i++)
process_node(node->mChildren[i], scene);
}

void ModelLoader::load_model(const std::string &model_path)
{
Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(model_path, aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_CalcTangentSpace);
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) // if is Not Zero
{
std::cout << "ERROR::ASSIMP:: " << importer.GetErrorString() << std::endl;
return;
}

std::string directory = model_path.substr(0, model_path.find_last_of('/'));
}

#endif
7 changes: 5 additions & 2 deletions HinaGUI/util/model_loader.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#ifndef HINAGUI_MODEL_LOADER_H
#define HINAGUI_MODEL_LOADER_H

#include "../core/renderable.h"

#include <string>

class ModelLoader
{

public:
static void load_model(const std::string& model_path);
};


#endif //HINAGUI_MODEL_LOADER_H
37 changes: 36 additions & 1 deletion samples/sample5/main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,46 @@
#include "HinaGUI/HinaViewer.h"

int main()
#include <fstream>

struct A
{
int a; // 4
float b; // 4
char c; // 1
};


class Foo
{

};

int main(int argc, char **argv)
{

HinaGUI::HinaViewer viewer;
// viewer.init("C:/Users/Administrator/Desktop/BFU_Graphics/HinaGUI/HinaGUI/builtin-desc/classic_viewer.json");
viewer.init("/Users/xayah/Desktop/BFU-Graphics/HinaGUI/HinaGUI/builtin-desc/classic_viewer.json");
viewer.launch();
viewer.kill();

std::unique_ptr<Foo> a = std::make_unique<Foo>();

std::vector<int> b; 8

b.push_back(1);
b.push_back(1);
b.push_back(1);
b.push_back(1);
b.push_back(1);
b.push_back(1);
b.push_back(1);
b.push_back(1);
b.push_back(1);

std::sqrt()

Foo * ptr = a.get();

return 0;
}

0 comments on commit a19286c

Please sign in to comment.