Load and map instances to plants, ryzom/ryzomcore#621

develop
kaetemi 4 years ago
parent 47d6e09099
commit d6fe42f6a0

@ -30,6 +30,7 @@
#include <nel/misc/common.h> #include <nel/misc/common.h>
#include <nel/misc/cmd_args.h> #include <nel/misc/cmd_args.h>
//#include <nel/misc/bitmap.h> //#include <nel/misc/bitmap.h>
#include <nel/misc/string_view.h>
#include <nel/georges/u_form.h> #include <nel/georges/u_form.h>
#include <nel/georges/u_form_elm.h> #include <nel/georges/u_form_elm.h>
@ -41,16 +42,17 @@
//#include <nel/3d/zone_smoother.h> //#include <nel/3d/zone_smoother.h>
//#include <nel/3d/zone_tgt_smoother.h> //#include <nel/3d/zone_tgt_smoother.h>
//#include <nel/3d/zone_corner_smoother.h> //#include <nel/3d/zone_corner_smoother.h>
//#include <nel/ligo/zone_region.h>
#include <nel/3d/scene_group.h> #include <nel/3d/scene_group.h>
//#include <nel/ligo/zone_region.h>
#include <vector> #include <vector>
//#include <set> //#include <set>
#include <map> #include <map>
using namespace std; using namespace std;
using namespace NLMISC; using namespace NLMISC;
//using namespace NL3D; using namespace NL3D;
using namespace NLGEORGES; using namespace NLGEORGES;
//using namespace NLLIGO; //using namespace NLLIGO;
@ -60,8 +62,8 @@ namespace /* anonymous */
/* /*
Process: Process:
- Load all .plant sheets, map from .shape to .plant and bounding radius - Load all .plant sheets, map from .shape to .plant and bounding radius (Reference: prim_export, main.cpp)
- Load all source igs - Load all source igs (Reference: ig_info, ig_info.cpp)
- Load all reference igs, remove matching entries from source igs - Load all reference igs, remove matching entries from source igs
- Generate primitives - Generate primitives
@ -83,12 +85,17 @@ Debug arguments:
struct CPoint struct CPoint
{ {
std::string ZoneLwr;
CVector Pos; /* Position, height not necessarily specified (X="26218.738281" Y="-1092.078979" Z="0.000000") */ CVector Pos; /* Position, height not necessarily specified (X="26218.738281" Y="-1092.078979" Z="0.000000") */
float Angle; /* (2.827213) */ float Angle; /* (2.827213) */
float Scale; /* Scale (0.643217) */
bool Plant;
std::string Form; /* (FY_S2_savantree_B) */ std::string Form; /* (FY_S2_savantree_B) */
std::string Name; /* Generated unique name (ilot_008_savantree 13) */ std::string Name; /* Generated unique name (ilot_008_savantree 13) */
float Radius; /* Bounding radius (from plant sheet and scale) (0.450252) */ float Radius; /* Bounding radius (calculated from plant sheet and scale) (0.450252) */
float Scale; /* Scale (0.643217) */
}; };
/* /*
@ -158,6 +165,7 @@ struct CPlant
}; };
std::map<std::string, CPlant> s_ShapeToForm; std::map<std::string, CPlant> s_ShapeToForm;
std::set<CPoint> s_Instances;
bool loadLeveldesign() bool loadLeveldesign()
{ {
@ -185,7 +193,7 @@ bool loadLeveldesign()
if (plant.Shape.empty()) if (plant.Shape.empty())
continue; continue;
plant.Shape.c_str(); plant.Shape.c_str();
toLowerAscii(&plant.Shape[0]); (void)toLowerAscii(&plant.Shape[0]);
if (!form->getRootNode().getValueByName(plant.Radius, "3D.Bounding Radius")) if (!form->getRootNode().getValueByName(plant.Radius, "3D.Bounding Radius"))
continue; continue;
printf(" = '%s', %f\n", plant.Shape.c_str(), plant.Radius); printf(" = '%s', %f\n", plant.Shape.c_str(), plant.Radius);
@ -195,26 +203,66 @@ bool loadLeveldesign()
return true; return true;
} }
bool unbuildFlora() bool loadInstances()
{ {
CPath::addSearchPath(s_DfnDir, true, false); std::vector<std::string> igs;
CPath::addSearchPath(s_LeveldesignDir, true, false); CPath::getPathContent(s_SourceDir, true, false, true, igs);
if (!loadLeveldesign())
return false;
for (std::vector<std::string>::iterator it(igs.begin()), end(igs.end()); it != end; ++it)
/*
CInstanceGroup ig;
CIFile inputStream;
if (!inputStream.open(string(argv[1])))
{ {
printf("unable to open %s\n", argv[1]); if (CFile::getExtension(*it) != nlstr("ig"))
return -1; 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<std::string, CPlant>::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) bool unbuildFlora(NLMISC::CCmdArgs &args)

Loading…
Cancel
Save