Created
May 2, 2017 21:10
-
-
Save PhoenixIllusion/f4d7df7982293e42d32bbaa8c515606f to your computer and use it in GitHub Desktop.
Store in Chrome Snippets and Run while on the 2D GCode Viewer to turn it into a 3D GCode Viewer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var addScript = function (url) { | |
| var doc = document; | |
| var tag = 'script'; | |
| return new Promise((resolve,reject) => { | |
| if(!doc.querySelector(tag+"[src='"+url+"']")){ | |
| var ele = doc.createElement(tag); | |
| var firstEle = doc.getElementsByTagName(tag)[0]; | |
| ele.async = 0; | |
| ele.src = url; | |
| firstEle.parentNode.insertBefore(ele, firstEle); | |
| ele.onload = () => resolve(url); | |
| } else { | |
| resolve(url); | |
| } | |
| }) | |
| } | |
| var scripts = [ | |
| "http://gcode.ws/lib/three.js", | |
| "http://gcode.ws/lib/TrackballControls.js", | |
| "http://gcode.ws/js/renderer3d.js" | |
| ] | |
| addScript(scripts[0]).then(() => addScript(scripts[1])).then(() => addScript(scripts[2])).then(() => run()); | |
| function run() { | |
| GCODE.renderer3d.setModel(GCODE.renderer.debugGetModel()); | |
| $("#gcode").attr('id','3d_container'); | |
| GCODE.renderer3d.doRender(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment