From 80a92a00f9c89c5012f4858b78f1f560d5780698 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Thu, 20 Aug 2015 23:41:31 -0400
Subject: [PATCH] offsets working in sim

---
 js/cam/assemblers/Assembler.js                | 10 ++++----
 js/cam/assemblers/Component.js                | 25 ++++++++++++++-----
 js/menus/templates/EditComponentMenuView.html |  2 +-
 js/plists/CamPList.js                         |  3 ++-
 4 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/js/cam/assemblers/Assembler.js b/js/cam/assemblers/Assembler.js
index a7906d52..381dc7f2 100644
--- a/js/cam/assemblers/Assembler.js
+++ b/js/cam/assemblers/Assembler.js
@@ -210,14 +210,14 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
             stock.show();
         });
         if (index.z%2 != 0) {//rotate on odd rows
-            this.components.frame.rotateTo(new THREE.Vector3(0, 0, Math.PI/2), speed, callback);
+            this.components.substrate.rotateTo(new THREE.Vector3(0, 0, Math.PI/2), speed, callback);
             return;
         }
-        this.components.frame.rotateTo(new THREE.Vector3(0, 0, 0), speed, callback);
+        this.components.substrate.rotateTo(new THREE.Vector3(0, 0, 0), speed, callback);
     };
 
     Assembler.prototype.rotateTo = function(index, speed, settings, callback){
-        this.components.frame.rotateTo(new THREE.Vector3(0, 0, Math.PI/2), speed, callback);
+        this.components.substrate.rotateTo(new THREE.Vector3(0, 0, Math.PI/2), speed, callback);
     };
     
     Assembler.prototype.releaseStock = function(index, settings){
@@ -237,11 +237,11 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
             callback();
         }
 
-        var startingPos = this.components.xAxis.getPosition().add(this.components.frame.getPosition().add(this.components.zAxis.getPosition()));//this.components.zAxis.getAbsolutePosition();//get position of end effector
+        var startingPos = this.components.xAxis.getPosition().add(this.components.yAxis.getPosition().add(this.components.zAxis.getPosition()));//this.components.zAxis.getAbsolutePosition();//get position of end effector
         speed = this._normalizeSpeed(startingPos, position, new THREE.Vector3(speed, speed, speed));//todo fix this
 
         this.components.xAxis.moveTo(position, speed.x, sketchyCallback);
-        this.components.frame.moveTo(position, speed.y, sketchyCallback);
+        this.components.yAxis.moveTo(position, speed.y, sketchyCallback);
         this.components.zAxis.moveTo(position, speed.z, sketchyCallback);
     };
     
diff --git a/js/cam/assemblers/Component.js b/js/cam/assemblers/Component.js
index 3069c7b4..f8a418fb 100644
--- a/js/cam/assemblers/Component.js
+++ b/js/cam/assemblers/Component.js
@@ -31,6 +31,7 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
     Component.prototype.makeGeometry = function(geo, material){
         this.stl = new THREE.Mesh(geo, material);
         this.object3D.add(this.stl);
+        if (this.rotary) this.stl.position.set(-this.centerOfRotation.x, -this.centerOfRotation.y, -this.centerOfRotation.z);
     };
 
     Component.prototype.addChild = function(child){
@@ -44,7 +45,19 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
         }
         this.children.push(child);
         child._addParent(this, this.id);
-        this.object3D.add(child.getObject3D());
+
+        if (this.rotary){
+            var wrapper = new THREE.Object3D();
+            wrapper.add(child.getObject3D());
+            wrapper.position.set(-this.centerOfRotation.x, -this.centerOfRotation.y, -this.centerOfRotation.z);
+            console.log("here");
+            this.secondWrapper = new THREE.Object3D();
+            this.secondWrapper.add(wrapper);
+            this.object3D.add(this.secondWrapper);
+            this.object3D.position.set(this.centerOfRotation.x, this.centerOfRotation.y, this.centerOfRotation.z);
+        } else {
+            this.object3D.add(child.getObject3D());
+        }
     };
 
     Component.prototype.checkAncestry = function(component){//return true if this is a parent/grandparent/great-grandparent...
@@ -110,7 +123,7 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
     };
 
     Component.prototype.getRotation = function(){//for rotary axes
-        return this.object3D.rotation.toVector3().clone();
+        return this.secondWrapper.rotation.toVector3().clone();
     };
 
     Component.prototype.getOrientation = function(){
@@ -191,14 +204,14 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
                 if (callback) callback();
                 return;
             } else if (remainingDist < Math.abs(increment)){
-                self.object3D.rotation.x = target.x;
-                self.object3D.rotation.y = target.y;
-                self.object3D.rotation.z = target.z;
+                self.secondWrapper.rotation.x = target.x;
+                self.secondWrapper.rotation.y = target.y;
+                self.secondWrapper.rotation.z = target.z;
                 if (callback) callback();
                 return;
             }
 
-            self.object3D.rotateOnAxis(axis.clone().normalize(), increment);
+            self.secondWrapper.rotateOnAxis(axis.clone().normalize(), increment);
             self._incrementalRotation(increment, target, axis, callback);
         }, 10);
     };
diff --git a/js/menus/templates/EditComponentMenuView.html b/js/menus/templates/EditComponentMenuView.html
index 56f5e3ea..6a430099 100644
--- a/js/menus/templates/EditComponentMenuView.html
+++ b/js/menus/templates/EditComponentMenuView.html
@@ -31,7 +31,7 @@ Parent: &nbsp;&nbsp;
         <% if (descendants.indexOf(id)<0) return; %>
         <% var component = components[id] || stock[id]; %>
         <% treeLevel++; %>
-        <div class="assemblerTree" <% if (treeLevel%2 == 0){ %> style="background-color:#ddd"<% } %> ><label style="padding-left:<%= (level-tree[editingComponent]-1)*10 + 20 %>px"><%= component.name %>
+        <div class="alternatingColorList<% if (treeLevel%2 == 0){ %> evenListItem<% } %>" ><label style="padding-left:<%= (level-tree[editingComponent]-1)*10 + 20 %>px"><%= component.name %>
             <% if(tree[editingComponent]+1 == level){ %><a data-id="<%= id %>" class="removeChild pull-right" href="#">Remove</a><% } %></label></div><br/>
     <% }); %><br/>
 
diff --git a/js/plists/CamPList.js b/js/plists/CamPList.js
index 8f251ae6..88c35637 100644
--- a/js/plists/CamPList.js
+++ b/js/plists/CamPList.js
@@ -80,7 +80,8 @@ define(['three'], function(THREE){
                         //minBound
                         //maxBound
                         parent: "frame",
-                        isStatic: true,
+                        motionVector: {x:0, y:1, z:0},
+//                        isStatic: true,
                         stl: {
                             filename: "assets/stls/stapler/frame.stl"
                         }
-- 
GitLab