-
Notifications
You must be signed in to change notification settings - Fork 5
/
BabylonJS_maze_01.html
75 lines (63 loc) · 2.89 KB
/
BabylonJS_maze_01.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> Babylon.js - Maze_01 Environment & Ground - 2019/12/15 by T. Fujita</title>
<link rel = "stylesheet" type="text/css" href = "./css/babylon_menu.css" />
<script src="https://code.jquery.com/pep/0.4.0/pep.min.js"></script>
<script src="https://cdn.babylonjs.com/babylon.js"></script>
</head>
<body onLoad = "init()">
<canvas id = "renderCanvas"></canvas>
<script type = "text/javascript">
"use strict";
var engine;
var scene;
var canvas = document.getElementById("renderCanvas");
var temp_Environment = "./textures/TropicalSunnyDay";
var camera;
var Maze_size_X = 33; // The row size of maze.
var Maze_size_Z = 25; // The col size of maze.
var BLOCK_SIZE = 8;
function init() {
engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true });
scene = createScene();
engine.runRenderLoop(function() {
scene.render();
});
}
var createScene = function() {
var scene = new BABYLON.Scene(engine);
// Camera
camera = new BABYLON.ArcRotateCamera("Camera", 0/180*Math.PI, 30/180*Math.PI, 10, new BABYLON.Vector3(0, 8, 0), scene);
camera.setPosition(new BABYLON.Vector3((BLOCK_SIZE * Maze_size_X / 2 * -1) - 40, 30, (BLOCK_SIZE * Maze_size_Z / 2 * -1) + 12));
// Ground
var groundMaterial = new BABYLON.StandardMaterial("ground", scene);
groundMaterial.diffuseTexture = new BABYLON.Texture("./textures/floor4.jpg", scene);
groundMaterial.diffuseTexture.uScale = Maze_size_X;
groundMaterial.diffuseTexture.vScale = Maze_size_Z;
groundMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
var ground = BABYLON.Mesh.CreateGround("ground", (Maze_size_X + 2) * BLOCK_SIZE, (Maze_size_Z + 2) * BLOCK_SIZE, 1, scene, false);
ground.material = groundMaterial;
//Skybox
var skybox = BABYLON.Mesh.CreateBox("skyBox", 800.0, scene);
var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
skyboxMaterial.backFaceCulling = false;
skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture(temp_Environment, scene);
skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
skybox.material = skyboxMaterial;
// Lights
var light0 = new BABYLON.DirectionalLight('light00', new BABYLON.Vector3(1000, -1000, 1000), scene);
// light0.position = new BABYLON.Vector3(0, 100, 100);
light0.intensity = 1.0;
var light1 = new BABYLON.HemisphericLight("light01", new BABYLON.Vector3(0, 1000, 0), scene);
light1.position = new BABYLON.Vector3(1000, 1000, -1000);
light1.intensity = 0.5;
camera.attachControl(canvas, true);
return scene;
};
</script>
</body>
</html>