Просмотр исходного кода

Adds support for .r16 file extension for RAW16 heightmap files.

sgrenier 13 лет назад
Родитель
Сommit
93bccc1919

+ 3 - 11
gameplay/src/HeightField.cpp

@@ -50,21 +50,13 @@ HeightField* HeightField::create(const char* path, unsigned int width, unsigned
     GP_ASSERT(path);
     GP_ASSERT(heightMax >= heightMin);
 
-    // Validate input parameters
-    size_t pathLength = strlen(path);
-    if (pathLength <= 4)
-    {
-        GP_WARN("Unrecognized file extension for heightfield image: %s.", path);
-        return NULL;
-    }
-
     float heightScale = heightMax - heightMin;
 
     HeightField* heightfield = NULL;
 
     // Load height data from image
-    const char* ext = path + (pathLength - 4);
-    if (ext[0] == '.' && toupper(ext[1]) == 'P' && toupper(ext[2]) == 'N' && toupper(ext[3]) == 'G')
+    std::string ext = FileSystem::getExtension(path);
+    if (ext == ".PNG")
     {
         // Normal image
         Image* image = Image::create(path);
@@ -102,7 +94,7 @@ HeightField* HeightField::create(const char* path, unsigned int width, unsigned
 
         SAFE_RELEASE(image);
     }
-    else if (ext[0] == '.' && toupper(ext[1]) == 'R' && toupper(ext[2]) == 'A' && toupper(ext[3]) == 'W')
+    else if (ext == ".RAW" || ext == ".R16")
     {
         // RAW image (headerless)
         if (width < 2 || height < 2 || heightMax < 0)

+ 2 - 2
gameplay/src/HeightField.h

@@ -52,7 +52,7 @@ namespace gameplay
          * or 16-bit (RAW16) format. RAW16 files must have little endian (PC) byte ordering. Since
          * RAW files have no header, you must specify the dimensions of the data in the file.
          * This method automatically determines (based on file size) whether the input file
-         * is RAW8 or RAW16.
+         * is RAW8 or RAW16. RAW files must have a .raw or .r16 file extension.
          *
          * RAW files are commonly used in software that produces heightmap images. Using RAW16 is 
          * preferred or any 8-bit heightfield source since it allows greater precision, resulting in
@@ -62,7 +62,7 @@ namespace gameplay
          * intensity to height values. The minHeight parameter is mapped to zero intensity
          * pixel, while maxHeight maxHeight is mapped to full intensity pixels.
          *
-         * @param path Path to the RAW file.
+         * @param path Path to the RAW file (must end in a .raw or .r16 file extension).
          * @param width Width of the RAW data.
          * @param height Height of the RAW data.
          * @param heightMin Minimum height value for a zero intensity pixel.

+ 1 - 1
gameplay/src/PhysicsCollisionShape.cpp

@@ -332,7 +332,7 @@ PhysicsCollisionShape::Definition PhysicsCollisionShape::Definition::create(Node
                 HeightField* heightfield = NULL;
                 if (ext == ".PNG")
                     heightfield = HeightField::createFromImage(imagePath, minHeight, maxHeight);
-                else if (ext == ".RAW")
+                else if (ext == ".RAW" || ext == ".R16")
                     heightfield = HeightField::createFromRAW(imagePath, (unsigned int)width, (unsigned int)height, minHeight, maxHeight);
 
                 if (heightfield)

+ 2 - 2
gameplay/src/Terrain.cpp

@@ -104,7 +104,7 @@ Terrain* Terrain::create(const char* path, Properties* properties)
                 // Read normalized height values from heightmap image
                 heightfield = HeightField::createFromImage(heightmap, 0, 1);
             }
-            else if (ext == ".RAW")
+            else if (ext == ".RAW" || ext == ".R16")
             {
                 // Require additional properties to be specified for RAW files
                 Vector2 imageSize;
@@ -146,7 +146,7 @@ Terrain* Terrain::create(const char* path, Properties* properties)
                 // Read normalized height values from heightmap image
                 heightfield = HeightField::createFromImage(heightmap, 0, 1);
             }
-            else if (ext == ".RAW")
+            else if (ext == ".RAW" || ext == ".R16")
             {
                 GP_WARN("RAW heightmaps must be specified inside a heightmap block with width and height properties.");
                 if (!externalProperties)

+ 2 - 1
gameplay/src/Terrain.h

@@ -24,7 +24,8 @@ class TerrainPatch;
  * 2. 24-bit high precision heightmap image (PNG), which can be generated from a mesh using
  *    gameplay-encoder.
  * 3. 8-bit or 16-bit RAW heightmap image using PC byte ordering (little endian), which is
- *    compatible with many external tools such as World Machine, Unity and more.
+ *    compatible with many external tools such as World Machine, Unity and more. The file
+ *    extension must be either .raw or .r16 for RAW files.
  *
  * Physics/collision is supported by setting a rigid body collision object on the Node that
  * the terrain is attached to. The collision shape should be specified using