setTerrainHeight: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
(Some wiki formatting)
Line 9: Line 9:


|descr= {{Wiki|WIP}}
|descr= {{Wiki|WIP}}
Set the current terrain's altitude on provided location(s).
{{Feature|important|
* Heightmap changes:
** are internally converted (rounded) to heightmap coordinates
** are stored in the JIP queue
** are '''not''' removed if the value is back to default value
** are updated in the JIP queue for updated positions '''if''' the same group of positions are edited (order does not matter, but amount does)
** are '''not''' updated and sent twice (old one then new one) if position edits are not exactly the same (see point above and {{Link|#Example 2}}).
* Edited terrain heights are '''not''' saved inside savegames, they need to be restored manually on savegame load.
}}


Warning, this command is dangerous and if used incorrectly will cause issues.
|s1= [[setTerrainHeight]] [positionAndAltitudeArray, adjustObjects]


Heightmap changes are stored in JIP queue, when doing multiple command invocations with the exact same XY positions (same number, same coordinates, order can be different) and different heights, the JIP messages will be merged which saves memory and network bandwidth and performance (each message is processed seperately) for joining clients.
|p1= positionAndAltitudeArray: [[Array]] of [[Array]] in format [[PositionASL]] - [<nowiki/>[x1, y1, newASLHeight1], [x2, y2, newASLHeight2], ... ]


If even just one position is missing or extra or different a new JIP message will be created, each new client will get the old and the new message, which costs bandwidth and performance because the client has to process both heightmap updates seperately.
|p2= adjustObjects: [[Boolean]] - (Optional, default [[true]]) if true then objects on modified points are moved up/down to keep the same ATL height
 
{{Feature|important|'''All''' objects above modified terrain will be adjusted, even flying ones.}}
JIP messages do NOT remove themselves if all positions are returned back to their original values, so if changes to different areas are done during a mission, they will accumulate in JIP queue.
 
setTerrainHeight should be used to set the height of an "area", and if that area should be further adjusted, the whole area should be adjusted and not just a subsection of it.
 
Edited terrain heights are not saved inside savegames, they need to be restored manually on savegame load.
 
 
|s1= [[setTerrainHeight]] [ [ [X, Y, NewHeight], ... ](, adjustObjects)]


|r1= [[Nothing]]
|r1= [[Nothing]]
Line 31: Line 33:
{
{
params ["_start", "_a", "_b", "_h"];
params ["_start", "_a", "_b", "_h"];
_NewPositions = [];
private _newPositions = [];
 
for "_xStep" from 0 to _a do
for "_xStep" from 0 to _a do
{
{
Line 38: Line 41:
private _newHeight = _start vectorAdd [_xStep, _yStep, 0];
private _newHeight = _start vectorAdd [_xStep, _yStep, 0];
_newHeight set [2, _h];
_newHeight set [2, _h];
_NewPositions pushBack _newHeight;
_newPositions pushBack _newHeight;
};
};
};
};
_NewPositions
 
_newPositions;
};
};


Line 48: Line 52:
</sqf>
</sqf>


|p1= [ [X, Y, NewHeight], ... ]: [[Array]] of [[Array]] in format [[PositionASL]]
|x2= Bad example:
XY are world coordinates, and are internally converted to heightmap coordinates like so
<sqf>
<sqf>
_hRes = (getTerrainInfo select 3)
// first update
_heightmapCoordinates = [round(_x/_hRes), round(_y/_hres)];
setTerrainHeight [[1000, 1000, 25], [1005, 1000, 25]];
 
// second update
setTerrainHeight [[1005, 1000, 50]]; // this will make the JIP queue keep both messages
</sqf>
</sqf>


|p2= adjustObjects: [[Bool]] optional, default true. If true then objects on modified points are moved up/down to keep the same ATL height (Danger! Even objects in the sky above modified terrain are adjusted)
Good example:
<sqf>
// first update
setTerrainHeight [[1000, 1000, 25], [1005, 1000, 25]];
 
// second update
setTerrainHeight [[1000, 1000, 25], [1005, 1000, 50]]; // this will update the JIP queue properly
</sqf>


|seealso= [[getTerrainInfo]] [[getTerrainHeight]]
|seealso= [[getTerrainInfo]] [[getTerrainHeight]]
}}
}}

Revision as of 15:13, 22 June 2022

Hover & click on the images for description
Only available in Development branch(es) until its release with Arma 3 patch v2.10.

Description

Description:
🏗
This article is a work in progress!

Set the current terrain's altitude on provided location(s).

  • Heightmap changes:
    • are internally converted (rounded) to heightmap coordinates
    • are stored in the JIP queue
    • are not removed if the value is back to default value
    • are updated in the JIP queue for updated positions if the same group of positions are edited (order does not matter, but amount does)
    • are not updated and sent twice (old one then new one) if position edits are not exactly the same (see point above and Example 2).
  • Edited terrain heights are not saved inside savegames, they need to be restored manually on savegame load.
Groups:
Diagnostic

Syntax

Syntax:
setTerrainHeight [positionAndAltitudeArray, adjustObjects]
Parameters:
positionAndAltitudeArray: Array of Array in format PositionASL - [[x1, y1, newASLHeight1], [x2, y2, newASLHeight2], ... ]
adjustObjects: Boolean - (Optional, default true) if true then objects on modified points are moved up/down to keep the same ATL height
All objects above modified terrain will be adjusted, even flying ones.
Return Value:
Nothing

Examples

Example 1:
private _fnc_flattenTerrain = { params ["_start", "_a", "_b", "_h"]; private _newPositions = []; for "_xStep" from 0 to _a do { for "_yStep" from 0 to _b do { private _newHeight = _start vectorAdd [_xStep, _yStep, 0]; _newHeight set [2, _h]; _newPositions pushBack _newHeight; }; }; _newPositions; }; private _desiredTerrainHeight = 150; setTerrainHeight [[getPosWorld player, 50, 50, _desiredTerrainHeight] call _fnc_flattenTerrain, true];
Example 2:
Bad example:
// first update setTerrainHeight [[1000, 1000, 25], [1005, 1000, 25]]; // second update setTerrainHeight [[1005, 1000, 50]]; // this will make the JIP queue keep both messages
Good example:
// first update setTerrainHeight [[1000, 1000, 25], [1005, 1000, 25]]; // second update setTerrainHeight [[1000, 1000, 25], [1005, 1000, 50]]; // this will update the JIP queue properly

Additional Information

See also:
getTerrainInfo getTerrainHeight

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note