added taking 3D board snapshots

This commit is contained in:
mig 2017-05-11 14:41:45 +02:00
parent 3a034e5880
commit 2c6056005c
3 changed files with 23 additions and 0 deletions

View file

@ -30,6 +30,7 @@
<button id="save">Save</button> <button id="save">Save</button>
<input type="file" id="fileElem" accept="application/json" style="display:none"/> <input type="file" id="fileElem" accept="application/json" style="display:none"/>
<button id="load">Load</button> <button id="load">Load</button>
<button id="snapshot">Snapshot</button>
<br/><br/> <br/><br/>
<select id="mode"> <select id="mode">
<option value="self-self">Self / Self</option> <option value="self-self">Self / Self</option>

View file

@ -278,6 +278,19 @@ $(document).ready(function () {
}); });
}); });
$("#snapshot").on("click",function() {
match.viewControl("takeSnapshot")
.then((snapshot)=>{
var a = document.createElement("a");
a.href = snapshot;
a.setAttribute("download",gameName+".png");
a.click();
})
.catch((error)=>{
console.warn("failed:",error);
})
});
// reading file locally // reading file locally
var fileElem = $("#fileElem").on("change",function() { var fileElem = $("#fileElem").on("change",function() {
var fileReader = new FileReader(); var fileReader = new FileReader();

View file

@ -2771,6 +2771,15 @@ if(window.JoclyXdViewCleanup)
}); });
xdv.removeGadget("panorama"); xdv.removeGadget("panorama");
} }
resolve();
break;
case "takeSnapshot":
if(threeCtx) {
var canvas = threeCtx.renderer.domElement;
threeCtx.renderer.render( threeCtx.scene, threeCtx.camera );
resolve(canvas.toDataURL("image/png"));
} else
reject(new Error("Snapshot only available on 3D views"));
break; break;
default: default: