skybox
60
main.js
@ -15,8 +15,8 @@ import MazeMesh from './MazeMesh.js';
|
|||||||
const mazeWidth = 23
|
const mazeWidth = 23
|
||||||
|
|
||||||
const parameters = {
|
const parameters = {
|
||||||
elevation: 1 + 89 * Math.random(),
|
elevation: 48,
|
||||||
azimuth: -160,
|
azimuth: 53,
|
||||||
};
|
};
|
||||||
|
|
||||||
const waves = {
|
const waves = {
|
||||||
@ -71,6 +71,17 @@ container.appendChild(renderer.domElement);
|
|||||||
|
|
||||||
const scene = new THREE.Scene();
|
const scene = new THREE.Scene();
|
||||||
|
|
||||||
|
scene.background = new THREE.CubeTextureLoader()
|
||||||
|
.setPath( 'textures/calm-sea-skybox/' )
|
||||||
|
.load( [
|
||||||
|
'ft.jpg',
|
||||||
|
'bk.jpg',
|
||||||
|
'up.jpg',
|
||||||
|
'dn.jpg',
|
||||||
|
'rt.jpg',
|
||||||
|
'lf.jpg',
|
||||||
|
] );
|
||||||
|
|
||||||
const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 1000);
|
const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 1000);
|
||||||
camera.rotation.order = 'YXZ';
|
camera.rotation.order = 'YXZ';
|
||||||
|
|
||||||
@ -79,11 +90,12 @@ const collisionner = new THREE.Group();
|
|||||||
// Maze
|
// Maze
|
||||||
|
|
||||||
const wallMaterial = new THREE.MeshStandardMaterial({
|
const wallMaterial = new THREE.MeshStandardMaterial({
|
||||||
map: loader.load('img/stonewall-albedo.png'),
|
map : loader.load('textures/stonewall/albedo.png'),
|
||||||
normalMap: loader.load('img/stonewall-normal.png'),
|
normalMap : loader.load('textures/stonewall/normal.png'),
|
||||||
metalnessMap: loader.load('img/stonewall-metalness.png'),
|
metalnessMap: loader.load('textures/stonewall/metalness.png'),
|
||||||
aoMap: loader.load('img/stonewall-ao.png'),
|
aoMap : loader.load('textures/stonewall/ao.png'),
|
||||||
roughnessMap: loader.load('img/stonewall-roughness.png'),
|
roughnessMap: loader.load('textures/stonewall/roughness.png'),
|
||||||
|
envMap : scene.background
|
||||||
})
|
})
|
||||||
|
|
||||||
const maze = new MazeMesh(mazeWidth, mazeWidth, 1, wallMaterial);
|
const maze = new MazeMesh(mazeWidth, mazeWidth, 1, wallMaterial);
|
||||||
@ -110,40 +122,41 @@ for (let i = 0; i < maze.count; i++) {
|
|||||||
const groundGeometry = new THREE.BoxGeometry(mazeWidth, mazeWidth, 1)
|
const groundGeometry = new THREE.BoxGeometry(mazeWidth, mazeWidth, 1)
|
||||||
const groundMaterial = new THREE.MeshStandardMaterial({
|
const groundMaterial = new THREE.MeshStandardMaterial({
|
||||||
map: loader.load(
|
map: loader.load(
|
||||||
'img/angled-blocks-vegetation_albedo.png',
|
'textures/angled-blocks-vegetation/albedo.png',
|
||||||
texture => {
|
texture => {
|
||||||
texture.wrapS = texture.wrapT = THREE.RepeatWrapping
|
texture.wrapS = texture.wrapT = THREE.RepeatWrapping
|
||||||
texture.repeat.set(mazeWidth / 4, mazeWidth / 4)
|
texture.repeat.set(mazeWidth / 4, mazeWidth / 4)
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
aoMap: loader.load(
|
aoMap: loader.load(
|
||||||
'img/angled-blocks-vegetation_ao.png',
|
'textures/angled-blocks-vegetation/ao.png',
|
||||||
texture => {
|
texture => {
|
||||||
texture.wrapS = texture.wrapT = THREE.RepeatWrapping
|
texture.wrapS = texture.wrapT = THREE.RepeatWrapping
|
||||||
texture.repeat.set(mazeWidth / 4, mazeWidth / 4)
|
texture.repeat.set(mazeWidth / 4, mazeWidth / 4)
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
metalnessMap: loader.load(
|
metalnessMap: loader.load(
|
||||||
'img/angled-blocks-vegetation_metallic.png',
|
'textures/angled-blocks-vegetation/metallic.png',
|
||||||
texture => {
|
texture => {
|
||||||
texture.wrapS = texture.wrapT = THREE.RepeatWrapping
|
texture.wrapS = texture.wrapT = THREE.RepeatWrapping
|
||||||
texture.repeat.set(mazeWidth / 4, mazeWidth / 4)
|
texture.repeat.set(mazeWidth / 4, mazeWidth / 4)
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
normalMap: loader.load(
|
normalMap: loader.load(
|
||||||
'img/angled-blocks-vegetation_normal-dx.png',
|
'textures/angled-blocks-vegetation/normal-dx.png',
|
||||||
texture => {
|
texture => {
|
||||||
texture.wrapS = texture.wrapT = THREE.RepeatWrapping
|
texture.wrapS = texture.wrapT = THREE.RepeatWrapping
|
||||||
texture.repeat.set(mazeWidth / 4, mazeWidth / 4)
|
texture.repeat.set(mazeWidth / 4, mazeWidth / 4)
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
roughnessMap: loader.load(
|
roughnessMap: loader.load(
|
||||||
'img/angled-blocks-vegetation_roughness.png',
|
'textures/angled-blocks-vegetation/roughness.png',
|
||||||
texture => {
|
texture => {
|
||||||
texture.wrapS = texture.wrapT = THREE.RepeatWrapping
|
texture.wrapS = texture.wrapT = THREE.RepeatWrapping
|
||||||
texture.repeat.set(mazeWidth / 4, mazeWidth / 4)
|
texture.repeat.set(mazeWidth / 4, mazeWidth / 4)
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
envMap: scene.background
|
||||||
})
|
})
|
||||||
const sideGroundMaterial = new THREE.MeshStandardMaterial()
|
const sideGroundMaterial = new THREE.MeshStandardMaterial()
|
||||||
sideGroundMaterial.map = wallMaterial.map.clone()
|
sideGroundMaterial.map = wallMaterial.map.clone()
|
||||||
@ -189,7 +202,7 @@ const ocean = new Water(waterGeometry, {
|
|||||||
textureWidth: 512,
|
textureWidth: 512,
|
||||||
textureHeight: 512,
|
textureHeight: 512,
|
||||||
waterNormals: loader.load(
|
waterNormals: loader.load(
|
||||||
'img/waternormals.jpg',
|
'textures/waternormals.jpg',
|
||||||
function (texture) {
|
function (texture) {
|
||||||
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
|
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
|
||||||
}
|
}
|
||||||
@ -244,25 +257,12 @@ scene.add(ocean);
|
|||||||
|
|
||||||
const sun = new THREE.Vector3();
|
const sun = new THREE.Vector3();
|
||||||
|
|
||||||
const sky = new Sky();
|
|
||||||
sky.scale.setScalar(10000);
|
|
||||||
scene.add(sky);
|
|
||||||
|
|
||||||
const skyUniforms = sky.material.uniforms;
|
|
||||||
|
|
||||||
skyUniforms['turbidity'].value = 10;
|
|
||||||
skyUniforms['rayleigh'].value = 2;
|
|
||||||
skyUniforms['mieCoefficient'].value = 0.005;
|
|
||||||
skyUniforms['mieDirectionalG'].value = 0.8;
|
|
||||||
|
|
||||||
//const pmremGenerator = new THREE.PMREMGenerator(renderer);
|
|
||||||
|
|
||||||
// Lights
|
// Lights
|
||||||
|
|
||||||
const ambientLight = new THREE.AmbientLight(0x404040, 9);
|
const ambientLight = new THREE.AmbientLight(0x404040, 9);
|
||||||
scene.add(ambientLight);
|
scene.add(ambientLight);
|
||||||
|
|
||||||
const sunLight = new THREE.DirectionalLight(0xfffae8, 1);
|
const sunLight = new THREE.DirectionalLight(0xfffae8, 0.7);
|
||||||
sunLight.castShadow = true;
|
sunLight.castShadow = true;
|
||||||
sunLight.shadow.camera.near = 0.1;
|
sunLight.shadow.camera.near = 0.1;
|
||||||
sunLight.shadow.camera.far = 1.4 * mazeWidth;
|
sunLight.shadow.camera.far = 1.4 * mazeWidth;
|
||||||
@ -285,22 +285,18 @@ function updateSun() {
|
|||||||
const theta = THREE.MathUtils.degToRad(parameters.azimuth);
|
const theta = THREE.MathUtils.degToRad(parameters.azimuth);
|
||||||
|
|
||||||
sun.setFromSphericalCoords(1.4 * mazeWidth/2, phi, theta);
|
sun.setFromSphericalCoords(1.4 * mazeWidth/2, phi, theta);
|
||||||
|
|
||||||
sky.material.uniforms['sunPosition'].value.copy(sun);
|
|
||||||
ocean.material.uniforms['sunDirection'].value.copy(sun).normalize();
|
ocean.material.uniforms['sunDirection'].value.copy(sun).normalize();
|
||||||
|
|
||||||
sunLight.position.copy(sun)
|
sunLight.position.copy(sun)
|
||||||
|
|
||||||
ambientLight.intensity = 5 + 5 * Math.sin(Math.max(THREE.MathUtils.degToRad(parameters.elevation), 0));
|
ambientLight.intensity = 5 + 5 * Math.sin(Math.max(THREE.MathUtils.degToRad(parameters.elevation), 0));
|
||||||
|
|
||||||
//scene.environment = pmremGenerator.fromScene(sky).texture;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Raft
|
// Raft
|
||||||
|
|
||||||
const raftGeometry = new THREE.BoxGeometry(1.8, .1, 1.1, 1, 1, 8)
|
const raftGeometry = new THREE.BoxGeometry(1.8, .1, 1.1, 1, 1, 8)
|
||||||
const woodTexture = loader.load('img/wood.jpg');
|
const woodTexture = loader.load('textures/wood.jpg');
|
||||||
const raftFaceMaterial = new THREE.MeshStandardMaterial({
|
const raftFaceMaterial = new THREE.MeshStandardMaterial({
|
||||||
map: woodTexture,
|
map: woodTexture,
|
||||||
aoMap: woodTexture,
|
aoMap: woodTexture,
|
||||||
|
Before Width: | Height: | Size: 7.2 MiB After Width: | Height: | Size: 7.2 MiB |
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
Before Width: | Height: | Size: 9.1 MiB After Width: | Height: | Size: 9.1 MiB |
Before Width: | Height: | Size: 1.8 MiB After Width: | Height: | Size: 1.8 MiB |
BIN
textures/calm-sea-skybox/bk.jpg
Normal file
After Width: | Height: | Size: 396 KiB |
BIN
textures/calm-sea-skybox/dn.jpg
Normal file
After Width: | Height: | Size: 114 KiB |
BIN
textures/calm-sea-skybox/ft.jpg
Normal file
After Width: | Height: | Size: 210 KiB |
BIN
textures/calm-sea-skybox/lf.jpg
Normal file
After Width: | Height: | Size: 252 KiB |
BIN
textures/calm-sea-skybox/rt.jpg
Normal file
After Width: | Height: | Size: 301 KiB |
BIN
textures/calm-sea-skybox/up.jpg
Normal file
After Width: | Height: | Size: 135 KiB |
Before Width: | Height: | Size: 7.0 MiB After Width: | Height: | Size: 7.0 MiB |
Before Width: | Height: | Size: 556 KiB After Width: | Height: | Size: 556 KiB |
Before Width: | Height: | Size: 5.6 MiB After Width: | Height: | Size: 5.6 MiB |
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 79 KiB |
Before Width: | Height: | Size: 9.6 MiB After Width: | Height: | Size: 9.6 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 243 KiB After Width: | Height: | Size: 243 KiB |
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 115 KiB |