-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathenvMap.js
45 lines (39 loc) · 1.09 KB
/
envMap.js
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
// Manages cube maps.
import {
sRGBEncoding,
CubeTextureLoader,
} from "../third_party/three.module.js";
const cubeTexLoader = new CubeTextureLoader();
cubeTexLoader.setPath("../assets/");
const environments = {
bridge: { file: "", extension: "jpg", texture: null },
park: { file: "park_", extension: "jpg", texture: null },
pisa: { file: "pisa_", extension: "png", texture: null },
};
function getTexture(name) {
if (!environments[name].texture) {
const f = environments[name].file;
const ext = environments[name].extension;
environments[name].texture = cubeTexLoader.load([
`${f}posx.${ext}`,
`${f}negx.${ext}`,
`${f}posy.${ext}`,
`${f}negy.${ext}`,
`${f}posz.${ext}`,
`${f}negz.${ext}`,
]);
environments[name].texture.encoding = sRGBEncoding;
}
return environments[name].texture;
}
const params = {
environment: "bridge",
};
function generateParams(gui, material) {
return gui
.add(params, "environment", Object.keys(environments))
.onChange((v) => {
material.envMap = getTexture(v);
});
}
export { generateParams };