tiny_gltf 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.travis.yml +7 -0
  4. data/.yardopts +2 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +31 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +63 -0
  9. data/Rakefile +24 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/ext/tiny_gltf/extconf.rb +5 -0
  13. data/ext/tiny_gltf/json.hpp +14722 -0
  14. data/ext/tiny_gltf/rb_tiny_gltf.cpp +55 -0
  15. data/ext/tiny_gltf/rb_tiny_gltf.h +118 -0
  16. data/ext/tiny_gltf/rb_tiny_gltf_accessor.cpp +42 -0
  17. data/ext/tiny_gltf/rb_tiny_gltf_animation.cpp +21 -0
  18. data/ext/tiny_gltf/rb_tiny_gltf_animation_channel.cpp +13 -0
  19. data/ext/tiny_gltf/rb_tiny_gltf_animation_sampler.cpp +16 -0
  20. data/ext/tiny_gltf/rb_tiny_gltf_asset.cpp +15 -0
  21. data/ext/tiny_gltf/rb_tiny_gltf_buffer.cpp +16 -0
  22. data/ext/tiny_gltf/rb_tiny_gltf_buffer_view.cpp +16 -0
  23. data/ext/tiny_gltf/rb_tiny_gltf_camera.cpp +29 -0
  24. data/ext/tiny_gltf/rb_tiny_gltf_extension_map.cpp +12 -0
  25. data/ext/tiny_gltf/rb_tiny_gltf_image.cpp +25 -0
  26. data/ext/tiny_gltf/rb_tiny_gltf_init.c +81 -0
  27. data/ext/tiny_gltf/rb_tiny_gltf_light.cpp +16 -0
  28. data/ext/tiny_gltf/rb_tiny_gltf_material.cpp +14 -0
  29. data/ext/tiny_gltf/rb_tiny_gltf_mesh.cpp +37 -0
  30. data/ext/tiny_gltf/rb_tiny_gltf_model.cpp +52 -0
  31. data/ext/tiny_gltf/rb_tiny_gltf_node.cpp +67 -0
  32. data/ext/tiny_gltf/rb_tiny_gltf_parameter_map.cpp +39 -0
  33. data/ext/tiny_gltf/rb_tiny_gltf_primitive.cpp +35 -0
  34. data/ext/tiny_gltf/rb_tiny_gltf_sampler.cpp +16 -0
  35. data/ext/tiny_gltf/rb_tiny_gltf_scene.cpp +17 -0
  36. data/ext/tiny_gltf/rb_tiny_gltf_skin.cpp +17 -0
  37. data/ext/tiny_gltf/rb_tiny_gltf_texture.cpp +14 -0
  38. data/ext/tiny_gltf/rb_tiny_gltf_types.cpp +229 -0
  39. data/ext/tiny_gltf/rb_tiny_gltf_value.cpp +32 -0
  40. data/ext/tiny_gltf/stb_image.h +6509 -0
  41. data/ext/tiny_gltf/stb_image_write.h +1831 -0
  42. data/ext/tiny_gltf/tiny_gltf.h +4830 -0
  43. data/lib/tiny_gltf.rb +260 -0
  44. data/lib/tiny_gltf/version.rb +3 -0
  45. data/tiny_gltf.gemspec +43 -0
  46. metadata +189 -0
