-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathvideo.js
156 lines (146 loc) · 7.89 KB
/
video.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
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
156
//https://developers.google.com/youtube/iframe_api_reference
/* this code failed on chrome app dueto security restrictions,
so for now I just show a url in a separate browser window
when the select value changes.
function init_video(){
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
var video_player;
function onYouTubeIframeAPIReady() {
video_player = new YT.Player('video_player_id', {
height: '390',
width: '640',
events: {
'onReady': onPlayerReady
}
});
}
function onPlayerReady(event) {
event.target.setVolume(100);
event.target.playVideo();
}
*/
//gets rid of innHTML and all the event listeners, needed when switching
//between dexter sim and stl view
//https://stackoverflow.com/questions/9251837/how-to-remove-all-listeners-in-an-element
function clear_out_sim_graphics_pane_id(){
var new_element = sim_graphics_pane_id.cloneNode(false);
sim_graphics_pane_id.parentNode.replaceChild(new_element, sim_graphics_pane_id);
}
var prev_make_instruction_src = undefined
function misc_pane_menu_changed(select_val){
if(MakeInstruction.is_shown()) {
prev_make_instruction_src = MakeInstruction.dialog_to_instruction_src()
}
if(select_val instanceof Event) { select_val = misc_pane_menu_id.value }
else {misc_pane_menu_id.value = select_val } //used when user clicks the demo button.
if (select_val == "Choose File") {
select_val = choose_file()
}
console.log(select_val)
if (select_val == "Simulate Dexter") {
//video_player_id.style.display = "none";
sim_pane_content_id.innerHTML =
'Simulate Job/Robot: <select id="job_or_robot_to_simulate_id">' +
'</select> <b>Move Dur: </b><span id="sim_pane_move_dur_id"></span><br/>' +
'<b>X,Y,Z:</b> ' +
'<span id="sim_pane_x_id" style="min-width:50px; text-align:left; display:inline-block"></span>,' + //"margin-left:5px;
'<span id="sim_pane_y_id" style="min-width:50px; text-align:left; display:inline-block"></span>,' + //"margin-left:5px;
'<span id="sim_pane_z_id" style="min-width:50px; text-align:left; display:inline-block"></span>' + //"margin-left:5px;
' <b> J1-5: </b>' +
'<span id="sim_pane_j1_id" style="min-width:30px; text-align:right; display:inline-block"></span>,' + //"margin-left:5px;
'<span id="sim_pane_j2_id" style="min-width:30px; text-align:right; display:inline-block"></span>,' +
'<span id="sim_pane_j3_id" style="min-width:30px; text-align:right; display:inline-block"></span>,' +
'<span id="sim_pane_j4_id" style="min-width:30px; text-align:right; display:inline-block"></span>,' +
'<span id="sim_pane_j5_id" style="min-width:30px; text-align:right; display:inline-block"></span>' +
'<div id="sim_graphics_pane_id"></div>'
refresh_job_or_robot_to_simulate_id()
open_doc(simulate_pane_doc_id)
init_simulation()
//sim.renderer.render(sim.scene, sim.camera);
SimUtils.render_once_with_prev_args_maybe() //restore sim graphics to prev state
}
else if (select_val.endsWith(".jpg") ||
select_val.endsWith(".png") ||
select_val.endsWith(".gif") ||
select_val.endsWith(".bmp") ||
select_val.endsWith(".svg")
){
sim_pane_content_id.innerHTML = "<img style='width:100%;' src='" + select_val + "'/>"
}
else if (select_val.endsWith(".stl")){
clear_out_sim_graphics_pane_id()
stl_init_viewer()
var STLLoader = require('three-stl-loader')(THREE)
var loader = new STLLoader()
loader.load(select_val, function (geometry) {
var material = new THREE.MeshNormalMaterial()
var mesh = new THREE.Mesh(geometry, material)
sim.scene.add(mesh)
})
stl_render()
}
// else if (select_val.startsWith("http")){
////play_youtube_video(select_val)
//show_page(select_val) //this doesn't show the page in the SIm pane,
//so I decided to remove it
//the below fails
// let content = get_page(select_val)
// sim_graphics_pane_id.innerHTML = content
//}
else if (select_val == "Reference Manual"){
let div_html = `<div contenteditable='false'
style='height:300px; width:300px; padding:5%; background-color:#DDDDDD; overflow:scroll;'>` +
"<div style='font-size:18px; font-weight:700;'>Reference Manual</div>"
let content = read_file(__dirname + "/doc/ref_man.html")
//sim_graphics_pane_id.style = "width:97%; height:90%; padding:5%; background-color:white; overflow:scroll !important;"
sim_pane_content_id.innerHTML = div_html + content + "</div>"
}
else if (select_val.endsWith(".txt") ||
select_val.endsWith(".js") ||
select_val.endsWith(".json") ||
select_val.endsWith(".dde")){
let div_html = `<div title="Click to choose a different file." onclick='sim_pane_menu_changed(\"Choose File\")' style='padding:7px; font-size:12px; font-weight:600;background-color:rgb(184, 187, 255);'>` +
select_val + "</div>" +
"<div contenteditable='false' style='height:300px; width:800px; padding:5%; background-color:white; overflow:scroll;'>"
let content = read_file(select_val)
content = replace_substrings(content, "<", "<")
//sim_graphics_pane_id.style = "width:97%; height:90%; padding:5%; background-color:white; overflow:scroll !important;"
sim_pane_content_id.innerHTML = div_html + "<pre>" + content + "</pre></div>"
}
else if (select_val = "Make Instruction"){
MakeInstruction.show(prev_make_instruction_src) //if arg value is undefined, show show's the default move_all_joints, otherwise, its previous state
open_doc(make_instruction_pane_doc_id)
}
else //if (select_val.endsWith(".html") || select_val.endsWith(".htm"))
{
let div_html = "<div contenteditable='false' style='height:300px; width:300px; padding:5%; background-color:white; overflow:scroll;'>"
let content = read_file(select_val)
//sim_graphics_pane_id.style = "width:97%; height:90%; padding:5%; background-color:white; overflow:scroll !important;"
sim_pane_content_id.innerHTML = div_html + content + "</div>"
}
}
function refresh_job_or_robot_to_simulate_id(){
if(window["job_or_robot_to_simulate_id"]){
let options_html = "<option>All</option>\n<option>Dexter.default</option>"
for(let job of Job.all_jobs()){
options_html += "<option>Job." + job.name + "</option>\n"
}
//for(let robot_name of Dexter.all_names){
// options_html += "<option>Dexter." + robot_name + "</option>\n"
//}
job_or_robot_to_simulate_id.innerHTML = options_html
}
}
//returns a string
function job_or_robot_to_simulate_name(){
if(job_or_robot_to_simulate_id.value) {
return job_or_robot_to_simulate_id.value
}
else { return "Dexter.default" }
}
var {replace_substrings} = require("./core/utils.js")