Finished today the loading of hmp's, (re-)saving for terrain entities and other functions for dealing with (modified) terrain entities.

For accomplish the following screenshot, I do the following:
  • create terrain from bitmap (height values on red channel are encoding the height)
  • create a lod version, in which the mesh is reduced by 95%
  • load some common terrain from .hmp file
  • create the same again and modify the terrain by the heightfield which I got after reducing the first terrain. Since the target terrain has more cells than the (reduced) source terrain, I bicubically interpolate the height data
  • then I save the modified terrain to file and load the newly created file from hard disc as a brand new entity


(click the image to enlarge)



Please note that all procedurally created / modified terrains have correct normals.

And the code it is simple:

Code:
function terrainPerlin ()
{
    my->scale_x = my->scale_y = my->scale_z = 0.07;
}

int main ()
{
    video_mode = 11;
    
    level_load("");
    vec_set(sky_color, vector(100, 50, 25));

    vec_set(camera->x,   vector(0, -663, 349));
    vec_set(camera->pan, vector(90, -26, 0));	
    
    // create terrain from bitmap
    
        BMAP* bmapDonut = bmap_create("donut.bmp");
        
        float minZ = -32, maxZ = 32; // min and max height for 0..255 grey values
        float width = 140, height = 140; // x- and y-size
        
        Hmp* hmpDonut = hmp_createfrombmap(bmapDonut, width, height, minZ, maxZ);
        hmp_addskin(hmpDonut, hmp_createskin(bmapDonut, NULL, NULL, NULL));
        
        // create entity from hmp representation
        ENTITY* entDonut = hmp_entcreate(hmpDonut, vector(-300,0,0));
        
    // create 5% lod version
    
        float lod = 0.05; // 5% (mesh reduced by 95%)
        ENTITY* entDonutReduced = hmp_entcreatelod(hmpDonut, vector(-150,0,0), lod);
        
        // derive hmp from entity
        Hmp* hmpDonutReduced = hmp_createfroment(entDonutReduced);
    
    // load some common terrain from .hmp file
        
        ENTITY* entPerlin = ent_create("perlin.hmp", vector(0,0,0), terrainPerlin);
        
    // create the same again and modify terrain by
    // reduced heightfield, bicubically interpolated
    
        ENTITY* entPerlinModified = ent_create("perlin.hmp", vector(150,0,0), terrainPerlin);
        hmp_entpaste(hmpDonutReduced, entPerlinModified);
        
    // save modified terrain to file and load as new entity
    
        hmp_entsaveto(entPerlinModified, "perlin_modified.hmp", false);
        ENTITY* entPerlinModifiedLoaded = ent_create("perlin_modified.hmp", vector(300,0,0), terrainPerlin);
}