@@ -0,0 +1,16 @@
1
+ #include "rb_tiny_gltf.h"
2
+
3
+ VALUE rLight_new(const Light *light) {
4
+ VALUE rlight = rb_funcall(rb_cLight, rb_intern("new"), 0);
5
+ // *Light_unwrap(rlight) = *light;
6
+
7
+ VALUE rcolor = rb_ary_new();
8
+ for (size_t i = 0; i < light->color.size(); i++)
9
+ rb_ary_push(rcolor, DBL2NUM(light->color[i]));
10
+
11
+ rb_ivar_set(rlight, rb_intern("@name"), rb_str_new2(light->name.c_str()));
12
+ rb_ivar_set(rlight, rb_intern("@type"), rb_intern(light->type.c_str()));
13
+ rb_ivar_set(rlight, rb_intern("@color"), rcolor);
14
+
15
+ return rlight;
16
+ }
@@ -0,0 +1,14 @@
1
+ #include "rb_tiny_gltf.h"
2
+
3
+ VALUE rMaterial_new(const Material *matr) {
4
+ VALUE rmatr = rb_funcall(rb_cMaterial, rb_intern("new"), 0);
5
+ // *Material_unwrap(rmatr) = *matr;
6
+
7
+ rb_ivar_set(rmatr, rb_intern("@name"), rb_str_new2(matr->name.c_str()));
8
+ rb_ivar_set(rmatr, rb_intern("@values"), rParameterMap_new(&matr->values));
9
+ rb_ivar_set(rmatr, rb_intern("@additional_values"), rParameterMap_new(&matr->additionalValues));
10
+ rb_ivar_set(rmatr, rb_intern("@extensions"), rExtensionMap_new(&matr->extensions));
11
+ rb_ivar_set(rmatr, rb_intern("@extras"), rValue_new(&matr->extras));
12
+
13
+ return rmatr;
14
+ }
@@ -0,0 +1,37 @@
1
+ #include "rb_tiny_gltf.h"
2
+
3
+ VALUE rMesh_new(const Mesh *mesh) {
4
+ VALUE rmesh = rb_funcall(rb_cMesh, rb_intern("new"), 0);
5
+ // *Mesh_unwrap(rmesh) = *mesh;
6
+
7
+ VALUE rtargets = rb_ary_new();
8
+ for (size_t i = 0; i < mesh->targets.size(); i++) {
9
+ VALUE rtarget = rb_hash_new();
10
+ rb_ary_push(rtargets, rtarget);
11
+ for (std::map<std::string, int>::const_iterator it = mesh->targets[i].begin();
12
+ it != mesh->targets[i].end(); ++it) {
13
+ std::string key = it->first;
14
+ std::transform(key.begin(), key.end(), key.begin(), ::tolower);
15
+ rb_hash_aset(rtarget, ID2SYM(rb_intern(key.c_str())), INT2NUM(it->second));
16
+ }
17
+ }
18
+
19
+ VALUE rprimitives = rb_ary_new();
20
+ for (size_t i = 0; i < mesh->primitives.size(); i++) {
21
+ rb_ary_push(rprimitives, rPrimitive_new(&mesh->primitives[i]));
22
+ }
23
+
24
+ VALUE rweights = rb_ary_new();
25
+ for (size_t i = 0; i < mesh->weights.size(); i++) {
26
+ rb_ary_push(rprimitives, DBL2NUM(mesh->weights[i]));
27
+ }
28
+
29
+ rb_ivar_set(rmesh, rb_intern("@name"), rb_str_new2(mesh->name.c_str()));
30
+ rb_ivar_set(rmesh, rb_intern("@primitives"), rprimitives);
31
+ rb_ivar_set(rmesh, rb_intern("@weights"), rweights);
32
+ rb_ivar_set(rmesh, rb_intern("@extensions"), rExtensionMap_new(&mesh->extensions));
33
+ rb_ivar_set(rmesh, rb_intern("@morph_targets"), rtargets);
34
+ rb_ivar_set(rmesh, rb_intern("@extras"), rValue_new(&mesh->extras));
35
+
36
+ return rmesh;
37
+ }
@@ -0,0 +1,52 @@
1
+ #include "rb_tiny_gltf.h"
2
+
3
+ VALUE rModel_new(const Model *model) {
4
+ VALUE rmodel = rb_funcall(rb_cModel, rb_intern("new"), 0);
5
+ // *Model_unwrap(rmodel) = *model;
6
+
7
+ VALUE rext_used = rb_ary_new();
8
+ for (size_t i = 0; i < model->extensionsUsed.size(); i++)
9
+ rb_ary_push(rext_used, rb_str_new2(model->extensionsUsed[i].c_str()));
10
+
11
+ VALUE rext_required = rb_ary_new();
12
+ for (size_t i = 0; i < model->extensionsRequired.size(); i++)
13
+ rb_ary_push(rext_required, rb_str_new2(model->extensionsRequired[i].c_str()));
14
+
15
+ rb_ivar_set(rmodel, rb_intern("@asset"), rAsset_new(&model->asset));
16
+ rb_ivar_set(rmodel, rb_intern("@default_scene_index"), INT2NUM(model->defaultScene));
17
+ rb_ivar_set(rmodel, rb_intern("@extensions"), rExtensionMap_new(&model->extensions));
18
+ rb_ivar_set(rmodel, rb_intern("@extras"), rValue_new(&model->extras));
19
+ rb_ivar_set(rmodel, rb_intern("@extensions_used"), rext_used);
20
+ rb_ivar_set(rmodel, rb_intern("@extensions_required"), rext_required);
21
+
22
+ /*
23
+ VALUE ary = rb_funcall(rmodel, rb_intern("accessors"), 0);
24
+ for (size_t i = 0; i < model->accessors.size(); i++) {
25
+ rb_ary_push(ary, rAccessor_new(&model->accessors[i]));
26
+ }
27
+ */
28
+ #define CONCAT_VECTOR_TO_RARRAY3(klass, name, method) { \
29
+ VALUE ary = rb_funcall(rmodel, rb_intern(method), 0); \
30
+ for (size_t i = 0; i < model->name.size(); i++) { \
31
+ rb_ary_push(ary, r ## klass ## _new(&model->name[i])); \
32
+ } \
33
+ }
34
+ #define CONCAT_VECTOR_TO_RARRAY(klass, name) CONCAT_VECTOR_TO_RARRAY3(klass, name, #name)
35
+
36
+ CONCAT_VECTOR_TO_RARRAY(Accessor, accessors);
37
+ CONCAT_VECTOR_TO_RARRAY(Animation, animations);
38
+ CONCAT_VECTOR_TO_RARRAY(Buffer, buffers);
39
+ CONCAT_VECTOR_TO_RARRAY3(BufferView, bufferViews, "buffer_views");
40
+ CONCAT_VECTOR_TO_RARRAY(Material, materials);
41
+ CONCAT_VECTOR_TO_RARRAY(Mesh, meshes);
42
+ CONCAT_VECTOR_TO_RARRAY(Node, nodes);
43
+ CONCAT_VECTOR_TO_RARRAY(Texture, textures);
44
+ CONCAT_VECTOR_TO_RARRAY(Image, images);
45
+ CONCAT_VECTOR_TO_RARRAY(Skin, skins);
46
+ CONCAT_VECTOR_TO_RARRAY(Sampler, samplers);
47
+ CONCAT_VECTOR_TO_RARRAY(Camera, cameras);
48
+ CONCAT_VECTOR_TO_RARRAY(Scene, scenes);
49
+ CONCAT_VECTOR_TO_RARRAY(Light, lights);
50
+
51
+ return rmodel;
52
+ }
@@ -0,0 +1,67 @@
1
+ #include "rb_tiny_gltf.h"
2
+
3
+ VALUE rNode_new(const Node *node) {
4
+ VALUE rnode = rb_funcall(rb_cNode, rb_intern("new"), 0);
5
+ // *Node_unwrap(rnode) = *node;
6
+
7
+ VALUE rweights = rb_ary_new();
8
+ for (size_t i = 0; i < node->weights.size(); i++)
9
+ rb_ary_push(rweights, DBL2NUM(node->weights[i]));
10
+
11
+ VALUE rchildren = rb_ary_new();
12
+ for (size_t i = 0; i < node->children.size(); i++)
13
+ rb_ary_push(rchildren, INT2NUM(node->children[i]));
14
+
15
+ VALUE rmatrix = Qnil, rrotation = Qnil, rtranslation = Qnil, rscale = Qnil;
16
+ if (node->matrix.size() == 0) {
17
+ rrotation = rb_ary_new();
18
+ if (node->rotation.size() == 0) {
19
+ rb_ary_push(rrotation, INT2NUM(0));
20
+ rb_ary_push(rrotation, INT2NUM(0));
21
+ rb_ary_push(rrotation, INT2NUM(0));
22
+ rb_ary_push(rrotation, INT2NUM(1));
23
+ } else {
24
+ for (size_t i = 0; i < node->rotation.size(); i++)
25
+ rb_ary_push(rrotation, INT2NUM(node->rotation[i]));
26
+ }
27
+
28
+ rscale = rb_ary_new();
29
+ if (node->rotation.size() == 0) {
30
+ rb_ary_push(rscale, INT2NUM(0));
31
+ rb_ary_push(rscale, INT2NUM(0));
32
+ rb_ary_push(rscale, INT2NUM(0));
33
+ } else {
34
+ for (size_t i = 0; i < node->scale.size(); i++)
35
+ rb_ary_push(rscale, INT2NUM(node->scale[i]));
36
+ }
37
+
38
+ rtranslation = rb_ary_new();
39
+ if (node->translation.size() == 0) {
40
+ rb_ary_push(rtranslation, INT2NUM(0));
41
+ rb_ary_push(rtranslation, INT2NUM(0));
42
+ rb_ary_push(rtranslation, INT2NUM(0));
43
+ } else {
44
+ for (size_t i = 0; i < node->translation.size(); i++)
45
+ rb_ary_push(rtranslation, INT2NUM(node->translation[i]));
46
+ }
47
+ } else {
48
+ rmatrix = rb_ary_new();
49
+ for (size_t i = 0; i < node->matrix.size(); i++)
50
+ rb_ary_push(rmatrix, INT2NUM(node->matrix[i]));
51
+ }
52
+
53
+ rb_ivar_set(rnode, rb_intern("@name"), rb_str_new2(node->name.c_str()));
54
+ rb_ivar_set(rnode, rb_intern("@camera_index"), INT2NUM(node->camera));
55
+ rb_ivar_set(rnode, rb_intern("@skin_index"), INT2NUM(node->skin));
56
+ rb_ivar_set(rnode, rb_intern("@mesh_index"), INT2NUM(node->mesh));
57
+ rb_ivar_set(rnode, rb_intern("@children_indices"), rchildren);
58
+ rb_ivar_set(rnode, rb_intern("@rotation"), rrotation);
59
+ rb_ivar_set(rnode, rb_intern("@translation"), rtranslation);
60
+ rb_ivar_set(rnode, rb_intern("@scale"), rscale);
61
+ rb_ivar_set(rnode, rb_intern("@matrix"), rmatrix);
62
+ rb_ivar_set(rnode, rb_intern("@weights"), rweights);
63
+ rb_ivar_set(rnode, rb_intern("@extensions"), rExtensionMap_new(&node->extensions));
64
+ rb_ivar_set(rnode, rb_intern("@extras"), rValue_new(&node->extras));
65
+
66
+ return rnode;
67
+ }
@@ -0,0 +1,39 @@
1
+ #include "rb_tiny_gltf.h"
2
+
3
+ VALUE rParameterMap_new(const ParameterMap *value) {
4
+ VALUE res = Qnil;
5
+
6
+ for (ParameterMap::const_iterator paramIt = value->begin(); paramIt != value->end();
7
+ ++paramIt) {
8
+ if (NIL_P(res)) res = rb_hash_new();
9
+ VALUE key = ID2SYM(rb_intern(paramIt->first.c_str()));
10
+ VALUE val = Qnil;
11
+
12
+ if (paramIt->second.number_array.size()) {
13
+ val = rb_ary_new();
14
+ for (size_t i = 0; i < paramIt->second.number_array.size(); i++)
15
+ rb_ary_push(val, DBL2NUM(paramIt->second.number_array[i]));
16
+ } else if (paramIt->second.json_double_value.size()) {
17
+ val = rb_hash_new();
18
+ for (std::map<std::string, double>::const_iterator it =
19
+ paramIt->second.json_double_value.begin();
20
+ it != paramIt->second.json_double_value.end(); ++it) {
21
+ if (it->first == "index") {
22
+ rb_hash_aset(val, ID2SYM(rb_intern("index")), INT2NUM(paramIt->second.TextureIndex()));
23
+ } else {
24
+ rb_hash_aset(val, ID2SYM(rb_intern(it->first.c_str())), DBL2NUM(it->second));
25
+ }
26
+ }
27
+ } else if (!paramIt->second.string_value.empty()) {
28
+ val = rb_str_new2(paramIt->second.string_value.c_str());
29
+ } else if (paramIt->second.has_number_value) {
30
+ val = DBL2NUM(paramIt->second.number_value);
31
+ } else {
32
+ val = paramIt->second.bool_value ? Qtrue : Qfalse;
33
+ }
34
+
35
+ rb_hash_aset(res, key, val);
36
+ }
37
+
38
+ return res;
39
+ }
@@ -0,0 +1,35 @@
1
+ #include "rb_tiny_gltf.h"
2
+
3
+ VALUE rPrimitive_new(const Primitive *prim) {
4
+ VALUE rprim = rb_funcall(rb_cPrimitive, rb_intern("new"), 0);
5
+ // *Primitive_unwrap(rprim) = *prim;
6
+
7
+ VALUE rattrs = rb_hash_new();
8
+ for (std::map<std::string, int>::const_iterator it = prim->attributes.begin();
9
+ it != prim->attributes.end(); ++it) {
10
+ std::string key = it->first;
11
+ std::transform(key.begin(), key.end(), key.begin(), ::tolower);
12
+ rb_hash_aset(rattrs, ID2SYM(rb_intern(key.c_str())), INT2NUM(it->second));
13
+ }
14
+
15
+ VALUE rtargets = rb_ary_new();
16
+ for (size_t i = 0; i < prim->targets.size(); i++) {
17
+ VALUE rtarget = rb_hash_new();
18
+ rb_ary_push(rtargets, rtarget);
19
+ for (std::map<std::string, int>::const_iterator it = prim->targets[i].begin();
20
+ it != prim->targets[i].end(); ++it) {
21
+ std::string key = it->first;
22
+ std::transform(key.begin(), key.end(), key.begin(), ::tolower);
23
+ rb_hash_aset(rtarget, ID2SYM(rb_intern(key.c_str())), INT2NUM(it->second));
24
+ }
25
+ }
26
+
27
+ rb_ivar_set(rprim, rb_intern("@attributes"), rattrs);
28
+ rb_ivar_set(rprim, rb_intern("@material_index"), INT2NUM(prim->material));
29
+ rb_ivar_set(rprim, rb_intern("@indices"), INT2NUM(prim->indices));
30
+ rb_ivar_set(rprim, rb_intern("@mode"), mode_to_sym(prim->mode));
31
+ rb_ivar_set(rprim, rb_intern("@morph_targets"), rtargets);
32
+ rb_ivar_set(rprim, rb_intern("@extras"), rValue_new(&prim->extras));
33
+
34
+ return rprim;
35
+ }
@@ -0,0 +1,16 @@
1
+ #include "rb_tiny_gltf.h"
2
+
3
+ VALUE rSampler_new(const Sampler *sampler) {
4
+ VALUE rsampler = rb_funcall(rb_cSampler, rb_intern("new"), 0);
5
+ // *Sampler_unwrap(rsampler) = *sampler;
6
+
7
+ rb_ivar_set(rsampler, rb_intern("@name"), rb_str_new2(sampler->name.c_str()));
8
+ rb_ivar_set(rsampler, rb_intern("@min_filter"), texture_filter_to_sym(sampler->minFilter));
9
+ rb_ivar_set(rsampler, rb_intern("@mag_filter"), texture_filter_to_sym(sampler->magFilter));
10
+ rb_ivar_set(rsampler, rb_intern("@wrap_s"), texture_wrap_to_sym(sampler->wrapS));
11
+ rb_ivar_set(rsampler, rb_intern("@wrap_t"), texture_wrap_to_sym(sampler->wrapT));
12
+ rb_ivar_set(rsampler, rb_intern("@wrap_r"), texture_wrap_to_sym(sampler->wrapR));
13
+ rb_ivar_set(rsampler, rb_intern("@extras"), rValue_new(&sampler->extras));
14
+
15
+ return rsampler;
16
+ }
@@ -0,0 +1,17 @@
1
+ #include "rb_tiny_gltf.h"
2
+
3
+ VALUE rScene_new(const Scene *scene) {
4
+ VALUE rscene = rb_funcall(rb_cScene, rb_intern("new"), 0);
5
+ // *Scene_unwrap(rscene) = *scene;
6
+
7
+ VALUE rnodes = rb_ary_new();
8
+ for (size_t i = 0; i < scene->nodes.size(); i++)
9
+ rb_ary_push(rnodes, INT2NUM(scene->nodes[i]));
10
+
11
+ rb_ivar_set(rscene, rb_intern("@name"), rb_str_new2(scene->name.c_str()));
12
+ rb_ivar_set(rscene, rb_intern("@nodes"), rnodes);
13
+ rb_ivar_set(rscene, rb_intern("@extensions"), rExtensionMap_new(&scene->extensions));
14
+ rb_ivar_set(rscene, rb_intern("@extras"), rValue_new(&scene->extras));
15
+
16
+ return rscene;
17
+ }
@@ -0,0 +1,17 @@
1
+ #include "rb_tiny_gltf.h"
2
+
3
+ VALUE rSkin_new(const Skin *skin) {
4
+ VALUE rskin = rb_funcall(rb_cSkin, rb_intern("new"), 0);
5
+ // *Skin_unwrap(rskin) = *skin;
6
+
7
+ VALUE rjoints = rb_ary_new();
8
+ for (size_t i = 0; i < skin->joints.size(); i++)
9
+ rb_ary_push(rjoints, INT2NUM(skin->joints[i]));
10
+
11
+ rb_ivar_set(rskin, rb_intern("@name"), rb_str_new2(skin->name.c_str()));
12
+ rb_ivar_set(rskin, rb_intern("@inverse_bind_matrices"), INT2NUM(skin->inverseBindMatrices));
13
+ rb_ivar_set(rskin, rb_intern("@skeleton_root_node_index"), INT2NUM(skin->skeleton));
14
+ rb_ivar_set(rskin, rb_intern("@joints"), rjoints);
15
+
16
+ return rskin;
17
+ }
@@ -0,0 +1,14 @@
1
+ #include "rb_tiny_gltf.h"
2
+
3
+ VALUE rTexture_new(const Texture *texture) {
4
+ VALUE rtexture = rb_funcall(rb_cTexture, rb_intern("new"), 0);
5
+ // *Texture_unwrap(rtexture) = *texture;
6
+
7
+ rb_ivar_set(rtexture, rb_intern("@name"), rb_str_new2(texture->name.c_str()));
8
+ rb_ivar_set(rtexture, rb_intern("@sampler_index"), INT2NUM(texture->sampler));
9
+ rb_ivar_set(rtexture, rb_intern("@source_index"), INT2NUM(texture->source));
10
+ rb_ivar_set(rtexture, rb_intern("@extensions"), rExtensionMap_new(&texture->extensions));
11
+ rb_ivar_set(rtexture, rb_intern("@extras"), rValue_new(&texture->extras));
12
+
13
+ return rtexture;
14
+ }
@@ -0,0 +1,229 @@
1
+ #include "rb_tiny_gltf.h"
2
+
3
+ /*
4
+ void model_free(void* data) {
5
+ Model *model = (Model *) data;
6
+ delete model;
7
+ }
8
+
9
+ size_t model_size(const void* data) {
10
+ return sizeof(Model);
11
+ }
12
+
13
+ static const rb_data_type_t T_Model = {
14
+ .wrap_struct_name = "TinyGLTFModel",
15
+ .function = {
16
+ .dmark = NULL,
17
+ .dfree = model_free,
18
+ .dsize = model_size,
19
+ .reserved = { 0, 0 }
20
+ },
21
+ .parent = NULL,
22
+ .data = NULL,
23
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
24
+ };
25
+
26
+ VALUE alloc_model(VALUE klass) {
27
+ return TypedData_Wrap_Struct(klass, &T_Model, new Model());
28
+ }
29
+
30
+ VALUE Model_is_equal(VALUE self, VALUE other) {
31
+ Model *a, *b;
32
+ TypedData_Get_Struct(self, Model, &T_Model, a);
33
+ TypedData_Get_Struct(other, Model, &T_Model, b);
34
+ return (*a) == (*b) ? Qtrue : Qfalse;
35
+ }
36
+ */
37
+ #define DEFN_GLTF_TYPE(klass) \
38
+ void klass ## _free(void* data) { \
39
+ klass *obj = (klass *) data; \
40
+ delete obj; \
41
+ } \
42
+ \
43
+ size_t klass ## _size(const void* data) { \
44
+ return sizeof(klass); \
45
+ } \
46
+ \
47
+ const rb_data_type_t T_ ## klass = { \
48
+ .wrap_struct_name = "TinyGLTF" #klass, \
49
+ .function = { \
50
+ .dmark = NULL, \
51
+ .dfree = klass ## _free, \
52
+ .dsize = klass ## _size, \
53
+ .reserved = { 0, 0 } \
54
+ }, \
55
+ .parent = NULL, \
56
+ .data = NULL, \
57
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY \
58
+ }; \
59
+ \
60
+ VALUE klass ## _alloc(VALUE k) { \
61
+ return TypedData_Wrap_Struct(k, &T_ ## klass, new klass()); \
62
+ } \
63
+ \
64
+ VALUE klass ## _is_equal(VALUE self, VALUE other) { \
65
+ klass *a, *b; \
66
+ TypedData_Get_Struct(self, klass, &T_ ## klass, a); \
67
+ TypedData_Get_Struct(other, klass, &T_ ## klass, b); \
68
+ return (*a) == (*b) ? Qtrue : Qfalse; \
69
+ }
70
+
71
+ DEFN_GLTF_TYPE(Model);
72
+ DEFN_GLTF_TYPE(Asset);
73
+ DEFN_GLTF_TYPE(Accessor);
74
+ DEFN_GLTF_TYPE(Animation);
75
+ DEFN_GLTF_TYPE(AnimationChannel);
76
+ DEFN_GLTF_TYPE(AnimationSampler);
77
+ DEFN_GLTF_TYPE(Buffer);
78
+ DEFN_GLTF_TYPE(BufferView);
79
+ DEFN_GLTF_TYPE(Material);
80
+ DEFN_GLTF_TYPE(Mesh);
81
+ DEFN_GLTF_TYPE(Node);
82
+ DEFN_GLTF_TYPE(Primitive);
83
+ DEFN_GLTF_TYPE(Texture);
84
+ DEFN_GLTF_TYPE(Image);
85
+ DEFN_GLTF_TYPE(Skin);
86
+ DEFN_GLTF_TYPE(Sampler);
87
+ DEFN_GLTF_TYPE(Camera);
88
+ DEFN_GLTF_TYPE(Scene);
89
+ DEFN_GLTF_TYPE(Light);
90
+
91
+ VALUE mode_to_sym(int mode) {
92
+ switch(mode) {
93
+ case TINYGLTF_MODE_POINTS: return ID2SYM(rb_intern("points"));
94
+ case TINYGLTF_MODE_LINE: return ID2SYM(rb_intern("line"));
95
+ case TINYGLTF_MODE_LINE_LOOP: return ID2SYM(rb_intern("line_loop"));
96
+ case TINYGLTF_MODE_TRIANGLES: return ID2SYM(rb_intern("triangles"));
97
+ case TINYGLTF_MODE_TRIANGLE_STRIP: return ID2SYM(rb_intern("triangle_strip"));
98
+ case TINYGLTF_MODE_TRIANGLE_FAN: return ID2SYM(rb_intern("triangle_fan"));
99
+ default: return ID2SYM(rb_intern("unknown"));
100
+ }
101
+ }
102
+
103
+ VALUE component_type_to_sym(int type) {
104
+ switch(type) {
105
+ case TINYGLTF_COMPONENT_TYPE_BYTE: return ID2SYM(rb_intern("byte"));
106
+ case TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE: return ID2SYM(rb_intern("ubyte"));
107
+ case TINYGLTF_COMPONENT_TYPE_SHORT: return ID2SYM(rb_intern("short"));
108
+ case TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT: return ID2SYM(rb_intern("ushort"));
109
+ case TINYGLTF_COMPONENT_TYPE_INT: return ID2SYM(rb_intern("int"));
110
+ case TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT: return ID2SYM(rb_intern("uint"));
111
+ case TINYGLTF_COMPONENT_TYPE_FLOAT: return ID2SYM(rb_intern("float"));
112
+ case TINYGLTF_COMPONENT_TYPE_DOUBLE: return ID2SYM(rb_intern("double"));
113
+ default: return ID2SYM(rb_intern("unknown"));
114
+ }
115
+ }
116
+
117
+ VALUE texture_filter_to_sym(int filter) {
118
+ switch(filter) {
119
+ case TINYGLTF_TEXTURE_FILTER_NEAREST: return ID2SYM(rb_intern("nearest"));
120
+ case TINYGLTF_TEXTURE_FILTER_LINEAR: return ID2SYM(rb_intern("linear"));
121
+ case TINYGLTF_TEXTURE_FILTER_NEAREST_MIPMAP_NEAREST: return ID2SYM(rb_intern("nearest_mipmap_nearest"));
122
+ case TINYGLTF_TEXTURE_FILTER_LINEAR_MIPMAP_NEAREST: return ID2SYM(rb_intern("linear_mipmap_nearest"));
123
+ case TINYGLTF_TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR: return ID2SYM(rb_intern("nearest_mipmap_linear"));
124
+ case TINYGLTF_TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR: return ID2SYM(rb_intern("linear_mipmap_linear"));
125
+ default: return ID2SYM(rb_intern("unknown"));
126
+ }
127
+ }
128
+
129
+ VALUE texture_wrap_to_sym(int wrap) {
130
+ switch(wrap) {
131
+ case TINYGLTF_TEXTURE_WRAP_REPEAT: return ID2SYM(rb_intern("repeat"));
132
+ case TINYGLTF_TEXTURE_WRAP_CLAMP_TO_EDGE: return ID2SYM(rb_intern("clamp_to_edge"));
133
+ case TINYGLTF_TEXTURE_WRAP_MIRRORED_REPEAT: return ID2SYM(rb_intern("mirrored_repeat"));
134
+ default: return ID2SYM(rb_intern("unknown"));
135
+ }
136
+ }
137
+
138
+ VALUE parameter_type_to_sym(int type) {
139
+ switch(type) {
140
+ case TINYGLTF_PARAMETER_TYPE_BYTE: return ID2SYM(rb_intern("byte"));
141
+ case TINYGLTF_PARAMETER_TYPE_UNSIGNED_BYTE: return ID2SYM(rb_intern("ubyte"));
142
+ case TINYGLTF_PARAMETER_TYPE_SHORT: return ID2SYM(rb_intern("short"));
143
+ case TINYGLTF_PARAMETER_TYPE_UNSIGNED_SHORT: return ID2SYM(rb_intern("ushort"));
144
+ case TINYGLTF_PARAMETER_TYPE_INT: return ID2SYM(rb_intern("int"));
145
+ case TINYGLTF_PARAMETER_TYPE_UNSIGNED_INT: return ID2SYM(rb_intern("uint"));
146
+ case TINYGLTF_PARAMETER_TYPE_FLOAT: return ID2SYM(rb_intern("float"));
147
+ case TINYGLTF_PARAMETER_TYPE_FLOAT_VEC2: return ID2SYM(rb_intern("float_vec2"));
148
+ case TINYGLTF_PARAMETER_TYPE_FLOAT_VEC3: return ID2SYM(rb_intern("float_vec3"));
149
+ case TINYGLTF_PARAMETER_TYPE_FLOAT_VEC4: return ID2SYM(rb_intern("float_vec4"));
150
+ case TINYGLTF_PARAMETER_TYPE_INT_VEC2: return ID2SYM(rb_intern("int_vec2"));
151
+ case TINYGLTF_PARAMETER_TYPE_INT_VEC3: return ID2SYM(rb_intern("int_vec3"));
152
+ case TINYGLTF_PARAMETER_TYPE_INT_VEC4: return ID2SYM(rb_intern("int_vec4"));
153
+ case TINYGLTF_PARAMETER_TYPE_BOOL: return ID2SYM(rb_intern("bool"));
154
+ case TINYGLTF_PARAMETER_TYPE_BOOL_VEC2: return ID2SYM(rb_intern("bool_vec2"));
155
+ case TINYGLTF_PARAMETER_TYPE_BOOL_VEC3: return ID2SYM(rb_intern("bool_vec3"));
156
+ case TINYGLTF_PARAMETER_TYPE_BOOL_VEC4: return ID2SYM(rb_intern("bool_vec4"));
157
+ case TINYGLTF_PARAMETER_TYPE_FLOAT_MAT2: return ID2SYM(rb_intern("float_mat2"));
158
+ case TINYGLTF_PARAMETER_TYPE_FLOAT_MAT3: return ID2SYM(rb_intern("float_mat3"));
159
+ case TINYGLTF_PARAMETER_TYPE_FLOAT_MAT4: return ID2SYM(rb_intern("float_mat4"));
160
+ case TINYGLTF_PARAMETER_TYPE_SAMPLER_2D: return ID2SYM(rb_intern("sampler_2d"));
161
+ default: return ID2SYM(rb_intern("unknown"));
162
+ }
163
+ }
164
+
165
+ VALUE type_to_sym(int type) {
166
+ switch(type) {
167
+ case TINYGLTF_TYPE_VEC2: return ID2SYM(rb_intern("vec2"));
168
+ case TINYGLTF_TYPE_VEC3: return ID2SYM(rb_intern("vec3"));
169
+ case TINYGLTF_TYPE_VEC4: return ID2SYM(rb_intern("vec4"));
170
+ case TINYGLTF_TYPE_MAT2: return ID2SYM(rb_intern("mat2"));
171
+ case TINYGLTF_TYPE_MAT3: return ID2SYM(rb_intern("mat3"));
172
+ case TINYGLTF_TYPE_MAT4: return ID2SYM(rb_intern("mat4"));
173
+ case TINYGLTF_TYPE_SCALAR: return ID2SYM(rb_intern("scalar"));
174
+ case TINYGLTF_TYPE_VECTOR: return ID2SYM(rb_intern("vector"));
175
+ case TINYGLTF_TYPE_MATRIX: return ID2SYM(rb_intern("matrix"));
176
+ default: return ID2SYM(rb_intern("unknown"));
177
+ }
178
+ }
179
+
180
+ VALUE image_format_to_sym(int fmt) {
181
+ switch(fmt) {
182
+ case TINYGLTF_IMAGE_FORMAT_JPEG: return ID2SYM(rb_intern("jpeg"));
183
+ case TINYGLTF_IMAGE_FORMAT_PNG: return ID2SYM(rb_intern("png"));
184
+ case TINYGLTF_IMAGE_FORMAT_BMP: return ID2SYM(rb_intern("bmp"));
185
+ case TINYGLTF_IMAGE_FORMAT_GIF: return ID2SYM(rb_intern("gif"));
186
+ default: return ID2SYM(rb_intern("unknown"));
187
+ }
188
+ }
189
+
190
+ VALUE texture_format_to_sym(int fmt) {
191
+ switch(fmt) {
192
+ case TINYGLTF_TEXTURE_FORMAT_ALPHA: return ID2SYM(rb_intern("alpha"));
193
+ case TINYGLTF_TEXTURE_FORMAT_RGB: return ID2SYM(rb_intern("rgb"));
194
+ case TINYGLTF_TEXTURE_FORMAT_RGBA: return ID2SYM(rb_intern("rgba"));
195
+ case TINYGLTF_TEXTURE_FORMAT_LUMINANCE: return ID2SYM(rb_intern("luminance"));
196
+ case TINYGLTF_TEXTURE_FORMAT_LUMINANCE_ALPHA: return ID2SYM(rb_intern("luminance_alpha"));
197
+ default: return ID2SYM(rb_intern("unknown"));
198
+ }
199
+ }
200
+
201
+ VALUE texture_target_to_sym(int tgt) {
202
+ switch(tgt) {
203
+ case TINYGLTF_TEXTURE_TARGET_TEXTURE2D: return ID2SYM(rb_intern("texture2d"));
204
+ default: return ID2SYM(rb_intern("unknown"));
205
+ }
206
+ }
207
+
208
+ VALUE texture_type_to_sym(int type) {
209
+ switch(type) {
210
+ case TINYGLTF_TEXTURE_TYPE_UNSIGNED_BYTE: return ID2SYM(rb_intern("ubyte"));
211
+ default: return ID2SYM(rb_intern("unknown"));
212
+ }
213
+ }
214
+
215
+ VALUE target_to_sym(int tgt) {
216
+ switch(tgt) {
217
+ case TINYGLTF_TARGET_ARRAY_BUFFER: return ID2SYM(rb_intern("array_buffer"));
218
+ case TINYGLTF_TARGET_ELEMENT_ARRAY_BUFFER: return ID2SYM(rb_intern("element_array_buffer"));
219
+ default: return ID2SYM(rb_intern("unknown"));
220
+ }
221
+ }
222
+
223
+ VALUE shader_type_to_sym(int type) {
224
+ switch(type) {
225
+ case TINYGLTF_SHADER_TYPE_VERTEX_SHADER: return ID2SYM(rb_intern("vertex_shader"));
226
+ case TINYGLTF_SHADER_TYPE_FRAGMENT_SHADER: return ID2SYM(rb_intern("fragment_shader"));
227
+ default: return ID2SYM(rb_intern("unknown"));
228
+ }
229
+ }