-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
internal_merge_gltf.h
93 lines (66 loc) · 3.4 KB
/
internal_merge_gltf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
#include <filesystem>
#include <drake_vendor/nlohmann/json.hpp>
#include "drake/common/eigen_types.h"
namespace drake {
namespace geometry {
namespace render_gltf_client {
namespace internal {
/* Returns the parsed result of the indicated json file. */
nlohmann::json ReadJsonFile(const std::filesystem::path& json_path);
/* Creates the glTF matrix array from the given 4x4 matrix.
@returns A json list of 16 number values. */
nlohmann::json GltfMatrixFromEigenMatrix(const Matrix4<double>& matrix);
/* Creates a 4x4 matrix from the the glTF json entry representing the matrix.
@param matrix_json A list of 16 number values. */
Matrix4<double> EigenMatrixFromGltfMatrix(const nlohmann::json& matrix_json);
/* Note: glTF interrelates elements of arrays by having one element refer
to another by the other's index into the array. For all of these merging
functions, when the array elements have such indices, the merged index values
get incremented by the size of the target array before merging.
*/
/* Merges the "scenes" array from j2 into j1.
Upon return, j1 will contain the following scenes:
- Each scene from j1 and j2 whose name only appears in one of the files.
- For scenes in j1 and j2 with the same name, the node list of j2's scene
appended to the scene in j1. Any extras or extensions in j2's scene will
be lost. */
void MergeScenes(nlohmann::json* j1, nlohmann::json&& j2);
/* Merges the "nodes" array from j2 into j1. */
void MergeNodes(nlohmann::json* j1, nlohmann::json&& j2);
/* Merges the "meshes" array from j2 into j1. */
void MergeMeshes(nlohmann::json* j1, nlohmann::json&& j2);
/* Merges the "materials" array from j2 into j1. */
void MergeMaterials(nlohmann::json* j1, nlohmann::json&& j2);
/* Merges the "cameras" array from j2 into j1. */
void MergeCameras(nlohmann::json* j1, nlohmann::json&& j2);
/* Merges the "accessors" array from j2 into j1. */
void MergeAccessors(nlohmann::json* j1, nlohmann::json&& j2);
/* Merges the "bufferViews" array from j2 into j1. */
void MergeBufferViews(nlohmann::json* j1, nlohmann::json&& j2);
/* Merges the "buffers" array from j2 into j1. */
void MergeBuffers(nlohmann::json* j1, nlohmann::json&& j2);
/* Merges the "textures" array from j2 into j1. */
void MergeTextures(nlohmann::json* j1, nlohmann::json&& j2);
/* Merges the "images" array from j2 into j1. */
void MergeImages(nlohmann::json* j1, nlohmann::json&& j2);
/* Merges the "samplers" array from j2 into j1. */
void MergeSamplers(nlohmann::json* j1, nlohmann::json&& j2);
// TODO(SeanCurtis-TRI): For elements that aren't copied over (e.g. animation),
// their corresponding *data* should be removed from the buffer(s). This is an
// awkward task because:
// a. We need to cut out the right part of the data (go from encoded string
// to bytes and back again).
// b. All bufferViews that reference the buffer at higher byte addresses need
// to be identified and offset.
/* Merges the glTF data stored in the json j2 into j1.
This explicitly excludes skin data, animation, and morph target elements
(although the underlying data contained in buffers remains).
All index references in j2's elements are updated based on the number of
indices already used by j1.
@pre Both j1 and j2 indicate version 2.0 glTF files. */
void MergeGltf(nlohmann::json* j1, nlohmann::json&& j2);
} // namespace internal
} // namespace render_gltf_client
} // namespace geometry
} // namespace drake