Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include "Model_generated.h"
- #include <vector>
- #include <cstdio>
- using namespace Resource::Model;
- /* Model.fbs
- namespace Resource.Model;
- struct Vec3 {
- x:float;
- y:float;
- z:float;
- }
- struct Vec2 {
- x:float;
- y:float;
- }
- table MeshData {
- Position:[Vec3];
- Normal:[Vec3];
- TexCoords:[Vec2];
- Tangent:[Vec3];
- Bitangent:[Vec3];
- }
- table VertexObject {
- MData:MeshData;
- Indices:[uint];
- MatNameHash:uint;
- }
- table Model {
- Name:uint;
- Meshes:[VertexObject];
- }
- root_type Model;
- */
- int main()
- {
- flatbuffers::FlatBufferBuilder builder;
- std::vector<Vec3> Positions;
- std::vector<Vec3> Normals;
- std::vector<Vec2> TexCoords;
- std::vector<Vec3> Tangents;
- std::vector<Vec3> Bitangents;
- std::vector<unsigned int>Indices;
- //Psudo Data Gen
- for (unsigned int i = 0; i < 40; i++)
- {
- Positions.push_back(Vec3(i, i, i));
- Normals.push_back(Vec3(i, i, i));
- TexCoords.push_back(Vec2(i, i));
- Tangents.push_back(Vec3(i, i, i));
- Bitangents.push_back(Vec3(i, i, i));
- Indices.push_back(i);
- }
- auto a = builder.CreateVectorOfStructs(Positions);
- auto b = builder.CreateVectorOfStructs(Normals);
- auto c = builder.CreateVectorOfStructs(TexCoords);
- auto d = builder.CreateVectorOfStructs(Tangents);
- auto e = builder.CreateVectorOfStructs(Bitangents);
- auto f = CreateMeshData(builder, a, b, c, d, e);
- auto g = builder.CreateVector<uint32_t>(Indices);
- unsigned int h = 1024; //Hash of Name of Material
- std::vector<flatbuffers::Offset<VertexObject>> VO;
- auto i = CreateVertexObject(builder, f, g, h);
- auto i2 = CreateVertexObject(builder, f, g, h);
- VO.push_back(i);
- VO.push_back(i2);
- auto j = builder.CreateVector(VO);
- auto k = 512; //Hash of name of Model
- auto l = CreateModel(builder, k, j);
- builder.Finish(l);
- auto m = builder.GetBufferPointer();
- int n = builder.GetSize();
- //File Output
- FILE* ofile = fopen("model_test.mon", "w");
- fwrite(m, sizeof(uint8_t), n, ofile);
- fclose(ofile);
- //-----------------------------------//
- FILE* file = fopen("model_test.mon", "rb");
- fseek(file, 0L, SEEK_END);
- int length = ftell(file);
- fseek(file, 0L, SEEK_SET);
- char *data = new char[length];
- fread(data, sizeof(char), length, file);
- fclose(file);
- auto test = GetModel(data);
- assert(test->Name());
- auto name = test->Name();
- assert(test->Meshes());
- auto FBMeshes = test->Meshes();
- for (unsigned int i = 0; i < FBMeshes->size(); i++)
- {
- std::vector<Vec3> nPos;
- std::vector<Vec3> nNor;
- std::vector<Vec2> nTex;
- std::vector<Vec3> nTan;
- std::vector<Vec3> nBit;
- std::vector<unsigned int> nInd;
- assert(FBMeshes->Get(i));
- auto FBMeshesIndex = FBMeshes->Get(i);
- //assert(FBMeshesIndex->MData());
- }
- std::cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement