12 #ifndef GLVIS_GLTF_HPP
13 #define GLVIS_GLTF_HPP
27 typedef std::array<float,2>
vec2f;
28 typedef std::array<float,3>
vec3f;
30 typedef std::vector<float>
vecnf;
54 std::unique_ptr<std::ofstream>
file;
100 {
false,
"baseColorFactor", {{0.f, 0.f, 0.f, 0.f}} };
102 {
false,
"baseColorTexture", {} };
109 {
false,
"pbrMetallicRoughness", {} };
142 static const char *
sep(
size_t i) {
return (i==0) ?
"" :
","; }
143 template <
typename T>
146 const std::string &pfx,
151 out <<
sep(pfx_counter++) << pfx <<
'"' << n.
key <<
"\" : ";
156 static void print(std::ostream &out,
const bool &v) { out << v; }
157 static void print(std::ostream &out,
const unsigned &v) { out << v; }
158 static void print(std::ostream &out,
const float &v) { out << v; }
159 static void print(std::ostream &out,
const std::string &v)
160 { out <<
'"' << v <<
'"'; }
161 template <
typename T,
size_t s>
162 static void print(std::ostream &out,
const std::array<T,s> &v)
165 for (
size_t i = 0; i != s; ++i) { out <<
sep(i) <<
' ' << v[i]; }
168 template <
typename T>
169 static void print(std::ostream &out,
const std::vector<T> &v)
172 for (
size_t i = 0; i != v.size(); ++i) { out <<
sep(i) <<
' ' << v[i]; }
218 static constexpr
unsigned INVALID_ID = std::numeric_limits<unsigned>::max();
283 buffer_id
addBuffer(
const std::string &bufferName);
319 image_id
addImage(
const std::string &imageName,
329 texture_id
addTexture(sampler_id sampler, image_id source);
331 material_id
addMaterial(
const std::string &materialName,
332 const pbr_matallic_roughness &pbrMetallicRoughness,
333 bool doubleSided =
false);
335 mesh_id
addMesh(
const std::string &meshName);
338 accessor_id vertexPositions,
339 accessor_id vertexNormals,
340 accessor_id vertexTexCoords0,
341 accessor_id vertexIndices,
342 material_id material);
345 accessor_id vertexPositions,
346 accessor_id vertexTexcoords0,
347 accessor_id vertexColors0,
348 material_id material);
350 node_id
addNode(
const std::string &nodeName);
359 pbr_matallic_roughness &pbr_mr_copy);
364 #endif // GLVIS_GLTF_HPP
node_unsigned componentType
node_type< std::string > node_string
static void print_node(std::ostream &out, int &pfx_counter, const std::string &pfx, const node_type< T > &n)
material_id addMaterial(const std::string &materialName, const pbr_matallic_roughness &pbrMetallicRoughness, bool doubleSided=false)
std::vector< struct_buffer > buffers
void addNodeScale(node_id node, vec3f scale)
node_type< unsigned > node_unsigned
accessor_id addAccessorVec3f(buffer_view_id bufferView, size_t byteOffset, size_t count, vec3f min, vec3f max)
buffer_view_id addBufferView(buffer_id buffer, const void *data, size_t byteLength, size_t byteStride, size_t byteAlign, target_type target)
sampler_id addSampler(mag_filter magFilter=mag_filter::NEAREST, min_filter minFilter=min_filter::NEAREST, wrap_type wrapS=wrap_type::CLAMP_TO_EDGE, wrap_type wrapT=wrap_type::CLAMP_TO_EDGE)
std::vector< float > vecnf
node_type< bool > node_bool
std::vector< struct_material > materials
glTF_Builder(const std::string &filePrefix)
void appendToBufferView(buffer_view_id bufferView, const void *data, size_t byteLength)
void addMeshLines(mesh_id mesh, accessor_id vertexPositions, accessor_id vertexTexcoords0, accessor_id vertexColors0, material_id material)
void addNodeTranslation(node_id node, vec3f translation)
static void print(std::ostream &out, const struct_pbrMetallicRoughness &pbr)
void addMeshTriangles(mesh_id mesh, accessor_id vertexPositions, accessor_id vertexNormals, accessor_id vertexTexCoords0, accessor_id vertexIndices, material_id material)
buffer_id addBuffer(const std::string &bufferName)
std::array< float, 3 > vec3f
std::vector< struct_mesh > meshes
node_type< struct_pbrMetallicRoughness > pbrMetallicRoughness
static void print(std::ostream &out, const std::vector< T > &v)
node_type< float > node_float
texture_id addTexture(sampler_id sampler, image_id source)
const std::string file_prefix
static const char * sep(size_t i)
static void print(std::ostream &out, const unsigned &v)
std::vector< struct_node > nodes
mesh_id addMesh(const std::string &meshName)
texture_id baseColorTexture
static void print(std::ostream &out, const struct_texture_info &ti)
std::vector< struct_image > images
static void print(std::ostream &out, const float &v)
std::vector< struct_accessor > accessors
node_id addNode(const std::string &nodeName)
static void print(std::ostream &out, const bool &v)
image_id addImage(const std::string &imageName, int width, int height, const color4f *pixels)
accessor_id addAccessor(buffer_view_id bufferView, size_t byteOffset, component_type componentType, size_t count, tensor_type tensorType)
std::array< float, 4 > color4f
void getMaterialPBRMR(material_id material, pbr_matallic_roughness &pbr_mr_copy)
static constexpr unsigned INVALID_ID
void addNodeMesh(node_id node, mesh_id mesh)
static void print(std::ostream &out, const std::array< T, s > &v)
node_type< struct_attributes > attributes
std::unique_ptr< std::ofstream > file
node_type< vecnf > node_vecnf
std::array< float, 2 > vec2f
std::vector< struct_buffer_view > buffer_views
static const char * tensorTypes[]
node_type< color4f > node_color4f
accessor_id addAccessorVec2f(buffer_view_id bufferView, size_t byteOffset, size_t count, vec2f min, vec2f max)
std::vector< struct_primitive > primitives
std::vector< struct_sampler > samplers
static void print(std::ostream &out, const std::string &v)
std::vector< struct_texture > textures
node_type< vec3f > node_vec3f
static void print(std::ostream &out, const struct_attributes &a)