API Docs for:
Show:

File: workspace\templates\dirConScript.js

  1. ;
  2. //<script>
  3.  
  4.  
  5. if( typeof(startupScripts) == 'undefined'){
  6.  
  7. var startupScripts = [
  8. function(){},
  9. function(){},
  10. function(){},
  11. function(){},
  12. function(){},
  13. function(){},
  14. function(){},
  15. function(){}
  16. ];
  17.  
  18. }
  19.  
  20.  
  21.  
  22.  
  23. // Put recieved data about assembly into here. The code handles the rest.
  24. // theXMLFile should be a string, and theSTLFiles as a binary ArrayBuffer
  25. // Any text-based STL files should be in an 8-bit encoding
  26. /**
  27. *
  28. * The function which handles the actual dir_rendering of the solution file animation
  29. * and loading in the models
  30. *
  31. * @method dir_recieveData
  32. * @for directionConfirmGlobal
  33. * @param {String} theXMLFile
  34. * @param {Object} theSTLFiles
  35. * @return {Void}
  36. *
  37. */
  38. function dir_receiveData(theXMLFile, theSTLFiles){
  39.  
  40. theXML=theXMLFile;
  41.  
  42. parts.length=0;
  43. var pos=0;
  44. var lim=theSTLFiles.length;
  45. var partGeom;
  46. var partMesh;
  47.  
  48. while(pos<lim){
  49. partGeom=null;
  50. partGeom=theSTLFiles[pos];
  51. if(partGeom===null){
  52. partGeom=parseStlBinary(fileReaders[pos].Reader.result);
  53. }
  54.  
  55. partMesh=new THREE.Mesh(
  56. partGeom,
  57. new THREE.MeshNormalMaterial()
  58. );
  59. parts.push({
  60. Mesh: partMesh,
  61. Name: fileReaders[pos].Name
  62. })
  63. scene.add(partMesh);
  64.  
  65. pos++;
  66. }
  67.  
  68. dir_renderParts();
  69.  
  70. }
  71.  
  72.  
  73.  
  74. // Gets called when the user submits the table and everything is properly filled out
  75. /**
  76. *
  77. * Is called whenever the user submits the part table and every entry has been
  78. * properly filled out.
  79. *
  80. * @method dir_sendData
  81. * @for directionConfirmGlobal
  82. * @param {String} theXMLText The contents of the disassembly directions in the webpage, as a string
  83. * in XML formatting
  84. * @return {Void}
  85. *
  86. */
  87. function dir_sendData(theXMLText){
  88.  
  89. // Do whatever you want with the resulting data to send it off, if you want
  90.  
  91.  
  92. }
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. /**
  100. *
  101. * Given an HTML element corresponding to a "confirm" button, moves the parent element
  102. * to the confirmed section of the webpage
  103. *
  104. * @method dir_confirmPair
  105. * @for directionConfirmGlobal
  106. * @param {HTML Element} theButton The confirm button of the element to be moved
  107. * @return {Void}
  108. *
  109. */
  110. function dir_confirmPair(theButton){
  111. document.getElementById("confirmed").appendChild(theButton.parentElement);
  112. theButton.innerHTML="unconfirm";
  113. theButton.onclick=function(){
  114. dir_deconfirmPair(theButton);
  115. };
  116. }
  117.  
  118.  
  119.  
  120. /**
  121. *
  122. * Given an HTML element corresponding to a "unconfirm" button, moves the parent element
  123. * to the unconfirmed section of the webpage
  124. *
  125. * @method dir_deconfirmPair
  126. * @for directionConfirmGlobal
  127. * @param {HTML Element} theButton The unconfirm button of the element to be moved
  128. * @return {Void}
  129. *
  130. */
  131. function dir_deconfirmPair(theButton){
  132. document.getElementById("unconfirmed").appendChild(theButton.parentElement);
  133. theButton.innerHTML="confirm";
  134. theButton.onclick=function(){
  135. dir_confirmPair(theButton);
  136. };
  137. }
  138.  
  139.  
  140.  
  141. /**
  142. *
  143. * Given an HTML element corresponding to a "focus" button, makes the corresponding pair
  144. * of parts to be displayed
  145. *
  146. * @method dir_changeCurrentPair
  147. * @for directionConfirmGlobal
  148. * @param {HTML Element} theButton The confirm button of the element to be moved
  149. * @return {Void}
  150. *
  151. */
  152. function dir_changeCurrentPair(theButton){
  153.  
  154. if(lastPair!==null){
  155. return;
  156. }
  157.  
  158. lastPair=currentPair;
  159. var theRef=theButton.parentElement.Ref;
  160. var theMov=theButton.parentElement.Mov;
  161. var pos=0;
  162. var lim=assemblyPairs.length;
  163. while(pos<lim){
  164. if(assemblyPairs[pos].Ref.Name===theRef & assemblyPairs[pos].Mov.Name===theMov){
  165. currentPair=assemblyPairs[pos];
  166. return;
  167. }
  168. pos++;
  169. }
  170.  
  171. }
  172.  
  173. /**
  174. *
  175. * Given a jQuery object and a string, returns the first child of the given element with
  176. * a tag equivalent to the given string.
  177. *
  178. * @method dir_grab
  179. * @for directionConfirmGlobal
  180. * @param {jQuery Object} theTree The jQuery object whose child is to be returned
  181. * @param {String} theMember The name of the tag being searched
  182. * @return {jQuery Object} The first child with the given tag. If such a child does not
  183. * exist, null is returned.
  184. *
  185. */
  186. function dir_grab(theTree,theMember){
  187.  
  188. if($(theTree).children(theMember).length!=0){
  189. return $(theTree).children(theMember)[0];
  190. }
  191. else{
  192. return null;
  193. }
  194.  
  195. }
  196.  
  197.  
  198. var time=0;
  199. var focusBox;
  200. var focusPoint;
  201.  
  202.  
  203. /**
  204. *
  205. * The dir_rendering function for the webpage
  206. *
  207. * @for directionConfirmGlobal
  208. * @return {Void}
  209. *
  210. */
  211. var dir_render = function () {
  212.  
  213. // The function that will manage frame requests
  214. requestAnimationFrame( dir_render );
  215.  
  216. if(lastPair!==null){
  217. var holder=currentPair;
  218. currentPair=lastPair;
  219. dir_dehighlight(currentPair);
  220. currentPair=holder;
  221. dir_highlight(currentPair);
  222. lastPair=null;
  223. }
  224.  
  225. currentPair.Ref.Mesh.geometry.computeBoundingBox();
  226. currentPair.Mov.Mesh.geometry.computeBoundingBox();
  227. focusBox=currentPair.Ref.Mesh.geometry.boundingBox.clone();
  228. focusBox.union(currentPair.Mov.Mesh.geometry.boundingBox);
  229.  
  230. focusPoint= new THREE.Vector3(
  231. (focusBox.min.x+focusBox.max.x)/2,
  232. (focusBox.min.y+focusBox.max.y)/2,
  233. (focusBox.min.z+focusBox.max.z)/2
  234. );
  235.  
  236. thePos.normalize();
  237.  
  238. thePos.applyEuler(theEul);
  239. theEul.set(0,0,0,'XYZ');
  240. thePos.multiplyScalar(theDistance);
  241. camera.position.copy(thePos);
  242. camera.position.add(focusPoint);
  243. camera.lookAt(focusPoint);
  244. camera.updateMatrix();
  245.  
  246. sunLight.position.set( (camera.position.x-focusPoint.x)*2+focusPoint.x,
  247. (camera.position.y-focusPoint.y)*2+focusPoint.y,
  248. (camera.position.z-focusPoint.z)*2+focusPoint.z );
  249. sunLight.target.position=focusPoint;
  250.  
  251.  
  252. time+=0.01;
  253.  
  254. dir_updateAxisLines();
  255.  
  256. // Call for the render
  257. renderer.render(scene, camera);
  258. };
  259.  
  260.  
  261.  
  262.  
  263. /**
  264. *
  265. * Accepts a string and outputs the string of all characters following the final '.' symbol
  266. * in the string. This is used internally to extract file extensions from file names.
  267. *
  268. * @method dir_grabExtension
  269. * @for directionConfirmGlobal
  270. * @param {String} theName The file name to be processed
  271. * @return {String} the extension in the given file name. If no extension is found, the
  272. * 'undefined' value is returned.
  273. *
  274. */
  275. function dir_grabExtension(theName){
  276. return (/[.]/.exec(theName)) ? /[^.]+$/.exec(theName) : undefined;
  277. }
  278.  
  279.  
  280.  
  281.  
  282.  
  283. // Returns from the given list of file readers those that have not completed loading
  284. /**
  285. *
  286. * Outputs through the console the list of FileReaders in theReaders which have
  287. * not yet completed their loading
  288. *
  289. * @method dir_whoIsLeft
  290. * @for directionConfirmGlobal
  291. * @param {FileReader Object List} theReaders The list of FileReaders to be checked
  292. * @return {Void}
  293. *
  294. */
  295. function dir_whoIsLeft(theReaders){
  296.  
  297. var pos=0;
  298. var lim=fileReaders.length;
  299. var theList=[];
  300. while(pos<lim){
  301. if(theReaders[pos].Reader.readyState!=2){
  302. theList.push(theReaders[pos].Name);
  303. }
  304. pos++;
  305. }
  306. console.log(theList);
  307.  
  308. }
  309.  
  310.  
  311.  
  312.  
  313. /**
  314. *
  315. * Accepts a fileinput event, presumably from a file upload event listener, and assigns
  316. * functions to each file reader listed in the event to be called upon the full loading
  317. * of that given reader's files
  318. *
  319. * @method dir_readMultipleFiles
  320. * @for directionConfirmGlobal
  321. * @param {Event} evt A fileinput event, to be given by a fileinput event listener
  322. * @return {Void}
  323. *
  324. */
  325. function dir_readMultipleFiles(evt) {
  326. //Retrieve all the files from the FileList object
  327. var files = evt.target.files;
  328.  
  329. if (files) {
  330. for (var i=0, f; f=files[i]; i++) {
  331.  
  332. var r = new FileReader();
  333. var extension=dir_grabExtension(f.name)[0];
  334. //console.log(f.name);
  335.  
  336. if(extension===undefined){
  337. continue;
  338. }
  339. if(extension.toLowerCase()==="stl"){
  340. r.onload = (function(f) {
  341. return function(e) {
  342. //console.log(f.name);
  343. var contents = e.target.result;
  344. if(r.result!=null){
  345. STLs.push(r.result);
  346. }
  347. dir_loadParts();
  348. };
  349. })(f);
  350. r.readAsArrayBuffer(f);
  351. fileReaders.push({Reader: r, Name: f.name});
  352. }
  353. else if(extension.toLowerCase()==="xml"){
  354. console.log(f.name);
  355. if(!(theXML===null)){
  356. console.log("Warning: More than one XML file provided");
  357. }
  358. r.onload = (function(f) {
  359. return function(e) {
  360. //console.log(f.name);
  361. var contents = e.target.result;
  362. theXML=e.target.result;
  363. dir_loadParts();
  364. };
  365. })(f);
  366. r.readAsText(f,"US-ASCII");
  367. fileReaders.push({Reader: r, Name: f.name});
  368. }
  369.  
  370. }
  371. console.log(fileReaders);
  372. }
  373. else {
  374. alert("Failed to load files");
  375. }
  376. }
  377.  
  378.  
  379.  
  380.  
  381. /**
  382. *
  383. * Called internally upon every recieved fileload event. Checks if every file reader in the
  384. * array "fileReaders" has fully read each of their files. If so, then the function converts
  385. * all recieved stl files into threeJS models and executes "dir_renderParts".
  386. *
  387. * @method dir_loadParts
  388. * @for directionConfirmGlobal
  389. * @return {Void}
  390. *
  391. */
  392. function dir_loadParts (){
  393.  
  394.  
  395. // Looks for unloaded files
  396. var pos=0;
  397. var lim=fileReaders.length;
  398. while(pos<lim){
  399. if(!(fileReaders[pos].Reader.readyState===2)){
  400. //console.log(pos);
  401. //console.log(fileReaders[pos].Name);
  402. break;
  403. }
  404. pos++;
  405. }
  406.  
  407.  
  408. // Executes if all files are loaded
  409. if(pos===lim){
  410. //console.log("ALL DONE");
  411. parts.length=0;
  412. pos=0;
  413. var partGeom=null;
  414. var partMesh;
  415. var theCenter;
  416. var ext;
  417. while(pos<lim){
  418. ext=dir_grabExtension(fileReaders[pos].Name)[0];
  419.  
  420. if(ext.toLowerCase()==="stl"){
  421.  
  422. partGeom=parseStl(fileReaders[pos].Reader.result);
  423. if(partGeom===null){
  424. partGeom=parseStlBinary(fileReaders[pos].Reader.result);
  425. }
  426.  
  427. //console.log(partGeom);
  428.  
  429. partMesh=new THREE.Mesh(
  430. partGeom,
  431. new THREE.MeshLambertMaterial(wireSettings)
  432. );
  433. parts.push({
  434. Mesh: partMesh,
  435. Name: fileReaders[pos].Name
  436. })
  437. scene.add(partMesh);
  438. }
  439.  
  440. pos++;
  441. }
  442.  
  443. dir_renderParts();
  444.  
  445. }
  446.  
  447.  
  448. }
  449.  
  450.  
  451. function dir_renderParts(){
  452.  
  453.  
  454. dir_parseData();
  455. dir_linkParts();
  456. console.log(assemblyPairs);
  457. dir_highlight(assemblyPairs[0]);
  458. lastPair=assemblyPairs[0];
  459. currentPair=assemblyPairs[0];
  460. dir_insertAssemblyPairs();
  461. dir_initAxisLines();
  462. dir_render();
  463.  
  464.  
  465. }
  466.  
  467.  
  468.  
  469. /**
  470. *
  471. * Accepts two strings, a and b, and a vector, vec, and outputs a
  472. * constructed part pair object if the two strings correspond to two
  473. * extant parts
  474. *
  475. * @method dir_linkPair
  476. * @for directionConfirmGlobal
  477. * @param {String} a The first part name
  478. * @param {String} b The second part name
  479. * @param {Vector3} vec The vector to be added to the pair
  480. * @return {Object} The resulting pair object
  481. *
  482. */
  483. function dir_linkPair(a,b,vec){
  484.  
  485. var thePair={Ref: null,
  486. Mov: null,
  487. Vec: null,
  488. Directed: null,
  489. DoublyDirected: null,
  490. InfiniteDirections: null};
  491.  
  492. //console.log(parts);
  493.  
  494. var pos=0;
  495. var lim=parts.length;
  496. while(pos<lim){
  497.  
  498. if(parts[pos].Name===a+".STL" || parts[pos].Name===a){
  499. thePair.Ref=parts[pos];
  500. }
  501. if(parts[pos].Name===b+".STL" || parts[pos].Name===b){
  502. thePair.Mov=parts[pos];
  503. }
  504. if(thePair.Ref!==null && thePair.Mov!==null){
  505. thePair.Vec=vec;
  506. return thePair;
  507. }
  508. pos++;
  509. }
  510. //console.log(thePair);
  511. return null;
  512.  
  513. }
  514.  
  515.  
  516.  
  517. /**
  518. *
  519. * Links together the pairs of parts corresponding to the strings present in
  520. * the namePairs array.
  521. *
  522. * @method dir_linkParts
  523. * @for directionConfirmGlobal
  524. * @return {Void}
  525. *
  526. */
  527. function dir_linkParts(){
  528.  
  529. var pos=0;
  530. var lim=namePairs.length;
  531. var thePair=null;
  532.  
  533. while(pos<lim){
  534. thePair=dir_linkPair(namePairs[pos].Ref,namePairs[pos].Mov,namePairs[pos].Vec);
  535.  
  536. if(thePair!=null){
  537. thePair.InfiniteDirections = namePairs[pos].InfiniteDirections;
  538. assemblyPairs.push(thePair);
  539. }
  540. pos++;
  541. }
  542. //console.log(assemblyPairs);
  543. }
  544.  
  545.  
  546. /**
  547. *
  548. * Populates the webpage with data stored int the global variable theSML
  549. *
  550. * @method dir_parseData
  551. * @for directionConfirmGlobal
  552. * @return {Void}
  553. *
  554. */
  555. function dir_parseData(){
  556.  
  557. //console.log(theXML);
  558. var doc = $.parseXML(theXML);
  559. //console.log(doc);
  560. doc = dir_grab(doc,"DirectionSaveStructure");
  561. var directions = dir_grab(doc,"Directions");
  562. directions = $(directions).children("ArrayOfDouble");
  563. var thePairs=dir_grab(doc,"arcs");
  564. //console.log(thePairs);
  565.  
  566. thePairs=$(thePairs).children("arc");
  567. //console.log(thePairs);
  568. var pos=0;
  569. var lim=thePairs.length;
  570. var thePair;
  571. var theMov;
  572. var theRef;
  573. var theVec;
  574. var vecPos;
  575. var vecLim;
  576. var directed;
  577. var docDirs;
  578. var doublyDirected;
  579. var docDubDirs;
  580. var infiniteDirections;
  581. var docInfDirs;
  582.  
  583. while(pos<lim){
  584.  
  585. theRef=dir_grab(thePairs[pos],"To");
  586. theMov=dir_grab(thePairs[pos],"From");
  587.  
  588. docDirs=dir_grab(thePairs[pos],"directed");
  589. directed=[];
  590.  
  591. docDubDirs=dir_grab(thePairs[pos],"doublyDirected");
  592. doublyDirected=[];
  593.  
  594. docInfDirs=dir_grab(thePairs[pos],"InfiniteDirections");
  595. infiniteDirections=[];
  596.  
  597. docFinDirs=dir_grab(thePairs[pos],"FiniteDirections");
  598. finiteDirections=[];
  599.  
  600.  
  601.  
  602. if($(docDirs[vecPos]).innerHTML != "false"){
  603. docDirs = $(docDirs).children("int");
  604. vecPos=0;
  605. vecLim=docDirs.length;
  606. while(vecPos<vecLim){
  607. theVec=parseInt(docDirs[vecPos].innerHTML);
  608. directed.push(theVec);
  609. vecPos++;
  610. }
  611. }
  612.  
  613.  
  614. if($(docDubDirs[vecPos]).innerHTML != "false"){
  615. docDubDirs = $(docDubDirs).children("int");
  616. vecPos=0;
  617. vecLim=docDubDirs.length;
  618. while(vecPos<vecLim){
  619. theVec=parseInt(docDubDirs[vecPos].innerHTML);
  620. doublyDirected.push(theVec);
  621. vecPos++;
  622. }
  623. }
  624.  
  625. if($(docInfDirs[vecPos]).innerHTML != "false"){
  626. docInfDirs = $(docInfDirs).children("int");
  627. vecPos=0;
  628. vecLim=docInfDirs.length;
  629. while(vecPos<vecLim){
  630. theVec=parseInt(docInfDirs[vecPos].innerHTML);
  631. infiniteDirections.push(theVec);
  632. vecPos++;
  633. }
  634. }
  635.  
  636.  
  637. theVec=dir_grab(thePairs[pos],"vector");
  638. namePairs.push({
  639. name: dir_grab(thePairs[pos],"name").innerHTML,
  640. Ref: theRef.innerHTML,
  641. Mov: theMov.innerHTML,
  642. localLabels: dir_grab(thePairs[pos],"localLabels").innerHTML,
  643. localVariables: dir_grab(thePairs[pos],"localVariables").innerHTML,
  644. Directed: dir_grab(thePairs[pos],"Directed").innerHTML,
  645. DoublyDirected: dir_grab(thePairs[pos],"DoublyDirected").innerHTML,
  646. InfiniteDirections: infiniteDirections,
  647. FiniteDirections: dir_grab(thePairs[pos],"FiniteDirections").innerHTML,
  648. Fasteners: dir_grab(thePairs[pos],"Fasteners").innerHTML,
  649. Certainty: dir_grab(thePairs[pos],"Certainty").innerHTML,
  650. ConnectionType: dir_grab(thePairs[pos],"ConnectionType").innerHTML
  651. });
  652. pos++;
  653. }
  654.  
  655. }
  656.  
  657.  
  658.  
  659. /**
  660. *
  661. * Populates the webpage with graphical representations of the assembly pairs
  662. * stored in the global variable assemblyPairs
  663. *
  664. * @method dir_insertAssemblyPairs
  665. * @for directionConfirmGlobal
  666. * @return {Void}
  667. *
  668. */
  669. function dir_insertAssemblyPairs(){
  670.  
  671. var pos=0;
  672. var lim=assemblyPairs.length;
  673. while(pos<lim){
  674. var theDiv = document.createElement("div");
  675. var theText = document.createElement("text");
  676. theText.innerHTML = assemblyPairs[pos].Ref.Name + " \n<---\n " + assemblyPairs[pos].Mov.Name;
  677. var theConfBut = document.createElement("button");
  678. theConfBut.innerHTML = "confirm";
  679. theConfBut.onclick = function (){
  680. dir_confirmPair(this);
  681. }
  682. var thedir_highlightBut = document.createElement("button");
  683. thedir_highlightBut.innerHTML = "focus";
  684. thedir_highlightBut.onclick = (function(position){
  685. return function(){
  686. lastPair=currentPair;
  687. console.log("assigning currentPair");
  688. console.log(position);
  689. console.log(assemblyPairs[position]);
  690. currentPair=assemblyPairs[position];
  691. console.log ("Doing the focus thing");
  692. }
  693. })(pos);
  694. theText.className="pairText";
  695. theConfBut.className="dirButton";
  696. thedir_highlightBut.className="dirButton";
  697. theDiv.appendChild(theText);
  698. theDiv.appendChild(document.createElement("br"));
  699. theDiv.appendChild(thedir_highlightBut);
  700. theDiv.appendChild(theConfBut);
  701. theDiv.className="dirPair";
  702. document.getElementById("unconfirmed").appendChild(theDiv);
  703. pos++;
  704. }
  705. pos--;
  706.  
  707. }
  708.  
  709.  
  710.  
  711.  
  712.  
  713. /**
  714. *
  715. * dir_dehighlights the given pair of parts
  716. *
  717. * @method dir_dehighlight
  718. * @for directionConfirmGlobal
  719. * @param {Object} thePair The pair object to be dir_dehighlighted
  720. * @return {Void}
  721. *
  722. */
  723. function dir_dehighlight(thePair){
  724. console.log("The number of vectors is ",theVectors.length);
  725. dir_removeVectorView(document.getElementById("expandButton"));
  726. thePair.Ref.Mesh.material=new THREE.MeshLambertMaterial(wireSettings);
  727. thePair.Mov.Mesh.material=new THREE.MeshLambertMaterial(wireSettings);
  728. }
  729.  
  730.  
  731.  
  732. /**
  733. *
  734. * dir_highlights the given pair of parts
  735. *
  736. * @method dir_highlight
  737. * @for directionConfirmGlobal
  738. * @param {Object} thePair The pair object to be dir_highlighted
  739. * @return {Void}
  740. *
  741. */
  742.  
  743. function dir_highlight(thePair){
  744.  
  745. console.log(thePair);
  746. thePair.Ref.Mesh.material=new THREE.MeshLambertMaterial({color: 0x4444FF /*, transparent: true, opacity: 0.6, depthTest: false */});
  747. thePair.Mov.Mesh.material=new THREE.MeshLambertMaterial({color: 0xFF4444 /*, transparent: true, opacity: 0.6, depthTest: false */});
  748. thePair.Ref.Mesh.geometry.computeBoundingBox();
  749. thePair.Mov.Mesh.geometry.computeBoundingBox();
  750. var theBox=thePair.Mov.Mesh.geometry.boundingBox.clone();
  751. var distBox = thePair.Mov.Mesh.geometry.boundingBox.clone();
  752. distBox.union(thePair.Ref.Mesh.geometry.boundingBox);
  753.  
  754.  
  755.  
  756. var pos=0;
  757. var lim=theVectors.length;
  758. while(pos<lim){
  759. scene.remove( theVectors[pos] );
  760. pos++;
  761. }
  762.  
  763.  
  764. theVectors.length=0;
  765. console.log("Just set the Vectors to 0");
  766. console.log("The pair is: ", thePair);
  767. var theVec;
  768.  
  769. var theDist = Math.sqrt(Math.pow(distBox.max.x-distBox.min.x,2)+
  770. Math.pow(distBox.max.y-distBox.min.y,2)+
  771. Math.pow(distBox.max.y-distBox.min.y,2));
  772.  
  773.  
  774. pos=0;
  775. lim=thePair.InfiniteDirections.length;
  776. while(pos<lim){
  777. theVec = new THREE.Line( new THREE.Geometry(), new THREE.LineBasicMaterial({color: 0xff0000}));
  778. theVec.geometry.vertices[0]=new THREE.Vector3(
  779. (theBox.min.x+theBox.max.x)/2,
  780. (theBox.min.y+theBox.max.y)/2,
  781. (theBox.min.z+theBox.max.z)/2
  782. );
  783. theVec.geometry.vertices[1]=new THREE.Vector3(theDist*theDirections[thePair.InfiniteDirections[pos]].X,
  784. theDist*theDirections[thePair.InfiniteDirections[pos]].Y,
  785. theDist*theDirections[thePair.InfiniteDirections[pos]].Z);
  786. theVec.geometry.vertices[1].add(theVec.geometry.vertices[0]);
  787. theVec.geometry.verticesNeedUpdate=true;
  788. scene.add(theVec);
  789. theVectors.push(theVec);
  790. console.log("Vector List Size is: ",theVectors.length);
  791. pos++;
  792. }
  793.  
  794. dir_insertVectorView(document.getElementById("expandButton"));
  795.  
  796. }
  797.  
  798.  
  799.  
  800.  
  801. /**
  802. *
  803. * Sets the opacity of each (non-dir_highlighted) mesh object to the value of the
  804. * slider element provided
  805. *
  806. * @method dir_fixOpacity
  807. * @for directionConfirmGlobal
  808. * @param {Object} theSlider The slider which is to be referenced when setting object opacity
  809. * @return {Void}
  810. *
  811. */
  812. function dir_fixOpacity(theSlider){
  813.  
  814. console.log("Changing Opacity");
  815. var val = theSlider.value;
  816. wireSettings.opacity=val;
  817. var pos=0;
  818. var lim=parts.length;
  819. while(pos<lim){
  820. if(parts[pos].Mesh!=currentPair.Ref.Mesh && parts[pos].Mesh!=currentPair.Mov.Mesh){
  821. parts[pos].Mesh.material=new THREE.MeshLambertMaterial(wireSettings);
  822. }
  823. pos++;
  824. }
  825.  
  826. }
  827.  
  828.  
  829.  
  830. /**
  831. *
  832. * Given a mouseup event, sets corresponding internal button states for mouse-related controls
  833. *
  834. * @method dir_doMouseUp
  835. * @for directionConfirmGlobal
  836. * @param {mouseup event} theEvent
  837. * @return {Void}
  838. *
  839. */
  840. function dir_doMouseUp(theEvent){
  841. if(theEvent.button == 0){
  842. leftDrag = false;
  843. }
  844. else if(theEvent.button == 2){
  845. rightDrag = false;
  846. }
  847. }
  848.  
  849.  
  850. /**
  851. *
  852. * Given a mousedown event, sets corresponding internal button states for mouse-related controls
  853. *
  854. * @method dir_doMouseDown
  855. * @for directionConfirmGlobal
  856. * @param {mousedown event} theEvent
  857. * @return {Void}
  858. *
  859. */
  860. function dir_doMouseDown(theEvent){
  861. if(theEvent.button == 0){
  862. leftDrag = true;
  863. }
  864. else if(theEvent.button == 2){
  865. rightDrag = true;
  866. }
  867. }
  868.  
  869.  
  870. /**
  871. *
  872. * Given a mouseleave event, sets corresponding internal button states for mouse-related controls
  873. *
  874. * @method dir_doMouseLeave
  875. * @for directionConfirmGlobal
  876. * @param {mouseup event} theEvent
  877. * @return {Void}
  878. *
  879. */
  880. function dir_doMouseLeave(theEvent){
  881. leftDrag = false;
  882. rightDrag = false;
  883. lastMouse = null;
  884. }
  885.  
  886.  
  887. /**
  888. *
  889. * Prevents the default response of the given event (used to prevent dropdown menus when right
  890. * clicking on the display).
  891. *
  892. * @method dir_justDont
  893. * @for directionConfirmGlobal
  894. * @param {Event Object} theEvent The event to suppress the default response of.
  895. * @return {Void}
  896. *
  897. */
  898. function dir_justDont(theEvent){
  899. theEvent.preventDefault();
  900. }
  901.  
  902.  
  903. /**
  904. *
  905. * Given a mousedrag event, rotates the camera or adds a vector to the currently displayed pair,
  906. * depending upon whether or not the left or right mouse button is depressed
  907. *
  908. * @method dir_doDrag
  909. * @for directionConfirmGlobal
  910. * @param {mouseup event} theEvent
  911. * @return {Void}
  912. *
  913. */
  914. function dir_doDrag(theEvent){
  915.  
  916.  
  917. if(theAddAxis !== null){
  918.  
  919. var theBox=currentPair.Mov.Mesh.geometry.boundingBox.clone();
  920. var theArea = document.getElementById("display");
  921. var areaW = theArea.clientWidth;
  922. var areaH = theArea.clientHeight;
  923. var areaT = theArea.offsetTop;
  924. var areaL = theArea.offsetLeft;
  925. var mouseX = theEvent.clientX;
  926. var mouseY = theEvent.clientY;
  927. //console.log("aW: "+areaW+" aH: "+areaH+" aT: "+areaT+" aL: "+areaL);
  928. //console.log("mX: "+(((mouseX-areaL)-areaW/2)/(areaW/2))+" mY: "+((areaH/2-(mouseY-areaT))/(areaH/2)));
  929. var theDir = dir_getDirectionFromMouse( ((mouseX-areaL)-areaW/2)/(areaW/2), (areaH/2-(mouseY-areaT))/(areaH/2) );
  930.  
  931. theAddAxis.geometry.vertices[0].set((theBox.min.x+theBox.max.x)/2,(theBox.min.y+theBox.max.y)/2,(theBox.min.z+theBox.max.z)/2);
  932. theAddAxis.geometry.vertices[1].set((theBox.min.x+theBox.max.x)/2+theDirections[theDir].X*theDistance*0.6,
  933. (theBox.min.y+theBox.max.y)/2+theDirections[theDir].Y*theDistance*0.6,
  934. (theBox.min.z+theBox.max.z)/2+theDirections[theDir].Z*theDistance*0.6 );
  935.  
  936. console.log( "X: "+(theBox.min.x+theBox.max.x)/2+
  937. " Y: "+(theBox.min.y+theBox.max.y)/2+
  938. " Z: "+(theBox.min.z+theBox.max.z)/2 );
  939.  
  940. console.log(" X: "+theDirections[theDir].X +
  941. " Y: "+theDirections[theDir].Y +
  942. " Z: "+theDirections[theDir].Z );
  943.  
  944. theAddAxis.geometry.verticesNeedUpdate=true;
  945.  
  946. }
  947.  
  948.  
  949. if(leftDrag==true){
  950. thePos.normalize();
  951. theEul.set(theEvent.movementY*(-0.02)*Math.cos(Math.atan2(thePos.x,thePos.z)),
  952. theEvent.movementX*(-0.02),
  953. theEvent.movementY*(0.02)*Math.sin(Math.atan2(thePos.x,thePos.z)),
  954. 'ZYX');
  955. }
  956. if(rightDrag==true){
  957. dir_addVectorFromMouse(theEvent.clientX, theEvent.clientY);
  958. }
  959. }
  960.  
  961.  
  962. /**
  963. *
  964. * Given a mousewheel event, changes the distance of the camera from the center of the scene
  965. *
  966. * @method dir_doMouseUp
  967. * @for directionConfirmGlobal
  968. * @param {mouseup event} theEvent
  969. * @return {Void}
  970. *
  971. */
  972. function dir_doZoom(theEvent){
  973. var theDelta = theEvent.deltaY == 0 ? 0 : ( theEvent.deltaY > 0 ? 1 : -1 );
  974. theDistance=theDistance*Math.pow(1.001,theDelta*(-40));
  975. }
  976.  
  977.  
  978.  
  979.  
  980.  
  981. /**
  982. *
  983. * Inserts the vector view into the webpage
  984. *
  985. * @method dir_insertVectorView
  986. * @for directionConfirmGlobal
  987. * @param {HTML Element} theButton The vector viewing button
  988. * @return {Void}
  989. *
  990. */
  991. function dir_insertVectorView(theButton){
  992.  
  993. console.log("doing dir_insertVectorView");
  994.  
  995. if(currentPair==null){
  996. return;
  997. }
  998.  
  999. currentPair.Ref.Mesh.geometry.computeBoundingBox();
  1000. currentPair.Mov.Mesh.geometry.computeBoundingBox();
  1001. var theBox=currentPair.Mov.Mesh.geometry.boundingBox.clone();
  1002. var distBox = currentPair.Mov.Mesh.geometry.boundingBox.clone()
  1003. distBox.union(currentPair.Ref.Mesh.geometry.boundingBox);
  1004.  
  1005. var theDist = Math.sqrt(Math.pow(distBox.max.x-distBox.min.x,2)+
  1006. Math.pow(distBox.max.y-distBox.min.y,2)+
  1007. Math.pow(distBox.max.y-distBox.min.y,2));
  1008.  
  1009. var theDiv=theButton.parentElement;
  1010. console.log(theDiv);
  1011. theButton.onclick=function () {dir_removeVectorView(this);};
  1012. var theVecList=document.createElement("div");
  1013. theVecList.id="vecList";
  1014. var addButton=document.createElement("button");
  1015. addButton.innerHTML="Add Vector";
  1016. addButton.id="addButton";
  1017. addButton.onclick=function () {dir_addVectorToPair(this);};
  1018.  
  1019. var pos=0;
  1020. var lim=theVectors.length;
  1021. var theEntry;
  1022. var remBut;
  1023. var xLab;
  1024. var xInp;
  1025. var yLab;
  1026. var yInp;
  1027. var zLabl;
  1028. var zInp;
  1029. while(pos<lim){
  1030. theEntry=document.createElement("div");
  1031. remBut=document.createElement("button");
  1032. remBut.innerHTML="Remove";
  1033. remBut.onclick=function () {dir_remVectorFromPair(this);};
  1034. xLab=document.createElement("text");
  1035. xLab.innerHTML="X";
  1036. xInp=document.createElement("input");
  1037. xInp.type="number";
  1038. xInp.step=0.01;
  1039. xInp.value=(theVectors[pos].geometry.vertices[1].x-theVectors[pos].geometry.vertices[0].x)/theDist;
  1040. xInp.onchange=function () {dir_vecEntryUpdate(this);};
  1041. yLab=document.createElement("text");
  1042. yLab.innerHTML="Y";
  1043. yInp=document.createElement("input");
  1044. yInp.type="number";
  1045. yInp.step=0.01;
  1046. yInp.value=(theVectors[pos].geometry.vertices[1].y-theVectors[pos].geometry.vertices[0].y)/theDist;
  1047. yInp.onchange=function () {dir_vecEntryUpdate(this);};
  1048. zLab=document.createElement("text");
  1049. zLab.innerHTML="Z";
  1050. zInp=document.createElement("input");
  1051. zInp.type="number";
  1052. zInp.step=0.01;
  1053. zInp.value=(theVectors[pos].geometry.vertices[1].z-theVectors[pos].geometry.vertices[0].z)/theDist;
  1054. zInp.onchange=function () {dir_vecEntryUpdate(this);};
  1055.  
  1056. theEntry.appendChild(xLab);
  1057. theEntry.appendChild(xInp);
  1058. theEntry.appendChild(document.createElement("br"));
  1059. theEntry.appendChild(yLab);
  1060. theEntry.appendChild(yInp);
  1061. theEntry.appendChild(document.createElement("br"));
  1062. theEntry.appendChild(zLab);
  1063. theEntry.appendChild(zInp);
  1064. theEntry.appendChild(document.createElement("br"));
  1065. theEntry.appendChild(remBut);
  1066.  
  1067. theEntry.counterPart=theVectors[pos];
  1068. theEntry.className="vecEntry";
  1069.  
  1070. theVecList.appendChild(theEntry);
  1071. pos++;
  1072. }
  1073.  
  1074. theDiv.appendChild(addButton);
  1075. theDiv.appendChild(theVecList);
  1076.  
  1077. }
  1078.  
  1079.  
  1080.  
  1081.  
  1082.  
  1083. /**
  1084. *
  1085. * Removes the vector view from the webpage
  1086. *
  1087. * @method dir_removeVectorView
  1088. * @for directionConfirmGlobal
  1089. * @param {HTML Element} theButton The vector viewing button
  1090. * @return {Void}
  1091. *
  1092. */
  1093. function dir_removeVectorView(theButton){
  1094.  
  1095. console.log("doing dir_removeVectorView");
  1096.  
  1097. var theDiv=theButton.parentElement;
  1098. var vecListHolder=document.getElementById("vecList");
  1099.  
  1100.  
  1101.  
  1102. if(vecListHolder!=null){
  1103. var vecPos=0;
  1104. var vecLim=theVectors.length;
  1105. console.log(theVectors);
  1106.  
  1107. var best;
  1108. var ang;
  1109. var testVector;
  1110. currentPair.InfiniteDirections.length=0;
  1111. while(vecPos<vecLim){
  1112. testVector=new THREE.Vector3(1,1,1);
  1113. //
  1114. testVector.copy(theVectors[vecPos].geometry.vertices[1]);
  1115. testVector.sub(theVectors[vecPos].geometry.vertices[0]);
  1116. testVector.normalize();
  1117. //console.log(testVector);
  1118. pos=dir_getDir(testVector);
  1119. console.log(theVectors[vecPos]);
  1120. if(theVectors[vecPos].material.color.r===1){
  1121. currentPair.InfiniteDirections.push(pos);
  1122. console.log("<--->");
  1123. }
  1124.  
  1125. console.log("Vector List Size is: ",theVectors.length);
  1126. console.log("InfDir List Size is: ",currentPair.InfiniteDirections.length);
  1127. vecPos++;
  1128. }
  1129.  
  1130. theDiv.removeChild(vecListHolder);
  1131. theDiv.removeChild(document.getElementById("addButton"));
  1132. }
  1133.  
  1134. theButton.onclick=function () {dir_insertVectorView(this);};
  1135.  
  1136. }
  1137.  
  1138.  
  1139. /**
  1140. *
  1141. * Inserts a blank vector widget into the vector view element
  1142. *
  1143. * @method dir_addVectorToPair
  1144. * @for directionConfirmGlobal
  1145. * @param {HTML Element} theButton The "add vector" button
  1146. * @return {Void}
  1147. *
  1148. */
  1149. function dir_addVectorToPair(theButton){
  1150.  
  1151. console.log("doing dir_addVectorToPair");
  1152.  
  1153. var theDiv=theButton.parentElement;
  1154. var theVecList=document.getElementById("vecList");
  1155. //console.log(theVecList);
  1156.  
  1157. var theEntry=document.createElement("div");
  1158. var remBut=document.createElement("button");
  1159. remBut.innerHTML="Remove";
  1160. remBut.onclick=function () {dir_remVectorFromPair(this);};
  1161. var xLab=document.createElement("text");
  1162. xLab.innerHTML="X";
  1163. var xInp=document.createElement("input");
  1164. xInp.type="number";
  1165. xInp.step=0.01;
  1166. xInp.onchange=function () {dir_vecEntryUpdate(this);};
  1167. var yLab=document.createElement("text");
  1168. yLab.innerHTML="Y";
  1169. var yInp=document.createElement("input");
  1170. yInp.type="number";
  1171. yInp.step=0.01;
  1172. yInp.onchange=function () {dir_vecEntryUpdate(this);};
  1173. var zLab=document.createElement("text");
  1174. zLab.innerHTML="Z";
  1175. var zInp=document.createElement("input");
  1176. zInp.type="number";
  1177. zInp.step=0.01;
  1178. zInp.onchange=function () {dir_vecEntryUpdate(this);};
  1179.  
  1180. theEntry.appendChild(xLab);
  1181. theEntry.appendChild(xInp);
  1182. theEntry.appendChild(document.createElement("br"));
  1183. theEntry.appendChild(yLab);
  1184. theEntry.appendChild(yInp);
  1185. theEntry.appendChild(document.createElement("br"));
  1186. theEntry.appendChild(zLab);
  1187. theEntry.appendChild(zInp);
  1188. theEntry.appendChild(document.createElement("br"));
  1189. theEntry.appendChild(remBut);
  1190.  
  1191. theEntry.counterPart=null;
  1192. theEntry.className="vecEntry";
  1193.  
  1194. theVecList.appendChild(theEntry);
  1195. return theEntry;
  1196.  
  1197. }
  1198.  
  1199.  
  1200.  
  1201.  
  1202. /**
  1203. *
  1204. * Removes a vector widget from the vector view element
  1205. *
  1206. * @method dir_remVectorFromPair
  1207. * @for directionConfirmGlobal
  1208. * @param {HTML Element} theButton The "remove" button of the widget to be removed
  1209. * @return {Void}
  1210. *
  1211. */
  1212. function dir_remVectorFromPair(theButton){
  1213.  
  1214. console.log("doing dir_remVectorFromPair");
  1215. if(theButton.parentElement.counterPart!=null){
  1216. scene.remove(theButton.parentElement.counterPart);
  1217. }
  1218.  
  1219. console.log("The vector length before splice: ",theVectors.lenth);
  1220. theVectors.splice(theVectors.indexOf(theButton.parentElement.counterPart),1);
  1221. console.log("The vector length after splice: ",theVectors.lenth);
  1222.  
  1223. theButton.parentElement.parentElement.removeChild(theButton.parentElement);
  1224.  
  1225. }
  1226.  
  1227.  
  1228. /**
  1229. *
  1230. * Updates a vector to match the values in its corresponding widget
  1231. * @method dir_vecEntryUpdate
  1232. * @for directionConfirmGlobal
  1233. * @param {HTML Element} theInput An input element of the vector's widget
  1234. * @return {Void}
  1235. *
  1236. */
  1237. function dir_vecEntryUpdate(theInput){
  1238.  
  1239. console.log("doing dir_vecEntryUpdate");
  1240.  
  1241. var theBox=currentPair.Mov.Mesh.geometry.boundingBox.clone();
  1242.  
  1243. currentPair.Ref.Mesh.geometry.computeBoundingBox();
  1244. currentPair.Mov.Mesh.geometry.computeBoundingBox();
  1245. var theBox=currentPair.Mov.Mesh.geometry.boundingBox.clone();
  1246. var distBox = currentPair.Mov.Mesh.geometry.boundingBox.clone();
  1247. distBox.union(currentPair.Ref.Mesh.geometry.boundingBox);
  1248.  
  1249. var theDist = Math.sqrt(Math.pow(distBox.max.x-distBox.min.x,2)+
  1250. Math.pow(distBox.max.y-distBox.min.y,2)+
  1251. Math.pow(distBox.max.y-distBox.min.y,2));
  1252.  
  1253.  
  1254. var theEntry=theInput.parentElement;
  1255. var theInputs=theEntry.getElementsByTagName("INPUT");
  1256. var pos=0;
  1257. var lim=theInputs.length;
  1258. var current;
  1259. while(pos<lim){
  1260. current=theInputs[pos];
  1261. if(theInputs[pos].value===""){
  1262. return;
  1263. }
  1264. pos++;
  1265. }
  1266.  
  1267. var theMag = Math.sqrt( Math.pow(parseFloat(theInputs[0].value),2)+
  1268. Math.pow(parseFloat(theInputs[1].value),2)+
  1269. Math.pow(parseFloat(theInputs[2].value),2));
  1270. theInputs[0].value = theInputs[0].value/theMag;
  1271. theInputs[1].value = theInputs[1].value/theMag;
  1272. theInputs[2].value = theInputs[2].value/theMag;
  1273.  
  1274. console.log(theInputs);
  1275. if(theEntry.counterPart===null){
  1276. var theVec = new THREE.Line( new THREE.Geometry(), new THREE.LineBasicMaterial({color: 0xff0000}));
  1277. theVec.geometry.vertices[0]=new THREE.Vector3(
  1278. (theBox.min.x+theBox.max.x)/2,
  1279. (theBox.min.y+theBox.max.y)/2,
  1280. (theBox.min.z+theBox.max.z)/2
  1281. );
  1282. theVec.geometry.vertices[1]=new THREE.Vector3(theVec.geometry.vertices[0].x+parseFloat(theInputs[0].value)*theDist,
  1283. theVec.geometry.vertices[0].y+parseFloat(theInputs[1].value)*theDist,
  1284. theVec.geometry.vertices[0].z+parseFloat(theInputs[2].value)*theDist);
  1285.  
  1286.  
  1287.  
  1288. scene.add(theVec);
  1289. theVectors.push(theVec);
  1290. console.log("theVectors Updated. New length is: ",theVectors.length);
  1291. theVec.geometry.verticesNeedUpdate=true;
  1292. theEntry.counterPart=theVec;
  1293. theEntry.counterPart.geometry.verticesNeedUpdate=true;
  1294. }
  1295. else{
  1296. var theVerts=theEntry.counterPart.geometry.vertices;
  1297. theVerts[1].x=theVerts[0].x+parseFloat(theInputs[0].value)*theDist;
  1298. theVerts[1].y=theVerts[0].y+parseFloat(theInputs[1].value)*theDist;
  1299. theVerts[1].z=theVerts[0].z+parseFloat(theInputs[2].value)*theDist;
  1300. theEntry.counterPart.geometry.verticesNeedUpdate=true;
  1301. }
  1302. console.log(theEntry.counterPart.geometry.vertices);
  1303.  
  1304. }
  1305.  
  1306.  
  1307.  
  1308. /**
  1309. *
  1310. * Finds and returns the index of the direction in the list of usable vector directions
  1311. * which best matches the given vector
  1312. *
  1313. * @method dir_getDir
  1314. * @for directionConfirmGlobal
  1315. * @param {Vector3} theVec The vector to be searched with
  1316. * @return {Int} The index of the best matching direction in the list of usable vector directions
  1317. *
  1318. */
  1319. function dir_getDir(theVec){
  1320.  
  1321. var maxDot=-1;
  1322. var theDot;
  1323. var best=-1;
  1324. var pos=0;
  1325. var lim=theDirections.length;
  1326. while(pos<lim){
  1327. theDot=theDirections[pos].X*theVec.x+theDirections[pos].Y*theVec.y+theDirections[pos].Z*theVec.z;
  1328. if(theDot>maxDot){
  1329. maxDot=theDot;
  1330. best=pos;
  1331. }
  1332. pos++;
  1333. }
  1334. return best;
  1335.  
  1336. }
  1337.  
  1338.  
  1339.  
  1340. /**
  1341. *
  1342. * Processes the information in the webpage into an XML string and inserts a download link
  1343. * for the data into the top of the page
  1344. *
  1345. * @method dir_renderXML
  1346. * @for directionConfirmGlobal
  1347. * @return {Void}
  1348. *
  1349. */
  1350. function dir_renderXML(){
  1351.  
  1352.  
  1353. var start= "<?xml version='1.0' encoding='utf-8'?>\n"+
  1354. "<DirectionSaveStructure xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\n";
  1355. var end= "</DirectionSaveStructure>\n";
  1356.  
  1357. var arcContent = "<arcs>\n";
  1358. var idxPos;
  1359. var idxLim;
  1360. pos=0;
  1361. lim=namePairs.length;
  1362. while(pos<lim){
  1363. arcContent = arcContent+"<arc xsi:type='Connection'>\n";
  1364. arcContent = arcContent+"<name>"+namePairs[pos].name+"</name>\n";
  1365. arcContent = arcContent+"<localLabels>"+namePairs[pos].localLabels+"</localLabels>\n";
  1366. arcContent = arcContent+"<localVariables>"+namePairs[pos].localVariables+"</localVariables>\n";
  1367. arcContent = arcContent+"<From>"+namePairs[pos].Mov+"</From>\n";
  1368. arcContent = arcContent+"<To>"+namePairs[pos].Ref+"</To>\n";
  1369. arcContent = arcContent+"<directed>"+namePairs[pos].Directed+"</directed>\n";
  1370. arcContent = arcContent+"<doublyDirected>"+namePairs[pos].DoublyDirected+"</doublyDirected>\n";
  1371. arcContent = arcContent+"<InfiniteDirections> \n";
  1372. idxPos=0;
  1373. idxLim=namePairs[pos].InfiniteDirections.length;
  1374. while(idxPos<idxLim){
  1375. arcContent = arcContent+"<int>"+namePairs[pos].InfiniteDirections[idxPos].toString()+"</int>\n";
  1376. idxPos++;
  1377. }
  1378. arcContent = arcContent+"</InfiniteDirections>\n";
  1379. arcContent = arcContent+"<FiniteDirections>"+namePairs[pos].FiniteDirections+"</FiniteDirections>\n";
  1380. arcContent = arcContent+"<Fasteners>"+namePairs[pos].Fasteners+"</Fasteners>\n";
  1381. arcContent = arcContent+"<Certainty>"+namePairs[pos].Certainty+"</Certainty>\n";
  1382. arcContent = arcContent+"<ConnectionType>"+namePairs[pos].ConnectionType+"</ConnectionType>\n";
  1383.  
  1384. arcContent = arcContent+"</arc>\n";
  1385. pos++;
  1386. }
  1387. arcContent= arcContent + "</arcs>\n";
  1388.  
  1389. var result = start + arcContent + end;
  1390.  
  1391. outText = result;
  1392. requestAdvance(5);
  1393.  
  1394. }
  1395.  
  1396.  
  1397.  
  1398. /**
  1399. *
  1400. * Initializes the lines for the XYZ compass in the display
  1401. *
  1402. * @method dir_initAxisLines
  1403. * @for directionConfirmGlobal
  1404. * @return {Void}
  1405. *
  1406. */
  1407. function dir_initAxisLines(){
  1408.  
  1409. theXAxis = new THREE.Line( new THREE.Geometry(), new THREE.LineBasicMaterial({color: 0xff0000, depthTest: false }));
  1410. theXAxis.geometry.vertices.push(new THREE.Vector3(0,0,0));
  1411. theXAxis.geometry.vertices.push(new THREE.Vector3(0,0,0));
  1412. theXAxis.frustumCulled = false;
  1413.  
  1414. theYAxis = new THREE.Line( new THREE.Geometry(), new THREE.LineBasicMaterial({color: 0x00ff00, depthTest: false }));
  1415. theYAxis.geometry.vertices.push(new THREE.Vector3(0,0,0));
  1416. theYAxis.geometry.vertices.push(new THREE.Vector3(0,0,0));
  1417. theYAxis.frustumCulled = false;
  1418.  
  1419. theZAxis = new THREE.Line( new THREE.Geometry(), new THREE.LineBasicMaterial({color: 0x0000ff, depthTest: false }));
  1420. theZAxis.geometry.vertices.push(new THREE.Vector3(0,0,0));
  1421. theZAxis.geometry.vertices.push(new THREE.Vector3(0,0,0));
  1422. theZAxis.frustumCulled = false;
  1423.  
  1424. theAddAxis = new THREE.Line( new THREE.Geometry(), new THREE.LineBasicMaterial({color: 0x00ff00, depthTest: true }));
  1425. theAddAxis.geometry.vertices.push(new THREE.Vector3(0,0,0));
  1426. theAddAxis.geometry.vertices.push(new THREE.Vector3(0,0,0));
  1427. theAddAxis.frustumCulled = false;
  1428.  
  1429.  
  1430. scene.add(theXAxis);
  1431. scene.add(theYAxis);
  1432. scene.add(theZAxis);
  1433. scene.add(theAddAxis);
  1434.  
  1435.  
  1436. }
  1437.  
  1438.  
  1439. /**
  1440. *
  1441. * Updates the lines for the XYZ compass in the display
  1442. *
  1443. * @method dir_updateAxisLines
  1444. * @for directionConfirmGlobal
  1445. * @return {Void}
  1446. *
  1447. */
  1448. function dir_updateAxisLines(){
  1449.  
  1450. var theRot= new THREE.Quaternion(0,0,0,0);
  1451. theRot.setFromEuler(camera.rotation);
  1452. var theDir= new THREE.Vector3(-3,-3,-5);
  1453.  
  1454. theDir.applyQuaternion(theRot);
  1455.  
  1456.  
  1457. var thePosition = camera.position.clone();
  1458.  
  1459. thePosition.add(theDir);
  1460.  
  1461. theXAxis.geometry.vertices[0].copy(thePosition);
  1462. theXAxis.geometry.vertices[0].x-=0.5;
  1463. theXAxis.geometry.vertices[1].copy(thePosition);
  1464. theXAxis.geometry.vertices[1].x+=1;
  1465. theXAxis.geometry.verticesNeedUpdate=true;
  1466.  
  1467. theYAxis.geometry.vertices[0].copy(thePosition);
  1468. theYAxis.geometry.vertices[0].y-=0.5;
  1469. theYAxis.geometry.vertices[1].copy(thePosition);
  1470. theYAxis.geometry.vertices[1].y+=1;
  1471. theYAxis.geometry.verticesNeedUpdate=true;
  1472.  
  1473. theZAxis.geometry.vertices[0].copy(thePosition);
  1474. theZAxis.geometry.vertices[0].z-=0.5;
  1475. theZAxis.geometry.vertices[1].copy(thePosition);
  1476. theZAxis.geometry.vertices[1].z+=1;
  1477. theZAxis.geometry.verticesNeedUpdate=true;
  1478.  
  1479. }
  1480.  
  1481.  
  1482.  
  1483.  
  1484. /**
  1485. *
  1486. * Maps a given mouse X position and mouse Y position to a point on a unit hemisphere facing
  1487. * towards the user then returns the index of the closest valid direction
  1488. *
  1489. * @method dir_getDirectionFromMouse
  1490. * @for directionConfirmGlobal
  1491. * @param {Float} mouseX
  1492. * @param {Float} mouseY
  1493. * @return {Int}
  1494. *
  1495. */
  1496. function dir_getDirectionFromMouse( mouseX, mouseY ){
  1497.  
  1498. var mouseZ;
  1499. mouseZ = Math.pow(1-((mouseX*mouseX)+(mouseY*mouseY)),0.5);
  1500.  
  1501. var theVec = new THREE.Vector3(mouseX,mouseY,mouseZ);
  1502. var theRot = new THREE.Euler( 0-Math.atan2(thePos.y,Math.sqrt(Math.pow(thePos.z,2)+Math.pow(thePos.x,2))),
  1503. Math.atan2(thePos.x,thePos.z),
  1504. 0,
  1505. 'ZYX' );
  1506. theVec.applyEuler(theRot);
  1507.  
  1508. var theDir = dir_getDir(theVec);
  1509. return theDir;
  1510.  
  1511. }
  1512.  
  1513.  
  1514.  
  1515.  
  1516. /**
  1517. *
  1518. * Adds a vector to the currently displayed pair based off of camera position, mouse X and mouse Y
  1519. *
  1520. * @method dir_addVectorFromMouse
  1521. * @for directionConfirmGlobal
  1522. * @param {Float} mouseX The X position of the mouse
  1523. * @param {Float} mouseY The Y position of the mouse
  1524. * @return {Void}
  1525. *
  1526. */
  1527. function dir_addVectorFromMouse ( mouseX, mouseY ){
  1528.  
  1529. var theButton = document.getElementById("addButton");
  1530. var theArea = document.getElementById("display");
  1531. var areaW = theArea.clientWidth;
  1532. var areaH = theArea.clientHeight;
  1533. var areaT = theArea.offsetTop;
  1534. var areaL = theArea.offsetLeft;
  1535. console.log("aW: "+areaW+" aH: "+areaH+" aT: "+areaT+" aL: "+areaL);
  1536. console.log("mX: "+(((mouseX-areaL)-areaW/2)/(areaW/2))+" mY: "+((areaH/2-(mouseY-areaT))/(areaH/2)));
  1537. var theDir = dir_getDirectionFromMouse( ((mouseX-areaL)-areaW/2)/(areaW/2), (areaH/2-(mouseY-areaT))/(areaH/2) );
  1538.  
  1539.  
  1540. var theVecList=document.getElementById("vecList");
  1541. var theVecs = theVecList.childNodes;
  1542. var pos = 0;
  1543. var lim = theVecs.length;
  1544. var testVec = new THREE.Vector3(theDirections[theDir].X,theDirections[theDir].Y,theDirections[theDir].Z);
  1545. var otherVec = new THREE.Vector3(0,0,0);
  1546. while(pos<lim){
  1547. if(theVecs[pos]!==null){
  1548. otherVec.copy(theVecs[pos].counterPart.geometry.vertices[1]);
  1549. otherVec.sub(theVecs[pos].counterPart.geometry.vertices[0]);
  1550. if(testVec.angleTo(otherVec) < 0.15){
  1551. return;
  1552. }
  1553. }
  1554. pos++;
  1555. }
  1556. delete testVec;
  1557. delete otherVec;
  1558. var theElem = dir_addVectorToPair(theButton);
  1559. var theInputs = theElem.getElementsByTagName("input");
  1560. theInputs[0].value = theDirections[theDir].X;
  1561. theInputs[1].value = theDirections[theDir].Y;
  1562. theInputs[2].value = theDirections[theDir].Z;
  1563. theInputs[0].onchange();
  1564.  
  1565. }
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576. startupScripts["4"] = function() {
  1577.  
  1578.  
  1579. lastPair=null;
  1580. currentPair=null;
  1581.  
  1582.  
  1583. theWidth=document.getElementById("display").clientWidth;
  1584. theHeight= document.getElementById("display").clientHeight;
  1585.  
  1586. // The scene of the assembly animation
  1587. //scene = new THREE.Scene();
  1588.  
  1589. // The camera
  1590. //camera = new THREE.PerspectiveCamera( 75, theWidth/theHeight, 1, 16000 );
  1591.  
  1592.  
  1593. document.getElementById("display").appendChild( renderer.domElement );
  1594.  
  1595.  
  1596.  
  1597. // Inserts the file loading manager into the document
  1598. //document.getElementById('fileinput').addEventListener('change', dir_readMultipleFiles, false);
  1599. document.getElementById("display").addEventListener("mousemove", dir_doDrag);
  1600. document.getElementById("display").addEventListener("wheel", dir_doZoom);
  1601.  
  1602. theXML = inText;
  1603.  
  1604. var i = 0;
  1605. var lim = directionList.length;
  1606. theDirections = [];
  1607. while( i < lim ){
  1608. theDirections.push({
  1609. X: directionList[i][0],
  1610. Y: directionList[i][1],
  1611. Z: directionList[i][2]
  1612. });
  1613. i++;
  1614. }
  1615.  
  1616. dir_renderParts();
  1617.  
  1618. }
  1619. //</script>
  1620.