-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
simple-water.ts
62 lines (58 loc) · 1.76 KB
/
simple-water.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { addComponent } from "bitecs";
import { addObject3DComponent } from "../utils/jsx-entity";
import { SimpleWater } from "../bit-components";
import { HubsWorld } from "../app";
import { SimpleWaterMesh } from "../objects/SimpleWaterMesh";
export type SimpleWaterParams = {
opacity: number;
color: string;
tideHeight: number;
tideScale: {
x: number;
y: number;
};
tideSpeed: {
x: number;
y: number;
};
waveHeight: number;
waveScale: {
x: number;
y: number;
};
waveSpeed: {
x: number;
y: number;
};
ripplesScale: number;
ripplesSpeed: number;
};
const DEFAULTS = {
opacity: 1,
color: "#0054df",
tideHeight: 0.01,
tideScale: { x: 1, y: 1 },
tideSpeed: { x: 0.5, y: 0.5 },
waveHeight: 0.1,
waveScale: { x: 1, y: 20 },
waveSpeed: { x: 0.05, y: 6 },
ripplesScale: 1,
ripplesSpeed: 0.25
};
export function inflateSimpleWater(world: HubsWorld, eid: number, params: SimpleWaterParams) {
params = Object.assign({}, DEFAULTS, params);
const lowQuality = APP.store.state.preferences.materialQualitySetting !== "high";
const simpleWater = new SimpleWaterMesh({ lowQuality });
simpleWater.opacity = params.opacity;
simpleWater.color.set(params.color);
simpleWater.tideHeight = params.tideHeight;
simpleWater.tideScale.set(params.tideScale.x, params.tideScale.y);
simpleWater.tideSpeed.set(params.tideSpeed.x, params.tideSpeed.y);
simpleWater.waveHeight = params.waveHeight;
simpleWater.waveScale.set(params.waveScale.x, params.waveScale.y);
simpleWater.waveSpeed.set(params.waveSpeed.x, params.waveSpeed.y);
simpleWater.ripplesScale = params.ripplesScale;
simpleWater.ripplesSpeed = params.ripplesSpeed;
addObject3DComponent(world, eid, simpleWater);
addComponent(world, SimpleWater, eid);
}