Anders and Briegel in Python
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

90 Zeilen
2.6KB

  1. var editor = {};
  2. var pi2 = Math.pi / 2;
  3. editor.nearest = undefined;
  4. editor.orientations = {
  5. xy: new THREE.Matrix4(),
  6. xz: new THREE.Matrix4(),
  7. yz: new THREE.Matrix4()
  8. };
  9. editor.orientations.xz.makeRotationX(pi2);
  10. editor.onFreeMove = function() {
  11. var n = editor.nearestNode(mouse.ray);
  12. if (editor.nearest !== n) {
  13. editor.nearest = n;
  14. if (n) {
  15. gui.nodeMessage("Node " + n + " (VOP:" + abj.vops[n] + ")" +
  16. "<br/>" + "Click to edit neighbourhood");
  17. } else {
  18. gui.hideNodeMessage();
  19. }
  20. }
  21. };
  22. editor.onClick = function() {
  23. var n = editor.nearestNode(mouse.ray);
  24. if (n) {
  25. var p = abj.meta[n].position;
  26. editor.grid.position.set(p.x, p.y, p.z);
  27. gui.controls.target.set(p.x, p.y, p.z);
  28. gui.hideNodeMessage();
  29. editor.nearest = undefined;
  30. gui.serverMessage("Selected node " + n + "");
  31. } else {
  32. //TODO: ghastly
  33. var intersection = mouse.ray.intersectPlane(editor.plane);
  34. intersection.x = Math.round(intersection.x, 0);
  35. intersection.y = Math.round(intersection.y, 0);
  36. intersection.z = Math.round(intersection.z, 0);
  37. var newNode = abj.order();
  38. abj.add_node(newNode, {
  39. position: intersection
  40. });
  41. editor.grid.position.set(intersection.x, intersection.y, intersection.z);
  42. gui.controls.target.set(intersection.x, intersection.y, intersection.z);
  43. graph.update();
  44. gui.serverMessage("Created node " + newNode + " at ");
  45. }
  46. };
  47. editor.prepare = function() {
  48. mouse.onFreeMove = editor.onFreeMove;
  49. mouse.onClick = editor.onClick;
  50. document.addEventListener("keydown", editor.onKey, false);
  51. editor.makeGrid();
  52. };
  53. editor.onKey = function(evt) {
  54. if (evt.keyCode == 32) {
  55. editor.grid.rotation.x += Math.PI / 2;
  56. editor.plane.applyMatrix4(m);
  57. gui.render();
  58. gui.serverMessage("Rotated into the XY plane or whatever");
  59. }
  60. };
  61. editor.makeGrid = function() {
  62. editor.grid = new THREE.GridHelper(10, 1);
  63. editor.grid.rotation.x = Math.PI / 2;
  64. editor.grid.setColors(0xbbbbbb, 0xeeeeee);
  65. //editor.grid.matrixAutoUpdate = false;
  66. editor.plane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
  67. gui.scene.add(editor.grid);
  68. };
  69. editor.update = function(){
  70. };
  71. // Gets a reference to the node nearest to the mouse cursor
  72. // TODO: get rid of meta{}
  73. editor.nearestNode = function(ray) {
  74. for (var j in abj.meta) {
  75. if (ray.distanceSqToPoint(abj.meta[j].position) < 0.03) {
  76. return j;
  77. }
  78. }
  79. return undefined;
  80. };