Skip to content

Commit 5011fed

Browse files
committed
improve the viewer for the first load
1 parent b845ada commit 5011fed

File tree

1 file changed

+41
-24
lines changed

1 file changed

+41
-24
lines changed

web_ui/_attachments/meshes.html

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
<!doctype html>
22
<html>
33
<head>
4-
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
4+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
55
<script type="text/javascript" src="js/jsc3d.js"></script>
66

77
<script>
8-
function image_for_object(object_id, mesh_id) {
9-
// Get the name of the object
10-
var object_name = '';
11-
$.getJSON("/object_recognition/" + object_id, function(data) {
12-
object_name = data.object_name;
13-
});
14-
8+
// Creates the icon of an object
9+
function iconForObject(object_id, mesh_id) {
1510
$.getJSON("/object_recognition/_design/observations/_view/by_object_id?key=\""
1611
+ object_id + "\"&limit=1",
1712
function(data) {
1813
if (data.rows.length == 0) {
19-
$("<a>").attr("href", "?mesh=" + mesh_id).text(
20-
object_name + ' (' + object_id + ')').appendTo("#links");
14+
$.getJSON("/object_recognition/" + object_id, function(data) {
15+
$("<a>").attr("href", "?mesh=" + mesh_id).text(
16+
data.object_name + ' (' + object_id + ')').appendTo("#links");
17+
});
2118
} else {
2219
var observation_id = data.rows[0].id
2320
var a = $("<a>").attr("href", "?mesh=" + mesh_id).appendTo("#links");
@@ -26,15 +23,28 @@
2623
}
2724
});
2825
}
29-
function get_list_of_urls() {
26+
27+
// Create the icons for the objects
28+
function createObjectIcons() {
3029
$.getJSON("/object_recognition/_design/models/_view/by_object_id_and_mesh",
3130
function(data) {
31+
var is_first = false;
32+
var vars = getUrlVars();
33+
if (!(vars.hasOwnProperty("mesh")))
34+
is_first = true;
35+
3236
$.each(data.rows, function(key, val) {
33-
image_for_object(val.value.object_id, val.id);
37+
if (is_first) {
38+
is_first = false;
39+
createViewer(val.id);
40+
}
41+
iconForObject(val.value.object_id, val.id);
42+
}
43+
);
3444
});
35-
});
3645
}
3746

47+
// Get the information embedded in the url
3848
function getUrlVars() {
3949
var vars = {}, hash;
4050
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
@@ -44,12 +54,10 @@
4454
}
4555
return vars;
4656
}
47-
window.onload = function() {
48-
get_list_of_urls();
49-
var vars = getUrlVars();
5057

51-
// Load the mesh
52-
$.getJSON("/object_recognition/" + vars.mesh, function(data) {
58+
// Create a 3d viewer for a given mesh_id
59+
function createViewer(mesh_id) {
60+
$.getJSON("/object_recognition/" + mesh_id, function(data) {
5361
if (!("_attachments" in data))
5462
return;
5563
// Find interesting names of the meshes
@@ -67,13 +75,13 @@
6775
str_stl = name;
6876
}
6977

70-
var viewer = new JSC3D.Viewer(document.getElementById('mesh'));
78+
var viewer = new JSC3D.Viewer(document.getElementById('mesh'));
7179
if (str_original)
72-
viewer.setParameter('SceneUrl', "/object_recognition/" + vars.mesh + "/" + str_original);
73-
else if (str_original)
74-
viewer.setParameter('SceneUrl', "/object_recognition/" + vars.mesh + "/" + str_obj);
75-
else if (str_original)
76-
viewer.setParameter('SceneUrl', "/object_recognition/" + vars.mesh + "/" + str_stl);
80+
viewer.setParameter('SceneUrl', "/object_recognition/" + mesh_id + "/" + str_original);
81+
else if (str_obj)
82+
viewer.setParameter('SceneUrl', "/object_recognition/" + mesh_id + "/" + str_obj);
83+
else if (str_stl)
84+
viewer.setParameter('SceneUrl', "/object_recognition/" + mesh_id + "/" + str_stl);
7785

7886
viewer.setParameter('BackgroundColor1', '#E5D7BA');
7987
viewer.setParameter('BackgroundColor2', '#383840');
@@ -85,6 +93,15 @@
8593
viewer.update();
8694
});
8795
}
96+
97+
window.onload = function() {
98+
createObjectIcons();
99+
var vars = getUrlVars();
100+
101+
// Load the mesh
102+
if (vars.hasOwnProperty("mesh"))
103+
createViewer(vars.mesh);
104+
}
88105
</script>
89106
</head>
90107
<body>

0 commit comments

Comments
 (0)