roamwright 0.54.0 → 0.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/examples/animals.js +27 -15
- package/examples/crowds.js +28 -18
- package/examples/effects.js +13 -11
- package/examples/figure-motion.js +17 -5
- package/examples/figure.js +12 -8
- package/examples/fliers.js +16 -12
- package/examples/fortification.js +31 -18
- package/examples/house-kit.js +17 -10
- package/examples/island.js +25 -12
- package/examples/land.js +14 -8
- package/examples/props-and-plants.js +21 -32
- package/examples/rooms.js +2 -2
- package/examples/ships.js +33 -15
- package/examples/small-world-land.js +3 -3
- package/examples/small-world-life.js +13 -5
- package/examples/small-world-town.js +8 -11
- package/examples/small-world.js +26 -19
- package/examples/soundscape.js +18 -18
- package/examples/stage-kits.js +5 -133
- package/examples/stage.js +1 -324
- package/examples/towns.js +25 -18
- package/examples/viaduct-landscape.js +1 -1
- package/examples/viaduct.js +3 -4
- package/geometry/builder.js +8 -18
- package/geometry/plant-broadleaf.js +10 -4
- package/geometry/plant-trees.js +15 -9
- package/geometry/still-mesh.js +35 -0
- package/index.js +11 -1
- package/motion/cast-actors.js +379 -0
- package/motion/cast-manager.js +321 -0
- package/motion/figure-mount.js +1 -0
- package/package.json +20 -1
- package/rendering/cast-stage.js +299 -0
- package/rendering/crowd-system.js +239 -0
- package/rendering/daylight-sky.js +212 -0
- package/rendering/house-kit-meshes.js +65 -16
- package/rendering/nameplate-groups.js +84 -0
- package/rendering/nameplates.js +386 -0
- package/rendering/orbit-camera.js +216 -0
- package/rendering/water-simple.js +112 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight single-plane procedural water without planar reflections: vertex-coloured depth
|
|
3
|
+
* tinting from a caller-supplied bed depth function plus animated gentle surface wave shimmer.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as THREE from 'three';
|
|
8
|
+
import { glslVec3 } from './glsl-literal.js';
|
|
9
|
+
|
|
10
|
+
const WATER_VERTEX_PARS = /* glsl */ `varying vec2 vWaterXZ;
|
|
11
|
+
`;
|
|
12
|
+
const WATER_VERTEX_BEGIN = /* glsl */ `#include <begin_vertex>
|
|
13
|
+
vWaterXZ = position.xz;`;
|
|
14
|
+
|
|
15
|
+
const WATER_FRAGMENT_PARS = /* glsl */ `uniform float uWaterTime;
|
|
16
|
+
varying vec2 vWaterXZ;
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Builds a single horizontal water plane tinted by water depth with gentle animated wave glint,
|
|
21
|
+
* requiring no planar reflection pass or depth render target.
|
|
22
|
+
*
|
|
23
|
+
* @param {object} [options]
|
|
24
|
+
* @param {number} [options.width=800] Plane width along X (metres).
|
|
25
|
+
* @param {number} [options.depth=800] Plane extent along Z (metres).
|
|
26
|
+
* @param {number} [options.segs=128] Grid subdivisions along each axis.
|
|
27
|
+
* @param {number} [options.level=0] Water surface elevation Y (metres).
|
|
28
|
+
* @param {(x: number, z: number) => number} [options.depthAt] Water depth in metres at local `(x, z)`; defaults to constant `6`.
|
|
29
|
+
* @param {number} [options.shallowColor=0x6ea6a0] Shallow-water colour (sRGB hex).
|
|
30
|
+
* @param {number} [options.deepColor=0x245d6d] Deep-water colour (sRGB hex).
|
|
31
|
+
* @param {number} [options.shallowDepth=0.1] Depth (metres) where colour begins transitioning from shallow to deep.
|
|
32
|
+
* @param {number} [options.deepDepth=4.5] Depth (metres) where colour reaches full deep tint.
|
|
33
|
+
* @param {number} [options.roughness=0.24] Surface roughness for specular sun highlights.
|
|
34
|
+
* @param {number} [options.metalness=0.08] Surface metalness.
|
|
35
|
+
* @param {number} [options.opacity=0.9] Surface opacity (`< 1` enables alpha blending).
|
|
36
|
+
* @param {[number, number, number]} [options.glintColor=[0.08, 0.13, 0.14]] Additive RGB crest shimmer tint.
|
|
37
|
+
* @returns {{ mesh: THREE.Mesh, material: THREE.MeshStandardMaterial, timeUniform: { value: number }, update: (elapsed: number) => void, dispose: () => void }}
|
|
38
|
+
*/
|
|
39
|
+
export function createSimpleWater({
|
|
40
|
+
width = 800,
|
|
41
|
+
depth = 800,
|
|
42
|
+
segs = 128,
|
|
43
|
+
level = 0,
|
|
44
|
+
depthAt = () => 6,
|
|
45
|
+
shallowColor = 0x6ea6a0,
|
|
46
|
+
deepColor = 0x245d6d,
|
|
47
|
+
shallowDepth = 0.1,
|
|
48
|
+
deepDepth = 4.5,
|
|
49
|
+
roughness = 0.24,
|
|
50
|
+
metalness = 0.08,
|
|
51
|
+
opacity = 0.9,
|
|
52
|
+
glintColor = [0.08, 0.13, 0.14],
|
|
53
|
+
} = {}) {
|
|
54
|
+
const geometry = new THREE.PlaneGeometry(width, depth, segs, segs).rotateX(-Math.PI / 2);
|
|
55
|
+
const positions = geometry.attributes.position;
|
|
56
|
+
const colors = new Float32Array(positions.count * 3);
|
|
57
|
+
const shallow = new THREE.Color(shallowColor);
|
|
58
|
+
const deep = new THREE.Color(deepColor);
|
|
59
|
+
const tint = new THREE.Color();
|
|
60
|
+
for (let i = 0; i < positions.count; i++) {
|
|
61
|
+
const waterDepth = depthAt(positions.getX(i), positions.getZ(i));
|
|
62
|
+
const mix = THREE.MathUtils.smoothstep(waterDepth, shallowDepth, deepDepth);
|
|
63
|
+
tint
|
|
64
|
+
.copy(shallow)
|
|
65
|
+
.lerp(deep, mix)
|
|
66
|
+
.toArray(colors, i * 3);
|
|
67
|
+
}
|
|
68
|
+
geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));
|
|
69
|
+
|
|
70
|
+
const material = new THREE.MeshStandardMaterial({
|
|
71
|
+
vertexColors: true,
|
|
72
|
+
roughness,
|
|
73
|
+
metalness,
|
|
74
|
+
transparent: opacity < 1,
|
|
75
|
+
opacity,
|
|
76
|
+
});
|
|
77
|
+
const timeUniform = { value: 0 };
|
|
78
|
+
const glintLiteral = glslVec3(glintColor);
|
|
79
|
+
const fragmentColor = /* glsl */ `#include <color_fragment>
|
|
80
|
+
vec2 wp = vWaterXZ;
|
|
81
|
+
float warp = sin(wp.x * 0.17 + wp.y * 0.13 + uWaterTime * 0.35) * 2.1
|
|
82
|
+
+ cos(wp.x * 0.09 - wp.y * 0.23 - uWaterTime * 0.28) * 1.6;
|
|
83
|
+
float swell = sin(wp.y * 0.85 + warp + uWaterTime * 1.05) * 0.52
|
|
84
|
+
+ sin(wp.y * 1.75 + wp.x * 0.19 - warp * 0.65 - uWaterTime * 1.35) * 0.33
|
|
85
|
+
+ sin(wp.y * 3.4 - wp.x * 0.27 + warp * 0.4 + uWaterTime * 1.8) * 0.15;
|
|
86
|
+
float shimmer = 0.45 + 0.55 * smoothstep(-0.3, 0.75, sin(wp.x * 0.29 + warp * 0.65));
|
|
87
|
+
float glint = smoothstep(0.54, 0.94, swell) * shimmer;
|
|
88
|
+
float vis = 1.0 - smoothstep(0.08, 0.5, fwidth(wp.y));
|
|
89
|
+
diffuseColor.rgb += ${glintLiteral} * glint * vis;`;
|
|
90
|
+
|
|
91
|
+
material.onBeforeCompile = shader => {
|
|
92
|
+
shader.uniforms.uWaterTime = timeUniform;
|
|
93
|
+
shader.vertexShader = WATER_VERTEX_PARS + shader.vertexShader.replace('#include <begin_vertex>', WATER_VERTEX_BEGIN);
|
|
94
|
+
shader.fragmentShader = WATER_FRAGMENT_PARS + shader.fragmentShader.replace('#include <color_fragment>', fragmentColor);
|
|
95
|
+
};
|
|
96
|
+
material.customProgramCacheKey = () => `roamwright-simple-water-v1:${glintLiteral}`;
|
|
97
|
+
|
|
98
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
99
|
+
mesh.position.y = level;
|
|
100
|
+
mesh.receiveShadow = true;
|
|
101
|
+
|
|
102
|
+
function update(elapsed) {
|
|
103
|
+
timeUniform.value = elapsed;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function dispose() {
|
|
107
|
+
geometry.dispose();
|
|
108
|
+
material.dispose();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return { mesh, material, timeUniform, update, dispose };
|
|
112
|
+
}
|