-
Notifications
You must be signed in to change notification settings - Fork 0
/
gb1.html
118 lines (90 loc) · 3.38 KB
/
gb1.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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Babylon Template</title>
<style>
html, body {
overflow: hidden;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#renderCanvas {
width: 100%;
height: 100%;
touch-action: none;
}
</style>
<script src="babylon.max.js"></script>
<script src="babylon.gui.js"></script>
</head>
<body>
<canvas id="renderCanvas" touch-action="none"></canvas> <!-- touch-action="none" for best results from PEP -->
<script>
const canvas = document.getElementById("renderCanvas"); // Get the canvas element
const engine = new BABYLON.Engine(canvas, true); // Generate the BABYLON 3D engine
// Add your code here matching the playground format
const createScene = function () {
const scene = new BABYLON.Scene(engine);
const light = new BABYLON.HemisphericLight("HemiLight", new BABYLON.Vector3(0, 1, 0), scene);
const camera = new BABYLON.ArcRotateCamera("camera1", -Math.PI / 2, Math.PI / 2.2, 5, new BABYLON.Vector3(0, 0, 0), scene);
camera.attachControl(canvas, true);
let m = 7;
let n = 6;
const makeGoldberg = function(m, n) {
const goldberg = BABYLON.MeshBuilder.CreateGoldberg("g", {m: m, n: n});
const colset = [];
colset.push([0, 11, new BABYLON.Color4(247 / 255, 150 / 255, 70 / 255, 1)]);
for (let k = 0; k < 12; k++) {
colset.push([goldberg.relatedGoldbergFace(k, 0), goldberg.relatedGoldbergFace(k, goldberg.goldbergData.nbFacesAtPole - 1), new BABYLON.Color4(k % 2, Math.floor(k / 2) % 2, Math.floor(k / 4), 1)]);
}
goldberg.setGoldbergFaceColors(colset);
return goldberg;
}
let g = makeGoldberg(m, n);
var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
var selectBox = new BABYLON.GUI.SelectionPanel("sp");
selectBox.width = 0.25;
selectBox.height = 0.35;
selectBox.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
selectBox.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_BOTTOM;
advancedTexture.addControl(selectBox);
const displayValue = function(value) {
if (value > m) {
n = m;
};
return n;
}
const setM = function(value) {
g.dispose();
m = Math.floor(value);
g = makeGoldberg(m, n);
}
const setN= function(value) {
g.dispose();
n = Math.floor(value);
if (n > m) {
n = m;
}
g = makeGoldberg(m, n);
}
var mnGroup = new BABYLON.GUI.SliderGroup("Set", "S");
mnGroup.addSlider("m", setM, "", 1, 20, m);
mnGroup.addSlider("n", setN, "", 0, 21, n, displayValue);
selectBox.addGroup(mnGroup);
return scene;
};
const scene = createScene(); //Call the createScene function
// Register a render loop to repeatedly render the scene
engine.runRenderLoop(function () {
scene.render();
});
// Watch for browser/canvas resize events
window.addEventListener("resize", function () {
engine.resize();
});
</script>
</body>
</html>