-
Notifications
You must be signed in to change notification settings - Fork 0
/
cube_envmap.html
108 lines (83 loc) · 3.21 KB
/
cube_envmap.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
105
106
107
108
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - materials - environment maps</title>
</head>
<body>
<script src="js/three.js"></script>
<script>
let controls, camera, scene, renderer;
let textureEquirec, textureCube;
let sphereMesh, sphereMaterial;
init();
animate();
function init() {
// CAMERAS
camera = new THREE.PerspectiveCamera(
70,
window.innerWidth / window.innerHeight,
1,
100000
);
camera.position.set(0, 0, 1000);
// SCENE
scene = new THREE.Scene();
// Lights
const ambient = new THREE.AmbientLight(0xffffff);
scene.add(ambient);
// Textures
const loader = new THREE.CubeTextureLoader();
textureCube = loader.load([
'./deconstructed/image1.png',
'./deconstructed/image3.png',
'./deconstructed/image6.png',
'./deconstructed/image6.png',
'./deconstructed/image4.png',
'./deconstructed/image2.png'
]);
textureCube.encoding = THREE.sRGBEncoding;
scene.background = textureCube;
//
/*const geometry = new THREE.IcosahedronBufferGeometry(400, 15);
sphereMaterial = new THREE.MeshLambertMaterial({
envMap: textureCube
});
sphereMesh = new THREE.Mesh(geometry, sphereMaterial);
scene.add(sphereMesh);*/
//
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputEncoding = THREE.sRGBEncoding;
document.body.appendChild(renderer.domElement);
//
const params = {
Cube: function() {
scene.background = textureCube;
sphereMaterial.envMap = textureCube;
sphereMaterial.needsUpdate = true;
}
};
window.addEventListener('resize', onWindowResize, false);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
//
var i = 0;
function animate() {
requestAnimationFrame(animate);
camera.position.x = 0.05 * Math.sin(i / (10 * Math.PI));
camera.rotation.y = i / (50 * Math.PI);
i += 1;
render();
}
function render() {
//camera.lookAt(scene.position);
renderer.render(scene, camera);
}
</script>
</body>
</html>