====== Scripts > Cube wrapped heightfield ====== ^ Description | Apply various wrapping and blending operations to generate a heightfield that may be wrapped onto a cube (nearly) seamlessly. | ^ Author | [[user>Aaron]] | ^ Created | 2012/03/09 | ^ Updated | 2012/03/14 --- //new images with better blending.// | ^ Requires | L3DT v12.03 build 1 or later | ^ Download | {{:scripts:cube_mapped_heightfield.zs|cube_mapped_heightfield.zs}} | ===== About ===== This script converts 4x3 aspect heightfields like this... {{:scripts:cube_wrapped_heightfield:2do.jpg?450|}} ...into cube-wrapped maps such as this: {{:scripts:cube_wrapped_heightfield:2d2.png?450|}} In principle, the above map could be 'folded' to create a 6 sided cube. With a some sort of [[plugins:calc:SphericalDistort|spherical distortion calculation]], this may allow spherical worlds to be generated from heightmaps. In Sapphire, the raw (unfolded) results look like: {{:scripts:cube_wrapped_heightfield:3d4.png?450|}} Note that the blending operations have some artefacts that you will need to clean up manually, including streaking near tile edges, and small steps at internal tile edges. ===== Script contents ===== // Author: A. Torpy // Updated: 10 Mar 2012 hvar hMap set hMap int nx ny set nx set ny assert "Map not initialised" int TileSize set TileSize
if >> echo >>>>> return -1 endif if >> echo "Width must be 4/3 height" return -1 endif if >> echo "Width must be exactly 4/3 height" return -1 endif int depth set depth
if > return -1 endif if echo "Blend depth must be greater than 0" return -1 endif if > echo ")">> return -1 endif L3DTio_Backup.BackupMap "HF" "BoxWrap HF" 0 "view.ShowMap \"HF\"" int px py int p pmax set p 0 set pmax 3 do // east/west calc.HF.BlendEdges hMap 0 TileSize 1 0 depth TileSize 1 2 depth TileSize 0.5 0 NULL // easternmost top to mid topmost (reversed) calc.HF.BlendEdges hMap 0 3 depth 2 3 depth TileSize 0.5 0 NULL // easternmost bottom to mid bottommost (reversed) calc.HF.BlendEdges hMap TileSize 0 1 depth 0 2 1 depth TileSize 0.5 0 NULL // northwest diag set px TileSize set py calc.HF.BlendEdges hMap px py 2 3 depth px py 1 0 depth TileSize 0.5 0 NULL // northeast diag set px set py calc.HF.BlendEdges hMap px py 1 2 depth px py 0 3 depth TileSize 0.5 0 NULL // southeast diag set px set py TileSize calc.HF.BlendEdges hMap px py 0 1 depth px py 3 2 depth TileSize 0.5 0 NULL // southwest diag set px TileSize set py TileSize calc.HF.BlendEdges hMap px py 2 1 depth px py 3 0 depth TileSize 0.5 0 NULL // interior vert b/w rightmost tiles (except for last pass, where we don't want changes if > set px set py TileSize calc.HF.BlendEdges hMap px py 2 1 depth px py 0 1 depth TileSize 0.5 0 NULL // interior of centre square, left edge set px TileSize set py TileSize calc.HF.BlendEdges hMap px py 1 2 depth px py 1 0 depth TileSize 0.5f 0 NULL // interior of centre square, right edge set px set py TileSize calc.HF.BlendEdges hMap px py 1 0 depth px py 1 2 depth TileSize 0.5f 0 NULL // interior of centre square, top edge set px TileSize set py calc.HF.BlendEdges hMap px py 0 1 depth px py 0 3 depth TileSize 0.5f 0 NULL // interior of centre square, bottom edge set px TileSize set py TileSize calc.HF.BlendEdges hMap px py 0 3 depth px py 0 1 depth TileSize 0.5f 0 NULL endif while pmax> // clear rects calc.map.ZeroArea hMap 0 0 TileSize TileSize 0 calc.map.ZeroArea hMap 0 TileSize 0 calc.map.ZeroArea hMap 0 TileSize TileSize 0 calc.map.ZeroArea hMap TileSize 0 map.SetFlag hMap 5 true view.ShowMap "HF" return 0