Anders and Briegel in Python
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

72 lines
1.9KB

  1. var editor = {};
  2. editor.nearest = undefined;
  3. editor.gimbalVertices = [];
  4. editor.onFreeMove = function() {
  5. var n = editor.nearestNode(mouse.ray);
  6. if (editor.nearest !== n) {
  7. editor.nearest = n;
  8. if (n) {
  9. gui.nodeMessage("Node " + n + " (VOP:" + abj.vops[n] + ")" +
  10. "<br/>" + "Click to edit neighbourhood");
  11. } else {
  12. gui.hideNodeMessage();
  13. }
  14. }
  15. };
  16. editor.onClick = function() {
  17. var n = editor.nearestNode(mouse.ray);
  18. //if (n.type=="node") {
  19. var p = abj.meta[n].position;
  20. editor.gimbal.position.set(p.x, p.y, p.z);
  21. gui.controls.target.set(p.x, p.y, p.z);
  22. gui.hideNodeMessage();
  23. editor.nearest = undefined;
  24. gui.render();
  25. //}
  26. };
  27. editor.prepare = function() {
  28. mouse.onFreeMove = editor.onFreeMove;
  29. mouse.onClick = editor.onClick;
  30. editor.makeGimbal();
  31. };
  32. // Gets a reference to the node nearest to the mouse cursor
  33. editor.nearestNode = function(ray) {
  34. for (var i=0; i < editor.gimbalVertices.length; ++i) {
  35. if (ray.distanceSqToPoint(editor.gimbalVertices[i]) < 0.03) {
  36. //return {type: "gimbal", node: i};
  37. }
  38. }
  39. for (var j in abj.meta) {
  40. if (ray.distanceSqToPoint(abj.meta[j].position) < 0.03) {
  41. //return {type: "node", node: i};
  42. return j;
  43. }
  44. }
  45. return undefined;
  46. };
  47. editor.makeGimbal = function(center) {
  48. editor.gimbal = new THREE.Object3D();
  49. var pointGeometry = new THREE.Geometry();
  50. pointGeometry.vertices = [
  51. new THREE.Vector3(1, 0, 0),
  52. new THREE.Vector3(0, 1, 0),
  53. new THREE.Vector3(0, 0, 1),
  54. new THREE.Vector3(-1, 0, 0),
  55. new THREE.Vector3(0, -1, 0),
  56. new THREE.Vector3(0, 0, -1)
  57. ];
  58. editor.gimbalVertices = pointGeometry.vertices;
  59. var tips = new THREE.Points(pointGeometry, materials.tip);
  60. editor.gimbal.add(tips);
  61. gui.scene.add(editor.gimbal);
  62. };