-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
104 lines (85 loc) · 4.24 KB
/
index.html
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html lang="en">
<body>
<canvas id="gl"></canvas>
<script type="module">
import * as THREE from "https://threejs.org/build/three.module.js";
import { OrbitControls } from "https://threejs.org/examples/jsm/controls/OrbitControls.js";
import { GLTFLoader } from "https://threejs.org/examples/jsm/loaders/GLTFLoader.js";
import { RGBELoader } from "https://threejs.org/examples/jsm/loaders/RGBELoader.js";
import { GUI } from "https://threejs.org/examples/jsm/libs/dat.gui.module.js";
const params = {
roughness: 1,
metalness: 0,
exposure: 0.25,
physicallyCorrectLights: true,
toneMapping: "ACESFilmic",
color : '#ffffff',
};
var toneMappingOptions = {
None: THREE.NoToneMapping,
Linear: THREE.LinearToneMapping,
Reinhard: THREE.ReinhardToneMapping,
Uncharted2: THREE.Uncharted2ToneMapping,
Cineon: THREE.CineonToneMapping,
ACESFilmic: THREE.ACESFilmicToneMapping,
};
const WIDTH = 1280;
const HEIGHT = 720;
const renderer = new THREE.WebGLRenderer({ canvas: document.getElementById("gl") });
renderer.setSize(WIDTH, HEIGHT);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.outputEncoding = THREE.sRGBEncoding;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(40, WIDTH / HEIGHT, 1, 10000);
camera.setFocalLength(50);
camera.position.set(0, 30, 0);
camera.lookAt(0, 0, 0);
const controls = new OrbitControls(camera, renderer.domElement);
const gui = new GUI();
gui.add(params, "roughness", 0, 1, 0.01).onChange(updateParams);
gui.add(params, "metalness", 0, 1, 0.01).onChange(updateParams);
gui.add(params, "toneMapping", Object.keys(toneMappingOptions)).onChange(updateParams);
gui.add(params, "exposure", 0, 4, 0.01).onChange(updateParams);
gui.add(params, "physicallyCorrectLights", true).onChange(updateParams);
gui.addColor(params, "color").onChange(updateParams);
gui.open();
const environmentLoader = new RGBELoader().setDataType(THREE.UnsignedByteType);
environmentLoader.load("abandoned_hopper_terminal_04_2k.hdr", function (texture, textureData) {
texture.mapping = THREE.EquirectangularReflectionMapping;
scene.background = texture;
const pmremGenerator = new THREE.PMREMGenerator(renderer);
scene.environment = pmremGenerator.fromEquirectangular(texture).texture;
});
var plane;
var gltfLoader = new GLTFLoader();
gltfLoader.load("simple-lightmap.glb", function (gltf) {
plane = gltf.scene.getObjectByName("Plane");
plane.material.map = null;
scene.add(plane);
const loader = new RGBELoader().setDataType(THREE.UnsignedByteType);
loader.load("Lightmap.hdr", function (texture, textureData) {
texture.flipY = false;
plane.material.lightMap = texture;
plane.material.needsUpdate = true;
});
updateParams();
});
renderer.setAnimationLoop(function () {
controls.update();
renderer.render(scene, camera);
});
function updateParams() {
plane.material.roughness = params.roughness;
plane.material.metalness = params.metalness;
plane.material.color.set(params.color);
renderer.toneMappingExposure = params.exposure;
renderer.physicallyCorrectLights = params.physicallyCorrectLights;
renderer.toneMapping = toneMappingOptions[params.toneMapping];
scene.traverse((o) => {
if (o.material) o.material.needsUpdate = true;
});
}
</script>
</body>
</html>