Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 868 vs 869 for /trunk/Source Code/Environment/Terrain/TerrainLoader.cpp

Diff revisions: vs.
  @@ -253,39 +253,9 @@
253 253
254 254 U16 heightmapWidth = terrainDimensions.width;
255 255 U16 heightmapHeight = terrainDimensions.height;
256 - vectorImpl<U16> heightValues;
257 -
258 256 const stringImpl& terrainMapLocation = terrainDescriptor->getVariable("heightmapLocation");
259 257
260 258 stringImpl terrainRawFile(terrainDescriptor->getVariable("heightmap"));
261 - if (terrainDescriptor->is16Bit()) {
262 - assert(heightmapWidth != 0 && heightmapHeight != 0);
263 - // only raw files for 16 bit support
264 - assert(hasExtension(terrainRawFile, "raw"));
265 - // Read File Data
266 -
267 - vectorImpl<Byte> data;
268 - readFile(terrainMapLocation + terrainRawFile, data, FileType::BINARY);
269 - if (data.empty()) {
270 - return false;
271 - }
272 -
273 - U32 positionCount = to_U32(data.size());
274 - heightValues.reserve(positionCount / 2);
275 - for (U32 i = 0; i < positionCount + 1; i += 2) {
276 - heightValues.push_back((data[i + 1] << 8) |
277 - data[i]);
278 - }
279 -
280 - } else {
281 - ImageTools::ImageData img;
282 - ImageTools::ImageDataInterface::CreateImageData(terrainMapLocation + terrainRawFile, img);
283 - assert(terrainDimensions == img.dimensions());
284 - // data will be destroyed when img gets out of scope
285 - const U8* data = (const U8*)img.data();
286 - assert(data);
287 - heightValues.insert(std::end(heightValues), &data[0], &data[img.imageLayers().front()._data.size()]);
288 - }
289 259
290 260 vec2<U16>& dimensions = Attorney::TerrainLoader::dimensions(*terrain);
291 261 Attorney::TerrainLoader::dimensions(*terrain).set(heightmapWidth, heightmapHeight);
  @@ -302,20 +272,18 @@
302 272 I32 terrainHeight = (I32)dimensions.y;
303 273 F32 minAltitude = terrainDescriptor->getAltitudeRange().x;
304 274 F32 maxAltitude = terrainDescriptor->getAltitudeRange().y;
305 - F32 altitudeRange = maxAltitude - minAltitude;
306 275
307 276 BoundingBox& terrainBB = Attorney::TerrainLoader::boundingBox(*terrain);
308 -
309 277 terrainBB.set(vec3<F32>(-terrainWidth * 0.5f, minAltitude, -terrainHeight * 0.5f),
310 278 vec3<F32>(terrainWidth * 0.5f, maxAltitude, terrainHeight * 0.5f));
311 279
312 280 terrainBB.translate(terrainDescriptor->getPosition());
313 281 terrainBB.multiply(vec3<F32>(terrainScaleFactor.x, terrainScaleFactor.y,
314 282 terrainScaleFactor.x));
315 - F32 yOffset = terrainDescriptor->getPosition().y;
283 +
316 284 const vec3<F32>& bMin = terrainBB.getMin();
317 285 const vec3<F32>& bMax = terrainBB.getMax();
318 - F32 yScaleFactor = terrainScaleFactor.y;
286 + F32 yOffset = terrainDescriptor->getPosition().y;
319 287
320 288 VertexBuffer* groundVB = terrain->getGeometryVB();
321 289
  @@ -325,6 +293,39 @@
325 293
326 294 ByteBuffer terrainCache;
327 295 if (!terrainCache.loadFromFile(cacheLocation) || !groundVB->deserialize(terrainCache)) {
296 + F32 altitudeRange = maxAltitude - minAltitude;
297 + F32 yScaleFactor = terrainScaleFactor.y;
298 +
299 + vectorImpl<U16> heightValues;
300 + if (terrainDescriptor->is16Bit()) {
301 + assert(heightmapWidth != 0 && heightmapHeight != 0);
302 + // only raw files for 16 bit support
303 + assert(hasExtension(terrainRawFile, "raw"));
304 + // Read File Data
305 +
306 + vectorImpl<Byte> data;
307 + readFile(terrainMapLocation + terrainRawFile, data, FileType::BINARY);
308 + if (data.empty()) {
309 + return false;
310 + }
311 +
312 + U32 positionCount = to_U32(data.size());
313 + heightValues.reserve(positionCount / 2);
314 + for (U32 i = 0; i < positionCount + 1; i += 2) {
315 + heightValues.push_back((data[i + 1] << 8) |
316 + data[i]);
317 + }
318 +
319 + } else {
320 + ImageTools::ImageData img;
321 + ImageTools::ImageDataInterface::CreateImageData(terrainMapLocation + terrainRawFile, img);
322 + assert(terrainDimensions == img.dimensions());
323 + // data will be destroyed when img gets out of scope
324 + const U8* data = (const U8*)img.data();
325 + assert(data);
326 + heightValues.insert(std::end(heightValues), &data[0], &data[img.imageLayers().front()._data.size()]);
327 + }
328 +
328 329 groundVB->resizeVertexCount(terrainWidth * terrainHeight);
329 330 // scale and translate all height by half to convert from 0-255 (0-65335) to -127 - 128 (-32767 - 32768)
330 331 if (terrainDescriptor->is16Bit()) {
  @@ -339,9 +340,9 @@
339 340 j < to_I32(heightmapHeight) ? j : j - 1,
340 341 heightmapWidth);
341 342
342 - vec3<F32> vertexData(bMin.x + (to_F32(i)) * (bMax.x - bMin.x) / (terrainWidth - 1), // X
343 + vec3<F32> vertexData(bMin.x + (to_F32(i)) * (bMax.x - bMin.x) / (terrainWidth - 1), // X
343 344 ((minAltitude + altitudeRange * (heightValues[idxIMG] / fMax)) * yScaleFactor) + yOffset, // Y
344 - bMin.z + (to_F32(j)) * (bMax.z - bMin.z) / (terrainHeight - 1)); // Z
345 + bMin.z + (to_F32(j)) * (bMax.z - bMin.z) / (terrainHeight - 1)); // Z
345 346 #pragma omp critical
346 347 {
347 348 groundVB->modifyPositionValue(idxHM, vertexData);
  @@ -365,7 +366,7 @@
365 366 heightValues[idxIMG * 3 + 2]) / 3.0f) / byteMax;
366 367
367 368 vec3<F32> vertexData(bMin.x + (to_F32(i)) * (bMax.x - bMin.x) / (terrainWidth - 1), //X
368 - ((minAltitude + altitudeRange * h) * yScaleFactor) + yOffset, //Y
369 + ((minAltitude + altitudeRange * h) * yScaleFactor) + yOffset, //Y
369 370 bMin.z + (to_F32(j)) * (bMax.z - bMin.z) / (terrainHeight - 1)); //Z
370 371
371 372