|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- var editor = {};
- var pi2 = Math.pi / 2;
-
- editor.nearest = undefined;
-
- editor.orientations = {
- xy: new THREE.Matrix4(),
- xz: new THREE.Matrix4(),
- yz: new THREE.Matrix4()
- };
- editor.orientations.xz.makeRotationX(pi2);
-
- editor.onFreeMove = function() {
- var n = editor.nearestNode(mouse.ray);
- if (editor.nearest !== n) {
- editor.nearest = n;
- if (n) {
- gui.nodeMessage("Node " + n + " (VOP:" + abj.vops[n] + ")" +
- "<br/>" + "Click to edit neighbourhood");
- } else {
- gui.hideNodeMessage();
- }
- }
- };
-
- editor.onClick = function() {
- var n = editor.nearestNode(mouse.ray);
- if (n) {
- var p = abj.meta[n].position;
- editor.grid.position.set(p.x, p.y, p.z);
- gui.controls.target.set(p.x, p.y, p.z);
- gui.hideNodeMessage();
- editor.nearest = undefined;
- gui.serverMessage("Selected node " + n + "");
- } else {
- //TODO: ghastly
- var intersection = mouse.ray.intersectPlane(editor.plane);
- intersection.x = Math.round(intersection.x, 0);
- intersection.y = Math.round(intersection.y, 0);
- intersection.z = Math.round(intersection.z, 0);
- var newNode = abj.order();
- abj.add_node(newNode, {
- position: intersection
- });
- editor.grid.position.set(intersection.x, intersection.y, intersection.z);
- gui.controls.target.set(intersection.x, intersection.y, intersection.z);
- graph.update();
- gui.serverMessage("Created node " + newNode + " at ");
- }
- };
-
- editor.prepare = function() {
- mouse.onFreeMove = editor.onFreeMove;
- mouse.onClick = editor.onClick;
- document.addEventListener("keydown", editor.onKey, false);
- editor.makeGrid();
- };
-
- editor.onKey = function(evt) {
- if (evt.keyCode == 32) {
- editor.grid.rotation.x += Math.PI / 2;
- editor.plane.applyMatrix4(m);
- gui.render();
- gui.serverMessage("Rotated into the XY plane or whatever");
- }
- };
-
- editor.makeGrid = function() {
- editor.grid = new THREE.GridHelper(10, 1);
- editor.grid.rotation.x = Math.PI / 2;
- editor.grid.setColors(0xbbbbbb, 0xeeeeee);
- //editor.grid.matrixAutoUpdate = false;
- editor.plane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
- gui.scene.add(editor.grid);
- };
-
- editor.update = function(){
- };
-
- // Gets a reference to the node nearest to the mouse cursor
- // TODO: get rid of meta{}
- editor.nearestNode = function(ray) {
- for (var j in abj.meta) {
- if (ray.distanceSqToPoint(abj.meta[j].position) < 0.03) {
- return j;
- }
- }
- return undefined;
- };
|