Commit f01f38db authored by legoc's avatar legoc
Browse files

First factorisation of material and geometry of HKLLine

parent 26c1a5dc
......@@ -10,6 +10,7 @@ class EnergyLine extends TrajectoryLine {
constructor(type, parent, start, end, center, steps) {
super(type, parent, start, end, center, steps);
// The data stored.
this._data = [];
// The line is a segment.
......@@ -114,7 +115,7 @@ class EnergyLine extends TrajectoryLine {
}
highlightSpheres(value) {
// The spheres are always visible in spy mode.
if (!mode.spyMode) {
this._deltaSphereGroup.visible = value;
......
......@@ -10,15 +10,19 @@ class HKLLine extends TrajectoryLine {
constructor(type, parent, start, end, center, steps) {
super(type, parent, start, end, center, steps);
let geometry = new THREE.SphereGeometry(1/scale, 8, 8);
let material = new THREE.MeshBasicMaterial({color: 0x0000ff, opacity: 0.5, depthTest: true, transparent: false});
// Geometry and material.
this._lineSphereGeometry = new THREE.SphereGeometry(0.5 / scale, 8, 8);
this._lineMaterial = new THREE.MeshBasicMaterial({ color: Color.Q, depthTest: true, transparent: false });
this._sphereGeometry = new THREE.SphereGeometry(1 / scale, 8, 8);
this._sphereMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff, depthTest: true, transparent: false });
// Create the trajectory start sphere
this._startSphere = new THREE.Mesh(geometry, material);
this._startSphere = new THREE.Mesh(this._lineSphereGeometry, this._lineMaterial);
this._startSphere.renderOrder = 1;
// Create the trajectory end sphere.
this._endSphere = new THREE.Mesh(geometry, material);
this._endSphere = new THREE.Mesh(this._lineSphereGeometry, this._lineMaterial);
this._endSphere.renderOrder = 1;
// The line is an array of segments.
......@@ -45,9 +49,7 @@ class HKLLine extends TrajectoryLine {
this._startSphere.position.copy(this._start.clone());
this._endSphere.position.copy(this._end.clone());
let geometry = new THREE.SphereGeometry(1 / scale, 8, 8);
let material = new THREE.MeshBasicMaterial({color: 0xffffff, depthTest: true, transparent: false});
// Define the iterator.
let iterator = null;
if (this._type == 'q') {
iterator = new TrajectorySegmentIterator(this._start, this._end, this._intervals);
......@@ -69,15 +71,11 @@ class HKLLine extends TrajectoryLine {
this._deltaSphereGroup.remove(this._deltaSphereGroup.children[i]);
}
// Create the line.
let lineMaterial = new THREE.LineBasicMaterial({ color: Color.Q, linewidth: 5, depthTest: true, transparent: false});
lineMaterial.color.set(this.getColor(true));
// Define the previous point for the line segments.
let previousPoint = null;
// Place new spheres and segments.
for (let i = 0; i < this._intervals; i++) {
for (let i = 0; i < this._intervals + 1; i++) {
// Get the current point.
let currentPoint = iterator.value().clone();
......@@ -87,14 +85,14 @@ class HKLLine extends TrajectoryLine {
let length = currentPoint.clone().sub(previousPoint).length();
// Add the segment if start and end points are different (bad drawing otherwise).
if (length !== 0) {
let segment = new LineSegment(previousPoint, currentPoint, 0.5 / scale, lineMaterial);
let segment = new LineSegment(previousPoint, currentPoint, 0.5 / scale, this._lineMaterial);
this._line.push(segment);
this._lineGroup.add(segment.object3D);
}
}
// Define a sphere.
let stepSphere = new THREE.Mesh(geometry, material);
let stepSphere = new THREE.Mesh(this._sphereGeometry, this._sphereMaterial);
stepSphere.renderOrder = 3;
stepSphere.position.copy(iterator.value());
this._deltaSphereGroup.add(stepSphere);
......@@ -105,25 +103,11 @@ class HKLLine extends TrajectoryLine {
// Next iteration.
iterator.next();
}
// Last segment.
if (previousPoint !== null) {
let lastPoint = iterator.value().clone();
let length = lastPoint.clone().sub(previousPoint).length();
// Add the segment if start and end points are different (bad drawing otherwise).
if (length !== 0) {
let segment = new LineSegment(previousPoint, lastPoint, 0.5 / scale, lineMaterial);
this._lineGroup.add(segment.object3D);
}
}
}
highlightLines(color) {
// Change the color of the segments.
for (let i = 0; i < this._line.length; i++) {
this._line[i].material.color.set(color);
}
// Change the line material color.
this._lineMaterial.color.set(color);
}
highlightSpheres(value) {
......@@ -144,15 +128,11 @@ class HKLLine extends TrajectoryLine {
* Remove this trajectory properly.
*/
destroy() {
this._startSphere.geometry.dispose();
this._endSphere.geometry.dispose();
this._startSphere.material.dispose();
this._endSphere.material.dispose();
for (let d of this._deltaSphereGroup.children) {
d.geometry.dispose();
d.material.dispose();
}
this._lineSphereGeometry.dispose();
this._lineMaterial.dispose();
this._sphereGeometry.dispose();
this._sphereMaterial.dispose();
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment