From 713eb30f18cfb4ecd313eec7119268b74eebeb44 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Tue, 2 Jun 2015 13:20:53 -0700 Subject: [PATCH] more require --- index.html | 102 -------- js/dependencies/analytics.js | 4 + js/main.js | 29 ++- .../{GlobalFileSaver.js => FileSaver.js} | 4 +- js/models/{AllAppPLists.js => PList.js} | 0 js/three/ThreeModel.js | 5 +- js/three/ThreeView.js | 238 +++++++++--------- 7 files changed, 156 insertions(+), 226 deletions(-) rename js/models/{GlobalFileSaver.js => FileSaver.js} (98%) rename js/models/{AllAppPLists.js => PList.js} (100%) diff --git a/index.html b/index.html index 02e08dc7..f44e533a 100644 --- a/index.html +++ b/index.html @@ -7,13 +7,6 @@ <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!--<script src="dependencies/analytics.js"></script>--> - <!--<!–UI–>--> - <!--<script src="dependencies/jquery-2.1.3.js"></script>--> - <!--<script src="dependencies/underscore.js"></script>--> - - <!--<!–backbone model/view framework–>--> - <!--<script src="dependencies/backbone.js"></script>--> - <!--flatUI bootstrap theme--> <link href="js/dependencies/flatUI/css/vendor/bootstrap.min.css" rel="stylesheet"><!-- Loading Bootstrap --> <link href="js/dependencies/flatUI/css/flat-ui.css" rel="stylesheet"><!-- Loading Flat UI --> @@ -24,106 +17,11 @@ <link href="js/dependencies/bootstrap-slider/bootstrap-slider.css" rel="stylesheet"> <!--<script src="dependencies/bootstrap-slider/bootstrap-slider.js"></script>--> - <!--<!–threeJS–>--> - <!--<script src="dependencies/three.js"></script>--> - <!--<script src="dependencies/OrbitControls.js"></script>--> - - <!--<!–stl import/export–>--> - <!--<script src="dependencies/loaders/FileSaver.min.js"></script>--> - <!--<script src="dependencies/THREE2STL.js"></script>--> - <!--<script src="dependencies/loaders/STLLoader.js"></script>--> - - <!--<!–numerical javascript–>--> - <!--<script src="dependencies/numeric-1.2.6.js"></script>--> - <!--<!– code mirror –>--> <!--<script src="dependencies/codemirror/codemirror.js"></script>--> <!--<script src="dependencies/codemirror/javascript.js"></script>--> <link rel="stylesheet" type="text/css" href="js/dependencies/codemirror/codemirror.css"> - <!--<script src="js/models/AllAppPLists.js"></script>--> - - <!--<!–multi-threading–>--> - <!--<script src="js/multiThreading/worker.js"></script>--> - <!--<script src="js/multiThreading/persistentWorkers.js"></script><!–global workers–>--> - - <!--<!–fea stuff–>--> - <!--<script src="js/fea/DmaNode.js"></script>--> - <!--<script src="js/fea/DmaBeam.js"></script>--> - - <!--<script src="js/cells/DMACell.js"></script>--> - <!--<script src="js/cells/supercells/DMASuperCell.js"></script>--> - <!--<script src="js/cells/OctaFaceCell.js"></script>--> - <!--<script src="js/cells/OctaEdgeCell.js"></script>--> - <!--<script src="js/cells/OctaRotEdgeCell.js"></script>--> - <!--<script src="js/cells/OctaVertexCell.js"></script>--> - - <!--<script src="js/cells/supercells/GIKSuperCell.js"></script>--> - <!--<script src="js/cells/DMACellFreeform.js"></script>--> - - <!--<script src="js/cells/CubeCell.js"></script>--> - <!--<script src="js/cells/GIKCell.js"></script>--> - <!--<script src="js/cells/TruncatedCubeCell.js"></script>--> - <!--<script src="js/cells/KelvinCell.js"></script>--> - <!--<!–<script src="js/cells/TetraEdgeCell.js"></script>–>--> - <!--<!–<script src="js/cells/TetraFaceCell.js"></script>–>--> - - <!--<script src="js/parts/DMAPart.js"></script>--> - <!--<script src="js/parts/GIKPart.js"></script>--> - <!--<script src="js/parts/OctaEdgeVoxPart.js"></script>--> - <!--<script src="js/parts/OctaFaceTriPart.js"></script>--> - - <!--<!–models–>--> - <!--<script src="js/three/ThreeModel.js"></script>--> - - <!--<script src="js/lattice/Lattice.js"></script>--> - <!--<script src="js/lattice/CubeLattice.js"></script>--> - <!--<script src="js/lattice/GIKLattice.js"></script>--> - <!--<script src="js/lattice/KelvinLattice.js"></script>--> - <!--<script src="js/lattice/OctaEdgeLattice.js"></script>--> - <!--<script src="js/lattice/OctaFaceLattice.js"></script>--> - <!--<script src="js/lattice/OctaFreeFormFaceLattice.js"></script>--> - <!--<script src="js/lattice/OctaRotEdgeLattice.js"></script>--> - <!--<script src="js/lattice/OctaVertexLattice.js"></script>--> - <!--<script src="js/lattice/TruncatedCubeLattice.js"></script>--> - - <!--<script src="js/three/FillGeometry.js"></script>--> - <!--<script src="js/three/BasePlane.js"></script>--> - <!--<script src="js/models/AppState.js"></script>--> - <!--<script src="js/cam/assemblers/Component.js"></script>--> - <!--<script src="js/cam/assemblers/Assembler.js"></script>--> - <!--<script src="js/cam/MachineOneBit.js"></script>--> - <!--<script src="js/cam/assemblers/StaplerAssembler.js"></script>--> - <!--<script src="js/cam/assemblers/DualStaplerAssembler.js"></script>--> - <!--<script src="js/cam/cam.js"></script>--> - <!--<script src="js/cam/ShopbotExporter.js"></script>--> - <!--<script src="js/cam/GCodeExporter.js"></script>--> - <!--<script src="js/cam/TinyGExporter.js"></script>--> - <!--<script src="js/models/GlobalFileSaver.js"></script>--> - - <!--<!–views–>--> - <!--<script src="js/menus/MenuWrapperView.js"></script>--> - <!--<script src="js/menus/Navbar.js"></script>--> - <!--<script src="js/menus/NavViewMenu.js"></script>--> - <!--<script src="js/menus/Ribbon.js"></script>--> - <!--<script src="js/menus/LatticeMenuView.js"></script>--> - <!--<script src="js/menus/ImportMenuView.js"></script>--> - <!--<script src="js/menus/PartMenuView.js"></script>--> - <!--<script src="js/menus/SketchMenuView.js"></script>--> - <!--<script src="js/menus/ScriptMenuView.js"></script>--> - <!--<script src="js/menus/ScriptView.js"></script>--> - <!--<script src="js/menus/PhysicsMenuView.js"></script>--> - <!--<script src="js/menus/MaterialMenuView.js"></script>--> - <!--<script src="js/menus/OptimizationMenuView.js"></script>--> - <!--<script src="js/menus/AssemblerMenuView.js"></script>--> - <!--<script src="js/menus/AnimationMenuView.js"></script>--> - <!--<script src="js/menus/CamMenuView.js"></script>--> - <!--<script src="js/menus/SendMenuView.js"></script>--> - - <!--<script src="js/three/Highlighter.js"></script>--> - <!--<script src="js/three/ThreeView.js"></script>--> - - <!--<script src="js/main.js"></script>--> <link rel="stylesheet" type="text/css" href="css/main.css"> <script data-main="js/main" src="js/dependencies/require.js"></script> diff --git a/js/dependencies/analytics.js b/js/dependencies/analytics.js index 3f501588..c4a27e25 100644 --- a/js/dependencies/analytics.js +++ b/js/dependencies/analytics.js @@ -2,6 +2,8 @@ * Created by aghassaei on 1/8/15. */ +define(function(){ + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) @@ -9,3 +11,5 @@ ga('create', 'UA-58379815-1', 'auto'); ga('send', 'pageview'); + +}); diff --git a/js/main.js b/js/main.js index 7cb954de..b156eb89 100644 --- a/js/main.js +++ b/js/main.js @@ -5,24 +5,45 @@ requirejs.config({ baseUrl: 'js', paths: { + analytics: 'dependencies/analytics', jquery: 'dependencies/jquery-2.1.3', underscore: 'dependencies/underscore', backbone: 'dependencies/backbone', + fileSaverLib: 'dependencies/loaders/FileSaver.min', + + //three three: 'dependencies/three', + orbitControls: 'dependencies/OrbitControls', + threeModel: 'three/ThreeModel', + threeView: 'three/ThreeView', - plist: 'models/AllAppPLists', + //models + plist: 'models/PList', appState: 'models/AppState', - lattice: 'lattice/Lattice' + lattice: 'lattice/Lattice', + fileSaver: 'models/FileSaver' + + //views + + + //UI }, shim: { three: { exports: 'THREE' + }, + orbitControls: { + deps: ['three'], + exports: 'THREE' + }, + fileSaverLib: { + exports: 'saveAs' } } }); -requirejs(['jquery', 'lattice'], function($, lattice) { - console.log(lattice); +requirejs(['fileSaver', 'analytics'], function(fileSaver) { + console.log(fileSaver); }); diff --git a/js/models/GlobalFileSaver.js b/js/models/FileSaver.js similarity index 98% rename from js/models/GlobalFileSaver.js rename to js/models/FileSaver.js index 683b5890..0679ec7b 100644 --- a/js/models/GlobalFileSaver.js +++ b/js/models/FileSaver.js @@ -3,7 +3,7 @@ */ -function GlobalFilesaver(){ +define(['fileSaverLib'], function(saveAs){ function _saveFile(data, name, extension){ var blob = new Blob([data], {type: "text/plain;charset=utf-8"}); @@ -80,4 +80,4 @@ function GlobalFilesaver(){ loadFile: loadFile, loadUser: loadUser } -} \ No newline at end of file +}); \ No newline at end of file diff --git a/js/models/AllAppPLists.js b/js/models/PList.js similarity index 100% rename from js/models/AllAppPLists.js rename to js/models/PList.js diff --git a/js/three/ThreeModel.js b/js/three/ThreeModel.js index ceb13b38..a2effd9e 100644 --- a/js/three/ThreeModel.js +++ b/js/three/ThreeModel.js @@ -3,7 +3,7 @@ */ -function ThreeModel(){ +define(['three'], function(THREE){ var camera = new THREE.PerspectiveCamera(60, window.innerWidth/window.innerHeight, 1, 10000); var scene = new THREE.Scene(); @@ -152,4 +152,5 @@ function ThreeModel(){ basePlane: basePlane, removeAllCells: removeAllCells } -} \ No newline at end of file + +}); \ No newline at end of file diff --git a/js/three/ThreeView.js b/js/three/ThreeView.js index 5661095b..4bc5b803 100644 --- a/js/three/ThreeView.js +++ b/js/three/ThreeView.js @@ -2,152 +2,158 @@ * Created by aghassaei on 1/16/15. */ -ThreeView = Backbone.View.extend({ +define(['backbone', 'threeModel', 'orbitControls', 'appState'], function(Backbone, threeModel, THREE, appState){ - events: { - "mousemove": "_mouseMoved", - "mouseup": "_mouseUp", - "mousedown": "_mouseDown", - "mouseout": "_mouseOut" - }, + var ThreeView = Backbone.View.extend({ - mouseIsDown: false,//store state of mouse click inside this el + events: { + "mousemove": "_mouseMoved", + "mouseup": "_mouseUp", + "mousedown": "_mouseDown", + "mouseout": "_mouseOut" + }, - //intersections/object highlighting - mouseProjection: new THREE.Raycaster(), - currentIntersectedPart: null, + mouseIsDown: false,//store state of mouse click inside this el - el: "#threeContainer", + //intersections/object highlighting + mouseProjection: new THREE.Raycaster(), + currentIntersectedPart: null, - controls: null, + el: "#threeContainer", - initialize: function(){ + controls: null, - _.bindAll(this, "_mouseMoved", "_animate"); + initialize: function(){ - //bind events - this.listenTo(globals.appState, "change:deleteMode change:extrudeMode change:shift", this._setControlsEnabled); + _.bindAll(this, "_mouseMoved", "_animate"); - this.controls = new THREE.OrbitControls(this.model.camera, this.$el.get(0)); - this.controls.addEventListener('change', this.model.render); + //bind events + this.listenTo(appState, "change:deleteMode change:extrudeMode change:shift", this._setControlsEnabled); - this.$el.append(this.model.domElement);//render only once + this.controls = new THREE.OrbitControls(this.model.camera, this.$el.get(0)); + this.controls.addEventListener('change', this.model.render); - this.model.render(); -// this._animate(); - }, + this.$el.append(this.model.domElement);//render only once - //////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////CONTROLS///////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// + this.model.render(); + // this._animate(); + }, - _animate: function(){ -// requestAnimationFrame(this._animate); -// this.controls.update(); - }, + //////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////CONTROLS///////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// - _setControlsEnabled: function(){ - var state = globals.appState.get("deleteMode") || globals.appState.get("shift") || globals.appState.get("extrudeMode"); - this.controls.noRotate = state; - }, + _animate: function(){ + // requestAnimationFrame(this._animate); + // this.controls.update(); + }, - //////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////MOUSE EVENTS///////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// + _setControlsEnabled: function(){ + var state = appState.get("deleteMode") || appState.get("shift") || appState.get("extrudeMode"); + this.controls.noRotate = state; + }, - _mouseOut: function(){ - globals.highlighter.setNothingHighlighted(); - this._setNoPartIntersections(); - }, + //////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////MOUSE EVENTS///////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// - _mouseUp: function(){ - this.mouseIsDown = false; - if (globals.appState.get("currentTab") == "cam" && globals.appState.get("manualSelectOrigin")){ - var position = globals.highlighter.getHighlightedObjectPosition(); - if (position){ - globals.cam.set("originPosition", position); - globals.appState.set("manualSelectOrigin", false); - return; + _mouseOut: function(){ + globals.highlighter.setNothingHighlighted(); + this._setNoPartIntersections(); + }, + + _mouseUp: function(){ + this.mouseIsDown = false; + if (appState.get("currentTab") == "cam" && appState.get("manualSelectOrigin")){ + var position = globals.highlighter.getHighlightedObjectPosition(); + if (position){ + globals.cam.set("originPosition", position); + appState.set("manualSelectOrigin", false); + return; + } } - } - if (this.currentIntersectedPart) this.currentIntersectedPart.removeFromCell(); - else globals.highlighter.addRemoveVoxel(!globals.appState.get("deleteMode")); - }, + if (this.currentIntersectedPart) this.currentIntersectedPart.removeFromCell(); + else globals.highlighter.addRemoveVoxel(!appState.get("deleteMode")); + }, - _mouseDown: function(){ - this.mouseIsDown = true; - }, + _mouseDown: function(){ + this.mouseIsDown = true; + }, - _mouseMoved: function(e){ + _mouseMoved: function(e){ - if (!globals.appState.get("highlightMode") && !(globals.appState.get("manualSelectOrigin"))) return; + if (!appState.get("highlightMode") && !(appState.get("manualSelectOrigin"))) return; - if (this.mouseIsDown && !this.controls.noRotate) {//in the middle of a camera move - globals.highlighter.setNothingHighlighted(); - this._setNoPartIntersections(); - return; - } + if (this.mouseIsDown && !this.controls.noRotate) {//in the middle of a camera move + globals.highlighter.setNothingHighlighted(); + this._setNoPartIntersections(); + return; + } - //make projection vector - var vector = new THREE.Vector2(2*(e.pageX-this.$el.offset().left)/this.$el.width()-1, 1-2*(e.pageY-this.$el.offset().top)/this.$el.height()); - this.mouseProjection.setFromCamera(vector, this.model.camera); + //make projection vector + var vector = new THREE.Vector2(2*(e.pageX-this.$el.offset().left)/this.$el.width()-1, 1-2*(e.pageY-this.$el.offset().top)/this.$el.height()); + this.mouseProjection.setFromCamera(vector, this.model.camera); - var objsToIntersect = this.model.cells.concat(this.model.basePlane); -// if (globals.highlighter.isVisible()) objsToIntersect = objsToIntersect.concat(globals.highlighter.mesh); - var intersections = this.mouseProjection.intersectObjects(objsToIntersect, false); - if (intersections.length == 0) {//no intersections - globals.highlighter.setNothingHighlighted(); - this._setNoPartIntersections(); - return; - } + var objsToIntersect = this.model.cells.concat(this.model.basePlane); + // if (globals.highlighter.isVisible()) objsToIntersect = objsToIntersect.concat(globals.highlighter.mesh); + var intersections = this.mouseProjection.intersectObjects(objsToIntersect, false); + if (intersections.length == 0) {//no intersections + globals.highlighter.setNothingHighlighted(); + this._setNoPartIntersections(); + return; + } - if(intersections[0].object == globals.highlighter.mesh) return; + if(intersections[0].object == globals.highlighter.mesh) return; - globals.highlighter.highlight(intersections[0]); + globals.highlighter.highlight(intersections[0]); - if (this.mouseIsDown) { - if (globals.appState.get("deleteMode")){ - globals.highlighter.addRemoveVoxel(false); - } else if (globals.appState.get("shift")){ - globals.highlighter.addRemoveVoxel(true); + if (this.mouseIsDown) { + if (appState.get("deleteMode")){ + globals.highlighter.addRemoveVoxel(false); + } else if (appState.get("shift")){ + globals.highlighter.addRemoveVoxel(true); + } } - } -// if (globals.appState.get("cellMode") == "part"){//additionally check for part intersections in part mode -// var partIntersections = this.mouseProjection.intersectObjects(this.model.parts, false); -// if (partIntersections.length == 0) { -// this._setNoPartIntersections(); -// return; -// } -// this._handlePartIntersections(partIntersections, intersections[0].distance); -// } - }, - - //////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////INTERSECTIONS//////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// - - _setNoPartIntersections: function(){ - if (this.currentIntersectedPart){ - this.currentIntersectedPart.unhighlight(); - this.currentIntersectedPart = null; - globals.three.render(); - } - }, + // if (appState.get("cellMode") == "part"){//additionally check for part intersections in part mode + // var partIntersections = this.mouseProjection.intersectObjects(this.model.parts, false); + // if (partIntersections.length == 0) { + // this._setNoPartIntersections(); + // return; + // } + // this._handlePartIntersections(partIntersections, intersections[0].distance); + // } + }, + + //////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////INTERSECTIONS//////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + + _setNoPartIntersections: function(){ + if (this.currentIntersectedPart){ + this.currentIntersectedPart.unhighlight(); + this.currentIntersectedPart = null; + this.model.render(); + } + }, - _handlePartIntersections: function(intersections, distanceToNearestCell){ - var part = intersections[0].object.myPart; - if (globals.highlighter.isVisible() && intersections[0].distance > distanceToNearestCell){ - this._setNoPartIntersections(); - return; - } - globals.highlighter.hide(); - if (part!= this.currentIntersectedPart){ - if (this.currentIntersectedPart) this.currentIntersectedPart.unhighlight(); - part.highlight(); - this.currentIntersectedPart = part; - globals.three.render(); + _handlePartIntersections: function(intersections, distanceToNearestCell){ + var part = intersections[0].object.myPart; + if (globals.highlighter.isVisible() && intersections[0].distance > distanceToNearestCell){ + this._setNoPartIntersections(); + return; + } + globals.highlighter.hide(); + if (part!= this.currentIntersectedPart){ + if (this.currentIntersectedPart) this.currentIntersectedPart.unhighlight(); + part.highlight(); + this.currentIntersectedPart = part; + this.model.render(); + } } - } + + }); + + return new ThreeView({model:threeModel}); }); \ No newline at end of file -- GitLab