13 descriptor.
_name = name;
24 if ( terrainDescriptorPath.
empty() )
31 AddVariable( descriptor,
"waterCaustics", pt.get<
string>(
"waterCaustics" ) );
32 AddVariable( descriptor,
"underwaterAlbedoTexture", pt.get<
string>(
"underwaterAlbedoTexture",
"sandfloor009a.jpg" ) );
33 AddVariable( descriptor,
"underwaterDetailTexture", pt.get<
string>(
"underwaterDetailTexture",
"terrain_detail_NM.png" ) );
34 AddVariable( descriptor,
"tileNoiseTexture", pt.get<
string>(
"tileNoiseTexture",
"bruit_gaussien_2.jpg" ) );
35 AddVariableF( descriptor,
"underwaterTileScale", pt.get<
F32>(
"underwaterTileScale", 1.0f ) );
38 boost::property_tree::ptree descTree = {};
39 XML::readXML( Paths::g_heightmapLocation / terrainDescriptorPath /
"descriptor.xml", descTree );
41 AddVariable( descriptor,
"heightfield", descTree.get<
string>(
"heightfield",
"" ) );
42 AddVariable( descriptor,
"heightfieldTex", descTree.get<
string>(
"heightfieldTex",
"" ) );
44 descriptor.
_dimensions.
set( descTree.get<
U16>(
"heightfieldResolution.<xmlattr>.x", 0 ),
45 descTree.get<
U16>(
"heightfieldResolution.<xmlattr>.y", 0 ) );
47 descriptor.
_ringCount =
to_U8( std::max( descTree.get<
U8>(
"tileSettings.<xmlattr>.ringCount", 4u ) + 1u, 2u ) );
48 descriptor.
_startWidth = descTree.get<
F32>(
"tileSettings.<xmlattr>.startWidth", 0.25f );
62 descTree.get<
F32>(
"altitudeRange.<xmlattr>.max", 255.0f ) );
64 AddVariable( descriptor,
"grassMap", descTree.get<
string>(
"vegetation.grassMap" ) );
65 AddVariable( descriptor,
"treeMap", descTree.get<
string>(
"vegetation.treeMap" ) );
67 for (
I32 j = 1; j < 5; ++j )
78 alphaMapDescriptor =
ResourcePath{ descTree.get<
string>(
"alphaMaps.<xmlattr>.file",
"" ) };
79 for ( boost::property_tree::ptree::iterator itLayerData = std::begin( descTree.get_child(
"alphaMaps" ) );
80 itLayerData != std::end( descTree.get_child(
"alphaMaps" ) );
83 const string format( itLayerData->first );
84 if ( format.find(
"<xmlcomment>" ) != string::npos || format.find(
"<xmlattr>" ) != string::npos )
89 const U8 matIndex = itLayerData->second.get<
U8>(
"<xmlattr>.material", 0u );
94 const U8 layerIndex = itLayerData->second.get<
U8>(
"<xmlattr>.channel", 0u );
98 tileFactors.
s =
CLAMPED( itLayerData->second.get(
"<xmlattr>.s", 1.f ), 1.f, 255.f );
99 tileFactors.
t =
CLAMPED( itLayerData->second.get(
"<xmlattr>.t", 1.f ), 1.f, 255.f );
105 if ( alphaMapDescriptor.
empty() )
111 boost::property_tree::ptree alphaTree = {};
112 XML::readXML( Paths::g_heightmapLocation / terrainDescriptorPath / alphaMapDescriptor, alphaTree );
114 const U8 numLayers = alphaTree.get<
U8>(
"AlphaData.nImages" );
115 const U8 numImages = alphaTree.get<
U8>(
"AlphaData.nLayers" );
116 if ( numLayers == 0 || numImages == 0 )
123 const std::string imageListNode =
"AlphaData.ImageList";
126 std::array<string, 4> arrayMaterials;
127 string layerOffsetStr;
128 for ( boost::property_tree::ptree::iterator itImage = std::begin( alphaTree.get_child( imageListNode ) );
129 itImage != std::end( alphaTree.get_child( imageListNode ) );
132 string layerName( itImage->second.data() );
133 string format( itImage->first );
135 if ( format.find(
"<xmlcomment>" ) != string::npos || format.find(
"<xmlattr>" ) != string::npos )
142 AddVariable( descriptor,
"blendMap" + layerOffsetStr,
stripQuotes( itImage->second.get<std::string>(
"FileName",
"" ).c_str() ) );
144 for ( boost::property_tree::ptree::iterator itLayer = std::begin( itImage->second.get_child(
"LayerList" ) );
145 itLayer != std::end( itImage->second.get_child(
"LayerList" ) );
148 if (
string( itLayer->first ).find(
"<xmlcomment>" ) != string::npos )
153 string layerColour = itLayer->second.get<
string>(
"LayerColour",
"" );
155 for ( boost::property_tree::ptree::iterator itMaterial = std::begin( itLayer->second.get_child(
"MtlList" ) );
156 itMaterial != std::end( itLayer->second.get_child(
"MtlList" ) );
159 if (
string( itMaterial->first ).find(
"<xmlcomment>" ) != string::npos )
164 materialName = itMaterial->second.data();
169 AddVariable( descriptor, layerColour + layerOffsetStr +
"_mat", materialName );
179 pt.put(
"descriptor",
GetVariable( descriptor,
"descriptor" ) );
180 pt.put(
"waterCaustics",
GetVariable( descriptor,
"waterCaustics" ) );
181 pt.put(
"underwaterAlbedoTexture",
GetVariable( descriptor,
"underwaterAlbedoTexture" ) );
182 pt.put(
"underwaterDetailTexture",
GetVariable( descriptor,
"underwaterDetailTexture" ) );
183 pt.put(
"tileNoiseTexture",
GetVariable( descriptor,
"tileNoiseTexture" ) );
184 pt.put(
"underwaterTileScale",
GetVariableF( descriptor,
"underwaterTileScale" ) );
200 if ( it != std::end( descriptor. _variables ) )
221 return descriptor._dimensions.maxComponent() / 4;
228 return descriptor._ringTileCount[index];
T minComponent() const noexcept
get the smallest value of X or Y
void set(const T *v) noexcept
set the 2 components of the vector manually using a source pointer to a (large enough) array
Str StringFormat(const char *fmt, Args &&...args)
string to_string(GET_PASS_TYPE< T > value)
void readXML(const ResourcePath &path, boost::property_tree::ptree &tree)
constexpr U8 g_minTerrainSideLength
Handle console commands that start with a forward slash.
U32 MaxNodesPerStage(const TerrainDescriptor &descriptor) noexcept
static const vec2< F32 > VECTOR2_UNIT
void AddVariable(TerrainDescriptor &descriptor, std::string_view name, std::string_view value)
F32 GetVariableF(const TerrainDescriptor &descriptor, std::string_view name)
void SaveToXML(const TerrainDescriptor &descriptor, boost::property_tree::ptree &pt)
bool LoadFromXML(TerrainDescriptor &descriptor, const boost::property_tree::ptree &pt, std::string_view name)
constexpr U64 _ID(const char *const str, const U64 value=val_64_const) noexcept
constexpr U8 to_U8(const T value)
::value constexpr T CLAMPED(T n, T min, T max) noexcept
string GetVariable(const TerrainDescriptor &descriptor, std::string_view name)
void AddVariableF(TerrainDescriptor &descriptor, std::string_view name, F32 value)
void Init(ImTextureID texture1, ImTextureID texture2, ImTextureID dockTexture)
Project const SceneEntry & entry
U8 TileRingCount(const TerrainDescriptor &descriptor, const U8 index) noexcept
string stripQuotes(const std::string_view input)
vec2< F32 > _altitudeRange
std::array< vec2< F32 >, 4 > LayerDataEntry
hashMap< U64, string > _variables
std::array< U8, 16 > _ringTileCount
LayerData _layerDataEntries
hashMap< U64, F32 > _variablesf
StringReturnType< N > string() const noexcept
bool empty() const noexcept