-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
183 lines (148 loc) · 7.36 KB
/
index.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Babylon.js sample code</title>
<!-- Babylon.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.6.2/dat.gui.min.js"></script>
<script src="https://preview.babylonjs.com/ammo.js"></script>
<script src="https://preview.babylonjs.com/cannon.js"></script>
<script src="https://preview.babylonjs.com/Oimo.js"></script>
<script src="https://preview.babylonjs.com/earcut.min.js"></script>
<script src="https://preview.babylonjs.com/babylon.js"></script>
<script src="https://preview.babylonjs.com/materialsLibrary/babylonjs.materials.min.js"></script>
<script src="https://preview.babylonjs.com/proceduralTexturesLibrary/babylonjs.proceduralTextures.min.js"></script>
<script src="https://preview.babylonjs.com/postProcessesLibrary/babylonjs.postProcess.min.js"></script>
<script src="https://preview.babylonjs.com/loaders/babylonjs.loaders.js"></script>
<script src="https://preview.babylonjs.com/serializers/babylonjs.serializers.min.js"></script>
<script src="https://preview.babylonjs.com/gui/babylon.gui.min.js"></script>
<script src="https://preview.babylonjs.com/inspector/babylon.inspector.bundle.js"></script>
<style>
html,
body {
overflow: hidden;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#renderCanvas {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<canvas id="renderCanvas"></canvas>
<script>
let canvas = document.getElementById("renderCanvas");
var engine = null;
var scene = null;
let sceneToRender = null;
let createDefaultEngine = function () { return new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true, disableWebGL2Support: false }); };
const createScene = async (scene) => {
scene = new BABYLON.Scene(engine);
let camera = new BABYLON.ArcRotateCamera("camera1", Math.PI / -1.2, Math.PI / 1.5, -350, new BABYLON.Vector3(0,80, 0), scene);
const classroom = BABYLON.SceneLoader.ImportMesh(
"",
"./assets/",
"classroom.gltf",
scene,
function (meshes) {
scene.createDefaultCameraOrLight(true, false, false);
scene.createDefaultEnvironment();
scene.activeCamera.attachControl(canvas, false);
}
);
const playground = await BABYLON.SceneLoader.ImportMeshAsync("", "./assets/", "playground.gltf", scene);
const sandBox = await BABYLON.SceneLoader.ImportMeshAsync("", "./assets/", "sandbox.gltf", scene);
const nodeBoard = await BABYLON.SceneLoader.ImportMeshAsync("", "./assets/", "board.gltf", scene);
loopMeshes(playground.meshes, scene, "Playground");
loopMeshes(sandBox.meshes, scene, "Sandbox");
loopMeshes(nodeBoard.meshes, scene, "Node Material Editor");
scene.onPointerDown = function (evt, pickResult) {
if (pickResult.pickedMesh.id === "playground") {
window.location.href = "https://playground.babylonjs.com/#"
} else if (pickResult.pickedMesh.id === "node"){
window.location.href = "https://nme.babylonjs.com/"
} else if (pickResult.pickedMesh.id === "Relief") {
window.location.href = "https://sandbox.babylonjs.com/"
}
}
return scene;
}
const loopMeshes = (array, scene, text) => {
for (let i = 0; i < array.length; i++) {
const mesh = array[i];
mesh.actionManager = new BABYLON.ActionManager(scene);
makeOverAndOut(mesh, scene, text);
}
}
const makeOverAndOut = (mesh, scene, givenText) => {
console.log(givenText)
mesh.actionManager.registerAction( new BABYLON.InterpolateValueAction( BABYLON.ActionManager.OnPointerOverTrigger, mesh, 'visibility', 0.2, 300));
mesh.actionManager.registerAction(new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPointerOutTrigger, mesh, 'visibility', 1, 300));
let advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
advancedTexture.useInvalidateRectOptimization = false;
let rect1 = new BABYLON.GUI.Rectangle();
advancedTexture.addControl(rect1);
rect1.width = "150px";
rect1.height = "30px";
rect1.thickness = 2;
rect1.linkOffsetY = "-100px";
rect1.transformCenterY = 1;
rect1.background = "white";
rect1.alpha = 0.5;
rect1.scaleX = 0;
rect1.scaleY = 0;
rect1.cornerRadius = 5
rect1.linkWithMesh(mesh);
let text1 = new BABYLON.GUI.TextBlock();
text1.text = givenText;
text1.color = "blue";
text1.fontSize = 15;
text1.textVerticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
text1.background = '#006994';
rect1.addControl(text1);
text1.alpha = (1 / text1.parent.alpha);
let scaleXAnimation = new BABYLON.Animation("myAnimation", "scaleX", 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
let scaleYAnimation = new BABYLON.Animation("myAnimation", "scaleY", 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
var keys = [];
keys.push({
frame: 0,
value: 0
});
keys.push({
frame: 10,
value: 1
});
scaleXAnimation.setKeys(keys);
scaleYAnimation.setKeys(keys);
rect1.animations = [];
rect1.animations.push(scaleXAnimation);
rect1.animations.push(scaleYAnimation);
mesh.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPointerOverTrigger, function (ev) {
scene.beginAnimation(rect1, 0, 10, false);
}));
mesh.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPointerOutTrigger, function (ev) {
scene.beginAnimation(rect1, 10, 0, false);
}));
}
const init = async () => {
engine = createDefaultEngine();
if (!engine) throw 'engine should not be null.';
scene = await createScene(scene);
sceneToRender = scene
engine.runRenderLoop(function () {
if (sceneToRender) {
sceneToRender.render();
}
});
window.addEventListener("resize", function () {
engine.resize();
});
}
init();
</script>
</body>
</html>