Anders and Briegel in Python
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

110 行
3.0KB

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