1
0
Fork 0

Add transparency wall

This commit is contained in:
Florian RICHER 2016-12-01 22:31:33 +01:00
parent ae050cfba9
commit 98d390e1e3

View file

@ -3,20 +3,20 @@
function runDemo(canvasId) { function runDemo(canvasId) {
var canvas = document.getElementById(canvasId); var canvas = document.getElementById(canvasId);
var engine = new BABYLON.Engine(canvas, true); var engine = new BABYLON.Engine(canvas, true);
// Cr<43>ation de la sc<73>ne // Cr<43>ation de la sc<73>ne
var scene = new BABYLON.Scene(engine); var scene = new BABYLON.Scene(engine);
scene.gravity = new BABYLON.Vector3(0, -9.81, 0); scene.gravity = new BABYLON.Vector3(0, -9.81, 0);
scene.collisionsEnabled = true; scene.collisionsEnabled = true;
// Ajout d'une cam<61>ra et de son contr<74>leur // Ajout d'une cam<61>ra et de son contr<74>leur
var camera = new BABYLON.FreeCamera("MainCamera", new BABYLON.Vector3(0, 2.5, 5), scene); var camera = new BABYLON.FreeCamera("MainCamera", new BABYLON.Vector3(0, 2.5, 5), scene);
camera.applyGravity = true; camera.applyGravity = true;
camera.checkCollisions = true; camera.checkCollisions = true;
camera.speed = 0.5; camera.speed = 0.5;
camera.angularSensibility = 1000; camera.angularSensibility = 1000;
camera.keysUp = [90]; // Touche Z camera.keysUp = [90]; // Touche Z
camera.keysDown = [83]; // Touche S camera.keysDown = [83]; // Touche S
camera.keysLeft = [81]; // Touche Q camera.keysLeft = [81]; // Touche Q
@ -28,19 +28,19 @@ function runDemo(canvasId) {
}else if(camera.position.x<-2){ }else if(camera.position.x<-2){
camera.position.x=-2; camera.position.x=-2;
} }
// Ajout d'une lumi<6D>re // Ajout d'une lumi<6D>re
var light = new BABYLON.PointLight("DirLight", new BABYLON.Vector3(0, 10, 0), scene); var light = new BABYLON.PointLight("DirLight", new BABYLON.Vector3(0, 10, 0), scene);
light.diffuse = new BABYLON.Color3(1, 1, 1); light.diffuse = new BABYLON.Color3(1, 1, 1);
light.specular = new BABYLON.Color3(0.6, 0.6, 0.6); light.specular = new BABYLON.Color3(0.6, 0.6, 0.6);
light.intensity = 1.5; light.intensity = 1.5;
// On ajoute une skybox // On ajoute une skybox
createSkybox(scene); createSkybox(scene);
// Enfin la sc<73>ne de d<>mo // Enfin la sc<73>ne de d<>mo
createDemoScene(scene); createDemoScene(scene);
// Lancement de la boucle principale // Lancement de la boucle principale
engine.runRenderLoop(function() { engine.runRenderLoop(function() {
scene.render(); scene.render();
@ -53,7 +53,7 @@ function createSkybox(scene) {
sMaterial.backFaceCulling = false; sMaterial.backFaceCulling = false;
sMaterial.reflectionTexture = new BABYLON.CubeTexture("images/skybox/skybox", scene); sMaterial.reflectionTexture = new BABYLON.CubeTexture("images/skybox/skybox", scene);
sMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE; sMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
// Cr<43>ation d'un cube avec la material adapt<70>e // Cr<43>ation d'un cube avec la material adapt<70>e
var skybox = BABYLON.Mesh.CreateBox("skybox", 250, scene); var skybox = BABYLON.Mesh.CreateBox("skybox", 250, scene);
skybox.material = sMaterial; skybox.material = sMaterial;
@ -71,41 +71,45 @@ function createDemoScene(scene) {
mur1.rotation.y = Math.PI / 2; mur1.rotation.y = Math.PI / 2;
mur1.position.y = 20; mur1.position.y = 20;
mur1.position.x = 25; mur1.position.x = 25;
mur1.visibility = 0;
mur1.checkCollisions = true; mur1.checkCollisions = true;
var mur2 = BABYLON.Mesh.CreatePlane("mur2", 50, scene); var mur2 = BABYLON.Mesh.CreatePlane("mur2", 50, scene);
mur2.rotation.y = -(Math.PI / 2); mur2.rotation.y = -(Math.PI / 2);
mur2.position.y = 20; mur2.position.y = 20;
mur2.position.x = -25; mur2.position.x = -25;
mur2.visibility = 0;
mur2.checkCollisions = true; mur2.checkCollisions = true;
var mur3 = BABYLON.Mesh.CreatePlane("mur3", 50, scene); var mur3 = BABYLON.Mesh.CreatePlane("mur3", 50, scene);
mur3.rotation.z = Math.PI / 2; mur3.rotation.z = Math.PI / 2;
mur3.position.z = 25; mur3.position.z = 25;
mur3.visibility = 0;
mur3.checkCollisions = true; mur3.checkCollisions = true;
var mur4 = BABYLON.Mesh.CreatePlane("mur4", 50, scene); var mur4 = BABYLON.Mesh.CreatePlane("mur4", 50, scene);
mur4.rotation.x = Math.PI; mur4.rotation.x = Math.PI;
mur4.position.z = -25; mur4.position.z = -25;
mur4.visibility = 0;
mur4.checkCollisions = true; mur4.checkCollisions = true;
// Et quelques cubes... // Et quelques cubes...
var boxMaterial = new BABYLON.StandardMaterial("bMaterial", scene); var boxMaterial = new BABYLON.StandardMaterial("bMaterial", scene);
boxMaterial.diffuseTexture = new BABYLON.Texture("images/box.png", scene); boxMaterial.diffuseTexture = new BABYLON.Texture("images/box.png", scene);
var positions = [ var positions = [
{ x: -15, z: 15 }, { x: -15, z: 15 },
{ x: -15, z: -15 }, { x: -15, z: -15 },
{ x: 15, z: 15 }, { x: 15, z: 15 },
{ x: 15, z: -15 } { x: 15, z: -15 }
]; ];
var cubeSize = 2.5; var cubeSize = 2.5;
for (var i = 0; i < 4; i++) { for (var i = 0; i < 4; i++) {
var box = BABYLON.Mesh.CreateBox("box1", cubeSize, scene); var box = BABYLON.Mesh.CreateBox("box1", cubeSize, scene);
box.position = new BABYLON.Vector3(positions[i].x, cubeSize / 2, positions[i].z); box.position = new BABYLON.Vector3(positions[i].x, cubeSize / 2, positions[i].z);
box.material = boxMaterial; box.material = boxMaterial;
box.checkCollisions = true; box.checkCollisions = true;
} }
} }