-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeman.html
227 lines (199 loc) · 10.3 KB
/
theman.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<!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%;
touch-action: none;
}
</style>
</head>
<body>
<canvas id="renderCanvas"></canvas>
<script>
var canvas = document.getElementById("renderCanvas");
var engine = null;
var scene = null;
var sceneToRender = null;
var createDefaultEngine = function() { return new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true, disableWebGL2Support: false}); };
var delayCreateScene = function () {
// Model by Mixamo
engine.enableOfflineSupport = false;
// This is really important to tell Babylon.js to use decomposeLerp and matrix interpolation
BABYLON.Animation.AllowMatricesInterpolation = true;
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.ArcRotateCamera("camera1", Math.PI / 2, Math.PI / 4, 3, new BABYLON.Vector3(0, 1, 0), scene);
camera.attachControl(canvas, true);
camera.lowerRadiusLimit = 2;
camera.upperRadiusLimit = 10;
camera.wheelDeltaPercentage = 0.01;
var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
light.intensity = 0.6;
light.specular = BABYLON.Color3.Black();
var light2 = new BABYLON.DirectionalLight("dir01", new BABYLON.Vector3(0, -0.5, -1.0), scene);
light2.position = new BABYLON.Vector3(0, 5, 5);
// Shadows
var shadowGenerator = new BABYLON.ShadowGenerator(1024, light2);
shadowGenerator.useBlurExponentialShadowMap = true;
shadowGenerator.blurKernel = 32;
engine.displayLoadingUI();
BABYLON.SceneLoader.ImportMesh("", "./scenes/", "dummy3.babylon", scene, function (newMeshes, particleSystems, skeletons) {
var skeleton = skeletons[0];
shadowGenerator.addShadowCaster(scene.meshes[0], true);
for (var index = 0; index < newMeshes.length; index++) {
newMeshes[index].receiveShadows = false;;
}
var helper = scene.createDefaultEnvironment({
enableGroundShadow: true
});
helper.setMainColor(BABYLON.Color3.Gray());
helper.ground.position.y += 0.01;
// ROBOT
skeleton.animationPropertiesOverride = new BABYLON.AnimationPropertiesOverride();
skeleton.animationPropertiesOverride.enableBlending = true;
skeleton.animationPropertiesOverride.blendingSpeed = 0.05;
skeleton.animationPropertiesOverride.loopMode = 1;
var idleRange = skeleton.getAnimationRange("YBot_Idle");
var walkRange = skeleton.getAnimationRange("YBot_Walk");
var runRange = skeleton.getAnimationRange("YBot_Run");
var leftRange = skeleton.getAnimationRange("YBot_LeftStrafeWalk");
var rightRange = skeleton.getAnimationRange("YBot_RightStrafeWalk");
// IDLE
if (idleRange) scene.beginAnimation(skeleton, idleRange.from, idleRange.to, true);
// UI
var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
var UiPanel = new BABYLON.GUI.StackPanel();
UiPanel.width = "220px";
UiPanel.fontSize = "14px";
UiPanel.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT;
UiPanel.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER;
advancedTexture.addControl(UiPanel);
// ..
var button = BABYLON.GUI.Button.CreateSimpleButton("but1", "Play Idle");
button.paddingTop = "10px";
button.width = "100px";
button.height = "50px";
button.color = "white";
button.background = "green";
button.onPointerDownObservable.add(()=> {
if (idleRange) scene.beginAnimation(skeleton, idleRange.from, idleRange.to, true);
});
UiPanel.addControl(button);
// ..
var button1 = BABYLON.GUI.Button.CreateSimpleButton("but2", "Play Walk");
button1.paddingTop = "10px";
button1.width = "100px";
button1.height = "50px";
button1.color = "white";
button1.background = "green";
button1.onPointerDownObservable.add(()=> {
if (walkRange) scene.beginAnimation(skeleton, walkRange.from, walkRange.to, true);
});
UiPanel.addControl(button1);
// ..
var button1 = BABYLON.GUI.Button.CreateSimpleButton("but3", "Play Run");
button1.paddingTop = "10px";
button1.width = "100px";
button1.height = "50px";
button1.color = "white";
button1.background = "green";
button1.onPointerDownObservable.add(()=> {
if (runRange) scene.beginAnimation(skeleton, runRange.from, runRange.to, true);
});
UiPanel.addControl(button1);
// ..
var button1 = BABYLON.GUI.Button.CreateSimpleButton("but4", "Play Left");
button1.paddingTop = "10px";
button1.width = "100px";
button1.height = "50px";
button1.color = "white";
button1.background = "green";
button1.onPointerDownObservable.add(()=> {
if (leftRange) scene.beginAnimation(skeleton, leftRange.from, leftRange.to, true);
});
UiPanel.addControl(button1);
// ..
var button1 = BABYLON.GUI.Button.CreateSimpleButton("but5", "Play Right");
button1.paddingTop = "10px";
button1.width = "100px";
button1.height = "50px";
button1.color = "white";
button1.background = "green";
button1.onPointerDownObservable.add(()=> {
if (rightRange) scene.beginAnimation(skeleton, rightRange.from, rightRange.to, true);
});
UiPanel.addControl(button1);
// ..
var button1 = BABYLON.GUI.Button.CreateSimpleButton("but6", "Play Blend");
button1.paddingTop = "10px";
button1.width = "100px";
button1.height = "50px";
button1.color = "white";
button1.background = "green";
button1.onPointerDownObservable.add(()=> {
if (walkRange && leftRange) {
scene.stopAnimation(skeleton);
var walkAnim = scene.beginWeightedAnimation(skeleton, walkRange.from, walkRange.to, 0.5, true);
var leftAnim = scene.beginWeightedAnimation(skeleton, leftRange.from, leftRange.to, 0.5, true);
// Note: Sync Speed Ratio With Master Walk Animation
walkAnim.syncWith(null);
leftAnim.syncWith(walkAnim);
}
});
UiPanel.addControl(button1);
engine.hideLoadingUI();
});
return scene;
};
var engine;
var scene;
initFunction = async function() {
var asyncEngineCreation = async function() {
try {
return createDefaultEngine();
} catch(e) {
console.log("the available createEngine function failed. Creating the default engine instead");
return createDefaultEngine();
}
}
engine = await asyncEngineCreation();
if (!engine) throw 'engine should not be null.';
scene = delayCreateScene();};
initFunction().then(() => {sceneToRender = scene
engine.runRenderLoop(function () {
if (sceneToRender && sceneToRender.activeCamera) {
sceneToRender.render();
}
});
});
// Resize
window.addEventListener("resize", function () {
engine.resize();
});
</script>
</body>
</html>