diff --git a/projects/FBX/FBXSDK.cpp b/projects/FBX/FBXSDK.cpp index 2d47400ee..d3398ed00 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 @@ -358,6 +360,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)); } @@ -457,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; @@ -573,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); @@ -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()); @@ -1021,6 +1022,107 @@ ZENDEFNODE(NewFBXImportSkin, { {"FBXSDK"}, }); +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"); + + 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()); + } + + set_output2("prim", prim); + } +}; + +ZENDEFNODE(NewFBXResolveTexPath, { + { + "prim", + {"string", "HintDirectory"}, + }, + { + "prim", + }, + {}, + {"FBXSDK"}, +}); + static int GetSkeletonFromBindPose(FbxManager* lSdkManager, FbxScene* lScene, std::shared_ptr& prim) { auto pose_count = lScene->GetPoseCount(); bool found_bind_pose = false; 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;