-
Notifications
You must be signed in to change notification settings - Fork 26
/
helper.js
74 lines (57 loc) · 1.88 KB
/
helper.js
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
export function get_canvas_width() {
var canvas = document.getElementById("render_canvas");
var rect = canvas.getBoundingClientRect();
return rect.width;
}
export function get_canvas_height() {
var canvas = document.getElementById("render_canvas");
var rect = canvas.getBoundingClientRect();
return rect.height;
}
export function cpu_cores() {
return navigator.hardwareConcurrency;
}
export function get_time_milliseconds() {
return performance.now();
}
export function get_webgl1_version() {
const gl = document.createElement("canvas").getContext("webgl");
return gl.getParameter(gl.VERSION);
}
export function get_webgl2_version() {
const gl = document.createElement("canvas").getContext("webgl2");
return gl.getParameter(gl.VERSION);
}
export function get_url_param() {
const params = new URLSearchParams(location.search);
if (params.has("url")) {
let url = params.get("url");
if (!url.toLowerCase().includes("http")) {
url = "https://huggingface.co/datasets/satyoshi/gauzilla-data/resolve/main/" + url;
}
return url;
} else {
return "";
}
}
function getVectorParam(paramName, defaultValue) {
const params = new URLSearchParams(window.location.search);
const param = params.get(paramName);
if (!param) {
return defaultValue; // Default value if the parameter is not found
}
const numbers = param.split(',').map(Number);
if (numbers.length !== 3 || numbers.some(isNaN)) {
return defaultValue; // Default value if the parameter is malformed
}
return numbers;
}
export function get_position_param() {
return getVectorParam('position', [0.0, 0.0, 5.0]);
}
export function get_target_param() {
return getVectorParam('target', [0.0, 0.0, 0.0]);
}
export function get_up_param() {
return getVectorParam('up', [0.0, 1.0, 0.0]);
}