Anders and Briegel in Python
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

107 lignes
2.8KB

  1. var editor = {};
  2. var pi2 = Math.PI / 2;
  3. editor.selection = undefined;
  4. editor.orientations = [
  5. new THREE.Euler(pi2, 0, 0),
  6. new THREE.Euler(0, 0, 0),
  7. new THREE.Euler(pi2, 0, pi2),
  8. ];
  9. editor.onFreeMove = function() {
  10. var found = editor.findNodeOnRay(mouse.ray);
  11. if (editor.selection !== found) {
  12. editor.selection = found;
  13. if (found) {
  14. gui.nodeMessage("Node " + found + " (VOP:" + abj.node[found].vop + ")" +
  15. "<br/>" + "Click to edit neighbourhood");
  16. } else {
  17. gui.hideNodeMessage();
  18. }
  19. }
  20. };
  21. editor.focus = function(node) {
  22. editor.grid.position.copy(abj.node[node].position);
  23. gui.controls.target.copy(abj.node[node].position);
  24. gui.hideNodeMessage();
  25. editor.selection = node;
  26. gui.serverMessage("Selected node " + node + ".");
  27. };
  28. editor.addQubitAtPoint = function(point) {
  29. if (point === null) {
  30. return;
  31. }
  32. point.round();
  33. // Check for clashes
  34. for (var node in abj.node) {
  35. var delta = new THREE.Vector3();
  36. delta.subVectors(abj.node[node].position, point);
  37. if (delta.length()<0.1){ return; }
  38. }
  39. abj.add_node(abj.order(), { position: point });
  40. editor.grid.position.copy(point);
  41. gui.controls.target.copy(point);
  42. graph.update();
  43. gui.serverMessage("Created node.");
  44. };
  45. editor.onClick = function() {
  46. var found = editor.findNodeOnRay(mouse.ray);
  47. if (found) {
  48. editor.focus(found);
  49. } else {
  50. var intersection = mouse.ray.intersectPlane(editor.plane);
  51. if (intersection !== null) {
  52. editor.addQubitAtPoint(intersection);
  53. }
  54. }
  55. };
  56. editor.prepare = function() {
  57. mouse.onFreeMove = editor.onFreeMove;
  58. mouse.onClick = editor.onClick;
  59. document.addEventListener("keydown", editor.onKey, false);
  60. editor.makeGrid();
  61. };
  62. editor.onKey = function(evt) {
  63. if (evt.keyCode !== 32) {return;}
  64. editor.setOrientation((editor.orientation + 1) % 3);
  65. };
  66. editor.setOrientation = function(orientation) {
  67. editor.orientation = orientation;
  68. var rotation = editor.orientations[orientation];
  69. var normal = new THREE.Vector3(0, 1, 0);
  70. normal.applyEuler(rotation);
  71. editor.grid.rotation.copy(rotation);
  72. editor.plane = new THREE.Plane();
  73. editor.plane.setFromNormalAndCoplanarPoint(normal, editor.grid.position);
  74. gui.render();
  75. };
  76. editor.makeGrid = function() {
  77. editor.grid = new THREE.GridHelper(10, 1);
  78. editor.grid.setColors(0xbbbbbb, 0xeeeeee);
  79. editor.setOrientation(0);
  80. gui.scene.add(editor.grid);
  81. };
  82. editor.update = function() {};
  83. // Gets a reference to the node nearest to the mouse cursor
  84. editor.findNodeOnRay = function(ray) {
  85. for (var n in abj.node) {
  86. if (ray.distanceSqToPoint(abj.node[n].position) < 0.012) {
  87. return n;
  88. }
  89. }
  90. return undefined;
  91. };