From b47eab23f55c729dd0258528b3fcae7b2352e566 Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Mon, 11 Dec 2023 20:29:54 +0800 Subject: [PATCH] improve json --- zeno/src/nodes/JsonProcess.cpp | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/zeno/src/nodes/JsonProcess.cpp b/zeno/src/nodes/JsonProcess.cpp index 6d84d27a13..7ac4d6d56c 100644 --- a/zeno/src/nodes/JsonProcess.cpp +++ b/zeno/src/nodes/JsonProcess.cpp @@ -5,6 +5,7 @@ #include #include #include "zeno/utils/fileio.h" +#include "zeno/utils/string.h" using Json = nlohmann::json; namespace zeno { @@ -215,4 +216,59 @@ ZENDEFNODE(JsonGetTypeName, { }, }); +struct JsonData : zeno::INode { + virtual void apply() override { + auto json = get_input("json"); + auto path = get_input2("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(); + 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" + }, +}); + } \ No newline at end of file