diff --git a/site/interface/site/home3D/Screen.js b/site/interface/site/home3D/Screen.js new file mode 100644 index 0000000..fb03467 --- /dev/null +++ b/site/interface/site/home3D/Screen.js @@ -0,0 +1,140 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Screen.js :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: edbernar { + const tv = gltf.scene.children[0]; + const boundingBox = new THREE.Box3().setFromObject(tv); + const center = boundingBox.getCenter(new THREE.Vector3()); + tv.geometry.center(); + this.tv = tv; + tv.position.set(0, 0.99, 2); + // tv.material = new THREE.MeshPhysicalMaterial({color: 0x222222}); + tv.scale.set(0.05, 0.05, 0.05); + tv.castShadow = true; + tv.receiveShadow = true; + scene.add(tv); + }, undefined, function ( error ) { + console.error( error ); + throw Error("Can't open file 'tv.glb'"); + } ); + this.#showVideo('/modeles/pong.mp4') + } + + #createScreen(scene) + { + const geometry = new THREE.PlaneGeometry(4.1, 3, 50, 50); + const positionAttribute = geometry.attributes.position; + const vertices = positionAttribute.array; + const material = new THREE.MeshStandardMaterial({color: 0xbbbbbb}); + const mesh = new THREE.Mesh(geometry, material); + const pointLight = new THREE.PointLight( 0xffffff, 5, 0, 2); + + for (let i = 0; i < vertices.length; i += 3) + { + const x = vertices[i]; + const y = vertices[i + 1]; + const distance = (Math.sqrt(x * x + y * y)); + const height = Math.pow(distance, 2) * -0.02; + vertices[i + 2] = height; + } + positionAttribute.needsUpdate = true; + mesh.scale.set(0.4, 0.4); + mesh.position.set(-0.155, 1.2, 1.3); + mesh.rotation.x = Math.PI + 0.05; + mesh.rotation.z = Math.PI; + scene.add(mesh); + pointLight.position.set(-0.155, 1.2, 0.8); + pointLight.castShadow = true; + pointLight.shadow.mapSize.width = 2048; + pointLight.shadow.mapSize.height = 2048; + pointLight.shadow.radius = 20; + scene.add(pointLight); + setInterval(() => { + const intensity = Math.random() * 2 + 5; + + pointLight.intensity = intensity < 5 ? 5 : (intensity > 7 ? 7 : intensity); + }, 100); + return (mesh); + } + + #showVideo(path) + { + const canvas = document.createElement('canvas'); + const context = canvas.getContext('2d', { willReadFrequently: true }); + const video = document.createElement('video'); + const texture = new THREE.CanvasTexture(canvas); + const material = new THREE.MeshBasicMaterial({ map: texture,color: 0xffffff }); + + canvas.width = 534; + canvas.height = 360; + video.src = path + '?t=' + new Date().getTime(); + video.loop = true; + video.muted = true; + video.crossOrigin = 'anonymous'; + + video.addEventListener('loadedmetadata', () => { + const texture = this.screen.material.map; + texture.needsUpdate = true; + video.play().then(() => { + updateCanvas(); + }).catch(err => console.error("Error playing video: ", err)); + }); + + function addNoiseOnImage(context) + { + const imageData = context.getImageData(0, 0, canvas.width, canvas.height); + const data = imageData.data; + for (let i = 0; i < data.length; i += 4) + { + const r = data[i]; + const g = data[i + 1]; + const b = data[i + 2]; + const brightness = (3 * r + 4 * g + b) >>> 3; + const noise = Math.random() * 32 - 16; + data[i] = data[i + 1] = data[i + 2] = brightness + noise; + } + context.putImageData(imageData, 0, 0); + } + + function updateCanvas() + { + if (!video.paused && !video.ended) + { + context.clearRect(0, 0, canvas.width, canvas.height); + context.drawImage(video, 0, 0, canvas.width, canvas.height); + addNoiseOnImage(context); + texture.needsUpdate = true; + requestAnimationFrame(updateCanvas); + } + } + + texture.offset.set(0.02, 0); + this.screen.material = material; + video.load(); + } +}; + +export { Screen }; \ No newline at end of file diff --git a/site/interface/site/home3D/home3D.js b/site/interface/site/home3D/home3D.js index 5b911f8..537fa2b 100644 --- a/site/interface/site/home3D/home3D.js +++ b/site/interface/site/home3D/home3D.js @@ -6,64 +6,80 @@ /* By: edbernar { + renderer.setSize(window.innerWidth, window.innerHeight); + camera.aspect = window.innerWidth / window.innerHeight; + camera.updateProjectionMatrix(); +}); + +/***** FOR DEBUGGING PURPOSES *****/ + +document.addEventListener('keydown', (e) => { + if (e.key === 'w') + camera.position.z += 0.1; + if (e.key === 's') + camera.position.z -= 0.1; + if (e.key === 'a') + camera.position.x -= 0.1; + if (e.key === 'd') + camera.position.x += 0.1; + if (e.key === 'q') + camera.position.y += 0.1; + if (e.key === 'e') + camera.position.y -= 0.1; + if (e.key === 'ArrowUp') + camera.rotation.x += 0.1; + if (e.key === 'ArrowDown') + camera.rotation.x -= 0.1; + if (e.key === 'ArrowLeft') + camera.rotation.y += 0.1; + if (e.key === 'ArrowRight') + camera.rotation.y -= 0.1; + if (e.key === 'p') + { + console.log(camera.position); + console.log(camera.rotation); + } + +}); + +/**********************************/ + function home3D() { createPlane(); - createBox(); - loader.load( './modeles/tv.glb', (gltf) => { - const tv = gltf.scene.children[0]; - console.log(tv); - tv.position.set(0, 0.68, 0); - tv.material = new THREE.MeshPhysicalMaterial({color: 0x222222}); - tv.scale.set(0.1, 0.08, 0.12); - tv.castShadow = true; - tv.receiveShadow = true; - scene.add(tv); - }, undefined, function ( error ) { - console.error( error ); - } ); - renderer.setAnimationLoop(loop) } function createPlane() { - const geometry = new THREE.PlaneGeometry(20, 20); - const material = new THREE.MeshPhysicalMaterial({side: THREE.DoubleSide, color: 0xffffff}); + const geometry = new THREE.PlaneGeometry(500, 500); + const material = new THREE.MeshPhysicalMaterial({side: THREE.DoubleSide, color: 0x020202}); const mesh = new THREE.Mesh(geometry, material); mesh.position.set(0, 0, 0); @@ -72,22 +88,11 @@ function createPlane() scene.add(mesh); } -function createBox() -{ - const geometry = new THREE.BoxGeometry(1, 1, 1); - const material = new THREE.MeshPhysicalMaterial({color: 0xffffff}); - const mesh = new THREE.Mesh(geometry, material); - - mesh.position.set(-3, 0.5, -3); - mesh.receiveShadow = true; - scene.add(mesh); -} - function loop() { - controls.update(); renderer.render(scene, camera); } + export { home3D }; \ No newline at end of file diff --git a/site/interface/site/modeles/pong.mp4 b/site/interface/site/modeles/pong.mp4 new file mode 100644 index 0000000..ef6dd1a Binary files /dev/null and b/site/interface/site/modeles/pong.mp4 differ