blockscad_compressed.js 131 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. // Do not edit this file; automatically generated by blockscad_build.py.
  2. "use strict";
  3. var blockscadpage={start:function(){var a;a=' <div id="main">\n <nav class="navbar navbar-default" id="top-navigation-bar">\n <div class="container-fluid">\n <a href="#" class="pull-left"><img src="imgs/bslogo.png" style="max-height:50px"></a>\n <ul class="nav navbar-nav">\n <li class="dropdown">\n <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><img src="imgs/globe.png" style="width:20px"><span class="caret"></span></a>\n <ul id="languageMenu" class="dropdown-menu" role="menu">\n </ul>\n </li>\n <li class="dropdown"> \n'+
  4. (' <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">'+Blockscad.Msg.PROJECT_MENU+'<span class="caret"></span></a>\n');a=a+' <ul id="file-menu" class="dropdown-menu" role="menu">\n'+(' <li><a href="#" class="new-project">'+Blockscad.Msg.NEW+"</a></li>\n");a=a+' <li class="divider"></li>\n'+(' <li><a href="#" id="saveLocal">'+Blockscad.Msg.SAVE_BLOCKS_LOCAL+"</a></li>\n");a=a+' <li>\n <input type="file" accept=".xml" id="loadLocal" style="visibility: hidden; width: 1px; height: 1px" />\n'+
  5. (' <a href="#" onclick="document.getElementById(\'loadLocal\').click(); return false">'+Blockscad.Msg.LOAD_BLOCKS_LOCAL+"</a>\n");a=a+' </li>\n <li class="divider"></li>\n <li>\n <input type="file" accept=".xml" id="importLocal" style="visibility: hidden; width: 1px; height: 1px" />\n'+(' <a href="#" onclick="document.getElementById(\'importLocal\').click(); return false">'+Blockscad.Msg.IMPORT_BLOCKS_LOCAL+"</a>\n");
  6. a=a+' </li>\n <li>\n <input type="file" accept=".stl" id="importStl" style="visibility: hidden; width: 1px; height: 1px" />\n'+(' <a href="#" onclick="document.getElementById(\'importStl\').click(); return false">'+Blockscad.Msg.IMPORT_STL_MENU+"</a>\n");a=a+' </li>\n <li class="divider"></li>\n'+(' <li><a href="#" id="saveOpenscad">'+Blockscad.Msg.SAVE_SCAD_LOCAL+"</a></li>\n");a=a+' </ul>\n </li>\n <li class="dropdown">\n'+
  7. (' <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">'+Blockscad.Msg.OPTIONS_MENU+'<span class="caret"></span></a>\n');a=a+' <ul id="options-menu" class="dropdown-menu" role="menu">\n'+(' <li><a href="#" id="simpleToolbox">'+Blockscad.Msg.SIMPLE_TOOLBOX+"</a></li>\n");a+=' <li><a href="#" id="advancedToolbox">'+Blockscad.Msg.ADVANCED_TOOLBOX+"</a></li>\n";a=a+" <li>\n"+(' <a class="trigger right-caret">'+
  8. Blockscad.Msg.BLOCK_COLORS+"</a>\n");a=a+' <ul class="dropdown-menu sub-menu">\n'+(' <li><a href="#" id="colors_one">'+Blockscad.Msg.CLASSIC_COLORS+"</a></li>\n");a+=' <li><a href="#" id="colors_two">'+Blockscad.Msg.PALE_COLORS+"</a></li>\n";a=a+' </ul>\n </li>\n </ul>\n </li>\n <li class="dropdown">\n'+(' <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">'+
  9. Blockscad.Msg.HELP_MENU+'<span class="caret"></span></a>\n');a=a+' <ul id="help-menu" class="dropdown-menu" role="menu">\n';(' <li><a href="#" data-toggle="modal" data-target="#about-modal">'+Blockscad.Msg.ABOUT_LINK+"</a></li>\n");a=a+' </ul>\n </li>\n <li class="dropdown">\n'+(' <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">'+
  10. Blockscad.Msg.EXAMPLES_MENU+'<span class="caret"></span></a>\n');a=a+' <ul id="examples-menu" class="dropdown-menu" role="menu">\n'+(' <li><a href="#" id="examples_cube_with_cutouts">'+Blockscad.Msg.EXAMPLE_CUBE_WITH_CUTOUTS+"</a></li>\n");a+=' <li><a href="#" id="examples_anthias_fish">'+Blockscad.Msg.EXAMPLE_ANTHIAS_FISH+"</a></li>\n";a+=' <li><a href="#" id="examples_torus">'+Blockscad.Msg.TORUS+"</a></li>\n";a+=' <li><a href="#" id="examples_box">'+
  11. Blockscad.Msg.EXAMPLE_PARAMETRIC_BOX+"</a></li>\n";a+=' <li><a href="#" id="examples_linear_extrude">'+Blockscad.Msg.LINEAR_EXTRUDE+"</a></li>\n";a+=' <li><a href="#" id="examples_rotate_extrude">'+Blockscad.Msg.ROTATE_EXTRUDE+"</a></li>\n";a+=' <li><a href="#" id="examples_hulled_loop_sun">'+Blockscad.Msg.EXAMPLE_LOOP_SUN+"</a></li>\n";a+=' <li><a href="#" id="examples_sine_function_with_loop">'+Blockscad.Msg.EXAMPLE_LOOP_SINE+"</a></li>\n";a+=
  12. ' <li><a href="#" id="examples_trefoil_knot_param_eq">'+Blockscad.Msg.EXAMPLE_PARAMETRIC_EQ_KNOT+"</a></li>\n";a=a+" </ul>\n </li>\n"+(' <a type="button" class="btn btn-default btn-lg" style="margin-top:2px" href="https://youtu.be/5RNKVn7lijM" target="_blank">'+Blockscad.Msg.GET_STARTED_VIDEO+"</a>");a=a+' </ul>\n <div id="login-area" class="navbar-right">\n </div>\n </div> \x3c!-- /.container-fluid --\x3e\n </nav>\n <div id="editView">\n <nav class="navbar navbar-default navbar-narrow"> \x3c!-- second nav row --\x3e\n <ul class="nav nav-pills navbar-right">\n'+
  13. (' <li class="active"><a href="#blocklyContainer" data-toggle="pill" id="displayBlocks">'+Blockscad.Msg.BLOCKS_TAB+"</a></li>\n");a+=' <li><a href="#openScadPre" data-toggle="pill" id="displayCode">'+Blockscad.Msg.CODE_TAB+"</a></li>\n";a=a+' </ul> \n <div class="input-group">\n'+(' <span class="input-group-addon" id="proj_name_label">'+Blockscad.Msg.PROJECT_NAME+"</span>\n");a+=' <input type="text" id="project-name" class="form-control proj-input" value="'+
  14. Blockscad.Msg.PROJECT_NAME_DEFAULT+'" maxlength="28" style="width: 300px;">\n';a=a+' </div>\n <div class="btn-over-blockly" style="margin-left: 20px">\n <div class="btn-group navbar-btn" role="group" aria-label="...">\n'+(' <div style="display: inline-block" title="'+Blockscad.Msg.MOUSEOVER_UNDO+'" style="margin-right:-5px">\n');a=a+' <button type="button" class="btn btn-default" id="undoButton" style="margin-right: -5px">\n <img src="imgs/undo.svg" width="25px" height="19px">\n </button>\n </div>\n'+
  15. (' <div style="display: inline-block" title="'+Blockscad.Msg.MOUSEOVER_REDO+'">\n');a=a+' <button type="button" class="btn btn-default" id="redoButton" style="margin-right: 20px">\n <img src="imgs/redo.svg" width="25px" height="19px">\n </button>\n </div>\n </div>\n'+(' <button id="trashButton" class="btn btn-default notext" title="'+Blockscad.Msg.MOUSEOVER_TRASHCAN+'">\n');a=a+' <img src="blockly/media/1x1.gif" class="trash icon21">\n </button>\n </div> \x3c!-- undo/redo/trash div --\x3e \n </nav> \x3c!-- end second nav row --\x3e\n \x3c!-- End of the header content --\x3e\n\n \x3c!-- beginning of page content (blockly + viewer) --\x3e\n <div class="tab-content">\n <div class="tab-pane active" id="blocklyContainer">\n <div id="blocklyDiv">\n\n <div class="resizableDiv">\n <div id="renderDiv">\n \x3c!-- <input type="text" id="colorButton"/> --\x3e\n </div> \x3c!--renderDiv --\x3e\n <div id="paneContainer">\n <div id="viewerButtons">\n <div class="btn-group">\n <input type="text" id="defColor"/>\n </div>\n <div class="btn-group">\n'+
  16. (' <button id="axesButton" type="button" title="'+Blockscad.Msg.AXES_BUTTON+'" class="btn vbut btn-default">\n');a=a+' <svg viewbox="0 0 26 26">\n <path style="stroke:#777;stroke-width:1.6;fill:none" d="m9 0.5v15h15"/>\n <path style="stroke:#777;stroke-width:1.6;fill:none" d="m9 15-9 9"/>\n </svg>\n </button>\n </div>\n <div class="btn-group">\n'+
  17. (' <button id="zInButton" type="button" title="'+Blockscad.Msg.ZOOM_IN_BUTTON+'" class="btn vbut btn-default">\n');a=a+' <svg viewbox="0 0 30 30">\n <circle r="14" style="stroke:#777;stroke-width:1.6;fill:none" cx="15" cy="15"/>\n <path style="stroke:#555;stroke-width:1.6;fill:none" d="m15 8v14"/>\n <path style="stroke:#555;stroke-width:1.6;fill:none" d="m8 15h14"/>\n </svg>\n </button>\n'+
  18. (' <button id="zOutButton" type="button" title="'+Blockscad.Msg.ZOOM_OUT_BUTTON+'" class="btn vbut btn-default">\n');a=a+' <svg viewbox="0 0 30 30">\n <circle r="14" style="stroke:#777;stroke-width:1.6;fill:none" cx="15" cy="15"/>\n <path style="stroke:#555;stroke-width:1.6;fill:none" d="m8 15h14"/>\n </svg>\n </button>\n </div>\n <div class="btn-group">\n'+
  19. (' <button id="zResetButton" type="button" title="'+Blockscad.Msg.ZOOM_RESET_BUTTON+'" class="btn vbut btn-default">\n');a=a+' <svg viewbox="0 0 30 30">\n <circle r="11" style="fill:none;stroke:#777;stroke-width:1.6" cx="15" cy="15"/>\n <path d="M 15,4 15,0" style="stroke:#666;stroke-width:1.6;" />\n <path d="m 26,15 4,0" style="stroke:#666;stroke-width:1.6;" />\n <path d="m 15,26 0,4" style="stroke:#666;stroke-width:1.6;" />\n <path d="M 4,15 0,15" style="stroke:#666;stroke-width:1.6;" />\n <circle r="3" cy="15" cx="15" style="fill:#777;stroke:#777;stroke-width:1.6;" />\n </svg>\n </button>\n <select id="viewMenu" class="btn btn-default">\n'+
  20. (' <option value="diagonal">'+Blockscad.Msg.DIRECTION_DIAGONAL+"</option>\n");a+=' <option value="front">'+Blockscad.Msg.DIRECTION_FRONT+"</option>\n";a+=' <option value="top">'+Blockscad.Msg.DIRECTION_TOP+"</option>\n";a+=' <option value="right">'+Blockscad.Msg.DIRECTION_RIGHT+"</option>\n";a+=' <option value="left">'+Blockscad.Msg.DIRECTION_LEFT+"</option>\n";a+=' <option value="back">'+
  21. Blockscad.Msg.DIRECTION_BACK+"</option>\n";a+=' <option value="bottom">'+Blockscad.Msg.DIRECTION_BOTTOM+"</option>\n";a=a+' </select>\n </div>\n <button type="button" id="cameraButton" class="btn vbut btn-default">\n <img src="imgs/cameraSmall.png">\n </button>\n </div>\n <div id="viewerDefaults">\n <span id="resolution_radio" class="btn btn-default"> \n <span>Smooth:&nbsp&nbsp</span>\n <label class="radio-inline"><input type="radio" name="resolution" value="0.4">Low</label>\n <label class="radio-inline"><input type="radio" name="resolution" value="1"checked>Medium</label>\n <label class="radio-inline"><input type="radio" name="resolution" value="2.25">High</label>\n </span>\n </div>\n <div id="renderPane">\n'+
  22. (' <button type="button" class="btn btn-default btn-lg changeable" id="renderButton">'+Blockscad.Msg.RENDER_BUTTON+"</button>\n");a+=' <button type="button" class="btn btn-default btn-lg btn-danger " id="abortButton">'+Blockscad.Msg.ABORT_BUTTON+"</button>\n";a=a+' <div id="stl_buttons" class="pull-right" style="padding:5px 5px;">\n <select id="render-type" style="padding:2px 4px;"></select>\n'+(' <button type="button" class="btn btn-default btn-lg changeable" id="stlButton">'+
  23. Blockscad.Msg.GENERATE_STL+"</button>\n");a=a+" </div>\n"+(' <div id="render-ongoing">'+Blockscad.Msg.PARSE_IN_PROGRESS+' <img id=busy src="imgs/busy2.gif"></div>\n');a=a+' <div id="error-message"></div>\n </div>\n </div> \x3c!-- paneContainer --\x3e\n </div> \x3c!-- resizable div --\x3e\n </div> \x3c!-- blocklyDiv --\x3e\n </div>\n \x3c!-- Blockly Container (tab pane)--\x3e\n <pre class="tab-pane content" id="openScadPre"></pre> </div>\n \x3c!-- end tab content --\x3e\n </div> \x3c!-- end of the #editView content --\x3e\n <div id="projectView" class="hidden">\n <div style="width:100%; background-color:#bbbbff;">\n'+
  24. (' <span class="proj-header">'+Blockscad.Msg.MY_PROJECTS+"</span>\n");a+=' <button type="button" class="btn btn-default new-project spacey">'+Blockscad.Msg.NEW_PROJECT_BUTTON+"</button>\n";a+=' <input type="text" class="search noselect" title="Filter" placeholder="'+Blockscad.Msg.PROJECT_LIST_FILTER+'" id="ptsearch"/>\n';a+=' <button type="button" class="btn btn-default plist-cancel spacey">'+Blockscad.Msg.PROJECT_LIST_EXIT+"</button>\n";a=a+' </div>\n <table id="projTable" class="table table-striped sortable" style="padding:0px">\n <colgroup>\n <col style="width:80px">\n <col class="col-md-4">\n <col class="col-md-4">\n \x3c!-- this was the column for "is project shared" attribute <col class="col-md-2"> --\x3e\n <col class="col-md-4">\n </colgroup>\n <thead>\n <th class="sorttable_nosort" style="width:80px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>\n'+
  25. (' <th class="noselect">'+Blockscad.Msg.PROJECT_NAME+"</th>\n");a+=' <th class="noselect">'+Blockscad.Msg.PROJECT_LIST_LAST_MODIFIED+"</th>\n";a=a+' <th class="sorttable_nosort"></th>\n </thead> \n <tbody id="projList">\n </tbody>\n </table>\n'+(' <button type="button" id="list-more" class="btn btn-default">'+Blockscad.Msg.PROJECT_LIST_MORE_BUTTON+"</button>\n");a=a+' </div> \x3c!-- end of projectView --\x3e\n </div> \x3c!-- end of main --\x3e\n\n\n <div id="login-user" class="modal">\n <div class="modal-dialog">\n <div class="modal-md">\n <div class="modal-content">\n <form id="login-form">\n <fieldset>\n <div class="modal-header">\n <a href="#" data-dismiss="modal" class="close">\n </a>\n'+
  26. (" <h3>"+Blockscad.Msg.LOGIN_BUTTON+"</h3>\n");a=a+' </div>\n <div class="modal-body">\n <div class="form-group"> \n'+(' <label class="control-label" for="username">'+Blockscad.Msg.USERNAME_FIELD+"</label>\n");a=a+' <input class="username pull-right" id="login-username" type="text" autocomplete="off" name="username" maxlength="30" />\n </div>\n <div class="form-group"> \n'+(' <label class="control-label" for="password">'+
  27. Blockscad.Msg.PASSWORD_FIELD+"</label>\n");a=a+' <input type="password" name="password" id="login-password" autocomplete="off" class="password pull-right" maxlength="30"/>\n </div>\n </div>\n <div class="modal-footer">\n <div class="footer-error" id="login-error" style="margin-top:-5px; margin-bottom:12px; "></div>\n <div>\n'+(' <button id="logbut" class="button primary" type="submit" style="float: left;">'+
  28. Blockscad.Msg.LOGIN_BUTTON+"</button> \n");a+=' <a href="#" id="forgot-password" style="float: right;">'+Blockscad.Msg.PASSWORD_FORGOT_FIELD+"</a>\n";a=a+' </div>\n </div>\n </fieldset>\n </form>\n </div>\x3c!-- /.modal-content --\x3e\n </div>\x3c!-- /.modal-md --\x3e\n </div>\x3c!-- /.modal-dialog --\x3e\n </div>\x3c!-- /.modal --\x3e\n <div id="change-password-modal" class="modal" data-backdrop="true">\n <div class="modal-dialog">\n <div class="modal-content">\n <form id="password-settings-form" novalidate>\n <fieldset>\n <div class="modal-header">\n <a href="#" data-dismiss="modal" data-target="#password-settings-modal" class="close">x\n </a>\n'+
  29. (" <h3>"+Blockscad.Msg.CHANGE_PASSWORD+"</h3>\n");a+=" <span>"+Blockscad.Msg.CHANGE_PASSWORD_INSTRUCTIONS+"</span>\n";a=a+' </div>\n <div class="modal-body">\n <div class="form-group"> \n'+(' <label class="control-label mycl" for="password">'+Blockscad.Msg.OLD_PASSWORD+" :</label>\n");a=a+' <input type="password" id="change-pw-old" name="old-password" autocomplete="off" class="password regform" maxlength="30"/>\n <div class="form-error">\n <span class="password-error"></span>\n </div>\n </div>\n <div class="form-group"> \n'+
  30. (' <label class="control-label mycl" for="password">'+Blockscad.Msg.NEW_PASSWORD+" :</label>\n");a=a+' <input type="password" id="change-pw-new" name="new-password" autocomplete="off" class="password regform" maxlength="30"/>\n <div class="form-error">\n <span class="password-error"></span>\n </div>\n </div>\n <div class="form-group"> \n'+(' <label class="control-label mycl" for="pass2">'+
  31. Blockscad.Msg.CONFIRM_NEW_PASSWORD+" :</label>\n");a=a+' <input type="password" id="change-pw-2" autocomplete="off" class="password regform" maxlength="30"/>\n <div class="form-error">\n <span class="password-confirm-error"></span>\n </div> \n </div>\n <div class="buttons-right">\n'+(' <button class="button primary" type="submit">'+Blockscad.Msg.CHANGE_PASSWORD+"</button> \n");a=a+' </div>\n </div>\n <div class="modal-footer">\n <span class="footer-error" id="pw-error"></span>\n </div>\n </fieldset>\n </form>\n </div>\x3c!-- /.modal-content --\x3e\n </div>\x3c!-- /.modal-dialog --\x3e\n </div>\x3c!-- /.modal --\x3e\n <div id="change-email-modal" class="modal" data-backdrop="true">\n <div class="modal-dialog">\n <div class="modal-content">\n <form id="email-settings-form" novalidate>\n <fieldset>\n <div class="modal-header">\n <a href="#" data-dismiss="modal" data-target="#email-settings-modal" class="close">x\n </a>\n'+
  32. (" <h3>"+Blockscad.Msg.CHANGE_EMAIL+"</h3>\n");a=a+' </div>\n <div class="modal-body">\n'+(' <p id="current-email">'+Blockscad.Msg.CHANGE_EMAIL_CURRENT+" :</p>\n");a=a+' <div class="form-group"> \n'+(' <label class="control-label mycl" for="email">'+Blockscad.Msg.CHANGE_EMAIL_NEW+" :</label>\n");a=a+' <input type="text" id="new-email" name="new-email" autocomplete="off" class="email regform" size="30"/>\n <div class="form-error">\n <span class="email-error"></span>\n </div> \n </div>\n <div class="form-group"> \n'+
  33. (' <label class="control-label mycl" for="password">'+Blockscad.Msg.PASSWORD_FIELD+" :</label>\n");a=a+' <input type="password" id="change-email-pw" name="password" autocomplete="off" class="password regform" maxlength="30"/>\n </div> \n <div class="buttons-right">\n'+(' <button class="button primary" type="submit">'+Blockscad.Msg.CHANGE_EMAIL+"</button> \n");a=a+' </div>\n </div>\n <div class="modal-footer">\n <span class="footer-error" id="email-pw-error"></span>\n </div>\n </fieldset>\n </form>\n </div>\x3c!-- /.modal-content --\x3e\n </div>\x3c!-- /.modal-dialog --\x3e\n </div>\x3c!-- /.modal --\x3e\n <div id="register-user" class="modal">\n <div class="modal-dialog">\n <div class="modal-content modal-md">\n <form id="register-form">\n <fieldset>\n <div class="modal-header">\n <a href="#" data-dismiss="modal" class="close">x\n </a>\n'+
  34. (" <h3>"+Blockscad.Msg.REGISTER_NEW_USER+"</h3>\n");a=a+' </div>\n <div class="modal-body">\n <div class="form-group"> \n'+(' <label class="control-label mycl" for="username">'+Blockscad.Msg.USERNAME_FIELD+"</label>\n");a=a+' <input class="username regform" id="register-username" type="text" autocomplete="off" name="username" maxlength="30" />\n <div class="form-error">\n <span id="username-error"></span>\n </div>\n </div>\n <div class="form-group"> \n'+
  35. (' <label class="control-label mycl" for="password">'+Blockscad.Msg.PASSWORD_FIELD+"</label>\n");a=a+' <input type="password" id="register-password" name="password" autocomplete="off" class="password regform" maxlength="30"/>\n <div class="form-error">\n <span class="password-error"></span>\n </div>\n </div>\n <div class="form-group"> \n'+(' <label class="control-label mycl" for="pass2">'+
  36. Blockscad.Msg.PASSWORD_RETYPE_FIELD+"</label>\n");a=a+' <input type="password" id="pass2" autocomplete="off" class="password regform" maxlength="30"/>\n <div class="form-error">\n <span class="password-confirm-error"></span>\n </div> \n </div>\n <div class="form-group"> \n'+(' <label class="control-label mycl" for="email">'+Blockscad.Msg.EMAIL_FIELD+"</label>\n");a=a+' <input type="text" id="register-email" name="email" autocomplete="off" class="email regform"/>\n <div class="form-error">\n <span class="email-error"></span>\n </div> \n </div>\n </div>\n <div class="modal-footer">\n <span class="error"></span>\n <div class="buttons-right">\n'+
  37. (' <button class="button primary" type="submit">'+Blockscad.Msg.REGISTER_BUTTON+"</button> \n");a=a+' </div>\n </div>\n </fieldset>\n </form>\n </div>\x3c!-- /.modal-content --\x3e\n </div>\x3c!-- /.modal-dialog --\x3e\n </div>\x3c!-- /.modal --\x3e\n <div id="pw-recover" class="modal">\n <div class="modal-dialog">\n <div class="modal-content modal-md">\n <form id="pw-recover-form" novalidate>\n <fieldset>\n <div class="modal-header">\n <a href="#" data-dismiss="modal" class="close">x\n </a>\n'+
  38. (" <h3>"+Blockscad.Msg.RESET_PASSWORD+"</h3>\n");a=a+' </div>\n <div class="modal-body">\n'+(" <p><b>"+Blockscad.Msg.PASSWORD_FORGOT_FIELD+"</b></p>\n");a+=" <p>"+Blockscad.Msg.RESET_PASSWORD_INSTRUCTIONS+"</p>\n";a=a+' <div class="form-group"> \n'+(' <label class="control-label mycl" for="username">'+Blockscad.Msg.USERNAME_FIELD+"</label>\n");a=a+' <input class="username regform" id="recover-username" type="text" autocomplete="off" name="username" maxlength="30" />\n <div>\n <span class="email-error" id="un-recover-error" style="color:#b04444;"></span>\n </div>\n'+
  39. (" </div><p>"+Blockscad.Msg.DIALOG_OR+"</p>\n");a=a+' <div class="form-group"> \n'+(' <label class="control-label mycl" for="email">'+Blockscad.Msg.EMAIL_FIELD+"</label>\n");a=a+' <input type="text" id="recover-email" name="email" autocomplete="off" class="email regform"/>\n <div>\n <span class="email-error" id="em-recover-error" style="color:#b04444;"></span>\n </div> \n </div>\n </div>\n <div class="modal-footer">\n <div class="buttons-right">\n'+
  40. (' <button class="button primary" type="submit">'+Blockscad.Msg.RESET_PASSWORD_LINK_BUTTON+"</button> \n");a=a+' </div>\n </div>\n </fieldset>\n </form>\n </div>\x3c!-- /.modal-content --\x3e\n </div>\x3c!-- /.modal-dialog --\x3e\n </div>\x3c!-- /.modal --\x3e \x3c!-- end of password recovery popup --\x3e\n <div id="recover-email-sent" class="modal">\n <div class="modal-dialog modal-sm">\n <div class="modal-content">\n <div class="modal-header">\n <a href="#" data-dismiss="modal" class="close">x\n </a>\n'+
  41. (" <h3>"+Blockscad.Msg.PASSWORD_RESET_EMAIL_SENT+"</h3>\n");a=a+" </div>\n"+(' <div class="modal-body">'+Blockscad.Msg.PASSWORD_RESET_EMAIL_INSTRUCTIONS);a=a+' </div>\n </div>\n </div>\n </div> \x3c!-- end of password recovery email sent modal --\x3e\n <div id="online-delete-confirm" class="modal" data-backdrop="false">\n <div class="modal-dialog modal-sm" style="width:400px">\n <div class="modal-content">\n <div class="modal-header">\n <a href="#" data-dismiss="modal" class="close">x\n </a>\n <h4 class="modal-title"></h4>\n </div>\n <div class="modal-footer">\n'+
  42. (' <button id="toss-it" class="button btn-lg btn-default primary pull-left" style="margin-left:90px" type="button" data-dismiss="modal" data-target="#online-delete-confirm">'+Blockscad.Msg.CONFIRM_DIALOG_YES+"</button> \n");a+=' <button id="whatthe" class="button btn-default btn-lg primary" style="margin-right:90px" type="button" data-dismiss="modal" data-target="#online-delete-confirm">'+Blockscad.Msg.CONFIRM_DIALOG_NO+"</button> \n";a=a+' </div>\n </div>\x3c!-- /.modal-content --\x3e\n </div>\x3c!-- /.modal-dialog --\x3e\n </div> \x3c!-- end of online delete-confirm popup --\x3e\n <div id="delete-account-confirm" class="modal">\n <div class="modal-dialog modal-sm" style="width:600px">\n <div class="modal-content">\n <div class="modal-header">\n'+
  43. (" <h4>"+Blockscad.Msg.DELETE_ACCOUNT_CONFIRM+"</h4>\n");a=a+' </div>\n <div class="modal-footer">\n'+(' <button id="delete-account-yes" class="button btn-lg btn-default primary pull-left" style="margin-left:10%" type="button" data-dismiss="modal" data-target="#delete-account-confirm">'+Blockscad.Msg.CONFIRM_DIALOG_YES+"</button> \n");a+=' <button class="button btn-default btn-lg primary" style="margin-right:10%" type="button" data-dismiss="modal" data-target="#delete-account-confirm">'+
  44. Blockscad.Msg.CONFIRM_DIALOG_NO+"</button> \n";a=a+' </div>\n </div>\x3c!-- /.modal-content --\x3e\n </div>\x3c!-- /.modal-dialog --\x3e\n </div>\n <div id="delete-account-modal" class="modal">\n <div class="modal-dialog modal-sm" style="width:600px">\n <div class="modal-content">\n <form id="delete-account-form" novalidate>\n <fieldset>\n <div class="modal-header">\n <a href="#" data-dismiss="modal" data-target="#delete-account-modal" class="close">x\n </a>\n'+
  45. (" <h4>"+Blockscad.Msg.DELETE_ACCOUNT+"</h4>\n");a+=" <h3>"+Blockscad.Msg.DELETE_ACCOUNT_INSTRUCTIONS_ONE+"</b></h3>\n";a+=" <p>"+Blockscad.Msg.DELETE_ACCOUNT_INSTRUCTIONS_TWO+"</p>\n";a=a+' </div>\n <div class="modal-body">\n <div class="form-group"> \n'+(' <label for="password">'+Blockscad.Msg.DELETE_ACCOUNT_CONFIRM_PASSWORD+" : </label>\n");a=a+' <input type="password" id="del-acct-pw" name="password" autocomplete="off" class="password regform" maxlength="30"/>\n <div class="form-error">\n <span class="password-error"></span>\n </div>\n </div>\n <div class="buttons-right">\n'+
  46. (' <button class="button primary btn-default btn-lg" type="submit">'+Blockscad.Msg.DELETE_ACCOUNT_BUTTON+"</button> \n");a=a+' </div>\n </div>\n <div class="modal-footer">\n <span class="footer-error" id="da-pw-error"></span>\n </div>\n </fieldset>\n </form>\n </div>\x3c!-- /.modal-content --\x3e\n </div>\x3c!-- /.modal-dialog --\x3e\n </div>\n <div id="delete-reactivate" class="modal">\n <div class="modal-dialog modal-sm" style="width:500px">\n <div class="modal-content">\n <div class="modal-header">\n <a href="#" data-dismiss="modal" class="close">x\n </a>\n'+
  47. (" <h4><b>"+Blockscad.Msg.REACTIVATE_ACCOUNT_TITLE+"</b></h4>\n");a=a+' </div>\n <div class="modal-body">\n'+(" <p>"+Blockscad.Msg.REACTIVATE_ACCOUNT_EXPLAINED+"</p>\n");a+=' <p><a href="#" data-toggle="modal" data-target="#change-password-modal" data-dismiss="modal" data-target="#delete-reactivate">'+Blockscad.Msg.CHANGE_PASSWORD+"</a><p>";a=a+' </div>\n <div class="modal-footer">\n'+(' <button class="button btn-default btn-lg primary" style="margin-right:10%" type="button" data-dismiss="modal" data-target="#delete-reactivate">'+
  48. Blockscad.Msg.REACTIVATE_BUTTON+"</button> \n");a=a+' </div>\n </div>\x3c!-- /.modal-content --\x3e\n </div>\x3c!-- /.modal-dialog --\x3e\n </div>\n <div id="about-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="about-modal" aria-hidden="true">\n <div class="modal-dialog">\n <div class="modal-content">\n <div class="modal-header">\n <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>\n <h3 class="modal-title">BlocksCAD\n <small>Easy, Open-Source Solid CAD for Everyone!</small></h3>\n </div>\n <div class="modal-body">\n <div>\n'+
  49. (" <p>Version "+Blockscad.version+" ("+Blockscad.releaseDate+")</p>\n");return a+' <br>\n <p>Contact us at: <a href="mailto://blockscad@einsteinsworkshop.com">blockscad@einsteinsworkshop.com</a>\n <p><a href="https://github.com/EinsteinsWorkshop/BlocksCAD">Visit our Git Repository</a></p>\n <p><small><small>Developed with the sponsorship of the Defense Advanced Research Projects Agency (DARPA) and delivered to the U.S. Government with Unlimited Rights as defined in DFARS 252.227-7013.<br>Approved for Public Release, Distribution Unlimited.<br>Created by Katy Hamilton, J. Yoder, and Matthew Minuti. Copyright and Trademark 2014-2015 H3XL, Inc.</small></small>\n </p>\n </div>\n </div>\n <div class="modal-footer">\n <div class="row">\n <div class="col-md-4">\n <a href="http://www.gnu.org/licenses/gpl-3.0-standalone.html" target="_blank">Licensed GPLv3 or later</a></div>\n <div class="col-md-4">\n <a href="TOS.html" target="_blank">Terms of Service</a></div>\n <div class="col-md-4">\n <a href="privacy.html" target="_blank">Privacy Policy</a></div>\n </div>\n </div>\n </div>\n </div>\n </div>\n <div id="message-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="message-modal" aria-hidden="true">\n <div class="modal-dialog modal-sm">\n <div class="modal-content">\n <div class="modal-header">\n <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>\n </div>\n <div id="message-text" class="modal-body">Display a message here.\n </div>\n </div>\n </div>\n </div>\n<div id="outage-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="outage-modal" aria-hidden="true">\n <div class="modal-dialog">\n <div class="modal-content">\n <div class="modal-header">\n <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>\n <h3 class="modal-title">Scheduled Database Maintenance Dec. 27</h3>\n </div>\n <div class="modal-body">\n <div>\n On Dec. 27, 2016, we will be upgrading the BlocksCAD project database. During this time, login will be disabled and you won\'t have access to your account or your saved projects. <br><br>If you plan to work on specific projects that day, be sure to download them to your computer before Dec. 27. Any edits to these projects or any new creations will need to be saved to your computer that day as well. \n </div>\n </div>\n </div>\n</div>\n'}};var BlocklyStorage=BlocklyStorage||{},Blockscad=Blockscad||{};Blockscad.Auth=Blockscad.Auth||{};var Blockly=Blockly||{};Blockly.Xml=Blockly.Xml||{};BlocklyStorage.autosaveBlocks=function(a){"localStorage"in window&&(localStorage.xml=a,localStorage.proj_name=$("#project-name").val())};
  50. BlocklyStorage.standaloneRestoreBlocks=function(){if(localStorage.xml){var a=Blockly.Xml.textToDom(localStorage.xml);Blockly.Xml.domToWorkspace(Blockly.mainWorkspace,a);a=localStorage.proj_name;"undefined"!=a?$("#project-name").val(a):$("#project-name").val("Untitled")}};
  51. BlocklyStorage.backupBlocks_=function(){if("localStorage"in window){localStorage.clear();for(var a=Blockly.Xml.workspaceToDom(Blockscad.workspace),b=window.location.href.split("#")[0],b=b.split("?lang")[0],e=b+"proj_name",h=b+"current_project",m=b+"current_project_key",g=b+"needToSave",l=b+"pLang",p=Blockscad.workspace.getAllBlocks(),w=0;w<p.length;w++)if("stl_import"==p[w].type){var n=p[w].getField("STL_CONTENTS").getText();if(0<n.length){var x=b+n,q=b+n+"center";if(3E6>Blockscad.csg_commands[n].length){var v=
  52. Base64.toBase64(RawDeflate.deflate(Base64.utob(Blockscad.csg_commands[n])));window.localStorage.setItem(x,v);window.localStorage.setItem(q,Blockscad.csg_center[n])}}}window.localStorage.setItem(b,Blockly.Xml.domToText(a));window.localStorage.setItem(e,$("#project-name").val());window.localStorage.setItem(h,Blockscad.Auth.currentProject);window.localStorage.setItem(m,Blockscad.Auth.currentProjectKey);window.localStorage.setItem(g,Blockscad.needToSave);Blockscad.pLang?window.localStorage.setItem(l,
  53. Blockscad.pLang):localStorage.removeItem(l)}};BlocklyStorage.backupOnUnload=function(){window.addEventListener("unload",BlocklyStorage.backupBlocks_,!1)};
  54. BlocklyStorage.restoreBlocks=function(){var a=window.location.href.split("#")[0],a=a.split("?lang")[0],b=a+"proj_name",e=a+"current_project",h=a+"current_project_key",m=a+"needToSave";if("localStorage"in window&&window.localStorage[a]){var g=Blockly.Xml.textToDom(window.localStorage[a]);Blockly.Xml.domToWorkspace(g,Blockscad.workspace);for(var g=Blockscad.workspace.getAllBlocks(),l=0;l<g.length;l++)if("stl_import"==g[l].type){var p=g[l].getField("STL_CONTENTS").getText(),w=g[l].getField("STL_FILENAME").getText(),
  55. n=g[l].getField("STL_BUTTON");if(0<p.length){var x=window.localStorage[a+p],q=window.localStorage[a+p+"center"];if(x&&0<x.length)n.setVisible(!1),console.log("csg contents compressed length is:",x.length),n=Base64.btou(RawDeflate.inflate(Base64.fromBase64(x))),console.log("decompressed lengeth is:",n.length),Blockscad.csg_commands[p]=n,Blockscad.csg_filename[p]=w+":::",Blockscad.csg_center[p]=q;else{console.log("couldn't find the stl in localStorage");$("#error-message").html("Warning: Re-load your .STL files");
  56. g[l].getField("STL_CONTENTS").setText("");g[l].getField("STL_FILENAME").setText("");p=g[l].getCommentText();p.match(/^RELOAD/)||(p="RELOAD: "+p);g[l].setCommentText(p);n.setText("Reload");g[l].backlight();if(p=g[l].collapsedParents())for(w=0;w<p.length;w++)p[w].backlight();g[l].isCollapsed()||n.setVisible(!0);n=g[l];for(p=null;n;)n.isCollapsed()&&(p=n),n=n.getSurroundParent();p&&p.setCollapsed(!0,!0)}g[l].render()}}a=window.localStorage[b];"undefined"!=a?$("#project-name").val(a):$("#project-name").val("Untitled");
  57. e=window.localStorage[e];Blockscad.Auth.currentProject="undefined"!=e?e:"";h=window.localStorage[h];"undefined"!=h&&(Blockscad.Auth.currentProjectKey=h);var v=Number(window.localStorage[m]);"undefined"==v||1!=v&&0!=v||setTimeout(function(){Blockscad.needToSave=v},300)}};Blockscad.getLangFromLS=function(){var a=window.location.href.split("#")[0],a=a.split("?lang")[0];return window.localStorage[a+"pLang"]};var BSUtils=BSUtils||{};BSUtils.LANGUAGE_NAME={en:"English",de:"Deutsch",fr:"Fran\u00e7ais"};BSUtils.LANGUAGE_RTL=["ar","fa","he"];BSUtils.LANGUAGES=void 0;BSUtils.getStringParamFromUrl=function(a,b){var e=window.location.search.match(new RegExp("[?&]"+a+"=([^&]+)"));return e?decodeURIComponent(e[1].replace(/\+/g,"%20")):b};
  58. BSUtils.getLang=function(){var a=BSUtils.getStringParamFromUrl("lang","");void 0===BSUtils.LANGUAGE_NAME[a]&&(a=(a=Blockscad.getLangFromLS())&&"null"!=a?a:"en");return Blockscad.pLang=a};BSUtils.LANG=BSUtils.getLang();BSUtils.isRtl=function(){return-1!=BSUtils.LANGUAGE_RTL.indexOf(BSUtils.LANG)};
  59. BSUtils.initReadonly=function(){Blockly.inject(document.getElementById("blockly"),{path:"./",readOnly:!0,rtl:BSUtils.isRtl(),scrollbars:!1});var a=BSUtils.getStringParamFromUrl("xml",""),a=Blockly.Xml.textToDom("<xml>"+a+"</xml>");Blockly.Xml.domToWorkspace(a,Blockly.mainWorkspace)};BSUtils.loadBlocks=function(a){a?(a=Blockly.Xml.textToDom(a),Blockly.Xml.domToWorkspace(a,Blockly.mainWorkspace)):"BlocklyStorage"in window&&window.setTimeout(BlocklyStorage.restoreBlocks,0)};
  60. BSUtils.changeLanguage=function(){console.log("in changeLanguage");BlocklyStorage.backupBlocks_();var a=encodeURIComponent($(this).data("lang"));console.log("newLang is:",a);var b=window.location.search,b=1>=b.length?"?lang="+a:b.match(/[?&]lang=[^&]*/)?b.replace(/([?&]lang=)[^&]*/,"$1"+a):b.replace(/\?/,"?lang="+a+"&");window.location=window.location.protocol+"//"+window.location.host+window.location.pathname+b};BSUtils.isDialogVisible_=!1;BSUtils.dialogOrigin_=null;BSUtils.dialogDispose_=null;
  61. BSUtils.showDialog=function(a,b,e,h,m,g){function l(){BSUtils.isDialogVisible_&&(p.style.visibility="visible",p.style.zIndex=1,w.style.visibility="hidden")}BSUtils.isDialogVisible_&&BSUtils.hideDialog(!1);BSUtils.isDialogVisible_=!0;BSUtils.dialogOrigin_=b;BSUtils.dialogDispose_=g;var p=document.getElementById("dialog");g=document.getElementById("dialogShadow");var w=document.getElementById("dialogBorder"),n;for(n in m)p.style[n]=m[n];h&&(g.style.visibility="visible",g.style.opacity=.3,h=document.createElement("div"),
  62. h.id="dialogHeader",p.appendChild(h),BSUtils.dialogMouseDownWrapper_=Blockly.bindEvent_(h,"mousedown",null,BSUtils.dialogMouseDown_));p.appendChild(a);a.className=a.className.replace("dialogHiddenContent","");e&&b?(BSUtils.matchBorder_(b,!1,.2),BSUtils.matchBorder_(p,!0,.8),window.setTimeout(l,175)):l()};BSUtils.dialogStartX_=0;BSUtils.dialogStartY_=0;
  63. BSUtils.dialogMouseDown_=function(a){BSUtils.dialogUnbindDragEvents_();if(!Blockly.isRightButton(a)){var b=document.getElementById("dialog");BSUtils.dialogStartX_=b.offsetLeft-a.clientX;BSUtils.dialogStartY_=b.offsetTop-a.clientY;BSUtils.dialogMouseUpWrapper_=Blockly.bindEvent_(document,"mouseup",null,BSUtils.dialogUnbindDragEvents_);BSUtils.dialogMouseMoveWrapper_=Blockly.bindEvent_(document,"mousemove",null,BSUtils.dialogMouseMove_);a.stopPropagation()}};
  64. BSUtils.dialogMouseMove_=function(a){var b=document.getElementById("dialog"),e=BSUtils.dialogStartX_+a.clientX;a=BSUtils.dialogStartY_+a.clientY;a=Math.max(a,0);a=Math.min(a,window.innerHeight-b.offsetHeight);e=Math.max(e,0);e=Math.min(e,window.innerWidth-b.offsetWidth);b.style.left=e+"px";b.style.top=a+"px"};
  65. BSUtils.dialogUnbindDragEvents_=function(){BSUtils.dialogMouseUpWrapper_&&(Blockly.unbindEvent_(BSUtils.dialogMouseUpWrapper_),BSUtils.dialogMouseUpWrapper_=null);BSUtils.dialogMouseMoveWrapper_&&(Blockly.unbindEvent_(BSUtils.dialogMouseMoveWrapper_),BSUtils.dialogMouseMoveWrapper_=null)};
  66. BSUtils.hideDialog=function(a){function b(){h.style.visibility="hidden";m.style.visibility="hidden"}if(BSUtils.isDialogVisible_){BSUtils.dialogUnbindDragEvents_();BSUtils.dialogMouseDownWrapper_&&(Blockly.unbindEvent_(BSUtils.dialogMouseDownWrapper_),BSUtils.dialogMouseDownWrapper_=null);BSUtils.isDialogVisible_=!1;BSUtils.dialogDispose_&&BSUtils.dialogDispose_();BSUtils.dialogDispose_=null;var e=!1===a?null:BSUtils.dialogOrigin_;a=document.getElementById("dialog");var h=document.getElementById("dialogShadow"),
  67. m=document.getElementById("dialogBorder");h.style.opacity=0;e?(BSUtils.matchBorder_(a,!1,.8),BSUtils.matchBorder_(e,!0,.2),window.setTimeout(b,175)):b();a.style.visibility="hidden";a.style.zIndex=-1;for((e=document.getElementById("dialogHeader"))&&e.parentNode.removeChild(e);a.firstChild;)e=a.firstChild,e.className+=" dialogHiddenContent",document.body.appendChild(e)}};
  68. BSUtils.matchBorder_=function(a,b,e){function h(){m.style.width=g.width+"px";m.style.height=g.height+"px";m.style.left=g.x+"px";m.style.top=g.y+"px";m.style.opacity=e}if(a){var m=document.getElementById("dialogBorder"),g=BSUtils.getBBox_(a);b?(m.className="dialogAnimate",window.setTimeout(h,1)):(m.className="",h());m.style.visibility="visible"}};
  69. BSUtils.getBBox_=function(a){var b=a.offsetHeight,e=a.offsetWidth,h=0,m=0;do h+=a.offsetLeft,m+=a.offsetTop,a=a.offsetParent;while(a);return{height:b,width:e,x:h,y:m}};
  70. BSUtils.storageAlert=function(a){var b=document.getElementById("containerStorage");b.textContent="";a=a.split("\n");for(var e=0;e<a.length;e++){var h=document.createElement("p");h.appendChild(document.createTextNode(a[e]));b.appendChild(h)}b=document.getElementById("dialogStorage");a=document.getElementById("linkButton");BSUtils.showDialog(b,a,!0,!0,{width:"50%",left:"25%",top:"5em"},BSUtils.stopDialogKeyDown());BSUtils.startDialogKeyDown()};
  71. BSUtils.dialogKeyDown_=function(a){!BSUtils.isDialogVisible_||13!=a.keyCode&&27!=a.keyCode&&32!=a.keyCode||(BSUtils.hideDialog(!0),a.stopPropagation(),a.preventDefault())};BSUtils.startDialogKeyDown=function(){document.body.addEventListener("keydown",BSUtils.dialogKeyDown_,!0)};BSUtils.stopDialogKeyDown=function(){document.body.removeEventListener("keydown",BSUtils.dialogKeyDown_,!0)};BSUtils.getMsg=function(a){var b=BSUtils.getMsgOrNull(a);return null===b?"[Unknown message: "+a+"]":b};
  72. BSUtils.getMsgOrNull=function(a){return(a=document.getElementById(a))?(a=a.textContent,a=a.replace(/\\n/g,"\n")):null};BSUtils.addTouchEvents=function(){if("ontouchstart"in document.documentElement)for(var a=document.getElementsByTagName("button"),b=0,e;e=a[b];b++)e.ontouchend||(e.ontouchend=e.onclick)};window.addEventListener("load",BSUtils.addTouchEvents,!1);
  73. BSUtils.bindClick=function(a,b){"string"==typeof a&&(a=document.getElementById(a));a.addEventListener("click",b,!0);a.addEventListener("touchend",b,!0)};Blockscad=Blockscad||{};Blockscad.Toolbox=Blockscad.Toolbox||{};Blockscad.Auth=Blockscad.Auth||{};BlocklyStorage=BlocklyStorage||{};Blockly=Blockly||{};BSUtils=BSUtils||{};Blockscad.version="1.7.1";Blockscad.releaseDate="2017/01/09";Blockscad.offline=!0;Blockscad.standalone=!1;Blockscad.gProcessor=null;var _includePath="./";Blockscad.drawAxes=1;Blockscad.resolution=1;Blockscad.showMessageModal=!1;
  74. Blockscad.init=function(){var a=blockscadpage.start();$("body").append(a);Blockscad.initLanguage();Blockscad.inputVersion=Blockscad.version;BSUtils.isRtl();Blockscad.missingFields=[];Blockscad.csg_commands={};Blockscad.csg_filename={};Blockscad.csg_center=[0,0,0];Blockscad.renderActions=[];var b=document.getElementById("main");window.addEventListener("resize",function(a){a=BSUtils.getBBox_(b);var e=document.getElementById("blocklyDiv");e.style.top=a.y+"px";e.style.left=a.x+"px";e.style.height=a.height-
  75. 88+"px";e.style.width=a.width+"px";null!=Blockscad.gProcessor&&Blockscad.gProcessor.viewer&&Blockscad.gProcessor.viewer.rendered_resize(Blockscad.gProcessor.viewerdiv.offsetWidth,Blockscad.gProcessor.viewerdiv.offsetHeight);70>$("#main").height()-$(".resizableDiv").height()&&$(".resizableDiv").height($("#main").height()-70);20>$("#main").width()-$(".resizableDiv").width()&&$(".resizableDiv").width($("#main").width()-20);$(".resizableDiv").position({of:$("#main"),my:"right top",at:"right top",offset:"-12 -55"})},
  76. !1);Blockscad.Toolbox.createToolbox();Blockscad.workspace=Blockly.inject(document.getElementById("blocklyDiv"),{media:"blockly/media/",zoom:{controls:!0,wheel:!0,startScale:1,maxScale:3,minScale:.3,scaleSpeed:1.2},trashcan:!1,toolbox:Blockscad.Toolbox.adv});Blockscad.workspace.addChangeListener(Blockscad.handleWorkspaceEvents);Blockscad.Toolbox.setColorScheme(Blockscad.Toolbox.colorScheme.one);Blockscad.Toolbox.setCatColors();$("#advancedToolbox").addClass("hidden");"BlocklyStorage"in window&&BlocklyStorage.backupOnUnload();
  77. $(".resizableDiv").resizable({handles:"s,w,sw",resize:function(a,b){var e;$(window).height();null!=Blockscad.gProcessor&&(e=Blockscad.gProcessor.viewerdiv.offsetHeight,Blockscad.gProcessor.viewer.rendered_resize(Blockscad.gProcessor.viewerdiv.offsetWidth,e));20>$("#main").width()-b.size.width&&(b.size.width=$("#main").width()-20);70>$("#main").height()-b.size.height&&(b.size.height=$("#main").height()-70);b.position.left=$(window).width()-(b.size.width+12);b.position.top=55}});Blockly.svgResize(Blockscad.workspace);
  78. window.dispatchEvent(new Event("resize"));Blockscad.offline||Blockscad.Auth.init();BSUtils.bindClick("trashButton",function(){Blockscad.discard()});BSUtils.bindClick("renderButton",Blockscad.doRender);BSUtils.bindClick("undoButton",function(){Blockscad.workspace.undo(!1)});BSUtils.bindClick("redoButton",function(){Blockscad.workspace.undo(!0)});$("#axesButton").click(function(){Blockscad.drawAxes=(Blockscad.drawAxes+1)%2;$("#axesButton").toggleClass("btn-pushed");Blockscad.gProcessor.viewer.onDraw()});
  79. $("#zInButton").click(function(){Blockscad.gProcessor.viewer.zoomIn()});$("#zOutButton").click(function(){Blockscad.gProcessor.viewer.zoomOut()});$("#zResetButton").click(function(){Blockscad.gProcessor.viewer.viewReset()});$("#cameraButton").click(function(){Blockscad.cameraPic()});$("#displayCode").click(function(){var a=document.getElementById("openScadPre"),b=Blockly.OpenSCAD.workspaceToCode(Blockscad.workspace),b=Blockscad.processCodeForOutput(b);a.textContent=b;Blockly.svgResize(Blockscad.workspace)});
  80. $("#main").on("click",".new-project",Blockscad.newProject);$("#file-menu").on("change","#loadLocal",function(a){Blockscad.loadLocalBlocks(a)});$("#file-menu").on("change","#importLocal",function(a){readSingleFile(a,!1)});$("#file-menu").on("change","#importStl",function(a){Blockscad.readStlFile(a)});Blockscad.picSize=[450,450];Blockscad.rpicSize=[250,250];Blockscad.picQuality=.85;Blockscad.numRotPics=13;$("#picButton").click(Blockscad.takePic);$("#rPicButton").click(Blockscad.takeRPic);Blockscad.gProcessor=
  81. new Blockscad.Processor(document.getElementById("renderDiv"));Blockscad.needToSave=0;Blockscad.offline||Blockscad.Auth.checkForUser();$("#help-menu").on("click","#about",function(){$("#about-modal").modal("show")});$("#file-menu").on("click","#saveLocal",Blockscad.saveBlocksLocal);$("#file-menu").on("click","#saveOpenscad",Blockscad.saveOpenscadLocal);$("#simpleToolbox").on("click",function(){$("#simpleToolbox").addClass("hidden");$("#advancedToolbox").removeClass("hidden");Blockscad.workspace&&(Blockscad.Toolbox.catIDs=
  82. [],Blockscad.workspace.updateToolbox(Blockscad.Toolbox.sim),Blockscad.Toolbox.setCatColors())});$("#advancedToolbox").on("click",function(){$("#advancedToolbox").addClass("hidden");$("#simpleToolbox").removeClass("hidden");Blockscad.workspace&&(Blockscad.Toolbox.catIDs=[],Blockscad.workspace.updateToolbox(Blockscad.Toolbox.adv),Blockscad.Toolbox.setCatColors())});$("#colors_one").on("click",function(){if(Blockscad.workspace){Blockscad.Toolbox.setColorScheme(Blockscad.Toolbox.colorScheme.one);Blockscad.Toolbox.setCatColors();
  83. var a=Blockly.Xml.workspaceToDom(Blockscad.workspace);Blockscad.workspace.clear();Blockly.Xml.domToWorkspace(a,Blockscad.workspace)}});$("#colors_two").on("click",function(){if(Blockscad.workspace){Blockscad.Toolbox.setColorScheme(Blockscad.Toolbox.colorScheme.two);Blockscad.Toolbox.setCatColors();var a=Blockly.Xml.workspaceToDom(Blockscad.workspace);Blockscad.workspace.clear();Blockly.Xml.domToWorkspace(a,Blockscad.workspace)}});Blockscad.setColor=function(a,b,m){if(null!=Blockscad.gProcessor&&Blockscad.gProcessor.viewer){Blockscad.gProcessor.viewer.defaultColor=
  84. [a/255,b/255,m/255,1];Blockscad.gProcessor.picviewer.defaultColor=[a/255,b/255,m/255,1];Blockscad.gProcessor.rpicviewer.defaultColor=[a/255,b/255,m/255,1];if(Blockscad.gProcessor.hasSolid()){Blockscad.gProcessor.viewer.setCsg(Blockscad.gProcessor.currentObject);Blockscad.gProcessor.picviewer.setCsg(Blockscad.gProcessor.currentObject);Blockscad.gProcessor.rpicviewer.setCsg(Blockscad.gProcessor.currentObject);var e=Blockscad.gProcessor.picviewer.takePic(Blockscad.picQuality,0);Blockscad.gProcessor.img=
  85. e[0];Blockscad.gProcessor.imgStrip=Blockscad.gProcessor.takeRotatingPic(.9,Blockscad.numRotPics);Blockscad.gProcessor.thumbnail=e[1]}Blockscad.defaultColor=Math.round(a)+","+Math.round(b)+","+Math.round(m);$("#defColor").spectrum("set","rgb("+Blockscad.defaultColor+")")}};$("#defColor").spectrum({color:"rgb(255,128,255)",showPalette:!0,className:"defaultColor btn btn-default",appendTo:"#viewerButtons",hideAfterPaletteSelect:!0,showPaletteOnly:!0,change:function(a){Blockscad.setColor(a._r,a._g,a._b)},
  86. palette:[["rgb(255,128,255);","rgb(153,153,153);","rgb(238,60,60);","rgb(250,150,0);"],["rgb(250,214,0);","rgb(50,220,50);","rgb(20,150,255);","rgb(180,85,254);"]]});$(".sp-dd").remove();$("#examples_torus").click({msg:"torus.xml"},Blockscad.showExample);$("#examples_box").click({msg:"box.xml"},Blockscad.showExample);$("#examples_linear_extrude").click({msg:"linear_extrude.xml"},Blockscad.showExample);$("#examples_rotate_extrude").click({msg:"rotate_extrude.xml"},Blockscad.showExample);$("#examples_cube_with_cutouts").click({msg:"cube_with_cutouts.xml"},
  87. Blockscad.showExample);$("#examples_anthias_fish").click({msg:"anthias_fish.xml"},Blockscad.showExample);$("#examples_hulled_loop_sun").click({msg:"hulled_loop_sun.xml"},Blockscad.showExample);$("#examples_sine_function_with_loop").click({msg:"sine_function_with_loop.xml"},Blockscad.showExample);$("#examples_trefoil_knot_param_eq").click({msg:"trefoil_knot_param_eq.xml"},Blockscad.showExample);$(function(){$(".dropdown-menu > li > a.trigger").on("click",function(a){var b=$(this).next(),e=$(this).parent().parent();
  88. ($(this).hasClass("left-caret")||$(this).hasClass("right-caret"))&&$(this).toggleClass("right-caret left-caret");e.find(".left-caret").not(this).toggleClass("right-caret left-caret");e.find(".sub-menu:visible").not(b).hide();b.toggle();a.stopPropagation()});$(".dropdown-menu > li > a:not(.trigger)").on("click",function(){var a=$(this).closest(".dropdown");a.find(".left-caret").toggleClass("right-caret left-caret");a.find(".sub-menu:visible").hide()})});$("#stl_buttons").addClass("hidden");Blockscad.standalone?
  89. BlocklyStorage.standaloneRestoreBlocks():BSUtils.loadBlocks("");Blockscad.showMessageModal&&$("#outage-modal").modal("show");setTimeout(Blockscad.typeWorkspace,10)};
  90. Blockscad.typeWorkspace=function(){for(var a=Blockscad.workspace.getAllBlocks(),b=0;b<a.length;b++)"variables_set"==a[b].type&&Blockscad.assignVarTypes(a[b]);for(var e=Blockscad.workspace.getTopBlocks(),b=0;b<e.length;b++)e[b].category&&"PROCEDURE"==e[b].category&&Blockscad.assignBlockTypes([e[b]]);for(b=0;b<a.length;b++)"variables_set"!=a[b].type&&"PROCEDURE"!=a[b].category&&Blockscad.assignBlockTypes(a[b]);Blockscad.assignBlockTypes(Blockscad.workspace.getTopBlocks())};
  91. Blockscad.typeNewStack=function(a){a=a.getRootBlock().getDescendants();for(var b=0;a&&b<a.length;b++)"variables_set"!=a[b].type&&"variables_get"!=a[b].type||Blockscad.assignVarTypes(a[b]);for(b=0;a&&b<a.length;b++)"PROCEDURE"==a[b].category&&Blockscad.assignBlockTypes([a[b]]);for(b=0;a&&b<a.length;b++)"SET_OP"!=a[b].category&&"TRANSFORM"!=a[b].category&&"LOOP"!=a[b].category||Blockscad.assignBlockTypes([a[b]])};
  92. Blockscad.takeRPic=function(){if(null!=Blockscad.gProcessor){var a=Blockscad.gProcessor.imgStrip;a&&Blockscad.savePic(a,$("#project-name").val()+".jpg")}};Blockscad.savePic=function(a,b){if(a){var e=atob(a.split(",")[1]);a.split(",")[0].split(":")[1].split(";");for(var h=new ArrayBuffer(e.length),m=new Uint8Array(h),g=0;g<e.length;g++)m[g]=e.charCodeAt(g);e=new Blob([h],{type:"img/jpeg"});saveAs(e,b)}};
  93. Blockscad.takePic=function(){Blockscad.gProcessor&&Blockscad.gProcessor.img&&"null"!=Blockscad.gProcessor.img&&Blockscad.savePic(Blockscad.gProcessor.img,$("#project-name").val()+".jpg")};Blockscad.cameraPic=function(){if(Blockscad.gProcessor.viewer){var a=Blockscad.gProcessor.viewer.takeCameraPic(.95);a&&Blockscad.savePic(a,$("#project-name").val()+".jpg")}};
  94. Blockscad.loadLocalBlocks=function(a){a.target.files.length&&(Blockscad.needToSave?promptForSave().then(function(b){"cancel"!=b&&("nosave"==b?Blockscad.setSaveNeeded():"save"==b&&Blockscad.saveBlocks(),Blockscad.createNewProject(),readSingleFile(a,!0))})["catch"](function(a){console.log("caught an error in new project. result is:"+a)}):(Blockscad.createNewProject(),readSingleFile(a,!0)))};
  95. function readSingleFile(a,b){var e=a.target.files[0];if(e){var h;b&&(h=e.name.substr(0,e.name.lastIndexOf("("))||e.name,h=h.substr(0,e.name.lastIndexOf("."))||h,h=h.replace(/^\s+|\s+$/g,""));b&&(Blockscad.Auth.currentProject="");b&&Blockly.getMainWorkspace().clear();var m={},g=new FileReader;g.onload=function(a){m=a.target.result;a=Blockly.Xml.textToDom(m);Blockly.Xml.domToWorkspace(a,Blockscad.workspace);Blockly.svgResize(Blockscad.workspace);Blockscad.clearStlBlocks()};g.readAsText(e);$("#importLocal")[0].value=
  96. "";$("#loadLocal")[0].value="";b&&$("#project-name").val(h);$("#projectView").addClass("hidden");$("#editView").removeClass("hidden");Blockscad.offline||$("#bigsavebutton").removeClass("hidden");$("#displayBlocks").click();window.dispatchEvent(new Event("resize"));Blockscad.gProcessor.clearViewer()}}
  97. Blockscad.readStlFile=function(a){var b=a.target.files[0];b?(a=new FileReader,a.onload=function(a){a=importSTL(a.target.result);var e=a[0];(a=a[1])||(a="blah");for(var m=b.name.substr(0,b.name.lastIndexOf("("))||b.name,m=m.substr(0,b.name.lastIndexOf("."))||m,g=m=m.replace(/^\s+|\s+$/g,""),l=1,p=0;Blockscad.csg_commands[g]&&!p;)e!=Blockscad.csg_commands[g]?(g=m+"_"+l,l++):p=1;Blockscad.csg_commands[g]=e;Blockscad.csg_filename[g]=p?Blockscad.csg_filename[g]+(b.name+":::"):b.name+":::";Blockscad.csg_center[g]=
  98. a;Blockscad.currentInterestingBlock?(m=Blockscad.currentInterestingBlock.getField("STL_FILENAME"),e=Blockscad.currentInterestingBlock.getField("STL_BUTTON"),l=Blockscad.currentInterestingBlock.getField("STL_CONTENTS"),m.setText(b.name),m.setVisible(!0),e.setVisible(!1),l.setText(g),Blockscad.currentInterestingBlock.setCommentText(b.name+"\ncenter:("+a+")"),Blockscad.currentInterestingBlock=null):(g=Blockly.Xml.textToDom('<xml xmlns="http://blockscad.einsteinsworkshop.com"><block type="stl_import" id="1" x="0" y="0"><field name="STL_FILENAME">'+
  99. b.name+'</field><field name="STL_BUTTON">'+Blockscad.Msg.BROWSE+'</field><field name="STL_CONTENTS">'+g+"</field></block></xml>"),g=Blockly.Xml.domToBlock(Blockscad.workspace,g.firstChild),g.moveBy(20+Blockscad.workspace.getMetrics().viewLeft/Blockscad.workspace.scale,20+Blockscad.workspace.getMetrics().viewTop/Blockscad.workspace.scale),e=g.getField("STL_BUTTON"),e.setVisible(!1),g.setCommentText(b.name+"\ncenter:("+a+")"),g.render())},a.readAsBinaryString(b),$("#importStl")[0].value="",$("#displayBlocks").click()):
  100. alert("Failed to load file")};document.write('<script src="blockly/msg/js/'+BSUtils.LANG+'.js">\x3c/script>\n');document.write('<script src="blockscad/msg/js/'+BSUtils.LANG+'.js">\x3c/script>\n');window.addEventListener("load",Blockscad.init);
  101. Blockscad.clearStlBlocks=function(){for(var a=Blockscad.workspace.getAllBlocks(),b=0;b<a.length;b++)if("stl_import"==a[b].type){var e=a[b].getField("STL_BUTTON");a[b].getField("STL_CONTENTS").setText("");a[b].getField("STL_FILENAME").setText("");var h=a[b].getCommentText();h.match(/^RELOAD/)||(h="RELOAD: "+h);a[b].setCommentText(h);e.setText("Reload");a[b].backlight();if(h=a[b].collapsedParents())for(var m=0;m<h.length;m++)h[m].backlight();a[b].isCollapsed()||e.setVisible(!0);e=a[b];for(h=null;e;)e.isCollapsed()&&
  102. (h=e),e=e.getSurroundParent();h&&h.setCollapsed(!0,!0);a[b].render();$("#error-message").html(Blockscad.Msg.WARNING_RELOAD_STL)}};Blockscad.newProject=function(){$("#displayBlocks").click();Blockscad.needToSave?promptForSave().then(function(a){"cancel"!=a&&("nosave"==a?Blockscad.setSaveNeeded():"save"==a&&Blockscad.saveBlocks(),Blockscad.createNewProject())})["catch"](function(a){console.log("caught an error in new project. result is:"+a)}):Blockscad.createNewProject()};
  103. Blockscad.createNewProject=function(){Blockscad.clearProject();Blockscad.workspace.clearUndo();setTimeout(Blockscad.setSaveNeeded,300);$("#displayBlocks").click();Blockscad.offline||$("#bigsavebutton").removeClass("hidden")};
  104. function promptForSave(){var a="<h4>"+Blockscad.Msg.SAVE_PROMPT+"</h4>";return new Promise(function(b,e){bootbox.dialog({message:a,backdrop:!0,size:"small",buttons:{save:{label:Blockscad.Msg.SAVE_PROMPT_YES,className:"btn-default btn-lg primary pull-right giant-yes",callback:function(a){b("save")}},dont_save:{label:Blockscad.Msg.SAVE_PROMPT_NO,className:"btn-default btn-lg primary pull-left giant-yes",callback:function(a){b("nosave")}}},onEscape:function(){b("cancel")}})})}
  105. Blockscad.saveBlocks=function(){!Blockscad.offline&&Blockscad.Auth.isLoggedIn?Blockscad.Auth.saveBlocksToAccount():Blockscad.saveBlocksLocal()};
  106. Blockscad.showExample=function(a){var b="examples/"+a.data.msg,e=a.data.msg.split(".")[0];Blockscad.needToSave?promptForSave().then(function(a){"cancel"!=a&&("nosave"==a?Blockscad.setSaveNeeded():"save"==a&&Blockscad.saveBlocks(),Blockscad.getExample(b,e))})["catch"](function(a){console.log("caught an error in show example 1. result is:"+a)}):Blockscad.getExample(b,e)};
  107. Blockscad.getExample=function(a,b){$.get(a,function(a){Blockscad.clearProject();a=window.ActiveXObject?a.xml:(new XMLSerializer).serializeToString(a);a=Blockly.Xml.textToDom(a);Blockly.Xml.domToWorkspace(a,Blockscad.workspace);Blockly.svgResize(Blockscad.workspace);$("#project-name").val(b+" example");setTimeout(Blockscad.setSaveNeeded,300)})};Blockscad.setSaveNeeded=function(a){Blockscad.needToSave=a?1:0};
  108. Blockscad.clearProject=function(){Blockscad.offline||(Blockscad.Auth.currentProject="",Blockscad.Auth.currentProjectKey="");Blockscad.workspace.clear();Blockscad.gProcessor.clearViewer();$("#project-name").val(Blockscad.Msg.PROJECT_NAME_DEFAULT);$("#projectView").addClass("hidden");$("#editView").removeClass("hidden");$("#bigsavebutton").removeClass("hidden");window.dispatchEvent(new Event("resize"))};
  109. Blockscad.discard=function(){var a=Blockly.mainWorkspace.getAllBlocks().length;2>a?(Blockly.mainWorkspace.clear(),window.location.hash=""):(a=Blockscad.Msg.DISCARD_ALL.replace("%1",a),bootbox.confirm({size:"small",message:a,buttons:{confirm:{label:Blockscad.Msg.CONFIRM_DIALOG_YES,className:"btn-default confirm-yes"},cancel:{label:Blockscad.Msg.CONFIRM_DIALOG_NO,className:"btn-default confirm-yes"}},callback:function(a){a&&(Blockly.mainWorkspace.clear(),window.location.hash="")}}))};
  110. Blockscad.resetView=function(){null!=Blockscad.gProcessor&&Blockscad.gProcessor.viewer&&Blockscad.gProcessor.viewer.viewReset()};
  111. Blockscad.mixes2and3D=function(){var a;a=Blockly.mainWorkspace.getTopBlocks();for(var b=0,e=0,h=0,m=0,g=0;g<a.length;g++)if(Blockscad.stackIsShape(a[g])){var m=1,l=a[g].category,p;"PRIMITIVE_CSG"==l&&b++;"PRIMITIVE_CAG"==l&&e++;if("TRANSFORM"==l||"SET_OP"==l)p=a[g].getInput("A").connection.check_,1==p.length&&"CSG"==p[0]&&b++,1==p.length&&"CAG"==p[0]&&e++;"LOOP"==l&&(p=a[g].getInput("DO").connection.check_,1==p.length&&"CSG"==p[0]&&b++,1==p.length&&"CAG"==p[0]&&e++);"COLOR"==l&&b++;"EXTRUDE"==l&&
  112. b++;"controls_if"==a[g].type&&h++}!m||b+e+h||Blockscad.assignBlockTypes(Blockly.mainWorkspace.getTopBlocks());return[b&&e,m]};
  113. Blockscad.doRender=function(){$("#error-message").html("");$("#error-message").removeClass("has-error");$("#renderButton").prop("disabled",!0);Blockscad.gProcessor.clearViewer();var a=Blockscad.mixes2and3D();if(0===a[1])$("#error-message").html(Blockscad.Msg.ERROR_MESSAGE+": "+Blockscad.Msg.RENDER_ERROR_EMPTY),$("#error-message").addClass("has-error"),$("#renderButton").prop("disabled",!1);else if(a[0])$("#error-message").html(Blockscad.Msg.ERROR_MESSAGE+": "+Blockscad.Msg.RENDER_ERROR_MIXED),$("#error-message").addClass("has-error"),
  114. $("#renderButton").prop("disabled",!1);else{Blockscad.missingFields=[];Blockscad.illegalValue=[];var a=Blockly.OpenSCAD.workspaceToCode(Blockscad.workspace),b=!1;if(0<Blockscad.missingFields.length)for(var e=0;e<Blockscad.missingFields.length;e++){b=Blockly.mainWorkspace.getBlockById(Blockscad.missingFields[e]);b.unselect();b.backlight();if(b=b.collapsedParents())for(var h=0;h<b.length;h++)b[h].unselect(),b[h].backlight();b=!0}if(0<Blockscad.illegalValue.length){for(e=0;e<Blockscad.illegalValue.length;e++)if(b=
  115. Blockly.mainWorkspace.getBlockById(Blockscad.illegalValue[e]),b.unselect(),b.backlight(),b=b.collapsedParents())for(h=0;h<b.length;h++)b[h].unselect(),b[h].backlight();b=!0}if(b)a="",Blockscad.missingFields.length&&(e=Blockscad.Msg.ERROR_MESSAGE+": "+Blockscad.Msg.PARSING_ERROR_MISSING_FIELDS,a=e.replace("%1",Blockscad.missingFields.length+" ")),Blockscad.missingFields.length&&Blockscad.illegalValue.length&&(a+="<br>"),Blockscad.illegalValue.length&&(e=Blockscad.Msg.ERROR_MESSAGE+": "+Blockscad.Msg.PARSING_ERROR_ILLEGAL_VALUE,
  116. a+=e.replace("%1",Blockscad.illegalValue.length+" ")),$("#error-message").html(a),$("#error-message").addClass("has-error"),$("#renderButton").prop("disabled",!1);else if(Blockscad.resolution=$('input[name="resolution"]:checked').val(),Blockscad.loadTheseFonts=Blockscad.whichFonts(a),$("#renderButton").html("working"),0<Blockscad.loadTheseFonts.length)for(e=Blockscad.numloaded=0;e<Blockscad.loadTheseFonts.length;e++)Blockscad.loadFontThenRender(e,a);else Blockscad.renderCode(a)}};
  117. Blockscad.renderCode=function(a,b){Blockscad.gProcessor.setBlockscad(a)};Blockscad.getExtraRootBlock=function(a,b){var e;if(a.length>b.length)for(var h=0;h<a.length;h++){for(var m=e=0;m<b.length;m++)if(a[h].getAttribute("id")==b[m].id){e=1;break}if(!e)return h}else for(h=0;h<b.length;h++){for(m=e=0;m<a.length;m++)if(b[h].id==a[m].getAttribute("id")){e=1;break}if(!e)return h}return 0};Blockscad.getBlockFromId=function(a,b){for(var e=0,h;h=b[e];e++)if(h.id==a)return h;return null};
  118. Blockscad.aCallerBlock=function(a,b){for(var e=0;e<b.length;e++)if(a==b[e])return!0;return!1};Blockscad.findBlockType=function(a,b){for(var e=a.getRootBlock().getDescendants(),h=0,m=0,g=0;g<e.length;g++)if(!Blockscad.aCallerBlock(e[g],b)&&e[g].category){var l=e[g].category;if("PRIMITIVE_CSG"==l||"EXTRUDE"==l||"COLOR"==l){h=1;break}"PRIMITIVE_CAG"==l&&(m=1)}return h?Blockscad.hasExtrudeParent(a)?"CAG":"CSG":m?"CAG":"EITHER"};
  119. Blockscad.hasParentOfType=function(a,b){if(!a)return null;for(var e=a.getParent();e;){if(e.type==b)return e;e=e.getParent()}return null};Blockscad.doVariableHack=function(a){if(!a)return null;for(a=a.getParent();a;){if("LOOP"==a.category||"TRANSFORM"==a.category||"EXTRUDE"==a.category||"SET_OP"==a.category||"COLOR"==a.category||"controls_if"==a.type)return!0;a=a.getParent()}return!1};
  120. Blockscad.stackIsShape=function(a){a=a.getDescendants();for(var b=0;b<a.length;b++){var e=a[b];if(("PRIMITIVE_CSG"==e.category||"PRIMITIVE_CAG"==e.category)&&!e.hasDisabledParent())return!0}return!1};
  121. Blockscad.assignVarTypes=function(a,b){setTimeout(function(){if(a&&"variables_get"==a.type){for(var e=Blockly.Variables.getInstances(a.getFieldValue("VAR"),Blockscad.workspace),h=0,m=0;m<e.length;m++){if("variables_set"==e[m].type){a.outputConnection.setCheck(e[m].myType_);h=1;break}if("controls_for"==e[m].type||"controls_for_chainhull"==e[m].type){a.outputConnection.setCheck(null);h=1;break}}h||a.outputConnection.setCheck(null);(m=a.getParent())&&"variables_set"==m.type&&Blockscad.assignVarTypes(m)}else if(a&&
  122. "variables_set"==a.type)if(e=a.getChildren(),0==e.length)a.setType(null);else{for(m=h=0;m<e.length;m++)e[m].outputConnection&&(h=e[m].outputConnection.check_,b&&(a.myType_="FALSE"),a.setType(h),h=1);0==h&&a.setType(null)}},0)};
  123. Blockscad.handleWorkspaceEvents=function(a){if(a.type!=Blockly.Events.UI)if(a.type==Blockly.Events.CREATE||a.type==Blockly.Events.DELETE){Blockscad.setSaveNeeded(!0);var b=Blockscad.workspace.getBlockById(a.ids[0]);b&&b.workspace&&!b.workspace.isFlyout&&("procedures_callnoreturn"!=b.type&&"procedures_callreturn"!=b.type||b.setType())}else if(a.type==Blockly.Events.CHANGE){Blockscad.setSaveNeeded(!0);if("field"==a.element&&"VAR"==a.name){var e=a.oldValue;if((b=Blockscad.workspace.getBlockById(a.blockId))&&
  124. "variables_set"==b.type){for(var e=Blockly.Variables.getInstances(e,Blockscad.workspace),h=0,m=0;e&&m<e.length;m++)"variables_set"==e[m].type&&Blockscad.assignVarTypes(e[m],!0),h=1;if(!h)for(m=0;e&&m<e.length;m++)"variables_get"==e[m].type&&Blockscad.assignVarTypes(e[m],!0)}Blockscad.assignVarTypes(b,!0)}"field"==a.element&&"NUM"==a.name&&(b=Blockscad.workspace.getBlockById(a.blockId),(a=b.getParent())&&"cylinder"==a.type&&a.updateRadii())}else a.type==Blockly.Events.MOVE&&(a.oldParentId?(b=Blockscad.workspace.getBlockById(a.blockId),
  125. e=Blockscad.workspace.getBlockById(a.oldParentId),Blockscad.assignBlockTypes([b]),Blockscad.assignBlockTypes([e]),b&&"variables_set"==b.type?Blockscad.assignVarTypes(b):e&&"variables_set"==e.type&&Blockscad.assignVarTypes(e)):a.newParentId&&(b=Blockscad.workspace.getBlockById(a.blockId),e=Blockscad.workspace.getBlockById(a.newParentId),Blockscad.assignBlockTypes([b]),e&&"variables_set"==e.type&&Blockscad.assignVarTypes(e)),(a.oldParentId||a.newParentId)&&Blockscad.setSaveNeeded(!0))};
  126. Blockscad.assignBlockTypes=function(a){goog.isArray(a)||(a=[a]);setTimeout(function(){for(var b=0;a&&a[b]&&b<a.length;b++){for(var e=a[b].getRootBlock().getDescendants(),h=0,m=0,g=0;g<e.length;g++)if(e[g].category){var l=e[g].category;if("PRIMITIVE_CSG"==l||"EXTRUDE"==l||"COLOR"==l){h=1;break}"PRIMITIVE_CAG"==l&&(m=1)}for(g=0;g<e.length;g++)!e[g].category||"TRANSFORM"!=e[g].category&&"SET_OP"!=e[g].category&&"PROCEDURE"!=e[g].category&&"LOOP"!=e[g].category||(l=!e[g].collapsedParents(),h?Blockscad.hasExtrudeParent(e[g])?
  127. e[g].setType(["CAG"],l):e[g].setType(["CSG"],l):m?e[g].setType(["CAG"],l):e[g].setType(["CSG","CAG"],l))}},0)};Blockscad.hasExtrudeParent=function(a){do{if("EXTRUDE"==a.category)return!0;a=a.parentBlock_}while(a);return!1};
  128. Blockscad.initLanguage=function(){var a=BSUtils.isRtl();document.head.parentElement.setAttribute("dir",a?"rtl":"ltr");document.head.parentElement.setAttribute("lang",BSUtils.LANG);var a=[],b;for(b in BSUtils.LANGUAGE_NAME)a.push([BSUtils.LANGUAGE_NAME[b],b]);a.sort(function(a,b){return a[0]>b[0]?1:a[0]<b[0]?-1:0});b=[];for(var e=0;e<a.length;e++)b.push('<li><a href="#" class="lang-option" data-lang="'+a[e][1]+'"</a>'+a[e][0]+"</li>");$("#languageMenu").append(b.join(""));$(".lang-option").on("click",
  129. BSUtils.changeLanguage)};Blockscad.saveBlocksLocal=function(){var a=Blockly.Xml.workspaceToDom(Blockly.getMainWorkspace()),a=Blockly.Xml.domToText(a),a=new Blob([a],{type:"text/plain;charset=utf-8"}),b=$("#project-name").val();b?(saveAs(a,b+".xml"),Blockscad.setSaveNeeded()):alert(Blockscad.Msg.SAVE_FAILED+"!\n"+Blockscad.Msg.SAVE_FAILED_PROJECT_NAME)};Blockscad.savePicLocal=function(a){a=new Blob([a],{type:"img/jpeg"});saveAs(a,"tryThis.jpg")};
  130. Blockscad.saveOpenscadLocal=function(){var a=Blockly.OpenSCAD.workspaceToCode(Blockscad.workspace),a=Blockscad.processCodeForOutput(a),a=new Blob([a],{type:"text/plain;charset=utf-8"}),b=$("#project-name").val();b?saveAs(a,b+".scad"):alert("SAVE FAILED. Please give your project a name, then try again.")};
  131. Blockscad.executeAfterDrag_=function(a,b){Blockscad.renderActions.push({action:a,thisArg:b});if(1===Blockscad.renderActions.length)var e=window.setInterval(function(){if(!Blockly.dragMode_){for(;0<Blockscad.renderActions.length;)Blockscad.renderActions.shift().action.call(Blockscad.renderActions.thisArg);window.clearInterval(e)}},10)};Blockscad.arraysEqual=function(a,b){if(null==a&&null==b)return!0;if(!a||!b||a.length!==b.length)return!1;for(var e=a.length;e--;)if(a[e]!==b[e])return!1;return!0};
  132. Blockscad.processCodeForOutput=function(a){return a.replace(/( *)assign\((\$fn=.+)\){(.+)/g,"$1{\n$1 $2; $3").replace(/( *)assign\((.+)\){/gm,"$1$2;").replace(/(\w+ = \w+),/g,"$1; ").replace(/.+end assign\n/g,"").replace(/\n\s*\n\s*\n/g,"\n\n").replace(/group\(\)\{/g,"union(){")};
  133. Blockly.OpenSCAD.returnIfVarCode=function(a){if("controls_if"==a.type){for(var b=[],e=0,h=0;h<a.inputList.length;h++)if(a.inputList[h].name.match(/DO./)||"ELSE"==a.inputList[h].name){var m=a.getInputTargetBlock(a.inputList[h].name);b[e]=[];m&&"variables_set"==m.type&&(b[e]=Blockly.OpenSCAD.getVariableCode(m));e++}a=[];e=[];for(m=0;m<b.length;m++){var g=b[m];a[m]="";e[m]="";if(g.length){a[m]+=" assign(";for(h=0;h<g.length;h++)a[m]+=g[h]+",";a[m]=a[m].slice(0,-1);a[m]+="){\n";e[m]=" }//end assign\n"}}return[a,
  134. e]}};Blockscad=Blockscad||{};Blockscad.fonts={};Blockscad.fontList="/fonts/Roboto/Roboto-Bold.ttf /fonts/liberation/LiberationSerif-Bold.ttf /fonts/nimbus/nimbus-sans-l_bold.ttf /fonts/AverageMono/AverageMonoSimp.ttf /fonts/Open_Sans/OpenSans-ExtraBold.ttf /fonts/stardos-stencil/StardosStencil-Bold.ttf /fonts/Chewy/Chewy.ttf /fonts/bangers/Bangers.ttf".split(" ");Blockscad.fontName="Roboto;Liberation Serif;Nimbus Sans;Average Mono;Open Sans;Stardos Stencil;Chewy;Bangers".split(";");
  135. Blockscad.loadFonts=function(){for(var a=0;a<Blockscad.fontList.length;a++)Blockscad.loadFont(a)};Blockscad.loadFont=function(a){opentype.load(Blockscad.fontList[a],function(b,e){if(b)console.log("Could not load font: ",e+":"+b);else return Blockscad.fonts[Blockscad.fontName[a]]=e})};
  136. Blockscad.loadFontThenRender=function(a,b){try{var e=Blockscad.fontList[Blockscad.loadTheseFonts[a]],h=new XMLHttpRequest;h.open("get",e,!0);h.responseType="arraybuffer";h.onload=function(){if(200!==h.status)throw Error("failed to load font in loadRawFont:"+e+h.statusText);Blockscad.fonts[Blockscad.fontName[Blockscad.loadTheseFonts[a]]]=h.response;Blockscad.numloaded++;Blockscad.numloaded==Blockscad.loadTheseFonts.length&&Blockscad.renderCode(b)};h.send()}catch(m){console.log("network error loading font in loadFontThenRender with: ",
  137. m)}};Blockscad.whichFonts=function(a){for(var b=[],e=0;e<Blockscad.fontList.length;e++)-1<a.indexOf(Blockscad.fontName[e])&&(Blockscad.fonts[Blockscad.fontName[e]]||b.push(e));return b};var GL=function(){function a(a,d,c){c=c||{};this.id=f.createTexture();this.width=a;this.height=d;this.format=c.format||f.RGBA;this.type=c.type||f.UNSIGNED_BYTE;f.bindTexture(f.TEXTURE_2D,this.id);f.pixelStorei(f.UNPACK_FLIP_Y_WEBGL,!0);f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MAG_FILTER,c.filter||c.magFilter||f.LINEAR);f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MIN_FILTER,c.filter||c.minFilter||f.LINEAR);f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_S,c.wrap||c.wrapS||f.CLAMP_TO_EDGE);f.texParameteri(f.TEXTURE_2D,
  138. f.TEXTURE_WRAP_T,c.wrap||c.wrapT||f.CLAMP_TO_EDGE);f.texImage2D(f.TEXTURE_2D,0,this.format,a,d,0,this.format,this.type,null)}function b(){this.unique=[];this.indices=[];this.map={}}function e(a,d){this.buffer=null;this.target=a;this.type=d;this.data=[]}function h(a){a=a||{};this.vertexBuffers={};this.indexBuffers={};this.addVertexBuffer("vertices","gl_Vertex");a.coords&&this.addVertexBuffer("coords","gl_TexCoord");a.normals&&this.addVertexBuffer("normals","gl_Normal");a.colors&&this.addVertexBuffer("colors",
  139. "gl_Color");"triangles"in a&&!a.triangles||this.addIndexBuffer("triangles");a.lines&&this.addIndexBuffer("lines")}function m(a){return new g(2*(a&1)-1,(a&2)-1,(a&4)/2-1)}function g(a,d,c){this.x=a||0;this.y=d||0;this.z=c||0}function l(a,d,c){for(var k;null!==(k=a.exec(d));)c(k)}function p(a,d){function c(a){var c=document.getElementById(a);return c?c.text:a}function k(a,c){var k={},d=/^((\s*\/\/.*\n|\s*#extension.*\n)+)\^*$/.exec(c);c=d?d[1]+a+c.substr(d[1].length):a+c;l(/\bgl_\w+\b/g,a,function(a){a in
  140. k||(c=c.replace(new RegExp("\\b"+a+"\\b","g"),"LIGHTGL"+a),k[a]=!0)});return c}function b(a,c){var k=f.createShader(a);f.shaderSource(k,c);f.compileShader(k);if(!f.getShaderParameter(k,f.COMPILE_STATUS))throw"compile error: "+f.getShaderInfoLog(k);return k}a=c(a);d=c(d);var e=a+d,g={};l(/\b(gl_[^;]*)\b;/g,"uniform mat3 gl_NormalMatrix;uniform mat4 gl_ModelViewMatrix;uniform mat4 gl_ProjectionMatrix;uniform mat4 gl_ModelViewProjectionMatrix;uniform mat4 gl_ModelViewMatrixInverse;uniform mat4 gl_ProjectionMatrixInverse;uniform mat4 gl_ModelViewProjectionMatrixInverse;",
  141. function(a){a=a[1];if(-1!=e.indexOf(a)){var c=a.replace(/[a-z_]/g,"");g[c]="LIGHTGL"+a}});-1!=e.indexOf("ftransform")&&(g.MVPM="LIGHTGLgl_ModelViewProjectionMatrix");this.usedMatrices=g;a=k("uniform mat3 gl_NormalMatrix;uniform mat4 gl_ModelViewMatrix;uniform mat4 gl_ProjectionMatrix;uniform mat4 gl_ModelViewProjectionMatrix;uniform mat4 gl_ModelViewMatrixInverse;uniform mat4 gl_ProjectionMatrixInverse;uniform mat4 gl_ModelViewProjectionMatrixInverse;attribute vec4 gl_Vertex;attribute vec4 gl_TexCoord;attribute vec3 gl_Normal;attribute vec4 gl_Color;vec4 ftransform() { return gl_ModelViewProjectionMatrix * gl_Vertex;}",
  142. a);d=k("precision highp float;uniform mat3 gl_NormalMatrix;uniform mat4 gl_ModelViewMatrix;uniform mat4 gl_ProjectionMatrix;uniform mat4 gl_ModelViewProjectionMatrix;uniform mat4 gl_ModelViewMatrixInverse;uniform mat4 gl_ProjectionMatrixInverse;uniform mat4 gl_ModelViewProjectionMatrixInverse;",d);this.program=f.createProgram();f.attachShader(this.program,b(f.VERTEX_SHADER,a));f.attachShader(this.program,b(f.FRAGMENT_SHADER,d));f.linkProgram(this.program);if(!f.getProgramParameter(this.program,f.LINK_STATUS))throw"link error: "+
  143. f.getProgramInfoLog(this.program);this.attributes={};this.uniformLocations={};var h={};l(/uniform\s+sampler(1D|2D|3D|Cube)\s+(\w+)\s*;/g,a+d,function(a){h[a[2]]=1});this.isSampler=h}function w(){f.MODELVIEW=S|1;f.PROJECTION=S|2;var a=new u,d=new u;f.modelviewMatrix=new u;f.projectionMatrix=new u;var c=[],b=[],e,h;f.matrixMode=function(a){switch(a){case f.MODELVIEW:e="modelviewMatrix";h=c;break;case f.PROJECTION:e="projectionMatrix";h=b;break;default:throw"invalid matrix mode "+a;}};f.loadIdentity=
  144. function(){u.identity(f[e])};f.loadMatrix=function(a){a=a.m;for(var c=f[e].m,k=0;16>k;k++)c[k]=a[k]};f.multMatrix=function(a){f.loadMatrix(u.multiply(f[e],a,d))};f.perspective=function(c,k,d,b){f.multMatrix(u.perspective(c,k,d,b,a))};f.frustum=function(c,k,d,b,e,A){f.multMatrix(u.frustum(c,k,d,b,e,A,a))};f.ortho=function(c,k,d,b,e,A){f.multMatrix(u.ortho(c,k,d,b,e,A,a))};f.scale=function(c,k,d){f.multMatrix(u.scale(c,k,d,a))};f.translate=function(c,k,d){f.multMatrix(u.translate(c,k,d,a))};f.rotate=
  145. function(c,k,d,b){f.multMatrix(u.rotate(c,k,d,b,a))};f.lookAt=function(c,k,d,b,e,A,g,h,K){f.multMatrix(u.lookAt(c,k,d,b,e,A,g,h,K,a))};f.pushMatrix=function(){h.push(Array.prototype.slice.call(f[e].m))};f.popMatrix=function(){var a=h.pop();f[e].m=N?new Float32Array(a):a};f.project=function(a,c,k,d,b,e){d=d||f.modelviewMatrix;b=b||f.projectionMatrix;e=e||f.getParameter(f.VIEWPORT);a=b.transformPoint(d.transformPoint(new g(a,c,k)));return new g(e[0]+e[2]*(.5*a.x+.5),e[1]+e[3]*(.5*a.y+.5),.5*a.z+.5)};
  146. f.unProject=function(c,k,b,e,A,h){e=e||f.modelviewMatrix;A=A||f.projectionMatrix;h=h||f.getParameter(f.VIEWPORT);c=new g((c-h[0])/h[2]*2-1,(k-h[1])/h[3]*2-1,2*b-1);return u.inverse(u.multiply(A,e,a),d).transformPoint(c)};f.matrixMode(f.MODELVIEW)}function n(){var a=new h({coords:!0,colors:!0,triangles:!1}),d=-1,c=[0,0,0,0],b=[1,1,1,1],e=new p("uniform float pointSize;varying vec4 color;varying vec4 coord;void main() {color = gl_Color;coord = gl_TexCoord;gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;gl_PointSize = pointSize;}",
  147. "uniform sampler2D texture;uniform float pointSize;uniform bool useTexture;varying vec4 color;varying vec4 coord;void main() {gl_FragColor = color;if (useTexture) gl_FragColor *= texture2D(texture, coord.xy);}");f.pointSize=function(a){e.uniforms({pointSize:a})};f.begin=function(c){if(-1!=d)throw"mismatched gl.begin() and gl.end() calls";d=c;a.colors=[];a.coords=[];a.vertices=[]};f.color=function(a,c,k,d){b=1==arguments.length?a.toArray().concat(1):[a,c,k,d||1]};f.texCoord=function(a,k){c=1==arguments.length?
  148. a.toArray(2):[a,k]};f.vertex=function(k,d,e){a.colors.push(b);a.coords.push(c);a.vertices.push(1==arguments.length?k.toArray():[k,d,e])};f.end=function(){if(-1==d)throw"mismatched gl.begin() and gl.end() calls";a.compile();e.uniforms({useTexture:!!f.getParameter(f.TEXTURE_BINDING_2D)}).draw(a,d);d=-1}}function x(){function a(){for(var a in t)if(u.call(t,a)&&t[a])return!0;return!1}function d(c){var k={},d;for(d in c)k[d]="function"==typeof c[d]?function(a){return function(){a.apply(c,arguments)}}(c[d]):
  149. c[d];k.original=c;k.x=k.pageX;k.y=k.pageY;for(d=f.canvas;d;d=d.offsetParent)k.x-=d.offsetLeft,k.y-=d.offsetTop;q?(k.deltaX=k.x-r,k.deltaY=k.y-E):(k.deltaX=0,k.deltaY=0,q=!0);r=k.x;E=k.y;k.dragging=a();k.preventDefault=function(){k.original.preventDefault()};k.stopPropagation=function(){k.original.stopPropagation()};return k}function c(a){var c={},k;for(k in a)c[k]="function"==typeof a[k]?function(c){return function(){c.apply(a,arguments)}}(a[k]):a[k];c.original=a;if(0<c.targetTouches.length){k=c.targetTouches[0];
  150. c.x=k.pageX;c.y=k.pageY;for(k=f.canvas;k;k=k.offsetParent)c.x-=k.offsetLeft,c.y-=k.offsetTop;q?(c.deltaX=c.x-r,c.deltaY=c.y-E):(c.deltaX=0,c.deltaY=0,q=!0);r=c.x;E=c.y;c.dragging=!0}c.preventDefault=function(){c.original.preventDefault()};c.stopPropagation=function(){c.original.stopPropagation()};return c}function b(a){f=n;a=d(a);if(f.onmousemove)f.onmousemove(a);a.preventDefault()}function e(c){f=n;t[c.which]=!1;a()||(document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",
  151. e),f.canvas.addEventListener("mousemove",b),f.canvas.addEventListener("mouseup",e));c=d(c);if(f.onmouseup)f.onmouseup(c);c.preventDefault()}function g(a){f=n;a=d(a);if(f.onmousewheel)f.onmousewheel(a);a.preventDefault()}function h(a){f=n;0===a.targetTouches.length&&m(a);a=c(a);if(f.ontouchmove)f.ontouchmove(a);a.preventDefault()}function m(a){document.removeEventListener("touchmove",h);document.removeEventListener("touchend",m);f.canvas.addEventListener("touchmove",h);f.canvas.addEventListener("touchend",
  152. m);f=n;a=c(a);if(f.ontouchend)f.ontouchend(a);a.preventDefault()}function l(){q=!1}function p(){t={};q=!1}var n=f,r=0,E=0,t={},q=!1,u=Object.prototype.hasOwnProperty;f.canvas.addEventListener("mousedown",function(c){f=n;a()||(document.addEventListener("mousemove",b),document.addEventListener("mouseup",e),f.canvas.removeEventListener("mousemove",b),f.canvas.removeEventListener("mouseup",e));t[c.which]=!0;c=d(c);if(f.onmousedown)f.onmousedown(c);c.preventDefault()});f.canvas.addEventListener("mousemove",
  153. b);f.canvas.addEventListener("mouseup",e);f.canvas.addEventListener("mousewheel",g);f.canvas.addEventListener("DOMMouseScroll",g);f.canvas.addEventListener("mouseover",l);f.canvas.addEventListener("mouseout",l);f.canvas.addEventListener("touchstart",function(a){p();document.addEventListener("touchmove",h);document.addEventListener("touchend",m);f.canvas.removeEventListener("touchmove",h);f.canvas.removeEventListener("touchend",m);f=n;a=c(a);if(f.ontouchstart)f.ontouchstart(a);a.preventDefault()});
  154. f.canvas.addEventListener("touchmove",h);f.canvas.addEventListener("touchend",m);document.addEventListener("contextmenu",p)}function q(a){return{8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",27:"ESCAPE",32:"SPACE",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN"}[a]||(65<=a&&90>=a?String.fromCharCode(a):null)}function v(a,d,c){a.addEventListener(d,c)}function L(){(function(a){f.makeCurrent=function(){f=a}})(f);f.animate=function(){function a(){f=b;var k=(new Date).getTime();if(f.onupdate)f.onupdate((k-c)/1E3);
  155. if(f.ondraw)f.ondraw();d(a);c=k}var d=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||function(a){setTimeout(a,1E3/60)},c=(new Date).getTime(),b=f;a()};f.fullscreen=function(a){function k(){f.canvas.width=window.innerWidth-b-e;f.canvas.height=window.innerHeight-c-h;f.viewport(0,0,f.canvas.width,f.canvas.height);!a.camera&&"camera"in a||(f.matrixMode(f.PROJECTION),f.loadIdentity(),f.perspective(a.fov||45,f.canvas.width/f.canvas.height,a.near||.1,a.far||
  156. 1E3),f.matrixMode(f.MODELVIEW));if(f.onresize)f.onresize();if(f.ondraw)f.ondraw()}a=a||{};var c=a.paddingTop||0,b=a.paddingLeft||0,e=a.paddingRight||0,h=a.paddingBottom||0;if(!document.body)throw"document.body doesn't exist yet (call gl.fullscreen() from window.onload() or from inside the <body> tag)";document.body.appendChild(f.canvas);document.body.style.overflow="hidden";f.canvas.style.position="absolute";f.canvas.style.left=b+"px";f.canvas.style.top=c+"px";window.addEventListener("resize",k);
  157. k()}}function u(){var a=Array.prototype.concat.apply([],arguments);a.length||(a=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);this.m=N?new Float32Array(a):a}function G(a,d,c){this.t=arguments.length?a:Number.MAX_VALUE;this.hit=d;this.normal=c}function J(){var a=f.getParameter(f.VIEWPORT),d=f.modelviewMatrix.m,c=new g(d[0],d[4],d[8]),b=new g(d[1],d[5],d[9]),e=new g(d[2],d[6],d[10]),d=new g(d[3],d[7],d[11]);this.eye=new g(-d.dot(c),-d.dot(b),-d.dot(e));c=a[0];b=c+a[2];e=a[1];d=e+a[3];this.ray00=f.unProject(c,
  158. e,1).subtract(this.eye);this.ray10=f.unProject(b,e,1).subtract(this.eye);this.ray01=f.unProject(c,d,1).subtract(this.eye);this.ray11=f.unProject(b,d,1).subtract(this.eye);this.viewport=a}var H,M,r;a.prototype={bind:function(a){f.activeTexture(f.TEXTURE0+(a||0));f.bindTexture(f.TEXTURE_2D,this.id)},unbind:function(a){f.activeTexture(f.TEXTURE0+(a||0));f.bindTexture(f.TEXTURE_2D,null)},drawTo:function(a,d){d=d||{};var c=f.getParameter(f.VIEWPORT);f.viewport(0,0,this.width,this.height);H=H||f.createFramebuffer();
  159. f.bindFramebuffer(f.FRAMEBUFFER,H);f.framebufferTexture2D(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0,f.TEXTURE_2D,this.id,0);if(!1!==d.depth){M=M||f.createRenderbuffer();f.bindRenderbuffer(f.RENDERBUFFER,M);if(this.width!=M.width||this.height!=M.height)M.width=this.width,M.height=this.height,f.renderbufferStorage(f.RENDERBUFFER,f.DEPTH_COMPONENT16,this.width,this.height);f.framebufferRenderbuffer(f.FRAMEBUFFER,f.DEPTH_ATTACHMENT,f.RENDERBUFFER,M)}a();f.bindFramebuffer(f.FRAMEBUFFER,null);f.bindRenderbuffer(f.RENDERBUFFER,
  160. null);f.viewport(c[0],c[1],c[2],c[3])},swapWith:function(a){var k;k=a.id;a.id=this.id;this.id=k;k=a.width;a.width=this.width;this.width=k;k=a.height;a.height=this.height;this.height=k}};a.fromImage=function(k,d){d=d||{};var c=new a(k.width,k.height,d);try{f.texImage2D(f.TEXTURE_2D,0,c.format,c.format,c.type,k)}catch(A){if("file:"==window.location.protocol)throw'image not loaded for security reasons (serve this page over "http://" instead)';throw"image not loaded for security reasons (image must originate from the same domain as this page or use Cross-Origin Resource Sharing)";
  161. }d.minFilter&&d.minFilter!=f.NEAREST&&d.minFilter!=f.LINEAR&&f.generateMipmap(f.TEXTURE_2D);return c};a.fromURL=function(k,d){r=r||function(){var a=document.createElement("canvas").getContext("2d");a.canvas.width=a.canvas.height=128;for(var c=0;c<a.canvas.height;c+=16)for(var k=0;k<a.canvas.width;k+=16)a.fillStyle=(k^c)&16?"#FFF":"#DDD",a.fillRect(k,c,16,16);return a.canvas}();var c=a.fromImage(r,d),b=new Image,e=f;b.onload=function(){e.makeCurrent();a.fromImage(b,d).swapWith(c)};b.src=k;return c};
  162. b.prototype={add:function(a){var k=JSON.stringify(a);k in this.map||(this.map[k]=this.unique.length,this.unique.push(a));return this.map[k]}};e.prototype={compile:function(a){for(var k=[],c=0;c<this.data.length;c+=1E4)k=Array.prototype.concat.apply(k,this.data.slice(c,c+1E4));c=this.data.length?k.length/this.data.length:0;if(c!=Math.round(c))throw"buffer elements not of consistent size, average size is "+c;this.buffer=this.buffer||f.createBuffer();this.buffer.length=k.length;this.buffer.spacing=c;
  163. f.bindBuffer(this.target,this.buffer);f.bufferData(this.target,new this.type(k),a||f.STATIC_DRAW)}};h.prototype={addVertexBuffer:function(a,d){(this.vertexBuffers[d]=new e(f.ARRAY_BUFFER,Float32Array)).name=a;this[a]=[]},addIndexBuffer:function(a){this.indexBuffers[a]=new e(f.ELEMENT_ARRAY_BUFFER,Uint16Array);this[a]=[]},compile:function(){for(var a in this.vertexBuffers){var d=this.vertexBuffers[a];d.data=this[d.name];d.compile()}for(var c in this.indexBuffers)d=this.indexBuffers[c],d.data=this[c],
  164. d.compile()},transform:function(a){this.vertices=this.vertices.map(function(c){return a.transformPoint(g.fromArray(c)).toArray()});if(this.normals){var k=a.inverse().transpose();this.normals=this.normals.map(function(a){return k.transformVector(g.fromArray(a)).unit().toArray()})}this.compile();return this},computeNormals:function(){this.normals||this.addVertexBuffer("normals","gl_Normal");for(var a=0;a<this.vertices.length;a++)this.normals[a]=new g;for(a=0;a<this.triangles.length;a++){var d=this.triangles[a],
  165. c=g.fromArray(this.vertices[d[0]]),b=g.fromArray(this.vertices[d[1]]),e=g.fromArray(this.vertices[d[2]]),c=b.subtract(c).cross(e.subtract(c)).unit();this.normals[d[0]]=this.normals[d[0]].add(c);this.normals[d[1]]=this.normals[d[1]].add(c);this.normals[d[2]]=this.normals[d[2]].add(c)}for(a=0;a<this.vertices.length;a++)this.normals[a]=this.normals[a].unit().toArray();this.compile();return this},computeWireframe:function(){for(var a=new b,d=0;d<this.triangles.length;d++)for(var c=this.triangles[d],e=
  166. 0;e<c.length;e++){var f=c[e],h=c[(e+1)%c.length];a.add([Math.min(f,h),Math.max(f,h)])}this.lines||this.addIndexBuffer("lines");this.lines=a.unique;this.compile();return this},getAABB:function(){var a={min:new g(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)};a.max=a.min.negative();for(var d=0;d<this.vertices.length;d++){var c=g.fromArray(this.vertices[d]);a.min=g.min(a.min,c);a.max=g.max(a.max,c)}return a},getBoundingSphere:function(){for(var a=this.getAABB(),a={center:a.min.add(a.max).divide(2),
  167. radius:0},d=0;d<this.vertices.length;d++)a.radius=Math.max(a.radius,g.fromArray(this.vertices[d]).subtract(a.center).length());return a}};h.plane=function(a){a=a||{};var k=new h(a),c=a.detailX||a.detail||1;a=a.detailY||a.detail||1;for(var b=0;b<=a;b++)for(var e=b/a,f=0;f<=c;f++){var g=f/c;k.vertices.push([2*g-1,2*e-1,0]);k.coords&&k.coords.push([g,e]);k.normals&&k.normals.push([0,0,1]);f<c&&b<a&&(g=f+b*(c+1),k.triangles.push([g,g+1,g+c+1]),k.triangles.push([g+c+1,g+1,g+c+2]))}k.compile();return k};
  168. var B=[[0,4,2,6,-1,0,0],[1,3,5,7,1,0,0],[0,1,4,5,0,-1,0],[2,6,3,7,0,1,0],[0,2,1,3,0,0,-1],[4,5,6,7,0,0,1]];h.cube=function(a){a=new h(a);for(var k=0;k<B.length;k++){for(var c=B[k],b=4*k,e=0;4>e;e++)a.vertices.push(m(c[e]).toArray()),a.coords&&a.coords.push([e&1,(e&2)/2]),a.normals&&a.normals.push(c.slice(4,7));a.triangles.push([b,b+1,b+2]);a.triangles.push([b+2,b+1,b+3])}a.compile();return a};h.sphere=function(a){function k(a,c,k){return n?[a,k,c]:[a,c,k]}a=a||{};var c=new h(a),e=new b;a=a.detail||
  169. 6;for(var f=0;8>f;f++)for(var l=m(f),n=0<l.x*l.y*l.z,p=[],r=0;r<=a;r++){for(var z=0;r+z<=a;z++){var D=r/a,q=z/a,E=(a-r-z)/a,q={vertex:(new g(D+(D-D*D)/2,q+(q-q*q)/2,E+(E-E*E)/2)).unit().multiply(l).toArray()};c.coords&&(q.coord=0<l.y?[1-D,E]:[E,1-D]);p.push(e.add(q))}if(0<r)for(z=0;r+z<=a;z++)D=(r-1)*(a+1)+(r-1-(r-1)*(r-1))/2+z,q=r*(a+1)+(r-r*r)/2+z,c.triangles.push(k(p[D],p[D+1],p[q])),r+z<a&&c.triangles.push(k(p[q],p[D+1],p[q+1]))}c.vertices=e.unique.map(function(a){return a.vertex});c.coords&&
  170. (c.coords=e.unique.map(function(a){return a.coord}));c.normals&&(c.normals=c.vertices);c.compile();return c};h.load=function(a,d){d=d||{};"coords"in d||(d.coords=!!a.coords);"normals"in d||(d.normals=!!a.normals);"colors"in d||(d.colors=!!a.colors);"triangles"in d||(d.triangles=!!a.triangles);"lines"in d||(d.lines=!!a.lines);var c=new h(d);c.vertices=a.vertices;c.coords&&(c.coords=a.coords);c.normals&&(c.normals=a.normals);c.colors&&(c.colors=a.colors);c.triangles&&(c.triangles=a.triangles);c.lines&&
  171. (c.lines=a.lines);c.compile();return c};g.prototype={negative:function(){return new g(-this.x,-this.y,-this.z)},add:function(a){return a instanceof g?new g(this.x+a.x,this.y+a.y,this.z+a.z):new g(this.x+a,this.y+a,this.z+a)},subtract:function(a){return a instanceof g?new g(this.x-a.x,this.y-a.y,this.z-a.z):new g(this.x-a,this.y-a,this.z-a)},multiply:function(a){return a instanceof g?new g(this.x*a.x,this.y*a.y,this.z*a.z):new g(this.x*a,this.y*a,this.z*a)},divide:function(a){return a instanceof g?
  172. new g(this.x/a.x,this.y/a.y,this.z/a.z):new g(this.x/a,this.y/a,this.z/a)},equals:function(a){return this.x==a.x&&this.y==a.y&&this.z==a.z},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},cross:function(a){return new g(this.y*a.z-this.z*a.y,this.z*a.x-this.x*a.z,this.x*a.y-this.y*a.x)},length:function(){return Math.sqrt(this.dot(this))},unit:function(){return this.divide(this.length())},min:function(){return Math.min(Math.min(this.x,this.y),this.z)},max:function(){return Math.max(Math.max(this.x,
  173. this.y),this.z)},toAngles:function(){return{theta:Math.atan2(this.z,this.x),phi:Math.asin(this.y/this.length())}},toArray:function(a){return[this.x,this.y,this.z].slice(0,a||3)},clone:function(){return new g(this.x,this.y,this.z)},init:function(a,d,c){this.x=a;this.y=d;this.z=c;return this}};g.negative=function(a,d){d.x=-a.x;d.y=-a.y;d.z=-a.z;return d};g.add=function(a,d,c){d instanceof g?(c.x=a.x+d.x,c.y=a.y+d.y,c.z=a.z+d.z):(c.x=a.x+d,c.y=a.y+d,c.z=a.z+d);return c};g.subtract=function(a,d,c){d instanceof
  174. g?(c.x=a.x-d.x,c.y=a.y-d.y,c.z=a.z-d.z):(c.x=a.x-d,c.y=a.y-d,c.z=a.z-d);return c};g.multiply=function(a,d,c){d instanceof g?(c.x=a.x*d.x,c.y=a.y*d.y,c.z=a.z*d.z):(c.x=a.x*d,c.y=a.y*d,c.z=a.z*d);return c};g.divide=function(a,d,c){d instanceof g?(c.x=a.x/d.x,c.y=a.y/d.y,c.z=a.z/d.z):(c.x=a.x/d,c.y=a.y/d,c.z=a.z/d);return c};g.cross=function(a,d,c){c.x=a.y*d.z-a.z*d.y;c.y=a.z*d.x-a.x*d.z;c.z=a.x*d.y-a.y*d.x;return c};g.unit=function(a,d){var c=a.length();d.x=a.x/c;d.y=a.y/c;d.z=a.z/c;return d};g.fromAngles=
  175. function(a,d){return new g(Math.cos(a)*Math.cos(d),Math.sin(d),Math.sin(a)*Math.cos(d))};g.randomDirection=function(){return g.fromAngles(Math.random()*Math.PI*2,Math.asin(2*Math.random()-1))};g.min=function(a,d){return new g(Math.min(a.x,d.x),Math.min(a.y,d.y),Math.min(a.z,d.z))};g.max=function(a,d){return new g(Math.max(a.x,d.x),Math.max(a.y,d.y),Math.max(a.z,d.z))};g.lerp=function(a,d,c){return d.subtract(a).multiply(c).add(a)};g.fromArray=function(a){return new g(a[0],a[1],a[2])};p.prototype=
  176. {uniforms:function(a){f.useProgram(this.program);for(var d in a){var c=this.uniformLocations[d]||f.getUniformLocation(this.program,d);if(c){this.uniformLocations[d]=c;var b=a[d];b instanceof g?b=[b.x,b.y,b.z]:b instanceof u&&(b=b.m);var k=Object.prototype.toString.call(b);if("[object Array]"==k||"[object Float32Array]"==k)switch(b.length){case 1:f.uniform1fv(c,new Float32Array(b));break;case 2:f.uniform2fv(c,new Float32Array(b));break;case 3:f.uniform3fv(c,new Float32Array(b));break;case 4:f.uniform4fv(c,
  177. new Float32Array(b));break;case 9:f.uniformMatrix3fv(c,!1,new Float32Array([b[0],b[3],b[6],b[1],b[4],b[7],b[2],b[5],b[8]]));break;case 16:f.uniformMatrix4fv(c,!1,new Float32Array([b[0],b[4],b[8],b[12],b[1],b[5],b[9],b[13],b[2],b[6],b[10],b[14],b[3],b[7],b[11],b[15]]));break;default:throw"don't know how to load uniform \""+d+'" of length '+b.length;}else if(k=Object.prototype.toString.call(b),"[object Number]"==k||"[object Boolean]"==k)(this.isSampler[d]?f.uniform1i:f.uniform1f).call(f,c,b);else throw'attempted to set uniform "'+
  178. d+'" to invalid value '+b;}}return this},draw:function(a,b){this.drawBuffers(a.vertexBuffers,a.indexBuffers[b==f.LINES?"lines":"triangles"],2>arguments.length?f.TRIANGLES:b)},drawBuffers:function(a,b,c){var d=this.usedMatrices,k=f.modelviewMatrix,e=f.projectionMatrix,g=d.MVMI||d.NM?k.inverse():null,h=d.PMI?e.inverse():null,m=d.MVPM||d.MVPMI?e.multiply(k):null,l={};d.MVM&&(l[d.MVM]=k);d.MVMI&&(l[d.MVMI]=g);d.PM&&(l[d.PM]=e);d.PMI&&(l[d.PMI]=h);d.MVPM&&(l[d.MVPM]=m);d.MVPMI&&(l[d.MVPMI]=m.inverse());
  179. d.NM&&(k=g.m,l[d.NM]=[k[0],k[4],k[8],k[1],k[5],k[9],k[2],k[6],k[10]]);this.uniforms(l);var d=0,r;for(r in a)l=a[r],k=this.attributes[r]||f.getAttribLocation(this.program,r.replace(/^(gl_.*)$/,"LIGHTGL$1")),-1!=k&&l.buffer&&(this.attributes[r]=k,f.bindBuffer(f.ARRAY_BUFFER,l.buffer),f.enableVertexAttribArray(k),f.vertexAttribPointer(k,l.buffer.spacing,f.FLOAT,!1,0,0),d=l.buffer.length/l.buffer.spacing);for(r in this.attributes)r in a||f.disableVertexAttribArray(this.attributes[r]);!d||b&&!b.buffer||
  180. (b?(f.bindBuffer(f.ELEMENT_ARRAY_BUFFER,b.buffer),f.drawElements(c,b.buffer.length,f.UNSIGNED_SHORT,0)):f.drawArrays(c,0,d));return this}};p.fromURL=function(a,b){var c=function(a){var c=new XMLHttpRequest;c.open("GET",a,!1);c.send(null);if(200!==c.status)throw"could not load "+a;return c.responseText},d=c(a),c=c(b);return new p(d,c)};p.from=function(a,b){try{return new p(a,b)}catch(c){return p.fromURL(a,b)}};var f,y={create:function(a){a=a||{};var b=a.canvas;b||(b=document.createElement("canvas"),
  181. b.width=a.width||800,b.height=a.height||600);"alpha"in a||(a.alpha=!1);try{f=b.getContext("webgl",a)}catch(c){}try{f=f||b.getContext("experimental-webgl",a)}catch(c){}if(!f)throw"WebGL not supported";w();n();x();L();return f},keys:{},Matrix:u,Indexer:b,Buffer:e,Mesh:h,HitTest:G,Raytracer:J,Shader:p,Texture:a,Vector:g};v(document,"keydown",function(a){if(!a.altKey&&!a.ctrlKey&&!a.metaKey){var b=q(a.keyCode);b&&(y.keys[b]=!0);y.keys[a.keyCode]=!0}});v(document,"keyup",function(a){if(!a.altKey&&!a.ctrlKey&&
  182. !a.metaKey){var b=q(a.keyCode);b&&(y.keys[b]=!1);y.keys[a.keyCode]=!1}});var S=305397760,N="undefined"!=typeof Float32Array;u.prototype={inverse:function(){return u.inverse(this,new u)},transpose:function(){return u.transpose(this,new u)},multiply:function(a){return u.multiply(this,a,new u)},transformPoint:function(a){var b=this.m;return(new g(b[0]*a.x+b[1]*a.y+b[2]*a.z+b[3],b[4]*a.x+b[5]*a.y+b[6]*a.z+b[7],b[8]*a.x+b[9]*a.y+b[10]*a.z+b[11])).divide(b[12]*a.x+b[13]*a.y+b[14]*a.z+b[15])},transformVector:function(a){var b=
  183. this.m;return new g(b[0]*a.x+b[1]*a.y+b[2]*a.z,b[4]*a.x+b[5]*a.y+b[6]*a.z,b[8]*a.x+b[9]*a.y+b[10]*a.z)}};u.inverse=function(a,b){b=b||new u;var c=a.m,d=b.m;d[0]=c[5]*c[10]*c[15]-c[5]*c[14]*c[11]-c[6]*c[9]*c[15]+c[6]*c[13]*c[11]+c[7]*c[9]*c[14]-c[7]*c[13]*c[10];d[1]=-c[1]*c[10]*c[15]+c[1]*c[14]*c[11]+c[2]*c[9]*c[15]-c[2]*c[13]*c[11]-c[3]*c[9]*c[14]+c[3]*c[13]*c[10];d[2]=c[1]*c[6]*c[15]-c[1]*c[14]*c[7]-c[2]*c[5]*c[15]+c[2]*c[13]*c[7]+c[3]*c[5]*c[14]-c[3]*c[13]*c[6];d[3]=-c[1]*c[6]*c[11]+c[1]*c[10]*
  184. c[7]+c[2]*c[5]*c[11]-c[2]*c[9]*c[7]-c[3]*c[5]*c[10]+c[3]*c[9]*c[6];d[4]=-c[4]*c[10]*c[15]+c[4]*c[14]*c[11]+c[6]*c[8]*c[15]-c[6]*c[12]*c[11]-c[7]*c[8]*c[14]+c[7]*c[12]*c[10];d[5]=c[0]*c[10]*c[15]-c[0]*c[14]*c[11]-c[2]*c[8]*c[15]+c[2]*c[12]*c[11]+c[3]*c[8]*c[14]-c[3]*c[12]*c[10];d[6]=-c[0]*c[6]*c[15]+c[0]*c[14]*c[7]+c[2]*c[4]*c[15]-c[2]*c[12]*c[7]-c[3]*c[4]*c[14]+c[3]*c[12]*c[6];d[7]=c[0]*c[6]*c[11]-c[0]*c[10]*c[7]-c[2]*c[4]*c[11]+c[2]*c[8]*c[7]+c[3]*c[4]*c[10]-c[3]*c[8]*c[6];d[8]=c[4]*c[9]*c[15]-c[4]*
  185. c[13]*c[11]-c[5]*c[8]*c[15]+c[5]*c[12]*c[11]+c[7]*c[8]*c[13]-c[7]*c[12]*c[9];d[9]=-c[0]*c[9]*c[15]+c[0]*c[13]*c[11]+c[1]*c[8]*c[15]-c[1]*c[12]*c[11]-c[3]*c[8]*c[13]+c[3]*c[12]*c[9];d[10]=c[0]*c[5]*c[15]-c[0]*c[13]*c[7]-c[1]*c[4]*c[15]+c[1]*c[12]*c[7]+c[3]*c[4]*c[13]-c[3]*c[12]*c[5];d[11]=-c[0]*c[5]*c[11]+c[0]*c[9]*c[7]+c[1]*c[4]*c[11]-c[1]*c[8]*c[7]-c[3]*c[4]*c[9]+c[3]*c[8]*c[5];d[12]=-c[4]*c[9]*c[14]+c[4]*c[13]*c[10]+c[5]*c[8]*c[14]-c[5]*c[12]*c[10]-c[6]*c[8]*c[13]+c[6]*c[12]*c[9];d[13]=c[0]*c[9]*
  186. c[14]-c[0]*c[13]*c[10]-c[1]*c[8]*c[14]+c[1]*c[12]*c[10]+c[2]*c[8]*c[13]-c[2]*c[12]*c[9];d[14]=-c[0]*c[5]*c[14]+c[0]*c[13]*c[6]+c[1]*c[4]*c[14]-c[1]*c[12]*c[6]-c[2]*c[4]*c[13]+c[2]*c[12]*c[5];d[15]=c[0]*c[5]*c[10]-c[0]*c[9]*c[6]-c[1]*c[4]*c[10]+c[1]*c[8]*c[6]+c[2]*c[4]*c[9]-c[2]*c[8]*c[5];for(var c=c[0]*d[0]+c[1]*d[4]+c[2]*d[8]+c[3]*d[12],e=0;16>e;e++)d[e]/=c;return b};u.transpose=function(a,b){b=b||new u;var c=a.m,d=b.m;d[0]=c[0];d[1]=c[4];d[2]=c[8];d[3]=c[12];d[4]=c[1];d[5]=c[5];d[6]=c[9];d[7]=c[13];
  187. d[8]=c[2];d[9]=c[6];d[10]=c[10];d[11]=c[14];d[12]=c[3];d[13]=c[7];d[14]=c[11];d[15]=c[15];return b};u.multiply=function(a,b,c){c=c||new u;a=a.m;b=b.m;var e=c.m;e[0]=a[0]*b[0]+a[1]*b[4]+a[2]*b[8]+a[3]*b[12];e[1]=a[0]*b[1]+a[1]*b[5]+a[2]*b[9]+a[3]*b[13];e[2]=a[0]*b[2]+a[1]*b[6]+a[2]*b[10]+a[3]*b[14];e[3]=a[0]*b[3]+a[1]*b[7]+a[2]*b[11]+a[3]*b[15];e[4]=a[4]*b[0]+a[5]*b[4]+a[6]*b[8]+a[7]*b[12];e[5]=a[4]*b[1]+a[5]*b[5]+a[6]*b[9]+a[7]*b[13];e[6]=a[4]*b[2]+a[5]*b[6]+a[6]*b[10]+a[7]*b[14];e[7]=a[4]*b[3]+a[5]*
  188. b[7]+a[6]*b[11]+a[7]*b[15];e[8]=a[8]*b[0]+a[9]*b[4]+a[10]*b[8]+a[11]*b[12];e[9]=a[8]*b[1]+a[9]*b[5]+a[10]*b[9]+a[11]*b[13];e[10]=a[8]*b[2]+a[9]*b[6]+a[10]*b[10]+a[11]*b[14];e[11]=a[8]*b[3]+a[9]*b[7]+a[10]*b[11]+a[11]*b[15];e[12]=a[12]*b[0]+a[13]*b[4]+a[14]*b[8]+a[15]*b[12];e[13]=a[12]*b[1]+a[13]*b[5]+a[14]*b[9]+a[15]*b[13];e[14]=a[12]*b[2]+a[13]*b[6]+a[14]*b[10]+a[15]*b[14];e[15]=a[12]*b[3]+a[13]*b[7]+a[14]*b[11]+a[15]*b[15];return c};u.identity=function(a){a=a||new u;var b=a.m;b[0]=b[5]=b[10]=b[15]=
  189. 1;b[1]=b[2]=b[3]=b[4]=b[6]=b[7]=b[8]=b[9]=b[11]=b[12]=b[13]=b[14]=0;return a};u.perspective=function(a,b,c,e,f){a=Math.tan(a*Math.PI/360)*c;b*=a;return u.frustum(-b,b,-a,a,c,e,f)};u.frustum=function(a,b,c,e,f,g,h){h=h||new u;var d=h.m;d[0]=2*f/(b-a);d[1]=0;d[2]=(b+a)/(b-a);d[3]=0;d[4]=0;d[5]=2*f/(e-c);d[6]=(e+c)/(e-c);d[7]=0;d[8]=0;d[9]=0;d[10]=-(g+f)/(g-f);d[11]=-2*g*f/(g-f);d[12]=0;d[13]=0;d[14]=-1;d[15]=0;return h};u.ortho=function(a,b,c,e,f,g,h){h=h||new u;var d=h.m;d[0]=2/(b-a);d[1]=0;d[2]=0;
  190. d[3]=-(b+a)/(b-a);d[4]=0;d[5]=2/(e-c);d[6]=0;d[7]=-(e+c)/(e-c);d[8]=0;d[9]=0;d[10]=-2/(g-f);d[11]=-(g+f)/(g-f);d[12]=0;d[13]=0;d[14]=0;d[15]=1;return h};u.scale=function(a,b,c,e){e=e||new u;var d=e.m;d[0]=a;d[1]=0;d[2]=0;d[3]=0;d[4]=0;d[5]=b;d[6]=0;d[7]=0;d[8]=0;d[9]=0;d[10]=c;d[11]=0;d[12]=0;d[13]=0;d[14]=0;d[15]=1;return e};u.translate=function(a,b,c,e){e=e||new u;var d=e.m;d[0]=1;d[1]=0;d[2]=0;d[3]=a;d[4]=0;d[5]=1;d[6]=0;d[7]=b;d[8]=0;d[9]=0;d[10]=1;d[11]=c;d[12]=0;d[13]=0;d[14]=0;d[15]=1;return e};
  191. u.rotate=function(a,b,c,e,f){if(!a||!b&&!c&&!e)return u.identity(f);f=f||new u;var d=f.m,g=Math.sqrt(b*b+c*c+e*e);a*=Math.PI/180;b/=g;c/=g;e/=g;g=Math.cos(a);a=Math.sin(a);var k=1-g;d[0]=b*b*k+g;d[1]=b*c*k-e*a;d[2]=b*e*k+c*a;d[3]=0;d[4]=c*b*k+e*a;d[5]=c*c*k+g;d[6]=c*e*k-b*a;d[7]=0;d[8]=e*b*k-c*a;d[9]=e*c*k+b*a;d[10]=e*e*k+g;d[11]=0;d[12]=0;d[13]=0;d[14]=0;d[15]=1;return f};u.lookAt=function(a,b,c,e,f,h,m,l,r,p){p=p||new u;var d=p.m;a=new g(a,b,c);e=new g(e,f,h);l=new g(m,l,r);m=a.subtract(e).unit();
  192. l=l.cross(m).unit();r=m.cross(l).unit();d[0]=l.x;d[1]=l.y;d[2]=l.z;d[3]=-l.dot(a);d[4]=r.x;d[5]=r.y;d[6]=r.z;d[7]=-r.dot(a);d[8]=m.x;d[9]=m.y;d[10]=m.z;d[11]=-m.dot(a);d[12]=0;d[13]=0;d[14]=0;d[15]=1;return p};G.prototype={mergeWith:function(a){0<a.t&&a.t<this.t&&(this.t=a.t,this.hit=a.hit,this.normal=a.normal)}};J.prototype={getRayForPixel:function(a,b){a=(a-this.viewport[0])/this.viewport[2];b=1-(b-this.viewport[1])/this.viewport[3];var c=g.lerp(this.ray00,this.ray10,a),e=g.lerp(this.ray01,this.ray11,
  193. a);return g.lerp(c,e,b).unit()}};J.hitTestBox=function(a,b,c,e){var d=c.subtract(a).divide(b),f=e.subtract(a).divide(b),h=g.min(d,f),d=g.max(d,f),h=h.max(),d=d.min();return 0<h&&h<d?(a=a.add(b.multiply(h)),c=c.add(1E-6),e=e.subtract(1E-6),new G(h,a,new g((a.x>e.x)-(a.x<c.x),(a.y>e.y)-(a.y<c.y),(a.z>e.z)-(a.z<c.z)))):null};J.hitTestSphere=function(a,b,c,e){var d=a.subtract(c),f=b.dot(b),g=2*b.dot(d),d=d.dot(d)-e*e,d=g*g-4*f*d;return 0<d?(f=(-g-Math.sqrt(d))/(2*f),a=a.add(b.multiply(f)),new G(f,a,a.subtract(c).divide(e))):
  194. null};J.hitTestTriangle=function(a,b,c,e,f){var d=e.subtract(c),g=f.subtract(c);f=d.cross(g).unit();e=f.dot(c.subtract(a))/f.dot(b);if(0<e){a=a.add(b.multiply(e));var h=a.subtract(c);c=g.dot(g);b=g.dot(d);var g=g.dot(h),k=d.dot(d),d=d.dot(h),h=c*k-b*b,k=(k*g-b*d)/h,d=(c*d-b*g)/h;if(0<=k&&0<=d&&1>=k+d)return new G(e,a,f)}return null};return y}();Blockscad=Blockscad||{};Blockscad.Toolbox={};Blockly=Blockly||{};Blockscad.Toolbox.catIDs=[];Blockscad.Toolbox.allcats="HEX_3D_PRIMITIVE HEX_2D_PRIMITIVE HEX_TRANSFORM HEX_SETOP HEX_MATH HEX_LOGIC HEX_LOOP HEX_TEXT HEX_VARIABLE HEX_PROCEDURE".split(" ");Blockscad.Toolbox.whichCatsInSimple=[0,2,3,4,8,9];Blockscad.Toolbox.colorScheme={};Blockscad.Toolbox.colorScheme.one="#006205 #209303 #26549E #7450E2 #0185E1 #BF6920 #612485 #727272 #8C7149 #900355".split(" ");Blockscad.Toolbox.colorScheme.two="#885ee3 #82af5a #23901c #377eb8 #ba9969 #afaf13 #a66658 #d761bf #999999 #b02375".split(" ");
  195. Blockscad.Toolbox.catHex=[];Blockscad.Toolbox.simpCatHex=[];Blockscad.Toolbox.setColorScheme=function(a){for(var b=0;b<Blockscad.Toolbox.allcats.length;b++)Blockscad.Toolbox[Blockscad.Toolbox.allcats[b]]=a[b],Blockscad.Toolbox.catHex[b]=a[b]};
  196. Blockscad.Toolbox.setCatColors=function(){if(Blockscad.Toolbox.catIDs.length<Blockscad.Toolbox.allcats.length)for(var a=0;a<Blockscad.Toolbox.catIDs.length;a++){var b=document.getElementById(Blockscad.Toolbox.catIDs[a]);b.style.background=Blockscad.Toolbox.catHex[Blockscad.Toolbox.whichCatsInSimple[a]]}else for(a=0;a<Blockscad.Toolbox.catIDs.length;a++)b=document.getElementById(Blockscad.Toolbox.catIDs[a]),b.style.background=Blockscad.Toolbox.catHex[a]};
  197. Blockscad.Toolbox.createToolbox=function(){Blockscad.Toolbox.cat_3D='<category name="'+Blockscad.Msg.CATEGORY_3D_SHAPES+'"><block type="sphere"><value name="RAD"><shadow type="math_number"><field name="NUM">10</field></shadow></value></block><block type="cube"><value name="XVAL"><shadow type="math_number"><field name="NUM">10</field></shadow></value><value name="YVAL"><shadow type="math_number"><field name="NUM">10</field></shadow></value><value name="ZVAL"><shadow type="math_number"><field name="NUM">10</field></shadow></value></block><block type="cylinder"><value name="RAD1"><shadow type="math_number"><field name="NUM">10</field></shadow></value><value name="RAD2"><shadow type="math_number"><field name="NUM">10</field></shadow></value><value name="HEIGHT"><shadow type="math_number"><field name="NUM">10</field></shadow></value></block><block type="torus"><value name="RAD1"><shadow type="math_number"><field name="NUM">4</field></shadow></value><value name="RAD2"><shadow type="math_number"><field name="NUM">1</field></shadow></value><value name="SIDES"><shadow type="math_number"><field name="NUM">8</field></shadow></value><value name="FACES"><shadow type="math_number"><field name="NUM">16</field></shadow></value></block></category>';
  198. Blockscad.Toolbox.cat_3D_sim='<category name="'+Blockscad.Msg.CATEGORY_3D_SHAPES+'"><block type="sphere"><value name="RAD"><shadow type="math_number"><field name="NUM">10</field></shadow></value></block><block type="cube"><value name="XVAL"><shadow type="math_number"><field name="NUM">10</field></shadow></value><value name="YVAL"><shadow type="math_number"><field name="NUM">10</field></shadow></value><value name="ZVAL"><shadow type="math_number"><field name="NUM">10</field></shadow></value></block><block type="cylinder"><value name="RAD1"><shadow type="math_number"><field name="NUM">10</field></shadow></value><value name="RAD2"><shadow type="math_number"><field name="NUM">10</field></shadow></value><value name="HEIGHT"><shadow type="math_number"><field name="NUM">10</field></shadow></value></block></category>';
  199. Blockscad.Toolbox.cat2D='<category name="'+Blockscad.Msg.CATEGORY_2D_SHAPES+'"><block type="circle"><value name="RAD"><shadow type="math_number"><field name="NUM">10</field></shadow></value></block><block type="square"><value name="XVAL"><shadow type="math_number"><field name="NUM">10</field></shadow></value><value name="YVAL"><shadow type="math_number"><field name="NUM">10</field></shadow></value></block></category>';Blockscad.Toolbox.catTransform='<category name="'+Blockscad.Msg.CATEGORY_TRANSFORMATIONS+
  200. '"><block type="translate"><value name="XVAL"><shadow type="math_number"><field name="NUM">0</field></shadow></value><value name="YVAL"><shadow type="math_number"><field name="NUM">0</field></shadow></value><value name="ZVAL"><shadow type="math_number"><field name="NUM">0</field></shadow></value></block><block type="simplerotate"><value name="XVAL"><shadow type="math_angle"><field name="NUM">0</field></shadow></value><value name="YVAL"><shadow type="math_angle"><field name="NUM">0</field></shadow></value><value name="ZVAL"><shadow type="math_angle"><field name="NUM">0</field></shadow></value></block><block type="simplemirror_new"></block><block type="scale"><value name="XVAL"><shadow type="math_number"><field name="NUM">1</field></shadow></value><value name="YVAL"><shadow type="math_number"><field name="NUM">1</field></shadow></value><value name="ZVAL"><shadow type="math_number"><field name="NUM">1</field></shadow></value></block><block type="color"><value name="COLOR"><shadow type="colour_picker"><field name="COLOUR">#ffcc00</field></shadow></value></block><block type="color_rgb"><value name="RED"><shadow type="math_number"><field name="NUM">100</field></shadow></value><value name="GREEN"><shadow type="math_number"><field name="NUM">100</field></shadow></value><value name="BLUE"><shadow type="math_number"><field name="NUM">100</field></shadow></value></block><block type="$fn"><value name="SIDES"><shadow type="math_number"><field name="NUM">8</field></shadow></value></block><block type="taper"><value name="FACTOR"><shadow type="math_number"><field name="NUM">1</field></shadow></value></block><block type="linearextrude"><value name="HEIGHT"><shadow type="math_number"><field name="NUM">10</field></shadow></value><value name="TWIST"><shadow type="math_angle"><field name="NUM">0</field></shadow></value><value name="XSCALE"><shadow type="math_number"><field name="NUM">1</field></shadow></value><value name="YSCALE"><shadow type="math_number"><field name="NUM">1</field></shadow></value></block><block type="rotateextrude"><value name="FACES"><shadow type="math_number"><field name="NUM">5</field></shadow></value></block><block type="fancyrotate"><value name="AVAL"><shadow type="math_angle"><field name="NUM">0</field></shadow></value><value name="XVAL"><shadow type="math_number"><field name="NUM">0</field></shadow></value><value name="YVAL"><shadow type="math_number"><field name="NUM">0</field></shadow></value><value name="ZVAL"><shadow type="math_number"><field name="NUM">0</field></shadow></value></block><block type="fancymirror"><value name="XVAL"><shadow type="math_number"><field name="NUM">1</field></shadow></value><value name="YVAL"><shadow type="math_number"><field name="NUM">1</field></shadow></value><value name="ZVAL"><shadow type="math_number"><field name="NUM">1</field></shadow></value></block></category>';
  201. Blockscad.Toolbox.catTransform_sim='<category name="'+Blockscad.Msg.CATEGORY_TRANSFORMATIONS+'"><block type="translate"><value name="XVAL"><shadow type="math_number"><field name="NUM">0</field></shadow></value><value name="YVAL"><shadow type="math_number"><field name="NUM">0</field></shadow></value><value name="ZVAL"><shadow type="math_number"><field name="NUM">0</field></shadow></value></block><block type="simplerotate"><value name="XVAL"><shadow type="math_angle"><field name="NUM">0</field></shadow></value><value name="YVAL"><shadow type="math_angle"><field name="NUM">0</field></shadow></value><value name="ZVAL"><shadow type="math_angle"><field name="NUM">0</field></shadow></value></block><block type="scale"><value name="XVAL"><shadow type="math_number"><field name="NUM">1</field></shadow></value><value name="YVAL"><shadow type="math_number"><field name="NUM">1</field></shadow></value><value name="ZVAL"><shadow type="math_number"><field name="NUM">1</field></shadow></value></block><block type="color"><value name="COLOR"><shadow type="colour_picker"><field name="COLOUR">#ffcc00</field></shadow></value></block><block type="$fn"><value name="SIDES"><shadow type="math_number"><field name="NUM">8</field></shadow></value></block></category>';
  202. Blockscad.Toolbox.catSetOps='<category name="'+Blockscad.Msg.CATEGORY_SET_OPERATIONS+'"><block type="union"></block><block type="difference"></block><block type="intersection"></block><block type="hull"></block></category>';Blockscad.Toolbox.catSetOps_sim='<category name="'+Blockscad.Msg.CATEGORY_SET_OPERATIONS+'"><block type="union"></block><block type="difference"></block><block type="intersection"></block></category>';Blockscad.Toolbox.catMathLogic='<category name="'+Blockscad.Msg.CATEGORY_MATH+
  203. '"><block type="math_number"></block><block type="math_angle"></block><block type="math_arithmetic"><value name="A"><shadow type="math_number"><field name="NUM">1</field></shadow></value><value name="B"><shadow type="math_number"><field name="NUM">1</field></shadow></value></block><block type="math_single"><value name="NUM"><shadow type="math_number"><field name="NUM">9</field></shadow></value></block><block type="math_trig"><value name="NUM"><shadow type="math_number"><field name="NUM">45</field></shadow></value></block><block type="math_constant_bs"></block><block type="math_number_property"><value name="NUMBER_TO_CHECK"><shadow type="math_number"><field name="NUM">0</field></shadow></value></block><block type="math_round"><value name="NUM"><shadow type="math_number"><field name="NUM">3.1</field></shadow></value></block><block type="math_modulo"><value name="DIVIDEND"><shadow type="math_number"><field name="NUM">64</field></shadow></value><value name="DIVISOR"><shadow type="math_number"><field name="NUM">10</field></shadow></value></block><block type="math_constrain"><value name="VALUE"><shadow type="math_number"><field name="NUM">50</field></shadow></value><value name="LOW"><shadow type="math_number"><field name="NUM">1</field></shadow></value><value name="HIGH"><shadow type="math_number"><field name="NUM">100</field></shadow></value></block><block type="math_random_int"><value name="FROM"><shadow type="math_number"><field name="NUM">1</field></shadow></value><value name="TO"><shadow type="math_number"><field name="NUM">100</field></shadow></value></block><block type="math_random_float"></block></category><category name="'+
  204. Blockscad.Msg.CATEGORY_LOGIC+'"><block type="controls_if"></block><block type="logic_compare"></block><block type="logic_operation"></block><block type="logic_negate"></block><block type="logic_boolean"></block><block type="logic_ternary"></block></category>';Blockscad.Toolbox.catMathLogic_sim='<category name="'+Blockscad.Msg.CATEGORY_MATH+'"><block type="math_number"></block><block type="math_angle"></block><block type="math_arithmetic"></block><block type="math_single"></block><block type="math_random_int"><value name="FROM"><shadow type="math_number"><field name="NUM">1</field></shadow></value><value name="TO"><shadow type="math_number"><field name="NUM">100</field></shadow></value></block></category>';
  205. Blockscad.Toolbox.catLoops='<category name="'+Blockscad.Msg.CATEGORY_LOOPS+'"><block type="controls_for"><value name="FROM"><shadow type="math_number"><field name="NUM">1</field></shadow> </value><value name="TO"><shadow type="math_number"><field name="NUM">10</field></shadow></value><value name="BY"><shadow type="math_number"><field name="NUM">1</field></shadow></value></block></category>';Blockscad.Toolbox.catOther='<category name="'+Blockscad.Msg.CATEGORY_TEXT+'"><block type="bs_text"><value name="TEXT"><shadow type="text"></shadow></value><value name="SIZE"><shadow type="math_number"><field name="NUM">10</field></shadow></value></block><block type="bs_3dtext"><value name="TEXT"><shadow type="text"></shadow></value><value name="SIZE"><shadow type="math_number"><field name="NUM">10</field></shadow></value><value name="THICKNESS"><shadow type="math_number"><field name="NUM">2</field></shadow></value></block><block type="text"></block><block type="bs_text_length"><value name="VALUE"><shadow type="text"><field name="TEXT">abc</field></shadow></value></block></category><category name="'+
  206. Blockscad.Msg.CATEGORY_VARIBLES+'" custom="VARIABLE"></category><category name="'+Blockscad.Msg.CATEGORY_PROCEDURES+'" custom="PROCEDURE"></category></xml>';Blockscad.Toolbox.catOther_sim='<category name="'+Blockscad.Msg.CATEGORY_VARIBLES+'" custom="VARIABLE"></category><category name="'+Blockscad.Msg.CATEGORY_PROCEDURES+'" custom="PROCEDURE"></category></xml>';Blockscad.Toolbox.adv='<xml id="toolbox" style="display: none">';Blockscad.Toolbox.adv+=Blockscad.Toolbox.cat_3D;Blockscad.Toolbox.adv+=Blockscad.Toolbox.cat2D;
  207. Blockscad.Toolbox.adv+=Blockscad.Toolbox.catTransform;Blockscad.Toolbox.adv+=Blockscad.Toolbox.catSetOps;Blockscad.Toolbox.adv+=Blockscad.Toolbox.catMathLogic;Blockscad.Toolbox.adv+=Blockscad.Toolbox.catLoops;Blockscad.Toolbox.adv+=Blockscad.Toolbox.catOther;Blockscad.Toolbox.sim='<xml id="toolbox" style="display: none">';Blockscad.Toolbox.sim+=Blockscad.Toolbox.cat_3D_sim;Blockscad.Toolbox.sim+=Blockscad.Toolbox.catTransform_sim;Blockscad.Toolbox.sim+=Blockscad.Toolbox.catSetOps_sim;Blockscad.Toolbox.sim+=
  208. Blockscad.Toolbox.catMathLogic_sim;Blockscad.Toolbox.sim+=Blockscad.Toolbox.catOther_sim};(function(a){var b,e,h=null,m,g,l,p,w,n,x,q,v,L,u,G,J,H,M,r=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],B=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],f=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,99,99],y=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],S=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],N=[16,17,18,0,8,7,9,6,
  209. 10,5,11,4,12,3,13,2,14,1,15],k=function(){this.list=this.next=null},d=function(){this.n=this.b=this.e=0;this.t=null},c=function(a,c,b,e,f,g){this.BMAX=16;this.N_MAX=288;this.status=0;this.root=null;this.m=0;var h=Array(this.BMAX+1),m,l,r,p,n,t,E,q=Array(this.BMAX+1),u,B,v,z=new d,x=Array(this.BMAX);p=Array(this.N_MAX);var w,y=Array(this.BMAX+1),D,A,I;I=this.root=null;for(n=0;n<h.length;n++)h[n]=0;for(n=0;n<q.length;n++)q[n]=0;for(n=0;n<x.length;n++)x[n]=null;for(n=0;n<p.length;n++)p[n]=0;for(n=0;n<
  210. y.length;n++)y[n]=0;m=256<c?a[256]:this.BMAX;u=a;B=0;n=c;do h[u[B]]++,B++;while(0<--n);if(h[0]==c)this.root=null,this.status=this.m=0;else{for(t=1;t<=this.BMAX&&0==h[t];t++);E=t;g<t&&(g=t);for(n=this.BMAX;0!=n&&0==h[n];n--);r=n;g>n&&(g=n);for(D=1<<t;t<n;t++,D<<=1)if(0>(D-=h[t])){this.status=2;this.m=g;return}if(0>(D-=h[n]))this.status=2,this.m=g;else{h[n]+=D;y[1]=t=0;u=h;B=1;for(v=2;0<--n;)y[v++]=t+=u[B++];u=a;n=B=0;do 0!=(t=u[B++])&&(p[y[t]++]=n);while(++n<c);c=y[r];y[0]=n=0;u=p;B=0;p=-1;w=q[0]=
  211. 0;v=null;for(A=0;E<=r;E++)for(a=h[E];0<a--;){for(;E>w+q[1+p];){w+=q[1+p];p++;A=(A=r-w)>g?g:A;if((l=1<<(t=E-w))>a+1)for(l-=a+1,v=E;++t<A&&!((l<<=1)<=h[++v]);)l-=h[v];w+t>m&&w<m&&(t=m-w);A=1<<t;q[1+p]=t;v=Array(A);for(l=0;l<A;l++)v[l]=new d;I=null==I?this.root=new k:I.next=new k;I.next=null;I.list=v;x[p]=v;0<p&&(y[p]=n,z.b=q[p],z.e=16+t,z.t=v,t=(n&(1<<w)-1)>>w-q[p],x[p-1][t].e=z.e,x[p-1][t].b=z.b,x[p-1][t].n=z.n,x[p-1][t].t=z.t)}z.b=E-w;B>=c?z.e=99:u[B]<b?(z.e=256>u[B]?16:15,z.n=u[B++]):(z.e=f[u[B]-
  212. b],z.n=e[u[B++]-b]);l=1<<E-w;for(t=n>>w;t<A;t+=l)v[t].e=z.e,v[t].b=z.b,v[t].n=z.n,v[t].t=z.t;for(t=1<<E-1;0!=(n&t);t>>=1)n^=t;for(n^=t;(n&(1<<w)-1)!=y[p];)w-=q[p],p--}this.m=q[1];this.status=0!=D&&1!=r?1:0}}},A=function(a){for(;w<a;){var c=p,b;b=H.length==M?-1:H.charCodeAt(M++)&255;p=c|b<<w;w+=8}},K=function(a){return p&r[a]},F=function(a){p>>=a;w-=a},O=function(a,c,d){var f,g,h;if(0==d)return 0;for(h=0;;){A(G);g=L.list[K(G)];for(f=g.e;16<f;){if(99==f)return-1;F(g.b);f-=16;A(f);g=g.t[K(f)];f=g.e}F(g.b);
  213. if(16==f)e&=32767,a[c+h++]=b[e++]=g.n;else{if(15==f)break;A(f);q=g.n+K(f);F(f);A(J);g=u.list[K(J)];for(f=g.e;16<f;){if(99==f)return-1;F(g.b);f-=16;A(f);g=g.t[K(f)];f=g.e}F(g.b);A(f);v=e-g.n-K(f);for(F(f);0<q&&h<d;)q--,v&=32767,e&=32767,a[c+h++]=b[e++]=b[v++]}if(h==d)return d}n=-1;return h},R=function(a,b,e){var d,g,h,k,m,l,n,p=Array(316);for(d=0;d<p.length;d++)p[d]=0;A(5);l=257+K(5);F(5);A(5);n=1+K(5);F(5);A(4);d=4+K(4);F(4);if(286<l||30<n)return-1;for(g=0;g<d;g++)A(3),p[N[g]]=K(3),F(3);for(;19>g;g++)p[N[g]]=
  214. 0;G=7;g=new c(p,19,19,null,null,G);if(0!=g.status)return-1;L=g.root;G=g.m;k=l+n;for(d=h=0;d<k;)if(A(G),m=L.list[K(G)],g=m.b,F(g),g=m.n,16>g)p[d++]=h=g;else if(16==g){A(2);g=3+K(2);F(2);if(d+g>k)return-1;for(;0<g--;)p[d++]=h}else{17==g?(A(3),g=3+K(3),F(3)):(A(7),g=11+K(7),F(7));if(d+g>k)return-1;for(;0<g--;)p[d++]=0;h=0}G=9;g=new c(p,l,257,B,f,G);0==G&&(g.status=1);if(0!=g.status&&1==g.status)return-1;L=g.root;G=g.m;for(d=0;d<n;d++)p[d]=p[d+l];J=6;g=new c(p,n,0,y,S,J);u=g.root;J=g.m;return 0==J&&257<
  215. l||0!=g.status?-1:O(a,b,e)},V=function(a,d,k){var r,t;for(r=0;r<k&&(!x||-1!=n);){if(0<q){if(0!=n)for(;0<q&&r<k;)q--,v&=32767,e&=32767,a[d+r++]=b[e++]=b[v++];else{for(;0<q&&r<k;)q--,e&=32767,A(8),a[d+r++]=b[e++]=K(8),F(8);0==q&&(n=-1)}if(r==k)break}if(-1==n){if(x)break;A(1);0!=K(1)&&(x=!0);F(1);A(2);n=K(2);F(2);L=null;q=0}switch(n){case 0:var z=a,D=d+r,H=k-r;t=w&7;F(t);A(16);t=K(16);F(16);A(16);if(t!=(~p&65535))t=-1;else{F(16);q=t;for(t=0;0<q&&t<H;)q--,e&=32767,A(8),z[D+t++]=b[e++]=K(8),F(8);0==q&&
  216. (n=-1)}break;case 1:if(null!=L)t=O(a,d+r,k-r);else a:{var C;t=a;z=d+r;D=k-r;if(null==h){H=Array(288);for(C=0;144>C;C++)H[C]=8;for(;256>C;C++)H[C]=9;for(;280>C;C++)H[C]=7;for(;288>C;C++)H[C]=8;g=7;C=new c(H,288,257,B,f,g);if(0!=C.status){alert("HufBuild error: "+C.status);t=-1;break a}h=C.root;g=C.m;for(C=0;30>C;C++)H[C]=5;l=5;C=new c(H,30,0,y,S,l);if(1<C.status){h=null;alert("HufBuild error: "+C.status);t=-1;break a}m=C.root;l=C.m}L=h;u=m;G=g;J=l;t=O(t,z,D)}break;case 2:t=null!=L?O(a,d+r,k-r):R(a,
  217. d+r,k-r);break;default:t=-1}if(-1==t)return x?0:-1;r+=t}return r};a.RawDeflate||(a.RawDeflate={});a.RawDeflate.inflate=function(a){var c;null==b&&(b=Array(65536));w=p=e=0;n=-1;x=!1;q=v=0;L=null;H=a;M=0;for(var d=Array(1024),f=[];0<(a=V(d,0,d.length));){var g=Array(a);for(c=0;c<a;c++)g[c]=String.fromCharCode(d[c]);f[f.length]=g.join("")}H=null;return f.join("")}})(this);
  218. (function(a){var b,e,h,m,g=null,l,p,w,n,x,q,v,L,u,G,J,H,M,r,B,f,y,S,N,k,d,c,A,K,F,O,R,V,z,D,Q,E,t,I,W,aa,C,ca,Z,ra,ha,ia,X,ja,sa,da,ka,ba,la,ma,ta,ea=function(){this.dl=this.fc=0},ua=function(){this.extra_bits=this.static_tree=this.dyn_tree=null;this.max_code=this.max_length=this.elems=this.extra_base=0},T=function(a,c,b,d){this.good_length=a;this.max_lazy=c;this.nice_length=b;this.max_chain=d},Ma=function(){this.next=null;this.len=0;this.ptr=Array(8192);this.off=0},va=[0,0,0,0,0,0,0,0,1,1,1,1,2,
  219. 2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],fa=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],Na=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],Aa=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],wa=[new T(0,0,0,0),new T(4,4,8,4),new T(4,5,16,8),new T(4,6,32,32),new T(4,4,16,16),new T(8,16,32,32),new T(8,16,128,128),new T(8,32,128,256),new T(32,128,258,1024),new T(32,258,258,4096)],na=function(a){g[p+l++]=a;if(8192==p+l&&0!=l){var c;null!=b?(a=b,b=b.next):a=new Ma;a.next=null;a.len=a.off=0;null==
  220. e?e=h=a:h=h.next=a;a.len=l-p;for(c=0;c<a.len;c++)a.ptr[c]=g[p+c];l=p=0}},oa=function(a){a&=65535;8190>p+l?(g[p+l++]=a&255,g[p+l++]=a>>>8):(na(a&255),na(a>>>8))},pa=function(){J=(J<<5^n[y+3-1]&255)&8191;H=v[32768+J];v[y&32767]=H;v[32768+J]=y},Y=function(a,c){P(c[a].fc,c[a].dl)},Ba=function(a,c,b){return a[c].fc<a[b].fc||a[c].fc==a[b].fc&&C[c]<=C[b]},Ca=function(a,c,b){var d;for(d=0;d<b&&ta<ma.length;d++)a[c+d]=ma.charCodeAt(ta++)&255;return d},Da=function(a){var c=d,b=y,e,g=f,h=32506<y?y-32506:0,k=
  221. y+258,m=n[b+g-1],l=n[b+g];f>=K&&(c>>=2);do if(e=a,n[e+g]==l&&n[e+g-1]==m&&n[e]==n[b]&&n[++e]==n[b+1]){b+=2;for(e++;n[++b]==n[++e]&&n[++b]==n[++e]&&n[++b]==n[++e]&&n[++b]==n[++e]&&n[++b]==n[++e]&&n[++b]==n[++e]&&n[++b]==n[++e]&&n[++b]==n[++e]&&b<k;);e=258-(k-b);b=k-258;if(e>g){S=a;g=e;if(258<=e)break;m=n[b+g-1];l=n[b+g]}}while((a=v[a&32767])>h&&0!=--c);return g},xa=function(){var a,c,b=65536-k-y;if(-1==b)b--;else if(65274<=y){for(a=0;32768>a;a++)n[a]=n[a+32768];S-=32768;y-=32768;G-=32768;for(a=0;8192>
  222. a;a++)c=v[32768+a],v[32768+a]=32768<=c?c-32768:0;for(a=0;32768>a;a++)c=v[a],v[a]=32768<=c?c-32768:0;b+=32768}N||(a=Ca(n,y+k,b),0>=a?N=!0:k+=a)},Oa=function(a,b,g){var h;if(!m){if(!N){u=L=0;var U,q;if(0==V[0].dl){D.dyn_tree=F;D.static_tree=R;D.extra_bits=va;D.extra_base=257;D.elems=286;D.max_length=15;D.max_code=0;Q.dyn_tree=O;Q.static_tree=V;Q.extra_bits=fa;Q.extra_base=0;Q.elems=30;Q.max_length=15;Q.max_code=0;E.dyn_tree=z;E.static_tree=null;E.extra_bits=Na;E.extra_base=0;E.elems=19;E.max_length=
  223. 7;for(q=U=E.max_code=0;28>q;q++)for(ra[q]=U,h=0;h<1<<va[q];h++)ca[U++]=q;ca[U-1]=q;for(q=U=0;16>q;q++)for(ha[q]=U,h=0;h<1<<fa[q];h++)Z[U++]=q;for(U>>=7;30>q;q++)for(ha[q]=U<<7,h=0;h<1<<fa[q]-7;h++)Z[256+U++]=q;for(h=0;15>=h;h++)t[h]=0;for(h=0;143>=h;)R[h++].dl=8,t[8]++;for(;255>=h;)R[h++].dl=9,t[9]++;for(;279>=h;)R[h++].dl=7,t[7]++;for(;287>=h;)R[h++].dl=8,t[8]++;Ea(R,287);for(h=0;30>h;h++)V[h].dl=5,V[h].fc=Fa(h,5);Ga()}for(h=0;8192>h;h++)v[32768+h]=0;c=wa[A].max_lazy;K=wa[A].good_length;d=wa[A].max_chain;
  224. G=y=0;k=Ca(n,0,65536);if(0>=k)N=!0,k=0;else{for(N=!1;262>k&&!N;)xa();for(h=J=0;2>h;h++)J=(J<<5^n[h]&255)&8191}e=null;r=p=l=0;3>=A?(f=2,B=0):(B=2,r=r=0);w=!1}m=!0;if(0==k)return w=!0,0}if((h=Ha(a,b,g))==g)return g;if(w)return h;if(3>=A)for(;0!=k&&null==e;){pa();0!=H&&32506>=y-H&&(B=Da(H),B>k&&(B=k));if(3<=B)if(q=ga(y-S,B-3),k-=B,B<=c){B--;do y++,pa();while(0!=--B);y++}else y+=B,B=0,J=n[y]&255,J=(J<<5^n[y+1]&255)&8191;else q=ga(0,n[y]&255),k--,y++;q&&(qa(0),G=y);for(;262>k&&!N;)xa()}else for(;0!=k&&
  225. null==e;){pa();f=B;M=S;B=2;0!=H&&f<c&&32506>=y-H&&(B=Da(H),B>k&&(B=k),3==B&&4096<y-S&&B--);if(3<=f&&B<=f){q=ga(y-1-M,f-3);k-=f-1;f-=2;do y++,pa();while(0!=--f);r=0;B=2;y++;q&&(qa(0),G=y)}else 0!=r?ga(0,n[y-1]&255)&&(qa(0),G=y):r=1,y++,k--;for(;262>k&&!N;)xa()}0==k&&(0!=r&&ga(0,n[y-1]&255),qa(1),w=!0);return h+Ha(a,h+b,g-h)},Ha=function(a,c,d){var f,h,k;for(f=0;null!=e&&f<d;){h=d-f;h>e.len&&(h=e.len);for(k=0;k<h;k++)a[c+f+k]=e.ptr[e.off+k];e.off+=h;e.len-=h;f+=h;0==e.len&&(h=e,e=e.next,h.next=b,b=
  226. h)}if(f==d)return f;if(p<l){h=d-f;h>l-p&&(h=l-p);for(k=0;k<h;k++)a[c+f+k]=g[p+k];p+=h;f+=h;l==p&&(l=p=0)}return f},Ga=function(){var a;for(a=0;286>a;a++)F[a].fc=0;for(a=0;30>a;a++)O[a].fc=0;for(a=0;19>a;a++)z[a].fc=0;F[256].fc=1;da=X=ja=sa=ba=la=0;ka=1},ya=function(a,c){for(var b=I[c],d=c<<1;d<=W;){d<W&&Ba(a,I[d+1],I[d])&&d++;if(Ba(a,b,I[d]))break;I[c]=I[d];c=d;d<<=1}I[c]=b},Ea=function(a,c){var b=Array(16),d=0,e;for(e=1;15>=e;e++)d=d+t[e-1]<<1,b[e]=d;for(d=0;d<=c;d++)e=a[d].dl,0!=e&&(a[d].fc=Fa(b[e]++,
  227. e))},za=function(a){var c=a.dyn_tree,b=a.static_tree,d=a.elems,e,f=-1,g=d;W=0;aa=573;for(e=0;e<d;e++)0!=c[e].fc?(I[++W]=f=e,C[e]=0):c[e].dl=0;for(;2>W;)e=I[++W]=2>f?++f:0,c[e].fc=1,C[e]=0,ba--,null!=b&&(la-=b[e].dl);a.max_code=f;for(e=W>>1;1<=e;e--)ya(c,e);do e=I[1],I[1]=I[W--],ya(c,1),b=I[1],I[--aa]=e,I[--aa]=b,c[g].fc=c[e].fc+c[b].fc,C[g]=C[e]>C[b]+1?C[e]:C[b]+1,c[e].dl=c[b].dl=g,I[1]=g++,ya(c,1);while(2<=W);I[--aa]=I[1];g=a.dyn_tree;e=a.extra_bits;var d=a.extra_base,b=a.max_code,h=a.max_length,
  228. k=a.static_tree,m,l,n,r,p=0;for(l=0;15>=l;l++)t[l]=0;g[I[aa]].dl=0;for(a=aa+1;573>a;a++)m=I[a],l=g[g[m].dl].dl+1,l>h&&(l=h,p++),g[m].dl=l,m>b||(t[l]++,n=0,m>=d&&(n=e[m-d]),r=g[m].fc,ba+=r*(l+n),null!=k&&(la+=r*(k[m].dl+n)));if(0!=p){do{for(l=h-1;0==t[l];)l--;t[l]--;t[l+1]+=2;t[h]--;p-=2}while(0<p);for(l=h;0!=l;l--)for(m=t[l];0!=m;)e=I[--a],e>b||(g[e].dl!=l&&(ba+=(l-g[e].dl)*g[e].fc,g[e].fc=l),m--)}Ea(c,f)},Ia=function(a,c){var b,e=-1,d,f=a[0].dl,g=0,h=7,k=4;0==f&&(h=138,k=3);a[c+1].dl=65535;for(b=
  229. 0;b<=c;b++)d=f,f=a[b+1].dl,++g<h&&d==f||(g<k?z[d].fc+=g:0!=d?(d!=e&&z[d].fc++,z[16].fc++):10>=g?z[17].fc++:z[18].fc++,g=0,e=d,0==f?(h=138,k=3):d==f?(h=6,k=3):(h=7,k=4))},Ja=function(a,c){var b,e=-1,d,f=a[0].dl,g=0,h=7,k=4;0==f&&(h=138,k=3);for(b=0;b<=c;b++)if(d=f,f=a[b+1].dl,!(++g<h&&d==f)){if(g<k){do Y(d,z);while(0!=--g)}else 0!=d?(d!=e&&(Y(d,z),g--),Y(16,z),P(g-3,2)):10>=g?(Y(17,z),P(g-3,3)):(Y(18,z),P(g-11,7));g=0;e=d;0==f?(h=138,k=3):d==f?(h=6,k=3):(h=7,k=4)}},qa=function(a){var c,b,d,e;e=y-G;
  230. ia[sa]=da;za(D);za(Q);Ia(F,D.max_code);Ia(O,Q.max_code);za(E);for(d=18;3<=d&&0==z[Aa[d]].dl;d--);ba+=3*(d+1)+14;c=ba+3+7>>3;b=la+3+7>>3;b<=c&&(c=b);if(e+4<=c&&0<=G)for(P(0+a,3),Ka(),oa(e),oa(~e),d=0;d<e;d++)na(n[G+d]);else if(b==c)P(2+a,3),La(R,V);else{P(4+a,3);e=D.max_code+1;c=Q.max_code+1;d+=1;P(e-257,5);P(c-1,5);P(d-4,4);for(b=0;b<d;b++)P(z[Aa[b]].dl,3);Ja(F,e-1);Ja(O,c-1);La(F,O)}Ga();0!=a&&Ka()},ga=function(a,c){q[X++]=c;0==a?F[c].fc++:(a--,F[ca[c]+256+1].fc++,O[(256>a?Z[a]:Z[256+(a>>7)])&255].fc++,
  231. x[ja++]=a,da|=ka);ka<<=1;0==(X&7)&&(ia[sa++]=da,da=0,ka=1);if(2<A&&0==(X&4095)){var b=8*X,d=y-G,e;for(e=0;30>e;e++)b+=O[e].fc*(5+fa[e]);b>>=3;if(ja<parseInt(X/2)&&b<parseInt(d/2))return!0}return 8191==X||8192==ja},La=function(a,c){var b,d=0,e=0,f=0,g=0,h,k;if(0!=X){do 0==(d&7)&&(g=ia[f++]),b=q[d++]&255,0==(g&1)?Y(b,a):(h=ca[b],Y(h+256+1,a),k=va[h],0!=k&&(b-=ra[h],P(b,k)),b=x[e++],h=(256>b?Z[b]:Z[256+(b>>7)])&255,Y(h,c),k=fa[h],0!=k&&(b-=ha[h],P(b,k))),g>>=1;while(d<X)}Y(256,a)},P=function(a,c){u>
  232. 16-c?(L|=a<<u,oa(L),L=a>>16-u,u+=c-16):(L|=a<<u,u+=c)},Fa=function(a,c){var b=0;do b|=a&1,a>>=1,b<<=1;while(0<--c);return b>>1},Ka=function(){8<u?oa(L):0<u&&na(L);u=L=0};a.RawDeflate||(a.RawDeflate={});a.RawDeflate.deflate=function(a,c){var d,f;ma=a;ta=0;"undefined"==typeof c&&(c=6);(d=c)?1>d?d=1:9<d&&(d=9):d=6;A=d;N=m=!1;if(null==g){b=e=h=null;g=Array(8192);n=Array(65536);x=Array(8192);q=Array(32832);v=Array(65536);F=Array(573);for(d=0;573>d;d++)F[d]=new ea;O=Array(61);for(d=0;61>d;d++)O[d]=new ea;
  233. R=Array(288);for(d=0;288>d;d++)R[d]=new ea;V=Array(30);for(d=0;30>d;d++)V[d]=new ea;z=Array(39);for(d=0;39>d;d++)z[d]=new ea;D=new ua;Q=new ua;E=new ua;t=Array(16);I=Array(573);C=Array(573);ca=Array(256);Z=Array(512);ra=Array(29);ha=Array(30);ia=Array(1024)}for(var k=Array(1024),l=[];0<(d=Oa(k,0,k.length));){var r=Array(d);for(f=0;f<d;f++)r[f]=String.fromCharCode(k[f]);l[l.length]=r.join("")}ma=null;return l.join("")}})(this);
  234. (function(a){if(!a.Base64){var b;"undefined"!==typeof module&&module.exports&&(b=require("buffer").Buffer);var e=function(a){for(var b={},e=0,g=a.length;e<g;e++)b[a.charAt(e)]=e;return b}("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),h=String.fromCharCode,m=function(a){if(2>a.length){var b=a.charCodeAt(0);return 128>b?a:2048>b?h(192|b>>>6)+h(128|b&63):h(224|b>>>12&15)+h(128|b>>>6&63)+h(128|b&63)}b=65536+1024*(a.charCodeAt(0)-55296)+(a.charCodeAt(1)-56320);return h(240|b>>>18&
  235. 7)+h(128|b>>>12&63)+h(128|b>>>6&63)+h(128|b&63)},g=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,l=function(a){return a.replace(g,m)},p=function(a){var b=[0,2,1][a.length%3];a=a.charCodeAt(0)<<16|(1<a.length?a.charCodeAt(1):0)<<8|(2<a.length?a.charCodeAt(2):0);return["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(a>>>18),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(a>>>12&63),2<=b?"=":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(a>>>
  236. 6&63),1<=b?"=":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(a&63)].join("")},w=a.btoa||function(a){return a.replace(/[\s\S]{1,3}/g,p)},n=b?function(a){return(new b(a)).toString("base64")}:function(a){return w(l(a))},x=function(a,b){return b?n(a).replace(/[+\/]/g,function(a){return"+"==a?"-":"_"}).replace(/=/g,""):n(a)},q=RegExp("[\u00c0-\u00df][\u0080-\u00bf]|[\u00e0-\u00ef][\u0080-\u00bf]{2}|[\u00f0-\u00f7][\u0080-\u00bf]{3}","g"),v=function(a){switch(a.length){case 4:return a=
  237. ((7&a.charCodeAt(0))<<18|(63&a.charCodeAt(1))<<12|(63&a.charCodeAt(2))<<6|63&a.charCodeAt(3))-65536,h((a>>>10)+55296)+h((a&1023)+56320);case 3:return h((15&a.charCodeAt(0))<<12|(63&a.charCodeAt(1))<<6|63&a.charCodeAt(2));default:return h((31&a.charCodeAt(0))<<6|63&a.charCodeAt(1))}},L=function(a){return a.replace(q,v)},u=function(a){var b=a.length,f=b%4;a=(0<b?e[a.charAt(0)]<<18:0)|(1<b?e[a.charAt(1)]<<12:0)|(2<b?e[a.charAt(2)]<<6:0)|(3<b?e[a.charAt(3)]:0);a=[h(a>>>16),h(a>>>8&255),h(a&255)];a.length-=
  238. [0,0,2,1][f];return a.join("")},G=a.atob||function(a){return a.replace(/[\s\S]{1,4}/g,u)},J=b?function(a){return(new b(a,"base64")).toString()}:function(a){return L(G(a))},H=function(a){return J(a.replace(/[-_]/g,function(a){return"-"==a?"+":"/"}).replace(/[^A-Za-z0-9\+\/]/g,""))};a.Base64={VERSION:"2.1.1",atob:G,btoa:w,fromBase64:H,toBase64:x,utob:l,encode:x,encodeURI:function(a){return x(a,!0)},btou:L,decode:H};if("function"===typeof Object.defineProperty){var M=function(a){return{value:a,enumerable:!1,
  239. writable:!0,configurable:!0}};a.Base64.extendString=function(){Object.defineProperty(String.prototype,"fromBase64",M(function(){return H(this)}));Object.defineProperty(String.prototype,"toBase64",M(function(a){return x(this,a)}));Object.defineProperty(String.prototype,"toBase64URI",M(function(){return x(this,!0)}))}}}})(this);function importSTL(a,b){for(var e=!0,h=0;h<a.length;h++)if(0==a[h].charCodeAt(0)){e=!1;break}console.log("STL file is ascii: ",e);return e?importAsciiSTL(a,b):importBinarySTL(a,b)}
  240. function importBinarySTL(a,b){var e=[],h=new BinaryReader(a);h.seek(80);for(var m=h.readUInt32(),g=[1E4,1E4,1E4],l=[-1E4,-1E4,-1E4],p=0;p<m;p++){h.readFloat();h.readFloat();h.readFloat();var w=[];w.push(h.readFloat());w.push(h.readFloat());w.push(h.readFloat());var n=[];n.push(h.readFloat());n.push(h.readFloat());n.push(h.readFloat());var x=[];x.push(h.readFloat());x.push(h.readFloat());x.push(h.readFloat());for(var q=0,v=0;3>v;v++)isNaN(w[v])&&q++,isNaN(n[v])&&q++,isNaN(x[v])&&q++;0<q&&console.log("this many bad vertices: ",
  241. q);h.readUInt16();if(!q)for(e.push(w),e.push(n),e.push(x),v=0;3>v;v++)g[v]=Math.min(g[v],w[v]),g[v]=Math.min(g[v],n[v]),g[v]=Math.min(g[v],x[v]),l[v]=Math.max(l[v],w[v]),l[v]=Math.max(l[v],n[v]),l[v]=Math.max(l[v],x[v])}q&&console.log("WARNING: import errors: expect some missing or bad triangles\n");h=[Math.round(l[0]-(l[0]-g[0])/2),Math.round(l[1]-(l[1]-g[1])/2),Math.round(l[2]-(l[2]-g[2])/2)];return[vt2csg(e),h]}
  242. function importAsciiSTL(a,b){for(var e="",h=[],m=0,g=0,l=[1E4,1E4,1E4],p=[-1E4,-1E4,-1E4],w=a.split("\n"),n=0;n<w.length;n++)if(!w[n].match(/facet/)&&!w[n].match(/endloop/))if(w[n].match(/outer/))var m=g=0,x=[[],[],[]];else if(w[n].match(/vertex/)){w[n]=w[n].replace(/^\s+|\s+$/g,"");var q=w[n].split(" ");x[g].push(parseFloat(q[1]));x[g].push(parseFloat(q[2]));x[g].push(parseFloat(q[3]));isNaN(x[g][0])&&m++;isNaN(x[g][1])&&m++;isNaN(x[g][2])&&m++;0<m&&(console.log("this many bad vertices: ",m),console.log("things are:",
  243. q));if(!m&&3==++g)for(h.push(x[0]),h.push(x[1]),h.push(x[2]),q=0;3>q;q++)l[q]=Math.min(l[q],x[0][q]),l[q]=Math.min(l[q],x[1][q]),l[q]=Math.min(l[q],x[2][q]),p[q]=Math.max(p[q],x[0][q]),p[q]=Math.max(p[q],x[1][q]),p[q]=Math.max(p[q],x[2][q])}m=[Math.round(p[0]-(p[0]-l[0])/2),Math.round(p[1]-(p[1]-l[1])/2),Math.round(p[2]-(p[2]-l[2])/2)];e+=vt2csg(h);return[e,m]}
  244. function vt2csg(a){var b;b="CSG.fromPolygons([";for(var e=0;e<a.length/3;e++){b+="new CSG.Polygon([";for(var h=0;3>h;h++)b+="new CSG.Vertex(new CSG.Vector3D([",b+=a[3*e+h]+"]))",2>h&&(b+=",");b+="])";e<a.length/3-1&&(b+=",")}return b+"])"}var BinaryReader=function(a){this._buffer=a;this._pos=0};
  245. BinaryReader.prototype={readInt8:function(){return this._decodeInt(8,!0)},readUInt8:function(){return this._decodeInt(8,!1)},readInt16:function(){return this._decodeInt(16,!0)},readUInt16:function(){return this._decodeInt(16,!1)},readInt32:function(){return this._decodeInt(32,!0)},readUInt32:function(){return this._decodeInt(32,!1)},readFloat:function(){return this._decodeFloat(23,8)},readDouble:function(){return this._decodeFloat(52,11)},readChar:function(){return this.readString(1)},readString:function(a){this._checkSize(8*
  246. a);var b=this._buffer.substr(this._pos,a);this._pos+=a;return b},seek:function(a){this._pos=a;this._checkSize(0)},getPosition:function(){return this._pos},getSize:function(){return this._buffer.length},_decodeFloat:function(a,b){var e=a+b+1,h=e>>3;this._checkSize(e);var e=Math.pow(2,b-1)-1,m=this._readBits(a+b,1,h),g=this._readBits(a,b,h),l=0,p=2,w=0;do for(var n=this._readByte(++w,h),x=a%8||8,q=1<<x;q>>=1;)n&q&&(l+=1/p),p*=2;while(a-=x);this._pos+=h;return g==(e<<1)+1?l?NaN:m?-Infinity:Infinity:
  247. (1+-2*m)*(g||l?g?Math.pow(2,g-e)*(1+l):Math.pow(2,-e+1)*l:0)},_decodeInt:function(a,b){var e=this._readBits(0,a,a/8),h=Math.pow(2,a);this._pos+=a/8;return b&&e>=h/2?e-h:e},_shl:function(a,b){for(++b;--b;a=1073741824==((a%=2147483648)&1073741824)?2*a:2*(a-1073741824)+2147483648);return a},_readByte:function(a,b){return this._buffer.charCodeAt(this._pos+b-a-1)&255},_readBits:function(a,b,e){var h=(a+b)%8,m=a%8,g=e-(a>>3)-1;a=e+(-(a+b)>>3);var l=g-a;b=this._readByte(g,e)>>m&(1<<(l?8-m:b))-1;for(l&&h&&
  248. (b+=(this._readByte(a++,e)&(1<<h)-1)<<(l--<<3)-m);l;)b+=this._shl(this._readByte(a++,e),(l--<<3)-m);return b},_checkSize:function(a){}};