Merge
This commit is contained in:
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* MultiGame.js :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/18 00:53:53 by edbernar #+# #+# */
|
||||
/* Updated: 2024/08/28 14:07:25 by edbernar ### ########.fr */
|
||||
/* Updated: 2024/08/28 16:34:39 by hubourge ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -106,6 +106,15 @@ class MultiGame
|
||||
player.pointOpponentAnimation(map, opponent.object);
|
||||
if (e.key == 'c')
|
||||
debug = !debug;
|
||||
if (e.key == 'p')
|
||||
{
|
||||
map.clearVideoCanvas();
|
||||
}
|
||||
if (e.key == 'o')
|
||||
{
|
||||
// map.clearVideoCanvas();
|
||||
map.putVideoOnCanvas(3, 'catch');
|
||||
}
|
||||
})
|
||||
|
||||
renderer.setAnimationLoop(loop)
|
||||
|
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* Map.js :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/20 14:52:55 by hubourge #+# #+# */
|
||||
/* Updated: 2024/08/28 11:04:41 by edbernar ### ########.fr */
|
||||
/* Updated: 2024/08/28 19:07:03 by hubourge ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -22,22 +22,12 @@ let interval2 = null;
|
||||
let videoCanvas = null;
|
||||
let videoCanvasTexture = null;
|
||||
let materialCanvas = null;
|
||||
|
||||
|
||||
// Plane
|
||||
|
||||
let textureLoaderPlane = null;
|
||||
let texturePlane = null;
|
||||
// Border wall
|
||||
// Gravity changer
|
||||
|
||||
|
||||
|
||||
// Wall obstacle
|
||||
|
||||
// Banner
|
||||
|
||||
// Gravity changer animation
|
||||
let ctx = null;
|
||||
let path = [];
|
||||
let spacingImages = [];
|
||||
let clearVideo = false;
|
||||
|
||||
class Map
|
||||
{
|
||||
@ -311,42 +301,87 @@ class Map
|
||||
- Faire une zone pour les pub (s'inspirer de theFinals) (ok)
|
||||
|
||||
- Effet gros pixel (ok)
|
||||
- Effet de lumière en 2d
|
||||
- Preparer une animation pour le but
|
||||
- Effet de lumière en 2d (direct dans les videos)
|
||||
- Preparer differents events
|
||||
*/
|
||||
#createBanner()
|
||||
{
|
||||
// Create canvas
|
||||
videoCanvas = document.createElement('canvas');
|
||||
const ctx = videoCanvas.getContext('2d');
|
||||
ctx = videoCanvas.getContext('2d');
|
||||
videoCanvas.width = 100 * 2.33 * 20;
|
||||
videoCanvas.height = 100;
|
||||
|
||||
const path = [
|
||||
'../textures/video/goal2.webm',
|
||||
'../textures/video/pingpong.mp4',
|
||||
'../textures/video/catch.mp4',
|
||||
'../textures/video/easteregg.webm',
|
||||
'../textures/video/fortnite.mp4',
|
||||
'../textures/video/Composition 1_1.webm',
|
||||
path = [
|
||||
{name: 'goal', src:'../textures/video/goal2.webm'},
|
||||
{name: 'ping', src:'../textures/video/pingpong.mp4'},
|
||||
{name: 'catch', src:'../textures/video/catch.mp4'},
|
||||
{name: 'easteregg', src:'../textures/video/easteregg.webm'},
|
||||
{name: 'fortnite', src:'../textures/video/fortnite.mp4'},
|
||||
{name: 'outstanding', src:'../textures/video/outstanding.webm'},
|
||||
]
|
||||
path.sort(() => Math.random() - 0.5);
|
||||
|
||||
let spacingImages = [
|
||||
spacingImages = [
|
||||
100 * 2.33 * 10 - (100 * 2.33), // 2 images
|
||||
100 * 2.33 * 5 - (100 * 2.33), // 4 images
|
||||
100 * 2.33 * 2.5 - (100 * 2.33), // 8 images
|
||||
100 * 2.33 * 1.25 - (100 * 2.33), // 16 images
|
||||
];
|
||||
|
||||
const nbVideos = 5; // 1, 2, 3, 4, 5
|
||||
const nbImages = 3; // 0 = 2 img, 1 = 4 img, 2 = 8 img, 3 = 16 img
|
||||
const startIndex = ((Math.random() * (path.length - nbVideos)).toFixed(0)) % path.length;
|
||||
// const startIndex = 5;
|
||||
// const nbImages = 3; // 0 = 2 img, 1 = 4 img, 2 = 8 img, 3 = 16 img
|
||||
|
||||
// // Create texture
|
||||
// videoCanvasTexture = new THREE.CanvasTexture(videoCanvas);
|
||||
// videoCanvasTexture.wrapS = THREE.RepeatWrapping;
|
||||
// videoCanvasTexture.wrapT = THREE.RepeatWrapping;
|
||||
// videoCanvasTexture.repeat.set(-1, 1);
|
||||
|
||||
// materialCanvas = new THREE.MeshBasicMaterial({ map: videoCanvasTexture, side: THREE.BackSide , transparent: false});
|
||||
|
||||
// loader.load( '../blender/exported/banner.glb', (gltf) => {
|
||||
// this.banner = gltf.scene.children[0];
|
||||
// gltf = null;
|
||||
// this.banner.material = materialCanvas;
|
||||
// this.banner.position.y += 1.7;
|
||||
// this.banner.rotation.x = (Math.PI);
|
||||
// this.banner.rotation.y += -0.15;
|
||||
// scene.add(this.banner);
|
||||
// interval2 = setInterval(() => {
|
||||
// this.banner.rotation.y += 0.001;
|
||||
// }, 10);
|
||||
// }, undefined, function ( error ) {
|
||||
// console.error( error );
|
||||
// } );
|
||||
}
|
||||
|
||||
putVideoOnCanvas(nbImage, name)
|
||||
{
|
||||
console.log('put video canvas');
|
||||
|
||||
let startIndex;
|
||||
let nbVideos = 1;
|
||||
|
||||
if (name && typeof(name) == 'number')
|
||||
nbVideos = name;
|
||||
if (name && typeof(name) == 'string')
|
||||
{
|
||||
for (let index = 0; index < path.length; index++)
|
||||
{
|
||||
if (path[index].name == name)
|
||||
{
|
||||
startIndex = index;
|
||||
break ;
|
||||
}
|
||||
startIndex = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
startIndex = ((Math.random() * (path.length - nbVideos)).toFixed(0)) % path.length;
|
||||
|
||||
for (let i = startIndex; i < (nbVideos + startIndex); i++)
|
||||
{
|
||||
let videoTmp = new Video(path[i]).video;
|
||||
let videoTmp = new Video(path[i].src).video;
|
||||
videoTmp.addEventListener('loadeddata', () => {
|
||||
videoTmp.play();
|
||||
drawVideoOnCanvas();
|
||||
@ -354,18 +389,23 @@ class Map
|
||||
videoList.push({video: videoTmp, imageWidth: 100 * 2.33, imageHeight: 100});
|
||||
}
|
||||
|
||||
console.log('videoList', videoList);
|
||||
|
||||
function drawVideoOnCanvas()
|
||||
{
|
||||
if (videoCanvas)
|
||||
{
|
||||
ctx.clearRect(0, 0, videoCanvas.width, videoCanvas.height);
|
||||
|
||||
if (clearVideo)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
if (nbVideos == 0)
|
||||
return ;
|
||||
let nbDraw = 0;
|
||||
let vIndex = 0;
|
||||
let y = 0;
|
||||
for (let x = 0; x < videoCanvas.width; x += (videoList[vIndex].imageWidth + spacingImages[nbImages]))
|
||||
for (let x = 0; x < videoCanvas.width; x += (videoList[vIndex].imageWidth + spacingImages[nbImage]))
|
||||
{
|
||||
ctx.drawImage(videoList[vIndex].video, x, y, videoList[vIndex].imageWidth, videoList[vIndex].imageHeight);
|
||||
nbDraw++;
|
||||
@ -374,19 +414,18 @@ class Map
|
||||
if (vIndex >= nbVideos)
|
||||
vIndex = 0;
|
||||
}
|
||||
|
||||
videoCanvasTexture.needsUpdate = true;
|
||||
if (videoCanvasTexture)
|
||||
videoCanvasTexture.needsUpdate = true;
|
||||
requestAnimationFrame(drawVideoOnCanvas);
|
||||
}
|
||||
}
|
||||
|
||||
// Create texture
|
||||
videoCanvasTexture = new THREE.CanvasTexture(videoCanvas);
|
||||
videoCanvasTexture.wrapS = THREE.RepeatWrapping;
|
||||
videoCanvasTexture.wrapT = THREE.RepeatWrapping;
|
||||
videoCanvasTexture.repeat.set(-1, 1);
|
||||
|
||||
materialCanvas = new THREE.MeshBasicMaterial({ map: videoCanvasTexture, side: THREE.BackSide , transparent: true});
|
||||
materialCanvas = new THREE.MeshBasicMaterial({ map: videoCanvasTexture, side: THREE.BackSide , transparent: false});
|
||||
|
||||
loader.load( '../blender/exported/banner.glb', (gltf) => {
|
||||
this.banner = gltf.scene.children[0];
|
||||
@ -404,6 +443,58 @@ class Map
|
||||
} );
|
||||
}
|
||||
|
||||
clearVideoCanvas()
|
||||
{
|
||||
console.log('clear video canvas');
|
||||
if (videoCanvas)
|
||||
{
|
||||
videoCanvas.remove();
|
||||
videoCanvas = null;
|
||||
}
|
||||
|
||||
if (videoList)
|
||||
{
|
||||
videoList.forEach(elem => {
|
||||
elem.video.pause();
|
||||
elem.video.src = '';
|
||||
elem.video.removeAttribute('src');
|
||||
elem.video.load();
|
||||
})
|
||||
videoList = null;
|
||||
videoList = [];
|
||||
}
|
||||
// if (videoCanvasTexture)
|
||||
// videoCanvasTexture.dispose();
|
||||
|
||||
// videoCanvas = null;
|
||||
// videoCanvasTexture = new THREE.CanvasTexture(videoCanvas);
|
||||
// videoCanvasTexture.wrapS = THREE.RepeatWrapping;
|
||||
// videoCanvasTexture.wrapT = THREE.RepeatWrapping;
|
||||
// videoCanvasTexture.repeat.set(-1, 1);
|
||||
|
||||
// if (materialCanvas)
|
||||
// materialCanvas.dispose();
|
||||
|
||||
// materialCanvas = new THREE.MeshBasicMaterial({ map: videoCanvasTexture, side: THREE.BackSide , transparent: false});
|
||||
|
||||
// loader.load( '../blender/exported/banner.glb', (gltf) => {
|
||||
// this.banner = gltf.scene.children[0];
|
||||
// gltf = null;
|
||||
// this.banner.material = materialCanvas;
|
||||
// this.banner.position.y += 1.7;
|
||||
// this.banner.rotation.x = (Math.PI);
|
||||
// this.banner.rotation.y += -0.15;
|
||||
// scene.add(this.banner);
|
||||
// interval2 = setInterval(() => {
|
||||
// this.banner.rotation.y += 0.001;
|
||||
// }, 10);
|
||||
// }, undefined, function ( error ) {
|
||||
// console.error( error );
|
||||
// } );
|
||||
|
||||
console.log('videoList', videoList);
|
||||
}
|
||||
|
||||
#animationGravityChanger(group, onTop)
|
||||
{
|
||||
let geometryGC = new THREE.TorusGeometry(1.5, 0.05, 12, 24);
|
||||
|
Reference in New Issue
Block a user