Commit c5efbdc6 authored by amandaghassaei's avatar amandaghassaei

starting svg export

parent 84201966
This diff is collapsed.
This diff is collapsed.
......@@ -343,6 +343,8 @@
<script type="text/javascript" src="dependencies/three.js"></script>
<script type="text/javascript" src="dependencies/binary_stl_writer.js"></script>
<script type="text/javascript" src="dependencies/OrthographicTrackballControls.js"></script>
<script type="text/javascript" src="dependencies/Projector.js"></script>
<script type="text/javascript" src="dependencies/SVGRenderer.js"></script>
<script type="text/javascript" src="dependencies/underscore-min.js"></script>
<script type="text/javascript" src="dependencies/FileSaver.min.js"></script>
<script type="text/javascript" src="dependencies/SVGLoader.js"></script>
......@@ -372,6 +374,8 @@
<script type="text/javascript" src="js/dynamic/dynamicSolver.js"></script>
<script type="text/javascript" src="js/pattern.js"></script>
<script type="text/javascript" src="js/saveSTL.js"></script>
<script type="text/javascript" src="js/importer.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</head>
......@@ -405,8 +409,11 @@
</li>
<li class="divider"></li>
<li><a class="loadFile" href="#">Import... (SVG / FOLD / txt)</a></li>
<!--<li><a id="saveSVG" href="#">Save Pattern as SVG...</a></li>-->
<li class="divider"></li>
<li><a id="exportSTL" href="#">Save Simulation as STL...</a></li>
<!--<li><a id="saveSVG" href="#">Save Pattern as SVG...</a></li>-->
<li><a id="saveSVGScreenshot" href="#">Save SVG screenshot</a></li>
</ul>
</li>
<li><a id="navPattern" href="#">Pattern</a></li>
......
This diff is collapsed.
This diff is collapsed.
......@@ -12,6 +12,7 @@ $(function() {
globals = initGlobals();
globals.UI3D = init3DUI(globals);
globals.importer = initImporter(globals);
globals.model = initModel(globals);
globals.staticSolver = initStaticSolver(globals);
globals.dynamicSolver = initDynamicSolver(globals);
......
......@@ -8,6 +8,7 @@ function initThreeView(globals) {
var modelWrapper = new THREE.Object3D();
var camera = new THREE.OrthographicCamera(window.innerWidth / -2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / -2, -10000, 10000);//-40, 40);
var renderer = new THREE.WebGLRenderer({antialias: true});
var svgRenderer = new THREE.SVGRenderer();
var controls;
var depthMaterial, effectComposer, depthRenderTarget;
......@@ -187,6 +188,36 @@ function initThreeView(globals) {
controls.enableRotate = state;
}
function saveSVG(){
// svgRenderer.setClearColor(0xffffff);
svgRenderer.setSize(window.innerWidth,window.innerHeight);
svgRenderer.setQuality('high');
svgRenderer.render(scene,camera);
//get svg source.
var serializer = new XMLSerializer();
var source = serializer.serializeToString(svgRenderer.domElement);
//add name spaces.
if(!source.match(/^<svg[^>]+xmlns="http\:\/\/www\.w3\.org\/2000\/svg"/)){
source = source.replace(/^<svg/, '<svg xmlns="http://www.w3.org/2000/svg"');
}
if(!source.match(/^<svg[^>]+"http\:\/\/www\.w3\.org\/1999\/xlink"/)){
source = source.replace(/^<svg/, '<svg xmlns:xlink="http://www.w3.org/1999/xlink"');
}
//add xml declaration
source = '<?xml version="1.0" standalone="no"?>\r\n' + source;
var svgBlob = new Blob([source], {type:"image/svg+xml;charset=utf-8"});
var svgUrl = URL.createObjectURL(svgBlob);
var downloadLink = document.createElement("a");
downloadLink.href = svgUrl;
downloadLink.download = globals.filename + " : " + parseInt(globals.creasePercent*100) + "PercentFolded.svg";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
}
return {
sceneAddModel: sceneAddModel,
......@@ -199,6 +230,7 @@ function initThreeView(globals) {
scene: scene,
camera: camera,
running: running,
setScale:setScale
setScale:setScale,
saveSVG: saveSVG
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment