@@ -115,11 +115,26 @@ editor.prepare = function() { | |||||
}; | }; | ||||
editor.onKey = function(evt) { | editor.onKey = function(evt) { | ||||
console.log(evt.keyCode); | |||||
if (evt.keyCode === 32) { | if (evt.keyCode === 32) { | ||||
editor.setOrientation((editor.orientation + 1) % 3); | editor.setOrientation((editor.orientation + 1) % 3); | ||||
editor.gridTimeOut = 0; | |||||
} | } | ||||
if (evt.keyCode === 46 || evt.keyCode === 68) { | |||||
if (evt.keyCode === 38) { | |||||
editor.moveGridNormal(1); | |||||
editor.gridTimeOut = 0; | |||||
} | |||||
if (evt.keyCode === 40) { | |||||
editor.moveGridNormal(-1); | |||||
editor.gridTimeOut = 0; | |||||
} | |||||
if (evt.keyCode === 46) { | |||||
editor.deleteNode(); | editor.deleteNode(); | ||||
editor.gridTimeOut = 0; | |||||
} | |||||
if (evt.keyCode === 67) { | |||||
materials.curveProperties.splineDensity = materials.curveProperties.splineDensity == 10 ? 0 : 10; | |||||
gui.render(); | |||||
} | } | ||||
}; | }; | ||||
@@ -134,6 +149,17 @@ editor.setOrientation = function(orientation) { | |||||
gui.render(); | gui.render(); | ||||
}; | }; | ||||
editor.moveGridNormal = function(delta) { | |||||
var orientation = editor.orientation; | |||||
var rotation = editor.orientations[orientation]; | |||||
var normal = new THREE.Vector3(0, 1, 0); | |||||
normal.applyEuler(rotation); | |||||
editor.grid.position.addScaledVector(normal, delta); | |||||
editor.plane = new THREE.Plane(); | |||||
editor.plane.setFromNormalAndCoplanarPoint(normal, editor.grid.position); | |||||
gui.render(); | |||||
}; | |||||
editor.makeGrid = function() { | editor.makeGrid = function() { | ||||
editor.grid = new THREE.GridHelper(10, 1); | editor.grid = new THREE.GridHelper(10, 1); | ||||
editor.grid.setColors(0xbbbbbb, 0xeeeeee); | editor.grid.setColors(0xbbbbbb, 0xeeeeee); | ||||
@@ -50,7 +50,7 @@ graph.update = function(newState) { | |||||
if (editor.selection) { | if (editor.selection) { | ||||
var node = editor.selection; | var node = editor.selection; | ||||
if (Object.prototype.hasOwnProperty.call(abj.node, node)) { | if (Object.prototype.hasOwnProperty.call(abj.node, node)) { | ||||
editor.grid.position.copy(abj.node[node].position); | |||||
// Do nothing ... | |||||
gui.controls.target.copy(abj.node[node].position); | gui.controls.target.copy(abj.node[node].position); | ||||
node_name.innerHTML = "Node " + node; | node_name.innerHTML = "Node " + node; | ||||
node_data.className = "visible"; | node_data.className = "visible"; | ||||
@@ -1,37 +1,36 @@ | |||||
var materials = {}; | var materials = {}; | ||||
var curveProperties = { | |||||
splineDensity: 10, | |||||
curvature: 20 | |||||
}; | |||||
// Is called on boot | // Is called on boot | ||||
materials.prepare = function() { | materials.prepare = function() { | ||||
var ballSprite = new THREE.Texture(document.getElementById("ball")); | var ballSprite = new THREE.Texture(document.getElementById("ball")); | ||||
ballSprite.needsUpdate = true; | ballSprite.needsUpdate = true; | ||||
materials.edge = new THREE.LineBasicMaterial({ | materials.edge = new THREE.LineBasicMaterial({ | ||||
color: "gray", | |||||
color: "black", | |||||
transparent: false, | transparent: false, | ||||
linewidth: 3 | |||||
linewidth: 1 | |||||
}); | }); | ||||
materials.edge.depthTest = false; | materials.edge.depthTest = false; | ||||
materials.qubit = new THREE.PointsMaterial({ | materials.qubit = new THREE.PointsMaterial({ | ||||
size: 0.6, | |||||
size: 0.4, | |||||
map: ballSprite, | map: ballSprite, | ||||
alphaTest: 0.5, | alphaTest: 0.5, | ||||
transparent: true, | transparent: true, | ||||
vertexColors: THREE.VertexColors | vertexColors: THREE.VertexColors | ||||
}); | }); | ||||
materials.curveProperties = { | |||||
splineDensity: 10, | |||||
curvature: 20 | |||||
}; | |||||
}; | }; | ||||
materials.makeCurve = function(a, b) { | materials.makeCurve = function(a, b) { | ||||
var length = new THREE.Vector3().subVectors(a, b).length(); | var length = new THREE.Vector3().subVectors(a, b).length(); | ||||
var bend = new THREE.Vector3(length / curveProperties.curvature, length / curveProperties.curvature, 0); | |||||
var bend = new THREE.Vector3(length / materials.curveProperties.curvature, length / materials.curveProperties.curvature, 0); | |||||
var mid = new THREE.Vector3().add(a).add(b).multiplyScalar(0.5).add(bend); | var mid = new THREE.Vector3().add(a).add(b).multiplyScalar(0.5).add(bend); | ||||
var spline = new THREE.CatmullRomCurve3([a, mid, b]); | var spline = new THREE.CatmullRomCurve3([a, mid, b]); | ||||
var geometry = new THREE.Geometry(); | var geometry = new THREE.Geometry(); | ||||
var splinePoints = spline.getPoints(curveProperties.splineDensity); | |||||
var splinePoints = spline.getPoints(materials.curveProperties.splineDensity); | |||||
Array.prototype.push.apply(geometry.vertices, splinePoints); | Array.prototype.push.apply(geometry.vertices, splinePoints); | ||||
return new THREE.Line(geometry, materials.edge); | return new THREE.Line(geometry, materials.edge); | ||||
}; | }; | ||||
@@ -9,6 +9,7 @@ The state is initialized as a blank canvas without any qubits. | |||||
- Click on a qubit to view its properties | - Click on a qubit to view its properties | ||||
- Select a qubit, then <kbd>Shift</kbd>-click another node to act a CZ gate | - Select a qubit, then <kbd>Shift</kbd>-click another node to act a CZ gate | ||||
- Press <kbd>Space</kbd> to rotate the grid | - Press <kbd>Space</kbd> to rotate the grid | ||||
- Use the <kbd>Up</kbd> and <kbd>Down</kbd> arrow keys to move the grid normal to its plane. | |||||
Arbitrary 3D structures can be constructed by rotating the grid. | Arbitrary 3D structures can be constructed by rotating the grid. | ||||
@@ -47,7 +47,7 @@ | |||||
<li><a onclick="editor.raussendorf()">Raussendorf</a></li> | <li><a onclick="editor.raussendorf()">Raussendorf</a></li> | ||||
<li><a onclick="share()">Share</a></li> | <li><a onclick="share()">Share</a></li> | ||||
<li><a href="/{{uuid}}/download">Download</a></li> | <li><a href="/{{uuid}}/download">Download</a></li> | ||||
<li><a href="/doc" id=help>Help</a></li> | |||||
<li><a href="/doc" id=help>Documentation</a></li> | |||||
</ul> | </ul> | ||||
</div> | </div> | ||||