-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
70 lines (56 loc) · 2.56 KB
/
index.js
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
window.addEventListener('DOMContentLoaded', function(){
// get the canvas DOM element
var canvas = document.getElementById('renderCanvas');
// load the 3D engine
var engine = new BABYLON.Engine(canvas, true);
// createScene function that creates and return the scene
var createScene = function () {
// This creates a basic Babylon Scene object (non-mesh)
var scene = new BABYLON.Scene(engine);
scene.clearColor = BABYLON.Color3.Blue();
// This creates and positions a free camera (non-mesh)
var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);
// This targets the camera to scene origin
camera.setTarget(BABYLON.Vector3.Zero());
// This attaches the camera to the canvas
camera.attachControl(canvas, true);
// This creates a light, aiming 0,1,0 - to the sky (non-mesh)
var light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 1, 0), scene);
// Default intensity is 1. Let's dim the light a small amount
light.intensity = 0.7;
// Our built-in 'sphere' shape.
var sun = BABYLON.MeshBuilder.CreateSphere("sphere", {diameter: 2, segments: 32}, scene);
var tower = BABYLON.MeshBuilder.CreateBox("box", {width:2.2, height:10, segments: 32}, scene);
var towertop = BABYLON.MeshBuilder.CreateCylinder("cylinder", {width:1.1, height:5, segments: 32}, scene);
// the tower position
tower.position.y = 5;
// tower top position
towertop.position.y = 10;
towertop.position.z = -0.000001;
// the sun position
sun.position.y = 50;
sun.position.z = 25;
sun.position.x = 10;
sun.overlayColor = BABYLON.Color3.Yellow()
tower.overlayColor = BABYLON.Color3.Black()
towertop.overlayColor = BABYLON.Color3.Black()
scene.getMeshByID("sphere").renderOverlay = true;
scene.getMeshByID("box").renderOverlay = true;
scene.getMeshByID("cylinder").renderOverlay = true;
// Our built-in 'ground' shape.
var ground = BABYLON.MeshBuilder.CreateGround("ground", {width: 12, height: 12}, scene);
scene.getMeshByID("ground").renderOverlay = true;
ground.overlayColor = BABYLON.Color3.Green()
return scene;
};
// call the createScene function
var scene = createScene();
// run the render loop
engine.runRenderLoop(function(){
scene.render();
});
// the canvas/window resize event handler
window.addEventListener('resize', function(){
engine.resize();
});
});