MCPcopy Create free account
hub / github.com/KhronosGroup/COLLADA2GLTF / writeJSON

Method writeJSON

GLTF/src/GLTFAnimation.cpp:30–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30void GLTF::Animation::writeJSON(void* writer, GLTF::Options* options) {
31 rapidjson::Writer<rapidjson::StringBuffer>* jsonWriter = (rapidjson::Writer<rapidjson::StringBuffer>*)writer;
32
33 jsonWriter->Key("channels");
34 jsonWriter->StartArray();
35
36 std::vector<GLTF::Animation::Sampler*> samplers;
37 for (GLTF::Animation::Channel* channel : channels) {
38 if (channel->target->node->id >= 0) {
39 if (channel->sampler->id < 0) {
40 channel->sampler->id = samplers.size();
41 channel->sampler->path = channel->target->path;
42 samplers.push_back(channel->sampler);
43 }
44 jsonWriter->StartObject();
45 channel->writeJSON(writer, options);
46 jsonWriter->EndObject();
47 }
48 }
49 jsonWriter->EndArray();
50
51 std::map<std::string, std::string> parameterMap;
52 if (options->version == "1.0") {
53 int timeIndex = 0;
54 std::map<std::string, std::string>::iterator findParameter;
55 std::map<std::string, int> pathCounts;
56 std::map<std::string, int>::iterator findPathCount;
57 for (GLTF::Animation::Sampler* sampler : samplers) {
58 std::string inputString = "TIME";
59 std::string inputAccessorId = sampler->input->getStringId();
60 if (timeIndex > 0) {
61 findParameter = parameterMap.find(inputAccessorId);
62 if (findParameter == parameterMap.end()) {
63 inputString = "TIME_" + std::to_string(timeIndex);
64 parameterMap[inputAccessorId] = inputString;
65 timeIndex++;
66 }
67 }
68 else {
69 parameterMap[inputAccessorId] = inputString;
70 timeIndex++;
71 }
72 sampler->inputString = inputString;
73 std::string path = pathString(sampler->path);
74 int count = 0;
75 findPathCount = pathCounts.find(path);
76 if (findPathCount == pathCounts.end()) {
77 pathCounts[path] = 1;
78 }
79 else {
80 count = findPathCount->second;
81 pathCounts[path]++;
82 }
83 std::string outputString = path + (count > 0 ? "_" + std::to_string(count) : "");
84 std::string outputAccessorId = sampler->output->getStringId();
85 parameterMap[outputAccessorId] = outputString;
86 sampler->outputString = outputString;
87 }

Callers

nothing calls this directly

Calls 2

pathStringFunction · 0.85
getStringIdMethod · 0.80

Tested by

no test coverage detected