Commit 569ecf75 authored by Amanda Ghassaei's avatar Amanda Ghassaei

svg screengrab and newer version of threejs

parent a2f5ba6e
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', 'component', 'stockComponent', 'assemblerPost'], define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', 'component', 'stockComponent', 'assemblerPost'],
function(_, appState, lattice, THREE, three, cam, Component, StockComponent, AssemblerPostMethods){ function(_, appState, lattice, THREE, three, cam, Component, StockComponent, AssemblerPostMethods){
var assemblerMaterial = new THREE.MeshLambertMaterial({color:0xaaaaaa, shading: THREE.FlatShading, transparent:true, opacity:0.3}); var assemblerMaterial = new THREE.MeshLambertMaterial({color:0xaaaaaa, transparent:true, opacity:0.3});
var stlLoader = new THREE.STLLoader(); var stlLoader = new THREE.STLLoader();
function Assembler(id, json){ function Assembler(id, json){
......
...@@ -27,6 +27,8 @@ require.config({ ...@@ -27,6 +27,8 @@ require.config({
threeView: 'three/ThreeView', threeView: 'three/ThreeView',
fillGeometry: 'three/FillGeometry', fillGeometry: 'three/FillGeometry',
axes: 'three/Axes', axes: 'three/Axes',
svgRenderer: '../dependencies/svgRenderer',
threeProjector: '../dependencies/Projector',
//plist //plist
plist: 'plists/PList', plist: 'plists/PList',
...@@ -237,6 +239,14 @@ require.config({ ...@@ -237,6 +239,14 @@ require.config({
deps: ['three'], deps: ['three'],
exports: 'THREE' exports: 'THREE'
}, },
threeProjector: {
deps: ['three'],
exports: "THREE"
},
svgRenderer: {
deps: ['three', 'threeProjector'],
exports: "THREE.SVGRenderer"
},
fileSaverLib: { fileSaverLib: {
exports: 'saveAs' exports: 'saveAs'
}, },
......
...@@ -220,8 +220,8 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu ...@@ -220,8 +220,8 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu
} }
function makeMaterialObject(color, transparent){ function makeMaterialObject(color, transparent){
if (transparent) return new THREE.MeshLambertMaterial({color:color, shading:THREE.FlatShading, transparent: true, opacity:0.1}); if (transparent) return new THREE.MeshLambertMaterial({color:color, transparent: true, opacity:0.1});
return new THREE.MeshLambertMaterial({color:color, shading:THREE.FlatShading}); return new THREE.MeshLambertMaterial({color:color});
} }
function setMaterialDefaults(){ function setMaterialDefaults(){
......
...@@ -220,9 +220,16 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'], fu ...@@ -220,9 +220,16 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'], fu
break; break;
case 69://e case 69://e
// if (currentTab != "sketch") return; // if (currentTab != "sketch") return;
this.set("extrudeMode", state); // this.set("extrudeMode", state);
break; break;
case 80://p part mode case 80://p part mode
if (e.ctrlKey || e.metaKey){//command
if (e.shiftKey){
e.preventDefault();
three.saveSVG();
return;
}
}
var cellMode = this.get("cellMode"); var cellMode = this.get("cellMode");
if (cellMode == "part") this.set("cellMode", "cell"); if (cellMode == "part") this.set("cellMode", "cell");
else if (cellMode == "cell") this.set("cellMode", "part"); else if (cellMode == "cell") this.set("cellMode", "part");
......
...@@ -14,8 +14,7 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra ...@@ -14,8 +14,7 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra
jsonString = jsonString.replace(/"/g, ''); jsonString = jsonString.replace(/"/g, '');
} }
var blob = new Blob([jsonString], {type: "text/plain;charset=utf-8"}); saveData(jsonString, name, extension);
saveAs(blob, name + extension);
if (data.assembler){ if (data.assembler){
jsonString.replace(/\\"/g,"\uFFFF"); //U+ FFFF jsonString.replace(/\\"/g,"\uFFFF"); //U+ FFFF
jsonString = jsonString.replace(/\"([^"]+)\":/g,"$1:").replace(/\uFFFF/g,"\\\""); jsonString = jsonString.replace(/\"([^"]+)\":/g,"$1:").replace(/\uFFFF/g,"\\\"");
...@@ -25,6 +24,11 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra ...@@ -25,6 +24,11 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra
// }); // });
} }
function saveData(data, name, extension){
var blob = new Blob([data], {type: "text/plain;charset=utf-8"});
saveAs(blob, name + extension);
}
// function save(name){ // function save(name){
// if (!name || name == "" || name == undefined) name = "file"; // if (!name || name == "" || name == undefined) name = "file";
// var data = { // var data = {
...@@ -125,9 +129,11 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra ...@@ -125,9 +129,11 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra
object.trigger("change"); object.trigger("change");
} }
return {//return public methods return {//return public methods
// save: save, // save: save,
save: save, save: save,
saveData: saveData,
saveMaterial: saveMaterial, saveMaterial: saveMaterial,
saveMachineConfig: saveMachineConfig, saveMachineConfig: saveMachineConfig,
// saveAssembler: saveAssembler, // saveAssembler: saveAssembler,
......
...@@ -29,7 +29,6 @@ define(['three', 'underscore', 'backbone', 'lattice', 'threeModel'], ...@@ -29,7 +29,6 @@ define(['three', 'underscore', 'backbone', 'lattice', 'threeModel'],
var mesh = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial({ var mesh = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial({
color:0xf25536, color:0xf25536,
shading: THREE.FlatShading,
transparent:true, transparent:true,
opacity:0.4, opacity:0.4,
side:THREE.DoubleSide side:THREE.DoubleSide
......
...@@ -9,6 +9,8 @@ define(['underscore', 'three'], function(_, THREE){ ...@@ -9,6 +9,8 @@ define(['underscore', 'three'], function(_, THREE){
var scene = new THREE.Scene(); var scene = new THREE.Scene();
var renderer = new THREE.WebGLRenderer({antialias:true});//antialiasing is not supported in ff and on mac+chrome var renderer = new THREE.WebGLRenderer({antialias:true});//antialiasing is not supported in ff and on mac+chrome
var svgRenderer = null;
var appState; var appState;
require(['appState'], function(globalAppState){ require(['appState'], function(globalAppState){
appState = globalAppState; appState = globalAppState;
...@@ -36,7 +38,6 @@ define(['underscore', 'three'], function(_, THREE){ ...@@ -36,7 +38,6 @@ define(['underscore', 'three'], function(_, THREE){
resetCameraPosition(); resetCameraPosition();
camera.up.set(0,0,1);//set z axis as "up" camera.up.set(0,0,1);//set z axis as "up"
var fogColor = 0xcccccc;
// scene.fog = new THREE.FogExp2(fogColor, 0.001); // scene.fog = new THREE.FogExp2(fogColor, 0.001);
// lights // lights
...@@ -61,12 +62,17 @@ define(['underscore', 'three'], function(_, THREE){ ...@@ -61,12 +62,17 @@ define(['underscore', 'three'], function(_, THREE){
// renderer // renderer
renderer.setClearColor(fogColor, 1); configRenderer(renderer);
renderer.setSize(window.innerWidth, window.innerHeight);
window.addEventListener('resize', onWindowResize, false); window.addEventListener('resize', onWindowResize, false);
} }
function configRenderer(_renderer){
var fogColor = 0xcccccc;
_renderer.setClearColor(fogColor, 1);
_renderer.setSize(window.innerWidth, window.innerHeight);
}
function resetCameraPosition(){ function resetCameraPosition(){
camera.position.x = initialCameraPosition.x; camera.position.x = initialCameraPosition.x;
camera.position.y = initialCameraPosition.y; camera.position.y = initialCameraPosition.y;
...@@ -182,6 +188,19 @@ define(['underscore', 'three'], function(_, THREE){ ...@@ -182,6 +188,19 @@ define(['underscore', 'three'], function(_, THREE){
shouldRender = false; shouldRender = false;
} }
function saveSVG(){
require(['svgRenderer', 'fileSaver'], function(SVGRenderer, fileSaver){
if (svgRenderer === null) {
svgRenderer = new SVGRenderer();
}
configRenderer(svgRenderer);
svgRenderer.render(scene, camera);
var XMLS = new XMLSerializer();
var svgfile = XMLS.serializeToString(svgRenderer.domElement);
fileSaver.saveData(svgfile, "screenshot", ".svg");
})
}
return {//return public properties/methods return {//return public properties/methods
render: render, render: render,
conditionalRender: conditionalRender, conditionalRender: conditionalRender,
...@@ -204,7 +223,8 @@ define(['underscore', 'three'], function(_, THREE){ ...@@ -204,7 +223,8 @@ define(['underscore', 'three'], function(_, THREE){
removeAllCells: removeAllCells, removeAllCells: removeAllCells,
removeAllCompositeCells: removeAllCompositeCells, removeAllCompositeCells: removeAllCompositeCells,
resetCameraPosition: resetCameraPosition, resetCameraPosition: resetCameraPosition,
setThreeView: setThreeView setThreeView: setThreeView,
saveSVG: saveSVG
} }
}); });
\ No newline at end of file
...@@ -6,4 +6,7 @@ git fetch upstream ...@@ -6,4 +6,7 @@ git fetch upstream
git merge upstream/master git merge upstream/master
git push origin master git push origin master
cd ~/Research/CBAStuff/git/archives/dma cd ~/Research/CBAStuff/git/archives/dma
git fetch origin
git merge origin/master
git subtree pull -P Web/mod/dmdesign fabpeople:people/amanda.ghassaei/dmdesign master --squash git subtree pull -P Web/mod/dmdesign fabpeople:people/amanda.ghassaei/dmdesign master --squash
git push origin master
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