9 using namespace VSFileSystem;
32 std::vector< std::string >
alpha;
33 std::vector< GFXMaterial >
mat;
34 std::vector< TerrainData >
data;
44 ( (
QuadTree*) userData )->endElement( name );
90 EnumMap::Pair(
"UNKNOWN",
UNKNOWN ),
91 EnumMap::Pair(
"Terrain",
TERRAIN ),
92 EnumMap::Pair(
"Texture",
TEXTURE ),
93 EnumMap::Pair(
"Material",
MATERIAL ),
94 EnumMap::Pair(
"Data",
DATA ),
102 EnumMap::Pair(
"UNKNOWN",
UNKNOWN ),
103 EnumMap::Pair(
"Detail",
DETAIL ),
105 EnumMap::Pair(
"Level",
LEVEL ),
106 EnumMap::Pair(
"Blend",
BLEND ),
107 EnumMap::Pair(
"File",
FFILE ),
111 EnumMap::Pair(
"Reflect",
REFLECT ),
112 EnumMap::Pair(
"Color",
COLOR ),
113 EnumMap::Pair(
"Scale",
SCALE ),
114 EnumMap::Pair(
"ScaleS",
SCALES ),
115 EnumMap::Pair(
"ScaleT",
SCALET ),
116 EnumMap::Pair(
"OriginX",
ORIGINX ),
117 EnumMap::Pair(
"OriginY",
ORIGINY ),
118 EnumMap::Pair(
"red",
RED ),
119 EnumMap::Pair(
"green",
GREEN ),
120 EnumMap::Pair(
"blue",
BLUE ),
121 EnumMap::Pair(
"alpha",
ALPHA ),
122 EnumMap::Pair(
"power",
POWER ),
123 EnumMap::Pair(
"radius",
RADIUS ),
140 using namespace TerrainXML;
145 AttributeList::const_iterator iter;
151 for (iter = attributes.begin(); iter != attributes.end(); iter++) {
161 RootCornerData.Level =
parse_int( (*iter).value );
185 xml->alpha.push_back( std::string() );
186 xml->animation.push_back( std::string() );
188 for (iter = attributes.begin(); iter != attributes.end(); iter++) {
192 textures.back().tex.filename = strdup( (*iter).value.c_str() );
195 xml->alpha.back() = (*iter).value.c_str();
198 xml->animation.back() = (*iter).value.c_str();
201 sscanf( ( (*iter).value ).c_str(),
"%s %s", csrc, cdst );
212 for (iter = attributes.begin(); iter != attributes.end(); iter++) {
219 xml->mat.back().power =
parse_float( (*iter).value );
225 for (iter = attributes.begin(); iter != attributes.end(); iter++) {
244 for (iter = attributes.begin(); iter != attributes.end(); iter++) {
263 for (iter = attributes.begin(); iter != attributes.end(); iter++) {
282 for (iter = attributes.begin(); iter != attributes.end(); iter++) {
302 for (iter = attributes.begin(); iter != attributes.end(); iter++) {
306 xml->data.back().scale =
parse_int( (*iter).value );
309 xml->data.back().OriginX =
parse_float( (*iter).value );
312 xml->data.back().OriginY =
parse_float( (*iter).value );
315 xml->data.back().file = (*iter).value;
318 xml->data.back().terrainfile = (*iter).value;
331 void QuadTree::SetXSizes(
int mX,
unsigned int maxX )
335 if (maxX > this->maxX)
339 void QuadTree::SetZSizes(
int mZ,
unsigned int maxZ )
343 if (maxZ > this->maxZ)
347 void QuadTree::LoadXML(
const char *filename,
const Vector &Scales,
const float Radius )
349 const int chunk_size = 16384;
350 std::vector< unsigned int >ind;
360 xml->SphereSizeZ = -1;
365 XML_Parser parser = XML_ParserCreate( NULL );
366 XML_SetUserData( parser,
this );
368 XML_Parse( parser, ( f.
ReadFull() ).c_str(), f.
Size(), 1 );
388 XML_ParserFree( parser );
390 for (i = 0; i <
textures.size(); i++) {
393 if (
textures[i].tex.filename || xml->animation[i].length() > 0) {
395 if (xml->animation[i].length() > 0) {
398 if (xml->alpha[i].length() > 0)
411 for (i = 0; i < xml->data.size(); i++) {
414 hm.
ZOrigin = (
int) xml->data[i].OriginY;
415 hm.
Scale = xml->data[i].scale;
416 unsigned char *palette;
424 hm.
XSize = tex.sizeX;
425 hm.
ZSize = tex.sizeY;
429 unsigned long xsize = 0;
430 unsigned long zsize = 0;
441 assert( xsize == hm.
XSize && zsize == hm.
ZSize );
447 if (Radius != 0 && xml->radius != 0) {
449 Radius < 0 ? xml->radius : Radius,
450 xml->SphereSizeZ < 0 ? hm.
ZSize<<hm.
Scale : xml->SphereSizeZ );
455 GFXVertex *
v = vertices.BeginMutate( 0 )->vertices;
459 v[0].
SetTexCoord( nonlinear_transform->TransformS( xmax,
461 nonlinear_transform->TransformT( hm.
ZOrigin, xml->scalet ) );
463 v[0].
SetNormal(
Vector( Norm0.i*Scales.i, Norm0.j*Scales.j, Norm0.k*Scales.k ) );
467 nonlinear_transform->TransformT( hm.
ZOrigin, xml->scalet ) );
469 v[1].
SetNormal(
Vector( Norm0.i*Scales.i, Norm0.j*Scales.j, Norm0.k*Scales.k ) );
474 nonlinear_transform->TransformT( zmax, xml->scalet ) );
476 v[2].
SetNormal(
Vector( Norm0.i*Scales.i, Norm0.j*Scales.j, Norm0.k*Scales.k ) );
478 v[3].
SetVertex( nonlinear_transform->Transform(
Vector( xmax, 0, zmax ) ) );
479 v[3].
SetTexCoord( nonlinear_transform->TransformS( zmax,
481 nonlinear_transform->TransformT( zmax, xml->scalet ) );
483 v[3].
SetNormal(
Vector( Norm0.i*Scales.i, Norm0.j*Scales.j, Norm0.k*Scales.k ) );
484 vertices.EndMutate();
491 Vector( 1.0F/Scales.i, 1.0F/Scales.j, 1.0F/Scales.k ),
495 root->AddHeightMap( RootCornerData, hm );
507 Vector( 1.0F/Scales.i, 1.0F/Scales.j, 1.0F/Scales.k ),