diff options
| author | yo mama <pepper@scannerjammer.com> | 2015-09-22 00:51:40 -0700 |
|---|---|---|
| committer | yo mama <pepper@scannerjammer.com> | 2015-09-22 00:51:40 -0700 |
| commit | d3e7b5708deffbed864c916de22663f48333c58b (patch) | |
| tree | ef76784a7827baff88c03670bf22832a3f146b17 /share/frontend/imlandscape/js/pb.js | |
| parent | 86c79f4372d7b2e7640a26473c7a4d331cdf7d16 (diff) | |
finishing server
Diffstat (limited to 'share/frontend/imlandscape/js/pb.js')
| -rw-r--r-- | share/frontend/imlandscape/js/pb.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/share/frontend/imlandscape/js/pb.js b/share/frontend/imlandscape/js/pb.js new file mode 100644 index 0000000..46c0bd6 --- /dev/null +++ b/share/frontend/imlandscape/js/pb.js @@ -0,0 +1,71 @@ +var loadUrl = '/img/load'; +var saveUrl = '/cgi-bin/im/landscape'; +var textureURL, heightmapURL; +function saveScene(){ + if (!renderer) { + alert("WebGL Rendering was not started yet!"); + } else { + // Prepare data + var imageData = renderer.domElement.toDataURL("image/png"); + //Remove header + var seconds = new Date() / 1000; + seconds = seconds.toFixed(0); + var userName = $("#username").val() + update_username(userName); + var filename; + if (!userName) { + filename = seconds + "_imlandscape"; + } else { + filename = seconds + "_imglandscape_" + userName; + } + filename += ".png"; + is_generating = true; + toggle_background(); + // Send post request + $.post( + saveUrl, + { + name: $("#username").val(), //FIXME + imgdata: imageData, + texture: $("#texture").val(), + heightmap: $("#heightmap").val(), + }, + function(response) { + console.log(response); + is_generating = false; + toggle_background(); + resp = response.split("\n"); + url = resp[3] + loadUrlResult(resp[3]) + } + ); + } +} + +function loadUrlResult(url){ + $(".url_result").show(); + url_shortened = "...."+ url.slice(url.length-10); + + $("a.url_result").attr("href", url); + $("a.url_result").html(url_shortened); + +}; +function loadNew() { + //Get values for url + textureURL = document.getElementById("texture").value.replace(/\s/,""); + heightmapURL = document.getElementById("heightmap").value.replace(/\s/,""); + + is_generating = true; + toggle_background(); + console.log(textureURL); + console.log(heightmapURL); + stop_animating(); + var new_texture = '/cgi-bin/proxy?'+textureURL; + var new_heightmap = '/cgi-bin/proxy?'+heightmapURL; + initGraphics(new_texture, new_heightmap, function(){ animate() } ); +} + +function isUrl(s) { + var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?\.(jpg|JPG|jpeg|JPEG)/; + return regexp.test(s); +} |
