Table of Contents

About

Although Corrade supports downloading the RAW terrain file via the terrain command there are cases where you do not have estate privileges but still want to have a height-map of terrain. The following PHP script uses Corrade's internal web-server in order to generate an red-channel height-map image of the terrain that Corrade is currently on.

Requirements

  • Corrade version 7.98 was used during testing.
  • Corrade's internal web-server has to be enabled.
  • Corrade needs the land permissions enabled.
  • A web-server with:
    • PHP (tested on PHP 5.5)
    • PHP-curl
    • gd

Usage

  • Upload the generateTerrainHeightMap.php script to your web-server.
  • Configure the generateTerrainHeightMap.php script in the CONFIGURATION section.
  • Visit the URL to the script in order to get the height-map for the current region that Corrade is on.

Examples

The following image is a height-map (an elevation map where the red channel varies from lowest black to highest represented by red) ripped from the simulator at Puguet Sound (on 10-April-2015):

this includes just the red channel that gives the raw land height without considering the other green and blue channels. Now we can inspect the world map and see some singularities of the terraforming process. One example is a ditch on the right-hand side of the image which is essentially a crater that was created by mistake some time ago:

Let us try the left-wing since we can see a very prominent crater on the height-map:

Code

generateTerrainHeightMap.php
<?php
 
###########################################################################
##  Copyright (C) Wizardry and Steamworks 2015 - License: CC BY 2.0      ##
###########################################################################
## This is a script that uses Corrade's "getterrainheight" command in    ##
## order to genereate a red-channel height-map of the terrain without    ##
## the need to be an estate / region owner. Essentially this script can  ##
## be used to give an overview of the terrain height for any region.     ##
###########################################################################

###########################################################################
##                            CONFIGURATION                              ##
###########################################################################

# Set this to the name of the group.
$GROUP = '[Wizardry and Steamworks]:Support';
# Set this to the group password.
$PASSWORD = 'gerbileum';
# Set this to Corrade's HTTP Server URL.
$URL = 'http://corrade.internal:8080';
 
###########################################################################
##                               INTERNALS                               ##
###########################################################################

###########################################################################
##  Copyright (C) Wizardry and Steamworks 2015 - License: CC BY 2.0      ##
###########################################################################
function wasKeyValueGet($key, $data) {
    return array_reduce(
        explode(
            "&", 
            $data
        ),
        function($o, $p) {
            $x = explode("=", $p);
            return array_shift($x) != $o ? $o : array_shift($x);
        },
        $key
    );
}
 
###########################################################################
##  Copyright (C) Wizardry and Steamworks 2015 - License: CC BY 2.0      ##
###########################################################################
function mapValueToRange($value, $xMin, $xMax, $yMin, $yMax) {
    return $yMin + (
        (
            $yMax - $yMin
        ) 
        *
        (
            $value - $xMin
        )
        /
        (
            $xMax - $xMin
        )
    );
}
 
# This constructs the command as an array of key-value pairs.
$params = array(
    'command' => 'getterrainheight',
    'group' => $GROUP,
    'entity' => 'region',
    'password' => $PASSWORD
);
 
# We now escape each key and value: this is very important, because the 
# data we send to Corrade may contain the '&' or '=' characters (we don't 
# in this example though but this will not hurt anyone).
array_walk($params,
 function(&$value, $key) {
     $value = rawurlencode($key)."=".rawurlencode($value);
 }
);
$postvars = implode('&', $params);
 
# Set the options, send the request and then display the outcome
if (!($curl = curl_init())) {
    echo "Could not initialise CURL".PHP_EOL;
}
 
curl_setopt($curl, CURLOPT_URL, $URL);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
$return = curl_exec($curl);
curl_close($curl);
 
$success = urldecode(
    wasKeyValueGet(
        "success", 
        $return
    )
);
 
// Unable to get the region heights?
if($success == 'False') return -1;
 
$map = str_getcsv(
    urldecode(
        wasKeyValueGet(
            "data", 
            $return
        )
    )
);
 
$max = max($map);
 
$im = imagecreatetruecolor(256, 256);
 
foreach(range(0, 255) as $x) {
    foreach(range(0, 255) as $y) {
        $red = mapValueToRange(
            $map[256 * $x + $y], 
            0,
            $max,
            0,
            256
        );
        imagesetpixel(
            $im,
            $x,
            256-$y,
            imagecolorallocate(
                $im,
                $red,
                0,
                0
            )
        );
    }
}
 
/* Uncomment to return Base64 data.
 * ob_start();
 * imagepng($im);
 * $png = ob_get_contents();
 * imagedestroy($im);
 * ob_end_clean();
 * echo base64_encode($png); 
 */
 
/* Just display the image. */
header('Content-Type: image/png');
imagepng($im);
 
?>

secondlife/scripted_agents/corrade/projects/external_services/generate_height_map.txt ยท Last modified: 2023/09/27 10:06 by office

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.