-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelmetOctree.html
More file actions
155 lines (121 loc) · 4.51 KB
/
helmetOctree.html
File metadata and controls
155 lines (121 loc) · 4.51 KB
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>hitTest</title>
<script src= "babylon.max.js"></script>
<script src = babylon.gui.min.js></script>
<script src= "babylon.glTFFileLoader.js"></script>
<script src= "morton.js"></script>
<script src= "bvhByNode.js"></script>
<script src= "radix.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>
if (BABYLON.Engine.isSupported()) {
var canvas = document.getElementById("renderCanvas");
var engine = new BABYLON.Engine(canvas, true);
var createScene = function () {
// This creates a basic Babylon Scene object (non-mesh)
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.ArcRotateCamera("Camera", - Math.PI / 2, Math.PI / 2.2, 5, BABYLON.Vector3.Zero(), scene);
camera.attachControl(canvas, true);
// This creates a light, aiming 0,1,0 - to the sky (non-mesh)
var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
// Default intensity is 1. Let's dim the light a small amount
light.intensity = 0.7;
BABYLON.SceneLoader.ImportMesh("", "https://www.babylonjs.com/Assets/DamagedHelmet/glTF/", "DamagedHelmet.gltf", scene, function (meshes) {
let box = meshes[1];
box.subdivide(50);
box.createOrUpdateSubmeshesOctree(64, 8);
box.useOctreeForPicking = true;
let gui = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("myUI");
let button = BABYLON.GUI.Button.CreateSimpleButton("button", "Click to Generate Octree");
button.top = "0px";
button.left = "0px";
button.width = "150px";
button.height = "150px";
button.cornerRadius = 20;
button.thickness = 4;
button.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT;
button.children[0].color = "#DFF9FB";
button.children[0].fontSize = 24;
button.color = "white";
button.background = "blue";
let button2 = BABYLON.GUI.Button.CreateSimpleButton("button2", "IntersectRay");
button2.top = "0px";
button2.left = "0px";
button2.width = "150px";
button2.height = "70px";
button2.cornerRadius = 20;
button2.thickness = 4;
button2.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT;
button2.children[0].color = "#DFF9FB";
button2.children[0].fontSize = 24;
button2.color = "white";
button2.background = "blue";
button2.isVisible = false;
let text1 = new BABYLON.GUI.TextBlock();
text1.text = "";
text1.color = "white";
text1.fontSize = 24;
text1.background = "blue";
text1.width = "650px";
text1.height = "70px";
text1.cornerRadius = 20;
text1.thickness = 4;
text1.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
text1.isVisible = false;
gui.addControl(text1);
let treeCluster;
button.onPointerClickObservable.add(function () {
button.isVisible = false
box.subdivide(4)
box.createOrUpdateSubmeshesOctree(64, 2);
box.useOctreeForPicking = true;
button2.isVisible = true;
});
button2.onPointerClickObservable.add(function () {
button2.isVisible = false;
let ray = new BABYLON.Ray(new BABYLON.Vector3(-8, 0, 0), BABYLON.Axis.X, 20);
BABYLON.RayHelper.CreateAndShow(ray, scene, BABYLON.Color3.White());
const t0 = performance.now();
let hit;
for (var k = 0; k < 10000; k++) {
hit = box.intersects(ray);
}
const t1 = performance.now();
text1.text = `Time for 10000 ray intersections ${t1 - t0} milliseconds.`;
text1.isVisible = true;
});
gui.addControl(button);
gui.addControl(button2);
});
return scene;
};
var scene = createScene();
engine.runRenderLoop(function () {
scene.render();
});
window.addEventListener("resize", function () {
engine.resize();
});
}
</script>
</body>
</html>