Skip to content

Commit

Permalink
Merge pull request #1611 from zenustech/improve-json
Browse files Browse the repository at this point in the history
improve json
  • Loading branch information
zhxx1987 authored Dec 11, 2023
2 parents 25602b8 + b47eab2 commit bbc213c
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions zeno/src/nodes/JsonProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <zeno/zeno.h>
#include <tinygltf/json.hpp>
#include "zeno/utils/fileio.h"
#include "zeno/utils/string.h"
using Json = nlohmann::json;

namespace zeno {
Expand Down Expand Up @@ -215,4 +216,59 @@ ZENDEFNODE(JsonGetTypeName, {
},
});

struct JsonData : zeno::INode {
virtual void apply() override {
auto json = get_input<JsonObject>("json");
auto path = get_input2<std::string>("path");
auto strings = zeno::split_str(path, ':');
auto type = strings[1];
path = strings[0];
auto names = split_str(path, '/');

for (auto & name : names) {
json->json = json->json[name];
}


if (type == "json") {
auto out_json = std::make_shared<JsonObject>();
out_json->json = json->json;
set_output("out", out_json);
}
else if (type == "int") {
set_output2("out", int(json->json));
}
else if (type == "float") {
set_output2("out", float(json->json));
}
else if (type == "string") {
set_output2("out", std::string(json->json));
}
else if (type == "vec2f") {
float x = float(json->json[0]);
float y = float(json->json[1]);
set_output2("out", vec2f(x, y));
}
else if (type == "vec3f") {
float x = float(json->json[0]);
float y = float(json->json[1]);
float z = float(json->json[2]);
set_output2("out", vec3f(x, y, z));
}
}
};
ZENDEFNODE(JsonData, {
{
{"json"},
{"string", "path"},
},
{
"out",
},
{},
{
"json"
},
});

}

0 comments on commit bbc213c

Please sign in to comment.