From d6fe42f6a0f3012b7a0d62a08d98ab673e34eef2 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 25 Nov 2020 08:43:19 +0800 Subject: [PATCH] Load and map instances to plants, ryzom/ryzomcore#621 --- .../ligo/unbuild_flora/unbuild_flora.cpp | 92 ++++++++++++++----- 1 file changed, 70 insertions(+), 22 deletions(-) diff --git a/nel/tools/ligo/unbuild_flora/unbuild_flora.cpp b/nel/tools/ligo/unbuild_flora/unbuild_flora.cpp index 7aeb404b4..5aa411fc2 100644 --- a/nel/tools/ligo/unbuild_flora/unbuild_flora.cpp +++ b/nel/tools/ligo/unbuild_flora/unbuild_flora.cpp @@ -30,6 +30,7 @@ #include #include //#include +#include #include #include @@ -41,16 +42,17 @@ //#include //#include //#include -//#include #include +//#include + #include //#include #include using namespace std; using namespace NLMISC; -//using namespace NL3D; +using namespace NL3D; using namespace NLGEORGES; //using namespace NLLIGO; @@ -60,8 +62,8 @@ namespace /* anonymous */ /* Process: -- Load all .plant sheets, map from .shape to .plant and bounding radius -- Load all source igs +- Load all .plant sheets, map from .shape to .plant and bounding radius (Reference: prim_export, main.cpp) +- Load all source igs (Reference: ig_info, ig_info.cpp) - Load all reference igs, remove matching entries from source igs - Generate primitives @@ -83,12 +85,17 @@ Debug arguments: struct CPoint { + std::string ZoneLwr; + CVector Pos; /* Position, height not necessarily specified (X="26218.738281" Y="-1092.078979" Z="0.000000") */ float Angle; /* (2.827213) */ + float Scale; /* Scale (0.643217) */ + + bool Plant; std::string Form; /* (FY_S2_savantree_B) */ std::string Name; /* Generated unique name (ilot_008_savantree 13) */ - float Radius; /* Bounding radius (from plant sheet and scale) (0.450252) */ - float Scale; /* Scale (0.643217) */ + float Radius; /* Bounding radius (calculated from plant sheet and scale) (0.450252) */ + }; /* @@ -158,6 +165,7 @@ struct CPlant }; std::map s_ShapeToForm; +std::set s_Instances; bool loadLeveldesign() { @@ -185,7 +193,7 @@ bool loadLeveldesign() if (plant.Shape.empty()) continue; plant.Shape.c_str(); - toLowerAscii(&plant.Shape[0]); + (void)toLowerAscii(&plant.Shape[0]); if (!form->getRootNode().getValueByName(plant.Radius, "3D.Bounding Radius")) continue; printf(" = '%s', %f\n", plant.Shape.c_str(), plant.Radius); @@ -195,26 +203,66 @@ bool loadLeveldesign() return true; } -bool unbuildFlora() +bool loadInstances() { - CPath::addSearchPath(s_DfnDir, true, false); - CPath::addSearchPath(s_LeveldesignDir, true, false); - - if (!loadLeveldesign()) - return false; + std::vector igs; + CPath::getPathContent(s_SourceDir, true, false, true, igs); - - /* - CInstanceGroup ig; - CIFile inputStream; - if (!inputStream.open(string(argv[1]))) + for (std::vector::iterator it(igs.begin()), end(igs.end()); it != end; ++it) { - printf("unable to open %s\n", argv[1]); - return -1; + if (CFile::getExtension(*it) != nlstr("ig")) + continue; + printf("%s\n", (*it).c_str()); + CInstanceGroup ig; + CIFile inputStream; + if (!inputStream.open(*it)) + { + nlwarning("Unable to open %s\n", (*it).c_str()); + return false; + } + ig.serial(inputStream); + CVector gpos = ig.getGlobalPos(); + if (gpos.x != 0.0f || gpos.y != 0.0f || gpos.z != 0.0f) + { + nlwarning("Invalid global pos: %f, %f, %f", gpos.x, gpos.y, gpos.z); + return false; + } + string zoneLwr = toLowerAscii(CFile::getFilenameWithoutExtension(*it)); + for (ptrdiff_t i = 0; i < (ptrdiff_t)ig._InstancesInfos.size(); ++i) + { + CInstanceGroup::CInstance &info = ig._InstancesInfos[i]; + CPoint instance; + instance.Pos = info.Pos; + instance.Angle = info.Rot.getAngle(); + instance.Scale = info.Scale.z; + string shape = toLowerAscii(info.Name); + printf("%s\n", shape.c_str()); + std::map::iterator formIt = s_ShapeToForm.find(shape); + if (formIt != s_ShapeToForm.end()) + { + instance.Form = formIt->second.Form; + instance.Name = CFile::getFilenameWithoutExtension(instance.Form) + nlstr("_") + zoneLwr + nlstr("_") + toString(i); + instance.Radius = instance.Scale * formIt->second.Radius; + printf(" = %f, %f, %f, %f, %f, '%s', '%s', %f\n", instance.Pos.x, instance.Pos.y, instance.Pos.z, instance.Angle, instance.Scale, instance.Form .c_str(), instance.Name.c_str(), instance.Radius); + instance.Plant = true; + } + else + { + instance.Plant = false; + } + } } - */ - return false; + return true; +} + +bool unbuildFlora() +{ + CPath::addSearchPath(s_DfnDir, true, false); + CPath::addSearchPath(s_LeveldesignDir, true, false); + + return loadLeveldesign() + && loadInstances(); } bool unbuildFlora(NLMISC::CCmdArgs &args)