-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbabyetl.js
124 lines (105 loc) · 5.39 KB
/
babyetl.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
function main() {
const canvas = document.getElementById('renderCanvas');
const engine = new BABYLON.Engine(canvas);
var createScene = function () {
// This creates a basic Babylon Scene object (non-mesh)
var scene = new BABYLON.Scene(engine);
// This creates and positions a free camera (non-mesh)
const camera = new BABYLON.ArcRotateCamera("Camera", -Math.PI / 2, Math.PI / 4, 10, BABYLON.Vector3.Zero());
// 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);
light.intensity = 0.7;
var coordinates = [[1, 1], [-1, 1], [1, -1], [-1, -1]];
for (const [x, y] of coordinates) {
var pl = new BABYLON.PointLight("pl", new BABYLON.Vector3(2*x, 0.5, 1*y), scene);
pl.diffuse = new BABYLON.Vector3(0.1, 0.1, 0.1);
}
// Our built-in 'sphere' shape. Params: name, subdivs, size, scene
var room = BABYLON.MeshBuilder.CreateBox("room", {size:3, width:5,height:2, sideOrientation:1}, scene);
var coordinates = [
[0.5, 1.25, {width:1}], [1.5, 1.25, {width:1}],
[2.25, 0.5, {depth:1}], [2.25, -0.5, {depth:1}],
[1.5, -1.25, {width:1}], [0.5, -1.25, {width:1}],
[0.75, 0, {depth:1}], [1.25, 0, {depth:1}]];
for (const [x, y, opt] of coordinates) {
opt['size'] = 0.5
// opt['height'] = 1
var room = BABYLON.MeshBuilder.CreateBox("desk", opt, scene);
room.position = new BABYLON.Vector3(x, -0.75, y);
}
var pillar = BABYLON.MeshBuilder.CreateBox('pillar', {size:0.5, height:2}, scene)
var pillar1 = BABYLON.MeshBuilder.CreateBox('pillar1', {size:0.5, height:2}, scene)
pillar1.position.x=-1.5
const cylTable = BABYLON.MeshBuilder.CreateCylinder("cylTable", {diameter: 1.3, height: 1.2, tessellation: 16}, scene);
cylTable.scaling=new BABYLON.Vector3(1.5, 0.5, 0.75);
cylTable.position = new BABYLON.Vector3(-1.25, -0.75, 0.75);
var door = BABYLON.MeshBuilder.CreateBox("door",{depth:0.05, height:1.5},scene)
door.position = new BABYLON.Vector3(-1.5, -0.25, -1.5)
// The first parameter can be used to specify which mesh to import. Here we import all meshes
// const resultPromise = BABYLON.SceneLoader.ImportMeshAsync('', "https://sion908.github.io/try-babylon/model/", "fun.glb", scene);
var sensor1 = BABYLON.MeshBuilder.CreateSphere("sensor",{diameter:0.2},scene)
sensor1.position = new BABYLON.Vector3(-0.5,-0.2,1.5)
var sensor2 = BABYLON.MeshBuilder.CreateSphere("sensor",{diameter:0.2},scene)
sensor2.position = new BABYLON.Vector3(0.5,-0.2,-1.5)
var sensor3 = BABYLON.MeshBuilder.CreateSphere("sensor",{diameter:0.2},scene)
sensor3.position = new BABYLON.Vector3(2.5,-0.2,0)
var sensor4 = BABYLON.MeshBuilder.CreateSphere("sensor",{diameter:0.2},scene)
sensor4.position = new BABYLON.Vector3(-2.5,-0.2,0)
var duplicate = function(container, offset_x, offset_z, rot_y, rot_z) {
let entries = container.instantiateModelsToScene();
for (var node of entries.rootNodes) {
if(!node.parent){
node.position.x = offset_x;
node.position.z = offset_z;
console.log(node.rotation);
node.rotation = new BABYLON.Vector3(Math.PI,Math.PI*rot_y, Math.PI*rot_z);
}
}
for (var group of entries.animationGroups) {
group.play(true);
}
}
BABYLON.SceneLoader.LoadAssetContainer("https://sion908.github.io/try-babylon/model/", "fun.glb", scene, function (container) {
for (var node of container.meshes) {
if(!node.parent){
node.name="fan";
node.position.y = 0.85;
node.scaling=new BABYLON.Vector3(0.25,0.25,0.25);
console.log(node.rotation)
}
}
duplicate(container, 1.0, 1.3, -1/2, 1/6);
duplicate(container, 1.0, -1.3, 1/2, 1/6);
duplicate(container, 2.3, 0, 0, 1/6);
duplicate(container, -1.0, 1.3, -1/2, 1/6);
duplicate(container, -1.0, -1.3, 1/2, 1/6);
duplicate(container, -2.3, 0, 0,-1/6);
});
// GUI
// var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
// var button = BABYLON.GUI.Button.CreateSimpleButton("but", "Click Me");
// button.width = 0.2;
// button.height = "40px";
// button.color = "white";
// button.background = "green";
// button.left = 200;
// button.top = 300;
// advancedTexture.addControl(button);
// button.onPointerClickObservable.add(()=>{
// sensor4.position.x+=0.1;
// })
return scene;
};
const scene = createScene();
engine.runRenderLoop(() => {
scene.render();
});
window.addEventListener('resize', () => {
engine.resize();
});
}
window.addEventListener('DOMContentLoaded', main);