Murs ajoutés
This commit is contained in:
parent
140cd2635d
commit
ae050cfba9
1 changed files with 35 additions and 7 deletions
|
@ -4,12 +4,12 @@ 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éation de la scène
|
// Cr<EFBFBD>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éra et de son contrôleur
|
// Ajout d'une cam<EFBFBD>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;
|
||||||
|
@ -23,7 +23,13 @@ function runDemo(canvasId) {
|
||||||
camera.keysRight = [68]; // Touche D;
|
camera.keysRight = [68]; // Touche D;
|
||||||
scene.activeCamera.attachControl(canvas);
|
scene.activeCamera.attachControl(canvas);
|
||||||
|
|
||||||
// Ajout d'une lumière
|
if(camera.position.x>2){
|
||||||
|
camera.position.x=2;
|
||||||
|
}else if(camera.position.x<-2){
|
||||||
|
camera.position.x=-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
@ -32,7 +38,7 @@ function runDemo(canvasId) {
|
||||||
// On ajoute une skybox
|
// On ajoute une skybox
|
||||||
createSkybox(scene);
|
createSkybox(scene);
|
||||||
|
|
||||||
// Enfin la scène de démo
|
// Enfin la sc<EFBFBD>ne de d<>mo
|
||||||
createDemoScene(scene);
|
createDemoScene(scene);
|
||||||
|
|
||||||
// Lancement de la boucle principale
|
// Lancement de la boucle principale
|
||||||
|
@ -42,25 +48,47 @@ function runDemo(canvasId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSkybox(scene) {
|
function createSkybox(scene) {
|
||||||
// Création d'une material
|
// Cr<EFBFBD>ation d'une material
|
||||||
var sMaterial = new BABYLON.StandardMaterial("skyboxMaterial", scene);
|
var sMaterial = new BABYLON.StandardMaterial("skyboxMaterial", 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éation d'un cube avec la material adaptée
|
// Cr<EFBFBD>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;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createDemoScene(scene) {
|
function createDemoScene(scene) {
|
||||||
// Création d'un sol
|
// Cr<EFBFBD>ation d'un sol
|
||||||
var ground = BABYLON.Mesh.CreatePlane("ground", 50, scene);
|
var ground = BABYLON.Mesh.CreatePlane("ground", 50, scene);
|
||||||
ground.rotation.x = Math.PI / 2;
|
ground.rotation.x = Math.PI / 2;
|
||||||
ground.material = new BABYLON.StandardMaterial("gMaterial", scene);
|
ground.material = new BABYLON.StandardMaterial("gMaterial", scene);
|
||||||
ground.material.diffuseTexture = new BABYLON.Texture("images/ground.png", scene);
|
ground.material.diffuseTexture = new BABYLON.Texture("images/ground.png", scene);
|
||||||
ground.checkCollisions = true;
|
ground.checkCollisions = true;
|
||||||
|
|
||||||
|
var mur1 = BABYLON.Mesh.CreatePlane("mur1", 50, scene);
|
||||||
|
mur1.rotation.y = Math.PI / 2;
|
||||||
|
mur1.position.y = 20;
|
||||||
|
mur1.position.x = 25;
|
||||||
|
mur1.checkCollisions = true;
|
||||||
|
|
||||||
|
var mur2 = BABYLON.Mesh.CreatePlane("mur2", 50, scene);
|
||||||
|
mur2.rotation.y = -(Math.PI / 2);
|
||||||
|
mur2.position.y = 20;
|
||||||
|
mur2.position.x = -25;
|
||||||
|
mur2.checkCollisions = true;
|
||||||
|
|
||||||
|
var mur3 = BABYLON.Mesh.CreatePlane("mur3", 50, scene);
|
||||||
|
mur3.rotation.z = Math.PI / 2;
|
||||||
|
mur3.position.z = 25;
|
||||||
|
mur3.checkCollisions = true;
|
||||||
|
|
||||||
|
var mur4 = BABYLON.Mesh.CreatePlane("mur4", 50, scene);
|
||||||
|
mur4.rotation.x = Math.PI;
|
||||||
|
mur4.position.z = -25;
|
||||||
|
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);
|
||||||
|
|
Reference in a new issue