-
Notifications
You must be signed in to change notification settings - Fork 0
/
teethStandard.html
127 lines (93 loc) · 3.64 KB
/
teethStandard.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Babylon Basic Pick</title>
<script src= "babylon.max.js"></script>
<script src = babylon.gui.min.js></script>
<script src= "babylon.stlFileLoader.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", 0, Math.PI / 2.2, 50, 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;
let mat = new BABYLON.StandardMaterial("", scene);
mat.diffuseColor = BABYLON.Color3.Red();
BABYLON.SceneLoader.ImportMesh("", "https://dl.dropbox.com/s/669cwldog3kdssw/", "2020-05-25_002_002-LowerJaw.stl", scene, function (meshes) {
let jaw = meshes[0];
let gui = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("myUI");
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 counter = 0;
let totalTime = 0;
scene.onPointerDown = function() {
//let ray = new BABYLON.Ray(new BABYLON.Vector3(-8, 0.1, 0.1), BABYLON.Axis.X, 120);
let ray = scene.createPickingRay(scene.pointerX, scene.pointerY, BABYLON.Matrix.Identity(), camera);
//BABYLON.RayHelper.CreateAndShow(ray, scene, BABYLON.Color3.White());
let positions = jaw.getVerticesData(BABYLON.VertexBuffer.PositionKind);
let indices = jaw.getIndices();
const t0 = performance.now();
let hits = [];
hit = jaw.intersects(ray);
const t1 = performance.now();
text1.text = `Time for ray intersection ${t1 - t0} milliseconds.`;
totalTime += t1 - t0;
counter++;
console.log("avg", totalTime / counter);
text1.isVisible = true;
box = BABYLON.MeshBuilder.CreateBox("", {size: 0.5}, scene);
box.position = ray.origin.add(ray.direction.normalize().scale(hit.distance))
box.material = mat;
};
});
return scene;
};
var scene = createScene();
engine.runRenderLoop(function () {
scene.render();
});
window.addEventListener("resize", function () {
engine.resize();
});
}
</script>
</body>
</html>