1
+ // #pragma once
2
+ // #include <string>
3
+ // #include <vector>
4
+ //
5
+ // #include "tiny_gltf.h"
6
+ //
7
+ // //#define TINYOBJLOADER_IMPLEMENTATION
8
+ // #define BUFFER_OFFSET(i) ((char *)NULL + (i))
9
+ //
10
+ // namespace UPCLASS {
11
+ // namespace UPMATH {
12
+ // struct upVector2 {
13
+ // uint32_t u = 0;
14
+ // uint32_t v = 0;
15
+ // }; //upVector3
16
+ //
17
+ // struct upVector3 {
18
+ // uint32_t x = 0;
19
+ // uint32_t y = 0;
20
+ // uint32_t z = 0;
21
+ //
22
+ // upVector3(uint32_t inX, uint32_t inY, uint32_t inZ) : x(inX), y(inY), z(inZ) {};
23
+ // }; //upVector3
24
+ //
25
+ // struct upVector4 {
26
+ // uint32_t r = 0;
27
+ // uint32_t g = 0;
28
+ // uint32_t b = 0;
29
+ // uint32_t a = 0;
30
+ // }; //upVector3
31
+ // }; //UpMath Namespace
32
+ //
33
+ // using namespace UPMATH;
34
+ //
35
+ // struct upAsset {
36
+ // std::vector < upVector4 > color;
37
+ // std::vector < upVector3 > vertices;
38
+ // std::vector < upVector3 > normals;
39
+ // std::vector < upVector2 > textureCoordinates;
40
+ // std::vector < uint32_t > indices;
41
+ //
42
+ // uint32_t faceCount;
43
+ // uint32_t vertexCount;
44
+ // uint32_t colorCount;
45
+ // uint32_t indexCount;
46
+ // uint32_t normalCount;
47
+ // }; //upAsset
48
+ //
49
+ // struct upClass {
50
+ // std::vector<upAsset*> upAssets;
51
+ // std::string err;
52
+ // std::vector<std::string> warn;
53
+ // uint32_t upAssetCount;
54
+ //
55
+ // upClass() = default;
56
+ // upClass(std::string filename, std::string extension) {
57
+ // if (extension == ".gltf" || extension == ".glb") {
58
+ // tinygltf::Model model;
59
+ // tinygltf::TinyGLTF loader;
60
+ // std::string gltfErr;
61
+ // std::string gltfWarn;
62
+ // if (extension == ".gltf")loader.LoadASCIIFromFile(&model, &gltfErr, &gltfWarn, filename + extension);
63
+ // if (extension == ".glb")loader.LoadBinaryFromFile(&model, &gltfErr, &gltfWarn, filename + extension);
64
+ // //if (extension == ".bin")loader.LoadBinaryFromFile(&model, &err, &warn, filename + extension);
65
+ //
66
+ // auto scene = model.scenes[model.defaultScene];
67
+ //
68
+ // uint32_t positionAccessIndex;
69
+ // uint32_t normalAccessIndex;
70
+ // uint32_t indexAccessIndex;
71
+ //
72
+ // uint32_t positionOffset;
73
+ // uint32_t positionBuffView;
74
+ // uint32_t positionBuffIndex;
75
+ //
76
+ // for (auto& nodeIndex : scene.nodes) {
77
+ // if (model.nodes[nodeIndex].mesh >= 0) {
78
+ // for (auto& primitive : model.meshes[model.nodes[nodeIndex].mesh].primitives) {
79
+ // for (auto& attrib : primitive.attributes) {
80
+ // //Second is the index to the item in the "model" hiearchy
81
+ // if (attrib.first == "POSITION") positionAccessIndex = attrib.second;
82
+ // if (attrib.first == "NORMAL") normalAccessIndex = attrib.second;
83
+ // }; //For every Attribute
84
+ // indexAccessIndex = primitive.indices;
85
+ // }; //primitives
86
+ //
87
+ // auto asset = new upAsset();
88
+ //
89
+ // asset->indexCount = model.accessors[indexAccessIndex].count;
90
+ // asset->vertexCount = model.accessors[positionAccessIndex].count;
91
+ // asset->normalCount = model.accessors[normalAccessIndex].count;
92
+ //
93
+ // //Creating Indices
94
+ // char* begin = BUFFER_OFFSET(model.accessors[indexAccessIndex].byteOffset);
95
+ // char* end = BUFFER_OFFSET(model.accessors[indexAccessIndex].byteOffset) + model.accessors[indexAccessIndex].count;
96
+ // if (!(model.accessors[indexAccessIndex].type == TINYGLTF_TYPE_SCALAR)) {
97
+ // warn.push_back("Bad Accessor: Index"); continue;
98
+ // };
99
+ // if (model.accessors[indexAccessIndex].componentType == TINYGLTF_COMPONENT_TYPE_BYTE)
100
+ // asset->indices = std::vector<uint32_t>((int8_t*)begin, (int8_t*)end);
101
+ // if (model.accessors[indexAccessIndex].componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE)
102
+ // asset->indices = std::vector<uint32_t>((uint8_t*)begin, (uint8_t*)end);
103
+ // if (model.accessors[indexAccessIndex].componentType == TINYGLTF_COMPONENT_TYPE_SHORT)
104
+ // asset->indices = std::vector<uint32_t>((int16_t*)begin, (int16_t*)end);
105
+ // if (model.accessors[indexAccessIndex].componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT)
106
+ // asset->indices = std::vector<uint32_t>((uint16_t*)begin, (uint16_t*)end);
107
+ // if (model.accessors[indexAccessIndex].componentType == TINYGLTF_COMPONENT_TYPE_INT)
108
+ // asset->indices = std::vector<uint32_t>((int32_t*)begin, (int32_t*)end);
109
+ // if (model.accessors[indexAccessIndex].componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT)
110
+ // asset->indices = std::vector<uint32_t>((uint32_t*)begin, (uint32_t*)end);
111
+ // if (model.accessors[indexAccessIndex].componentType == TINYGLTF_COMPONENT_TYPE_FLOAT)
112
+ // asset->indices = std::vector<uint32_t>((float*)begin, (float*)end);
113
+ //
114
+ // //Creating Vertices
115
+ // positionOffset = model.accessors[positionAccessIndex].byteOffset;
116
+ // positionBuffView = model.accessors[positionAccessIndex].bufferView;
117
+ // positionBuffIndex = model.bufferViews[positionBuffView].buffer;
118
+ //
119
+ // if (!(model.accessors[indexAccessIndex].type == TINYGLTF_TYPE_VEC3)) {
120
+ // warn.push_back("Bad Accessor: Vertex"); continue;
121
+ // }; //Warning
122
+ // if (model.accessors[indexAccessIndex].componentType == TINYGLTF_COMPONENT_TYPE_FLOAT) {
123
+ // uint_fast32_t i = 0;
124
+ // auto verticeIndex = model.buffers[positionBuffIndex].data.at(0);
125
+ // for (; i < model.bufferViews[positionBuffView].byteLength / model.accessors[positionAccessIndex].count; ++i) {
126
+ // asset->vertices.emplace_back(
127
+ // UPMATH::upVector3(
128
+ // *(float*)verticeIndex,
129
+ // *(float*)verticeIndex += 4,
130
+ // *(float*)verticeIndex += 4));
131
+ // verticeIndex += 4;
132
+ // }; //for
133
+ // } //if model
134
+ // else warn.push_back("Bad Accessor: Vertex"); continue;
135
+ // upAssets.emplace_back(asset);
136
+ // }; //for every mesh
137
+ // }//for every node
138
+ // } //gltf, glb
139
+ // //if (extension == ".obj") {
140
+ // // std::string objWarn;
141
+ // // std::string objErr;
142
+ // // tinyobj::shape_t shapes;
143
+ // //};
144
+ // }; //upAsset ctor
145
+ //
146
+ // void AddUpAsset(std::string file) {
147
+ //
148
+ // }; //AddUpAsset
149
+ //
150
+ // void AddUpAsset(upAsset* asset) {
151
+ // upAssets.emplace_back(asset);
152
+ // ++upAssetCount;
153
+ // }; //AddUpAsset
154
+ //
155
+ // void AppendUpClass(upClass& upclass) {
156
+ // upAssets.insert(--upAssets.end(), upclass.upAssets.begin(), upclass.upAssets.end());
157
+ // upAssetCount = upAssets.size();
158
+ // }; //AppendUpClass
159
+ //
160
+ // upAsset* GetUpAsset(uint_fast8_t index) {
161
+ // return upAssets[index];
162
+ // }; //GetUpAsset
163
+ //
164
+ // upAsset* GetLastUpAsset() {
165
+ // return *(--upAssets.end());
166
+ // }; //GetLastUpAsset
167
+ //
168
+ // }; //Asset
169
+ // }; //UpClass
0 commit comments