Commit 71b43491 authored by legoc's avatar legoc
Browse files

Trajectory line uses point and not iterator in EnergyLine

parent a3d1a922
......@@ -2,8 +2,6 @@ const TrajectoryLine = require('./trajectory-line');
const {scale, vector3WorldToView, scalarWorldToView, vector3ViewToWorld} = require('../conversion');
const Color = require('../colors');
const {mapColor} = require('../map-color');
const TrajectorySegmentIterator = require('./trajectory-segment-iterator');
const TrajectoryCircleIterator = require('./trajectory-circle-iterator');
const THREE = require('three');
class EnergyLine extends TrajectoryLine {
......@@ -16,6 +14,11 @@ class EnergyLine extends TrajectoryLine {
this._dataGroup = new THREE.Group();
this._group.add(this._dataGroup);
this._dataGroup.add(this._trajectoryLine);
this._deltaSphereGroup = new THREE.Group();
this._dataGroup.add(this._deltaSphereGroup);
this.highlight(false);
this.updateLine();
}
......@@ -25,7 +28,7 @@ class EnergyLine extends TrajectoryLine {
}
highlightSpheres(value) {
this._dataGroup.visible = value;
this._deltaSphereGroup.visible = value;
}
updateDataGroup() {
......@@ -40,8 +43,8 @@ class EnergyLine extends TrajectoryLine {
this._dataGroup.applyMatrix(matrix4);
// Remove old spheres.
for (var i = this._dataGroup.children.length - 1; i >= 0; i--) {
this._dataGroup.remove(this._dataGroup.children[i]);
for (var i = this._deltaSphereGroup.children.length - 1; i >= 0; i--) {
this._deltaSphereGroup.remove(this._deltaSphereGroup.children[i]);
}
// Calculate delta between spheres.
......@@ -52,25 +55,33 @@ class EnergyLine extends TrajectoryLine {
let dataGeometry = new THREE.SphereGeometry(0.5 * delta, 8, 8);
let pointGeometry = new THREE.SphereGeometry(0.25/scale, 8, 8);
// Iterate the points and draw data sphere or point sphere.
for (let i = 0; i < this._intervals + 1; i++) {
let position = new THREE.Vector3(0, 0, i * delta);
let sphere;
// Draw a data sphere.
if (i < this._data.length) {
let dataMaterial = new THREE.MeshBasicMaterial({color: 0xffffff, depthTest: true, transparent: false});
const color = mapColor(this._data[i], 0, 500);
dataMaterial.color.setRGB(color.r, color.g, color.b);
sphere = new THREE.Mesh(dataGeometry, dataMaterial);
}
// Draw a point sphere.
else {
let pointMaterial = new THREE.MeshBasicMaterial({color: 0xffffff, depthTest: true, transparent: false});
sphere = new THREE.Mesh(pointGeometry, pointMaterial);
}
sphere.renderOrder = 4;
sphere.position.copy(new THREE.Vector3(0, 0, i * delta));
this._dataGroup.add(sphere);
sphere.position.copy(position);
this._deltaSphereGroup.add(sphere);
// Add a vertex for the trajectory line.
this._trajectoryLine.geometry.vertices.push(position.clone());
}
}
/**
......@@ -80,15 +91,7 @@ class EnergyLine extends TrajectoryLine {
// Remove the line from the scene before rebuilding it.
// Indeed trying to update the line by updating the vertices does not work.
this._group.remove(this._trajectoryLine);
let iterator = null;
if (this._type == 'q') {
iterator = new TrajectorySegmentIterator(this._start, this._end, this._intervals);
}
else if (this._type == 'ki' || this._type == 'kf') {
iterator = new TrajectoryCircleIterator(this._center, this._start, this._end, this._intervals);
}
this._dataGroup.remove(this._trajectoryLine);
// Create the line.
let lineMaterial = new THREE.LineBasicMaterial({ color: Color.Q, linewidth: 5, depthTest: true, transparent: false});
......@@ -99,19 +102,9 @@ class EnergyLine extends TrajectoryLine {
// Set the color.
this.highlight(true);
// Place new spheres.
for(let i = 0; i < this._intervals; i++) {
this._trajectoryLine.geometry.vertices.push(iterator.value());
iterator.next();
}
this._trajectoryLine.geometry.vertices.push(iterator.value());
this._trajectoryLine.geometry.verticesNeedUpdate = true;
// Add the newly created line.
this._group.add(this._trajectoryLine);
this._dataGroup.add(this._trajectoryLine);
// Update the data.
this.updateDataGroup();
......@@ -132,7 +125,7 @@ class EnergyLine extends TrajectoryLine {
this._trajectoryLine.geometry.dispose();
this._trajectoryLine.material.dispose();
for (let d of this._dataGroup.children) {
for (let d of this._deltaSphereGroup.children) {
d.geometry.dispose();
d.material.dispose();
}
......
......@@ -9,6 +9,8 @@ class HKLLine extends TrajectoryLine {
constructor(type, parent, start, end, center, steps) {
super(type, parent, start, end, center, steps);
this._group.add(this._trajectoryLine);
let geometry = new THREE.SphereGeometry(1/scale, 8, 8);
let material = new THREE.MeshBasicMaterial({color: 0x0000ff, opacity: 0.5, depthTest: true, transparent: false});
......@@ -20,9 +22,7 @@ class HKLLine extends TrajectoryLine {
this._trajESphere = new THREE.Mesh(geometry, material);
this._trajESphere.renderOrder = 1;
this._deltaSphereGroup = new THREE.Group();
this._group.add(this._trajSSphere);
this._group.add(this._trajESphere);
this._group.add(this._deltaSphereGroup);
......
......@@ -33,8 +33,6 @@ class TrajectoryLine {
// Add elements to the parent.
this._parent.add(this._group);
this._group.add(this._trajectoryLine);
}
_setIntervals() {
......
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