ocean3dplugin
A spectral sea, the same on every machine, and the height of its surface anywhere.
Putting it in a scene
List it before render3d, and after any plugin it takes a mod from. The scene's sim lists the ocean3d kind from #plugins/ocean3d/ocean3d.sim.ts, and the scene has one { "is": "ocean3d" } actor.
"plugins": ["loader", "scenemanager", "player", "terrain3d", "skydome3d", "ocean3d", "render3d"],
"world": {
"ocean3d": {
"windSpeed": 8, "windDeg": 30, "fetchKm": 20,
"swellScale": 0.5, "swellDeg": 65,
"amp": 1, "chop": 0.9, "foamRecovery": 0.35, "seed": 731,
"patches": [240, 40, 9],
"shoalDepth": 2, "shoalFloor": 0, "repeat": 200,
"weather": { "windRef": 12, "floor": 0.3 },
"mods": { "land": "terrain3d", "wind": "skydome3d", "light": "skydome3d" },
"deep": "#0b2a2f", "scatter": "#1f6a66", "glow": 0.3, "glowPower": 4,
"glint": 1.4, "glintPower": 480,
"foamColour": "#e8f0f0", "foamJ": [0.5, 0.8], "bubbles": 2, "bubbleEdge": 0.25,
"alpha": 0.55, "clearDepth": 8,
"rings": 120, "segs": 192, "far": 6000,
"depthHalf": 1200, "depthMax": 32, "depthRes": 256, "depthRows": 8
}
},
"prefabs": { "ocean3d": { "t": 0 } }
Properties
The row
.t : number
The sea's clock in seconds. It advances with the game's clock and wraps at repeat. The prefab holds only this.
The waves
Read from world.ocean3d. These make the same waves on every machine, so a rule on the server floats things on the surface every seat draws.
| Setting | Meaning |
|---|---|
windSpeed, windDeg, fetchKm | Wind speed in metres per second, the direction it blows toward in degrees clockwise from north (0 toward −z, 90 toward +x), and the distance of open water it has blown over, in kilometres. A longer fetch makes bigger waves. |
swellScale, swellDeg | The swell's share of the waves, and the direction it travels. 0 for no swell. |
amp, chop | Multipliers for every wave's height, and for how far the water is pushed sideways, which sharpens the crests. |
seed | Starts the random numbers the waves are made from. |
patches | The size of each wave layer's repeating tile, in metres, largest first. Each layer carries the waves too short for the layer before it, so each patch must be smaller than the last. |
repeat | Seconds after which the sea is exactly itself again. |
shoalDepth, shoalFloor | Water shallower than shoalDepth metres has smaller waves, down to the fraction shoalFloor of the full size at zero depth. |
foamRecovery | How fast foam fades after a wave breaks. |
weather | { windRef, floor }. When a wind mod is named, the waves are scaled by floor + (1 − floor) × the wind ÷ windRef, up to 1. A calm sky gives a calmer sea. |
The surface
| Setting | Meaning |
|---|---|
deep, scatter | The water's colours, deep and where light scatters through the waves. sRGB colour strings. |
glow, glowPower | The glow on the sun's side of the waves, and how tight it is. |
glint, glintPower | The sun's sparkle on the waves, and how tight it is. |
foamColour, foamJ, bubbles, bubbleEdge | The foam's colour, the range over which foam goes from full to none, the size of the bubble pattern in cycles per metre, and how hard its edge is. |
alpha, clearDepth | The sea's opacity looking straight down over shallow water, and the depth in metres at which it becomes opaque. In shallows, the seabed shows through. |
rings, segs, far | The sea is a disc centred on the camera: rings rings out to far metres, each of segs vertices. |
depthHalf, depthMax, depthRes, depthRows | The seabed map taken from the land: it covers depthHalf metres each way round the camera, depthRes texels across, depth up to depthMax metres, rebuilt depthRows rows a frame. |
light | A fixed light, used when no light mod is named: { sun: [x, y, z], sunColor, zenith, horizon }, the direction toward the sun, its colour, and the sky straight up and at the horizon. With neither a light mod nor this, the scene throws. |
Methods
From #plugins/ocean3d/ocean3d.sim.ts. ground is { depth(x, z) }; an actor passes { depth: (x, z) => depthAt(w, x, z) }.
waveAt( w, x, z, ground ) : number
The height of the drawn surface over the point (x, z), in metres.
floatAt( w, x, z, span, ground ) : { y, normal }
The height and surface normal for something span metres wide floating there. It samples the four corners of that square, so a boat does not bob on ripples smaller than itself.
Mods
Name them in world.ocean3d.mods.
- skydome3d
light: the sea is lit by the sky and reflects it.wind: the waves rise and fall with the sky's wind. List skydome3d before ocean3d. - terrain3d
land: the seabed, so waves shrink and water clears over shallows. With none, the sea is open ocean everywhere.