OceanDisplacementPointConstraint

← prev index next →

Rolls an animated FFT ocean-wave surface across a subdivided host — turns a flat plane, mesh, or cloner into moving water on the GPU.

Remarks

This is the ocean member of the PointConstraint family: like every point-constraint it runs a GPU kernel over all of a host's points at once. Here the kernel samples an FFT-evolved wave field that advances every frame, so a densely subdivided surface heaves and ripples like open water. Unlike most point-constraints it needs no SpatialField — the wave field is its own driver — and it attaches to any points host: a mesh (a sk-plane is the usual ocean), a spline, or a sk-cloner.

Key attributes. preset picks a sea state (e.g. calm, rough) — the one-shot way to set the whole wave spectrum, and all the example needs. For finer control the individual spectrum controls (wind-speed, wind-direction, vertical-amplitude, time-scale, …) set the swell directly — higher wind gives longer, steeper waves. Either way the host must be finely subdivided (many segments) for the waves to read; a low-poly plane shows facets instead of a smooth surface.

Composition. Point-constraints on the same host apply in attach order, each building on the previous displacement. Attach the ocean FIRST so a later sk-radial-push-point-constraint (say, a wake around a boat) layers on top of the waves rather than being flattened by them.

Related. Its siblings in the PointConstraint family are sk-simple-point-constraint, sk-radial-push-point-constraint, sk-target-at-point-constraint, and the fully custom sk-custom-wgsl-point-constraint.

Projection modes (see OceanDisplacementProjection): 'planar-xz' (default) projects the field down a single world-XZ plane — correct for roughly-horizontal hosts. 'triplanar-surface' is an opt-in, MESH-only surface-relative projection (height along the surface normal, blended across three axis planes) that wraps the ocean around a non-planar host so it reads as churning water; bind origin to the host/rig for the object-locked "ball of water" look.

Constructor

constructor(config?: { show?: boolean; windSpeed?: number; verticalAmplitude?: number; windDirection?: number; horizontalAmplitude?: number; timeScale?: number; smallWaveLengthCutOff?: number; tileSize?: number; textureSize?: number; affectsNormals?: boolean; projection?: OceanDisplacementProjection; origin?: SceneNode | null; fieldWeightRange?: readonly [number, number] })

Properties

Config Properties

PropertyTypeDefaultDescriptionDeclared by
show boolean — Whether ocean displacement is active. OceanDisplacementPointConstraint
windSpeedanimatable number — Wind speed (animatable). OceanDisplacementPointConstraint
verticalAmplitudeanimatable number — Vertical amplitude (animatable). OceanDisplacementPointConstraint
windDirectionanimatable number — Wind direction in degrees (animatable). OceanDisplacementPointConstraint
horizontalAmplitudeanimatable number — Horizontal amplitude (animatable). OceanDisplacementPointConstraint
timeScaleanimatable number — Effect-time speed factor (animatable). Scales the sampled scene time in the OceanDisplacementPointConstraint
smallWaveLengthCutOff number — Small wavelength cutoff for ocean spectrum filtering. OceanDisplacementPointConstraint
tileSize number — Wave-pattern tile size in world units. OceanDisplacementPointConstraint
textureSizeconfig-only number — Displacement-texture resolution. OceanDisplacementPointConstraintConfig
affectsNormalsconfig-only boolean — Whether the constraint kernel writes a recomputed normal to the OceanDisplacementPointConstraintConfig
projection OceanDisplacementProjection — Projection mode. See OceanDisplacementProjection. OceanDisplacementPointConstraint
originanimatable SceneNode | null — Optional SceneNode whose world matrix defines the ocean frame. OceanDisplacementPointConstraint
fieldWeightRangeanimatable readonly [number, number] — The [lo, hi] range the normalized field weight maps onto. PointConstraint

Other Properties

PropertyTypeDefaultDescriptionDeclared by
targetread-only ConstrainablePointsHost | null — The target host this modifier applies to, or null before PointConstraint
fieldread-only Field | null — The field used by this point constraint, if any. PointConstraint
sceneread-only any — Gets the Scene this animatable belongs to, if any. SkenraAnimatable
animationsread-only SkenraAnimation[] — Public getter for the animations affecting this target. SkenraAnimatable

Methods

MethodDescriptionDeclared by
getPresetDefaults(preset: OceanDisplacementPreset): OceanDisplacementPointConstraintConfig Returns default ocean-displacement parameters for a named preset. OceanDisplacementPointConstraint
animate(firstArg: TypedKeyframe<this>[] | TypedPropertyIndexedKeyframes<this> | Record<string, any> | globalThis.Keyframe[] | globalThis.PropertyIndexedKeyframes | null, secondArg?: number | KeyframeAnimationOptions | globalThis.KeyframeAnimationOptions): SkenraAnimation & Animation Creates a new SkenraAnimation for this target per Web Animations API. SkenraAnimatable
removeAnimation(animation: SkenraAnimation): boolean Removes a specific animation from this object. SkenraAnimatable
constrain(type: K, config: ConstraintConfigMap[K]): ConstraintReturnMap[K] Creates a constraint on this Animatable using a fluent API. SkenraAnimatable

Example

const ocean = new Plane({ id: 'ocean', width: 200, height: 200, widthSegments: 256, heightSegments: 256 });
const wave = new OceanDisplacementPointConstraint({ windSpeed: 35 });
ocean.addPointConstraint(wave);