1
0
Fork 0

Add Obj Loader

This commit is contained in:
Florian RICHER 2016-12-02 00:37:38 +01:00
parent d7fc954da7
commit fee8e01b88
4 changed files with 61 additions and 98 deletions

View file

@ -21,7 +21,7 @@
<canvas id="renderCanvas"></canvas>
<script src="scripts/babylon.1.6.js"></script>
<script src="scripts/babylon.custom.js"></script>
<script src="scripts/babylon_obj.js"></script>
<script src="scripts/hand-1.1.3.js"></script>
<script src="scripts/demo.js"></script>

File diff suppressed because one or more lines are too long

40
scripts/babylon.custom.js Normal file

File diff suppressed because one or more lines are too long

View file

@ -6,6 +6,8 @@ function runDemo(canvasId) {
// Cr<43>ation de la sc<73>ne
var scene = new BABYLON.Scene(engine);
var loader = new BABYLON.AssetsManager(scene);//Obj loader
BABYLON.OBJFileLoader.OPTIMIZE_WITH_UV = true;
scene.gravity = new BABYLON.Vector3(0, -9.81, 0);
scene.collisionsEnabled = true;
@ -35,11 +37,6 @@ function runDemo(canvasId) {
light.specular = new BABYLON.Color3(0.6, 0.6, 0.6);
light.intensity = 1.5;
var light2 = new BABYLON.PointLight("DirLight", new BABYLON.Vector3(0, 10, 80), scene);
light2.diffuse = new BABYLON.Color3(1, 1, 1);
light2.specular = new BABYLON.Color3(0.6, 0.6, 0.6);
light2.intensity = 1.5;
// On ajoute une skybox
createSkybox(scene);
@ -47,28 +44,27 @@ function runDemo(canvasId) {
createDemoScene(scene);
// Creer l obj
//createObj(scene);
createObj(loader,scene);
// Lancement de la boucle principale
engine.runRenderLoop(function() {
scene.render();
});
loader.onFinish = function() {
engine.runRenderLoop(function () {
scene.render();
});
};
loader.load();
return scene;
}
// function createObj(scene){
// var loader = new BABYLON.AssetsManager(scene);
// var batman = loader.addMeshTask("bunny", "", "assets/", "bunny.obj");
// batman.position.x = 10;
// batman.position.z = 10;
//
// loader.onFinish = function() {
// engine.runRenderLoop(function () {
// scene.render();
// });
// };
//
// loader.load();
// }
function createObj(loader,scene){
var batman = loader.addMeshTask("bunny", "", "assets/", "bunny.obj");
batman.onSuccess = function(t){
t.loadedMeshes.forEach(function(m) {
m.position.x = 10;
m.scale = 100;
});
};
}
function createSkybox(scene) {
// Cr<43>ation d'une material
@ -118,59 +114,6 @@ function createDemoScene(scene) {
mur4.visibility = 0;
mur4.checkCollisions = true;
/*-----------------SALLE 2----------------------------------*/
var groundSalle2 = BABYLON.Mesh.CreatePlane("groundSalle2", 50, scene);
groundSalle2.rotation.x = Math.PI / 2;
groundSalle2.position.z = 70;
groundSalle2.material = new BABYLON.StandardMaterial("gMaterial", scene);
groundSalle2.material.diffuseTexture = new BABYLON.Texture("images/ground.png", scene);
groundSalle2.checkCollisions = true;
var mur11Salle2 = BABYLON.Mesh.CreatePlane("mur11Salle2", 20, scene);
mur11Salle2.rotation.x = Math.PI;
mur11Salle2.position.z = 45;
mur11Salle2.position.x = 15;
mur11Salle2.visibility = 0;
mur11Salle2.checkCollisions = true;
var mur12Salle2 = BABYLON.Mesh.CreatePlane("mur12Salle2", 20, scene);
mur12Salle2.rotation.x = Math.PI;
mur12Salle2.position.z = 45;
mur12Salle2.position.x = -15;
mur12Salle2.visibility = 0;
mur12Salle2.checkCollisions = true;
var mur2Salle2 = BABYLON.Mesh.CreatePlane("mur2Salle2", 50, scene);
mur2Salle2.rotation.y = -(Math.PI / 2);
mur2Salle2.position.y = 20;
mur2Salle2.position.x = -25;
mur2Salle2.position.z = 70;
mur2Salle2.visibility = 0;
mur2Salle2.checkCollisions = true;
var mur31Salle1 = BABYLON.Mesh.CreatePlane("mur31Salle1", 20, scene);
mur31Salle1.rotation.z = Math.PI / 2;
mur31Salle1.position.z = 95;
mur31Salle1.position.x = -15;
mur31Salle1.visibility = 0;
mur31Salle1.checkCollisions = true;
var mur32Salle1 = BABYLON.Mesh.CreatePlane("mur32Salle1", 20, scene);
mur32Salle1.rotation.z = Math.PI / 2;
mur32Salle1.position.z = 95;
mur32Salle1.position.x = 15;
mur32Salle1.visibility = 0;
mur32Salle1.checkCollisions = true;
var mur4Salle2 = BABYLON.Mesh.CreatePlane("mur4Salle2", 50, scene);
mur4Salle2.rotation.y = Math.PI / 2;
mur4Salle2.position.y = 20;
mur4Salle2.position.x = 25;
mur4Salle2.position.z = 70;
mur4Salle2.visibility = 0;
mur4Salle2.checkCollisions = true;
// Et quelques cubes...
var boxMaterial = new BABYLON.StandardMaterial("bMaterial", scene);
boxMaterial.diffuseTexture = new BABYLON.Texture("images/box.png", scene);