From ff85fcb175f86d4bb9ee8e5aa76f6cc7a89a29bf Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Fri, 6 Dec 2024 19:54:32 +0800 Subject: [PATCH 1/5] fbx filepath & userdata material --- projects/FBX/FBXSDK.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/projects/FBX/FBXSDK.cpp b/projects/FBX/FBXSDK.cpp index 407ed40af..f51018884 100644 --- a/projects/FBX/FBXSDK.cpp +++ b/projects/FBX/FBXSDK.cpp @@ -358,6 +358,7 @@ struct ReadFBXFile: INode { fbx_object->userData().set2("version", vec3i(major, minor, revision)); usedPath = lFilename; _inner_fbx_object = fbx_object; + fbx_object->userData().set2("file_path", usedPath); set_output("fbx_object", std::move(fbx_object)); } @@ -616,7 +617,6 @@ static std::shared_ptr GetMesh(FbxNode* pNode) { ud.set2("faceset_count", mat_count); prim_set_abcpath(prim.get(), format("/ABC/{}", nodeName)); if (mat_count > 0) { - Json mat_json; for (auto i = 0; i < mat_count; i++) { FbxSurfaceMaterial* material = pNode->GetMaterial(i); ud.set2(format("faceset_{}", i), material->GetName()); @@ -768,9 +768,8 @@ static std::shared_ptr GetMesh(FbxNode* pNode) { } } } - mat_json[mat_name] = json; + ud.set2(mat_name, json.dump()); } - ud.set2("material", mat_json.dump()); } return prim; } @@ -997,6 +996,8 @@ struct NewFBXImportSkin : INode { for (int i = 0; i < availableRootNames.size(); i++) { ud.set2(format("AvailableRootName_{}", i), availableRootNames[i]); } + auto file_path = fbx_object->userData().get2("file_path"); + ud.set2("file_path", file_path); } if (get_input2("CopyFacesetToMatid")) { prim_copy_faceset_to_matid(prim.get()); From 57157eb5efd9f6234a0a1c5aa931498bef4b2a18 Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Fri, 6 Dec 2024 20:37:06 +0800 Subject: [PATCH 2/5] WIP --- projects/FBX/FBXSDK.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/projects/FBX/FBXSDK.cpp b/projects/FBX/FBXSDK.cpp index f51018884..69de181c6 100644 --- a/projects/FBX/FBXSDK.cpp +++ b/projects/FBX/FBXSDK.cpp @@ -1022,6 +1022,32 @@ ZENDEFNODE(NewFBXImportSkin, { {"FBXSDK"}, }); +struct NewFBXResolveTexPath : INode { + void apply() override { + auto prim = get_input("prim"); + + std::string hint_directory = get_input2("HintDirectory"); + std::string target_directory = get_input2("TargetDirectory"); + zeno::log_info("hint_path: {}", hint_directory); + + set_output2("prim", prim); + } +}; + +ZENDEFNODE(NewFBXResolveTexPath, { + { + "prim", + {"directory", "HintDirectory"}, + {"bool", "CopyImage", "0"}, + {"directory", "TargetDirectory"}, + }, + { + "prim", + }, + {}, + {"FBXSDK"}, +}); + static int GetSkeletonFromBindPose(FbxManager* lSdkManager, FbxScene* lScene, std::shared_ptr& prim) { auto pose_count = lScene->GetPoseCount(); bool found_bind_pose = false; From 1282039729c11fe94bf26f1d468ee543d1d31d14 Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Sat, 7 Dec 2024 00:29:48 +0800 Subject: [PATCH 3/5] WIP --- projects/FBX/FBXSDK.cpp | 90 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 5 deletions(-) diff --git a/projects/FBX/FBXSDK.cpp b/projects/FBX/FBXSDK.cpp index 69de181c6..5b030cd15 100644 --- a/projects/FBX/FBXSDK.cpp +++ b/projects/FBX/FBXSDK.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -30,6 +31,7 @@ #include "magic_enum.hpp" #include using Json = nlohmann::ordered_json; +namespace fs = std::filesystem; #ifdef ZENO_FBXSDK #include @@ -458,7 +460,6 @@ void getAttr(T* arr, std::string name, std::shared_ptr prim) { } } else if (arr->GetMappingMode() == FbxLayerElement::EMappingMode::eByPolygonVertex) { - zeno::log_info("{}, eByPolygonVertex", name); auto &attr = prim->loops.add_attr(name); for (auto i = 0; i < prim->loops.size(); i++) { int pIndex = i; @@ -574,7 +575,6 @@ static std::shared_ptr GetMesh(FbxNode* pNode) { } } else if (arr->GetMappingMode() == FbxLayerElement::EMappingMode::eByPolygonVertex) { - zeno::log_info("{}, eByPolygonVertex", name); if (arr->GetReferenceMode() == FbxLayerElement::EReferenceMode::eDirect) { auto &uvs = prim->loops.add_attr("uvs"); std::iota(uvs.begin(), uvs.end(), 0); @@ -1023,11 +1023,91 @@ ZENDEFNODE(NewFBXImportSkin, { }); struct NewFBXResolveTexPath : INode { + void StringSplitReverse(std::string str, const char split, std::vector & ostrs) + { + std::istringstream iss(str); + std::string token; + std::vector res(0); + while(getline(iss, token, split)) + { + res.push_back(token); + } + ostrs.resize(0); + for(int i=res.size()-1; i>=0;i--) + { + ostrs.push_back(res[i]); + } + } + void formPath(std::vector &tokens) + { + for(int i=1; i paths; + StringSplitReverse(origPath, '/', paths); + formPath(paths); + for(int i=0; i("prim"); std::string hint_directory = get_input2("HintDirectory"); std::string target_directory = get_input2("TargetDirectory"); + + auto &ud = prim->userData(); + auto file_path = prim->userData().get2("file_path"); + fs::path path = fs::u8path(file_path); + auto file_path_directory = path.parent_path().u8string(); + if (hint_directory.empty()) { + hint_directory = file_path_directory; + } + auto faceset_count = ud.get2("faceset_count", 0); + for (auto i = 0; i < faceset_count; i++) { + auto mat_name = ud.get2(format("faceset_{}", i)); + auto content = ud.get2(mat_name); + Json mat_json = Json::parse(content); + std::vector keys; + for (auto &[key, _]: mat_json.items()) { + if (zeno::ends_with(key, "_tex")) { + keys.push_back(key); + } + } + for (auto &key: keys) { + std::string tex_path_str = mat_json[key]; + if (key == "diffuse_tex") { + + } + tex_path_str = zeno::replace_all(tex_path_str, "\\", "/"); + + std::string oPath; + findFile(hint_directory, tex_path_str, oPath); + mat_json[key] = oPath; + } + ud.set2(mat_name, mat_json.dump()); + } + zeno::log_info("hint_path: {}", hint_directory); set_output2("prim", prim); @@ -1037,9 +1117,9 @@ struct NewFBXResolveTexPath : INode { ZENDEFNODE(NewFBXResolveTexPath, { { "prim", - {"directory", "HintDirectory"}, - {"bool", "CopyImage", "0"}, - {"directory", "TargetDirectory"}, + {"string", "HintDirectory"}, + {"bool", "CopyImageToTargetDirectory", "0"}, + {"string", "TargetDirectory"}, }, { "prim", From 3e98ab1b05cf9092c6bd39bd01e75f995ae862dd Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Sat, 7 Dec 2024 00:34:48 +0800 Subject: [PATCH 4/5] improve --- projects/FBX/FBXSDK.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/projects/FBX/FBXSDK.cpp b/projects/FBX/FBXSDK.cpp index 5b030cd15..f16887f38 100644 --- a/projects/FBX/FBXSDK.cpp +++ b/projects/FBX/FBXSDK.cpp @@ -1074,7 +1074,6 @@ struct NewFBXResolveTexPath : INode { auto prim = get_input("prim"); std::string hint_directory = get_input2("HintDirectory"); - std::string target_directory = get_input2("TargetDirectory"); auto &ud = prim->userData(); auto file_path = prim->userData().get2("file_path"); @@ -1108,8 +1107,6 @@ struct NewFBXResolveTexPath : INode { ud.set2(mat_name, mat_json.dump()); } - zeno::log_info("hint_path: {}", hint_directory); - set_output2("prim", prim); } }; @@ -1118,8 +1115,6 @@ ZENDEFNODE(NewFBXResolveTexPath, { { "prim", {"string", "HintDirectory"}, - {"bool", "CopyImageToTargetDirectory", "0"}, - {"string", "TargetDirectory"}, }, { "prim", From adacaf99a2b2b963875645bace95384bab3c34b2 Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Sat, 7 Dec 2024 00:50:06 +0800 Subject: [PATCH 5/5] CopyFile --- zeno/src/nodes/prim/SimpleGeometry.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/zeno/src/nodes/prim/SimpleGeometry.cpp b/zeno/src/nodes/prim/SimpleGeometry.cpp index 3bcfe5b2f..3dfb9463c 100644 --- a/zeno/src/nodes/prim/SimpleGeometry.cpp +++ b/zeno/src/nodes/prim/SimpleGeometry.cpp @@ -1457,6 +1457,29 @@ ZENDEFNODE(RemoveFolder, { {"create"}, }); +struct CopyFile : zeno::INode { + void apply() override { + namespace fs = std::filesystem; + auto sourcePath = fs::u8path(get_input2("sourcePath")); + auto targetPath = fs::u8path(get_input2("targetPath")); + auto folderPath = targetPath.parent_path(); + if (fs::exists(folderPath) == false) { + fs::create_directories(folderPath); + } + fs::copy(sourcePath, targetPath, fs::copy_options::overwrite_existing); + } +}; + +ZENDEFNODE(CopyFile, { + { + {"readpath", "sourcePath"}, + {"writepath", "targetPath"}, + }, + {}, + {}, + {"create"}, +}); + struct FFMPEGImagesToVideo : zeno::INode { virtual void apply() override { namespace fs = std::filesystem;