BabylonJS / Documentation

Babylon.js's documentation website
https://doc.babylonjs.com
Apache License 2.0
78 stars 234 forks source link

DynamicTerrain Community Extension: "height" is used for both Y and Z axes #1118

Closed gmofishsauce closed 5 months ago

gmofishsauce commented 5 months ago

What's the problem?

Throughout the documentation for the DynamicTerrain Community Extension, the word "height" is used to refer to both the Z axis and the Y axis. I found this extremely confusing. Here's a specific example:

const mapCoords = [some_big_flat_array_of_coordinates];
const mapWidthPointNb = 2000; // 2000 points in the map width
const mapHeightPointNb = 1000; // 1000 points in the map height
const terrainSub = 100; // the terrain wil be 100x100 vertices only
const mapParams = {
  mapData: mapCoords,
  mapSubX: mapWidthPointNb,
  mapSubZ: mapHeightPointNb,
  terrainSub: terrainSub,
};

All uses of the term height in this quote do not refer to the terrain's elevation or "altitude". They refer to the Z-axis of the 3-D world, its "depth". This becomes clear later:

If we need to know what the altitude is on the map at the coordinates (x, z) in the World, even if this point is not one of the points defined in the map (not one of the points in the map array), we can use the method getHeightFromMap(x, z).

const y = terrain.getHeightFromMap(x, z); // returns y at (x, z) in the World

Here the term "height" is used to refer to height, the elevation or altitude of the terrain in the map.

The most confusing example is in the section on height maps:

  • width and height are optional floats (default 300), the dimensions the map in the World,
  • subX and subZ are optional integers (default 100), the number of points on each map dimension,
  • minHeight and maxHeight are the optional minimal and maximal heights (floats, default 0 and 10),

I added the boldface. Here the first boldface use of the word height refers to the Z-axis of the 3-D world, while the second use refers to the Y-axis.

So, what to do?

In the hmOptions (see the third example), the term height has found its way into the code. This is not fixable without breaking binary compatibility, which is not even close to justifiable in this case. But the documentation can be improved.

In a minute I will submit two pull requests, one against the Documentation repo and one against the Extensions repo. In these PRs, I changed all the Z axis references to use the term depth, leaving the word height for Y axis references.

I made a second change: I replaced the world altitude with elevation where it referred to the terrain. But I left the word altitude where it referred to the the camera. In the US, at least, the word elevation is more commonly used to refer to terrain elevation. The word altitude is perfectly understandable in context, but it is more commonly used to refer to objects that are not part of the terrain, like aircraft and satellites. So altitude makes sense for references to the camera (e.g. "orbital camera", like a satellite).