diff --git a/01_Code/physical_computing_interface/app.js b/01_Code/physical_computing_interface/app.js index 167f8762e199a8b12b20b1b81e5ee055fb4c11c2..ade4d4a8414932059b2117b03ba9a431b98ce48c 100644 --- a/01_Code/physical_computing_interface/app.js +++ b/01_Code/physical_computing_interface/app.js @@ -10,8 +10,8 @@ var GLOBALS=new globals(utils); var three=new threejs(GLOBALS,utils,'webgl','threejs'); three.init(); -// var assembler= new Assembler(three,GLOBALS,1,50,[new THREE.Vector3(0,0,0)],[new THREE.Vector3(GLOBALS.gridSize/2.0*GLOBALS.voxelSpacing,0,0)]); -// assembler.run(); +var assembler= new Assembler(three,GLOBALS,1,50,[new THREE.Vector3(0,0,0)],[new THREE.Vector3(GLOBALS.gridSize/2.0*GLOBALS.voxelSpacing,0,0)]); +assembler.run(); //TODO ADD GRAPH STUFF AND JSON STUFF HERE diff --git a/01_Code/physical_computing_interface/assembly/assembly.js b/01_Code/physical_computing_interface/assembly/assembly.js index 550f5eda214422cfdcc15c2b54611d31fb06fa2e..2130a44342a6e872f6f60a862f213184e0ab487d 100644 --- a/01_Code/physical_computing_interface/assembly/assembly.js +++ b/01_Code/physical_computing_interface/assembly/assembly.js @@ -89,7 +89,7 @@ function Assembler(three,GLOBALS,numberOfRobots,speed,robotLocations,depositLoca this.totalNumberofSteps=[]; this.locations=[] - this.showPath=true; + this.showPath=false; this.init(); //TODO INIT LATER, CHECK IF i CAN CHANGE THIS } @@ -98,7 +98,8 @@ function Assembler(three,GLOBALS,numberOfRobots,speed,robotLocations,depositLoca Assembler.prototype.run=function(){ for( i=0;i<this.numberOfRobots;i++) { - this.assemble(i); + // this.assemble(i); + this.steps[i].push(this.startLocations[i]); } } @@ -232,6 +233,7 @@ Assembler.prototype.THREERobot=function(robotIndex,V_initial, limits,group) { this.carriedVoxel[robotIndex].position.x=x+2.5*this.voxelSpacing; this.carriedVoxel[robotIndex].position.y=y; this.carriedVoxel[robotIndex].position.z=z ; + this.carriedVoxel[robotIndex].visible=false; linkGeo.add( this.carriedVoxel[robotIndex] ); } @@ -874,7 +876,7 @@ Assembler.prototype.moveRobot=function(robotIndex,leaveVoxel,voxelLoc){ } -Assembler.prototype.move=function(robotIndex){ +Assembler.prototype.move=function(robotIndex,forward){ this.guiControls[robotIndex].x=this.path[robotIndex].points[this.path[robotIndex].currentPoint].x; this.guiControls[robotIndex].y=this.path[robotIndex].points[this.path[robotIndex].currentPoint].y; this.guiControls[robotIndex].z=this.path[robotIndex].points[this.path[robotIndex].currentPoint].z; @@ -891,7 +893,12 @@ Assembler.prototype.move=function(robotIndex){ this.target[robotIndex].position.y = this.guiControls[robotIndex].y; this.target[robotIndex].position.z = this.guiControls[robotIndex].z; - this.path[robotIndex].currentPoint++; + if(forward){ + this.path[robotIndex].currentPoint++; + }else{ + this.path[robotIndex].currentPoint--; + } + } Assembler.prototype.buildShape=function(){ @@ -940,6 +947,29 @@ Assembler.prototype.addPath=function(robotIndex,loc,carry){ this.carry[robotIndex].push(!carry); this.createPath(robotIndex,this.steps[robotIndex][this.steps[robotIndex].length-2],this.steps[robotIndex][this.steps[robotIndex].length-1]); +} + +Assembler.prototype.stepRobot=function(robotIndex,stepIndex,forward){ + if(stepIndex>0&&stepIndex<this.steps[robotIndex].length){ + var robot=this; + var voxelLoc=this.steps[robotIndex][stepIndex]; + + // if(this.carry[stepIndex]){ + // setTimeout(function(){ robot.buildVoxelAt(voxelLoc);robot.showTargetPosition(robotIndex,voxelLoc,false) }, this.path[robotIndex].timeout); + + + // }else{ + // setTimeout(function(){robot.showTargetPosition(robotIndex,voxelLoc,true) }, this.path[robotIndex].timeout); + + // } + for(var i=0;i<=robot.path[robotIndex].number;i++) + { + setTimeout(function(){ robot.move(robotIndex,forward); }, this.path[robotIndex].timeout+=this.path[robotIndex].delay); + } + + } + + } //////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1220,8 +1250,8 @@ Assembler.prototype.showTargetPosition=function(robotIndex,targetPos,show){ this.targetPositionMesh[robotIndex].position.x=targetPos.x; this.targetPositionMesh[robotIndex].position.y=targetPos.y; this.targetPositionMesh[robotIndex].position.z=targetPos.z+this.voxelSpacing/2; - this.carriedVoxel[robotIndex].visible=true; - this.targetPositionMesh[robotIndex].visible=true; + // this.carriedVoxel[robotIndex].visible=true;//todo change + // this.targetPositionMesh[robotIndex].visible=true;//todo change }else { @@ -1236,18 +1266,32 @@ Assembler.prototype.showTargetPosition=function(robotIndex,targetPos,show){ /////////////////////////////////////////////////////////////////////// document.addEventListener('addNode', function (e) { + var robotIndex=0; if(!e.detail.replay){ //first one create path - // assembler.addPath(0,new THREE.Vector3(e.detail.posX,,),true) + assembler.addPath(robotIndex,new THREE.Vector3(e.detail.posX,e.detail.posY,e.detail.posZ),true); + assembler.path[robotIndex].currentPoint=2*GLOBALS.timeStep*assembler.path[robotIndex].number; }else{ //move + assembler.path[robotIndex].currentPoint=2*GLOBALS.timeStep*assembler.path[robotIndex].number; + assembler.path[robotIndex].timeout=0; + assembler.stepRobot(robotIndex,2*GLOBALS.timeStep,true); + assembler.stepRobot(robotIndex,2*GLOBALS.timeStep+1,true); + } }, false); document.addEventListener('removeNode', function (e) { + var robotIndex=0; if(!e.detail.replay){//first one create path + assembler.addPath(robotIndex,new THREE.Vector3(e.detail.posX,e.detail.posY,e.detail.posY),false); + assembler.path[robotIndex].currentPoint=2*GLOBALS.timeStep*assembler.path[robotIndex].number; - }else{//first one create path + }else{//first one create path + assembler.path[robotIndex].currentPoint=2*GLOBALS.timeStep*assembler.path[robotIndex].number; + assembler.path[robotIndex].timeout=0; + assembler.stepRobot(robotIndex,2*GLOBALS.timeStep,false); + assembler.stepRobot(robotIndex,2*GLOBALS.timeStep+1,false); } }, false); diff --git a/01_Code/physical_computing_interface/assembly/replay.js b/01_Code/physical_computing_interface/assembly/replay.js index 187d33177b8341659b0f8df0fbb1df1637193d00..36ed6e6f237b52d6d688579675b5d46b23162423 100644 --- a/01_Code/physical_computing_interface/assembly/replay.js +++ b/01_Code/physical_computing_interface/assembly/replay.js @@ -1,7 +1,4 @@ var slider = document.getElementById("time"); -var totalTimeSteps=0; -var timeline=[]; -var timeStep=0.; slider.oninput = function() { replay(this.value); @@ -36,17 +33,15 @@ document.addEventListener('removeNode', function (e) { }, false); document.addEventListener('adjustTimeStep', function (e) { - // timeStepOccupancy.push([timeStepOccupancy[totalTimeSteps][0]]); - totalTimeSteps++; - // timeStepOccupancy[totalTimeSteps][0][e.detail.x][e.detail.y][e.detail.z]=e.detail.addRemove; + GLOBALS.totalTimeSteps++; GLOBALS.occupancy[e.detail.x][e.detail.y][e.detail.z]=e.detail.addRemove; - slider.max=totalTimeSteps; - slider.value=totalTimeSteps; - timeline.push([e.detail]); - replay(parseInt(totalTimeSteps-1)); - timeStep=parseInt(totalTimeSteps); + slider.max=GLOBALS.totalTimeSteps; + slider.value=GLOBALS.totalTimeSteps; + GLOBALS.timeline.push([e.detail]); + replay(parseInt(GLOBALS.totalTimeSteps-1)); + GLOBALS.timeStep=parseInt(GLOBALS.totalTimeSteps); }, false); @@ -54,30 +49,30 @@ document.addEventListener('adjustTimeStep', function (e) { //todo enclose to prototype function replay(currValue){ - if(currValue<timeStep){ - for(var i=timeStep;i>currValue;i--) { + if(currValue<GLOBALS.timeStep){ + for(var i=GLOBALS.timeStep;i>currValue;i--) { var ii=i-1; - for(var j=0;j<timeline[ii].length;j++) { - if(!timeline[ii][j].addRemove){ - GLOBALS.occupancy[timeline[ii][j].x][timeline[ii][j].y][timeline[ii][j].z]=true; - GLOBALS.addNode(timeline[ii][j].x,timeline[ii][j].y,timeline[ii][j].z,true); + for(var j=0;j<GLOBALS.timeline[ii].length;j++) { + if(!GLOBALS.timeline[ii][j].addRemove){ + GLOBALS.occupancy[GLOBALS.timeline[ii][j].x][GLOBALS.timeline[ii][j].y][GLOBALS.timeline[ii][j].z]=true; + GLOBALS.addNode(GLOBALS.timeline[ii][j].x,GLOBALS.timeline[ii][j].y,GLOBALS.timeline[ii][j].z,true); }else{ - GLOBALS.occupancy[timeline[ii][j].x][timeline[ii][j].y][timeline[ii][j].z]=false; - GLOBALS.removeNode(timeline[ii][j].x,timeline[ii][j].y,timeline[ii][j].z,true); + GLOBALS.occupancy[GLOBALS.timeline[ii][j].x][GLOBALS.timeline[ii][j].y][GLOBALS.timeline[ii][j].z]=false; + GLOBALS.removeNode(GLOBALS.timeline[ii][j].x,GLOBALS.timeline[ii][j].y,GLOBALS.timeline[ii][j].z,true); } } } - }else if (currValue>timeStep){ - for(var i=timeStep;i<currValue;i++) { + }else if (currValue>GLOBALS.timeStep){ + for(var i=GLOBALS.timeStep;i<currValue;i++) { var ii=i-0; - for(var j=0;j<timeline[ii].length;j++) { - if(timeline[ii][j].addRemove){ - GLOBALS.occupancy[timeline[ii][j].x][timeline[ii][j].y][timeline[ii][j].z]=true; - GLOBALS.addNode(timeline[ii][j].x,timeline[ii][j].y,timeline[ii][j].z,true); + for(var j=0;j<GLOBALS.timeline[ii].length;j++) { + if(GLOBALS.timeline[ii][j].addRemove){ + GLOBALS.occupancy[GLOBALS.timeline[ii][j].x][GLOBALS.timeline[ii][j].y][GLOBALS.timeline[ii][j].z]=true; + GLOBALS.addNode(GLOBALS.timeline[ii][j].x,GLOBALS.timeline[ii][j].y,GLOBALS.timeline[ii][j].z,true); }else{ - GLOBALS.occupancy[timeline[ii][j].x][timeline[ii][j].y][timeline[ii][j].z]=false; - GLOBALS.removeNode(timeline[ii][j].x,timeline[ii][j].y,timeline[ii][j].z,true); + GLOBALS.occupancy[GLOBALS.timeline[ii][j].x][GLOBALS.timeline[ii][j].y][GLOBALS.timeline[ii][j].z]=false; + GLOBALS.removeNode(GLOBALS.timeline[ii][j].x,GLOBALS.timeline[ii][j].y,GLOBALS.timeline[ii][j].z,true); } } @@ -88,7 +83,7 @@ function replay(currValue){ // console.log("No Replay!"); } - timeStep=parseInt(currValue); + GLOBALS.timeStep=parseInt(currValue); } \ No newline at end of file diff --git a/01_Code/physical_computing_interface/globals.js b/01_Code/physical_computing_interface/globals.js index 6a10425aa9bc2e46102c8b93643de0e0c0002dd5..f5fcdd1c54984465c0c6c112551a07aaad53fcad 100644 --- a/01_Code/physical_computing_interface/globals.js +++ b/01_Code/physical_computing_interface/globals.js @@ -232,6 +232,9 @@ function globals(utils){ } } } + this.timeStep=0; + this.totalTimeSteps=0; + this.timeline=[]; } diff --git a/01_Code/physical_computing_interface/index.html b/01_Code/physical_computing_interface/index.html index 064140a1b927f6f7283fbda30657d5534f7339ae..8b3b3dbdfa71cf323b5ea8c064d752e45beeb21a 100644 --- a/01_Code/physical_computing_interface/index.html +++ b/01_Code/physical_computing_interface/index.html @@ -114,10 +114,11 @@ <script src="./globals.js"></script> <!-- event handling and GLOBALS,UTILS --> <script src="./threejs/grid.js"></script><!-- threejs visualization --> <script src="./assembly/assembly.js"></script><!-- robot assembly --> +<script src="./assembly/replay.js"></script><!-- assembly and timestep handling --> + <script src="./app.js"></script><!-- threejs visualization --> -<script src="./assembly/replay.js"></script><!-- assembly and timestep handling --> <script src="./graph/graph.js"></script><!-- graph flow visualization--> <script src="./json/json.js"></script><!-- json --> diff --git a/01_Code/physical_computing_interface/threejs/grid.js b/01_Code/physical_computing_interface/threejs/grid.js index 90c6181e513c57c5a8bea72b6dcb277c331135b0..131c709f531156d287e2db91f67c5a0d25b696df 100644 --- a/01_Code/physical_computing_interface/threejs/grid.js +++ b/01_Code/physical_computing_interface/threejs/grid.js @@ -1,5 +1,3 @@ - - function threejs(GLOBALS,utils,containerName,container1Name){ this.camera; this.scene;