Commit ac4c054e authored by legoc's avatar legoc
Browse files

Reviewed material and geometry use for HKLLine and EnergyLine

parent c9edfee6
......@@ -731,7 +731,11 @@ class TrajectoriesDataData {
update(trajectoriesDataModel) {
this._currentId = trajectoriesDataModel.id;
this._data = trajectoriesDataModel.data;
// Add the trajectories to the current data but do not replace them.
for (let id in trajectoriesDataModel.data) {
this._data[id] = trajectoriesDataModel.data[id];
}
return true;
}
......
......@@ -69,11 +69,13 @@ class TrajectoryController extends Controller {
this._trajectoryPanel.clearTrajectories();
this._trajectory3D.clearTrajectories();
for(let id in trajectory.trajectories) {
for (let id in trajectory.trajectories) {
let traj = trajectory.trajectories[id];
this._trajectoryPanel.addTrajectory(traj, trajectory.isVisible(id), false);
this._trajectory3D.createTrajectory(traj);
}
this.updateTrajectoryData();
}
/**
......
......@@ -10,6 +10,9 @@ class EnergyLine extends TrajectoryLine {
constructor(type, parent, start, end, center, steps) {
super(type, parent, start, end, center, steps);
// Material.
this._lineMaterial = new THREE.MeshBasicMaterial({ color: Color.Q, depthTest: true, transparent: false });
// The data stored.
this._data = [];
......@@ -28,7 +31,11 @@ class EnergyLine extends TrajectoryLine {
}
setData(data) {
this._data = data;
// Update only if the new data has more points.
if (data.length > this._data.length) {
this._data = data;
}
}
updateDataGroup() {
......@@ -43,8 +50,9 @@ class EnergyLine extends TrajectoryLine {
this._dataGroup.applyMatrix(matrix4);
// Remove old spheres.
for (let i = this._deltaSphereGroup.children.length - 1; i >= 0; i--) {
this._deltaSphereGroup.remove(this._deltaSphereGroup.children[i]);
for (let s of this._deltaSphereGroup.children) {
s.material.dispose();
this._deltaSphereGroup.remove(s);
}
// Calculate length of the segment.
......@@ -53,10 +61,6 @@ class EnergyLine extends TrajectoryLine {
// Calculate delta between spheres.
let delta = length / this._intervals;
// Place new spheres.
let dataGeometry = new THREE.SphereGeometry(0.5 * delta, 8, 8);
let pointGeometry = new THREE.SphereGeometry(1 / scale, 8, 8);
// Iterate the points and draw data sphere or point sphere.
for (let i = 0; i < this._intervals + 1; i++) {
......@@ -69,12 +73,14 @@ class EnergyLine extends TrajectoryLine {
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);
sphere = new THREE.Mesh(this.sphereGeometry, dataMaterial);
sphere.scale.multiplyScalar(0.5 * delta);
}
// Draw a point sphere.
else {
let pointMaterial = new THREE.MeshBasicMaterial({color: 0xffffff, depthTest: true, transparent: false});
sphere = new THREE.Mesh(pointGeometry, pointMaterial);
sphere = new THREE.Mesh(this.sphereGeometry, pointMaterial);
sphere.scale.multiplyScalar(1 / scale);
}
sphere.renderOrder = 4;
......@@ -88,10 +94,6 @@ class EnergyLine extends TrajectoryLine {
*/
updateLine() {
// Create the line.
let lineMaterial = new THREE.LineBasicMaterial({ color: Color.Q, linewidth: 5, depthTest: true, transparent: false});
lineMaterial.color.set(this.getColor(true));
// Remove the line from the data group.
if (this._line !== null) {
this._dataGroup.remove(this._line.object3D);
......@@ -101,7 +103,7 @@ class EnergyLine extends TrajectoryLine {
let length = this._end.clone().sub(this._start).length();
// Create a line segment for the line.
let segment = new LineSegment(new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, 0, length), 0.5/scale, lineMaterial);
let segment = new LineSegment(new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, 0, length), 0.5/scale, this._lineMaterial);
this._line = segment;
// Add the line to the data group.
......@@ -137,13 +139,15 @@ class EnergyLine extends TrajectoryLine {
* Remove this trajectory properly.
*/
destroy() {
// Remove from the parent.
this._parent.remove(this._group);
// Destroy the line segment.
this._line.destroy();
for (let d of this._deltaSphereGroup.children) {
d.geometry.dispose();
d.material.dispose();
// Dispose the materials of the spheres.
for (let s of this._deltaSphereGroup.children) {
s.material.dispose();
}
}
}
......
......@@ -10,20 +10,21 @@ class HKLLine extends TrajectoryLine {
constructor(type, parent, start, end, center, steps) {
super(type, parent, start, end, center, steps);
// Geometry and material.
this._lineSphereGeometry = new THREE.SphereGeometry(0.5 / scale, 8, 8);
// Material.
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(this._lineSphereGeometry, this._lineMaterial);
// Create the trajectory start sphere.
this._startSphere = new THREE.Mesh(this.sphereGeometry, this._lineMaterial);
this._startSphere.renderOrder = 1;
// Set the size of the sphere.
this._startSphere.scale.multiplyScalar(0.5 / scale);
// Create the trajectory end sphere.
this._endSphere = new THREE.Mesh(this._lineSphereGeometry, this._lineMaterial);
this._endSphere = new THREE.Mesh(this.sphereGeometry, this._lineMaterial);
this._endSphere.renderOrder = 1;
// Set the size of the sphere.
this._endSphere.scale.multiplyScalar(0.5 / scale);
// The line is an array of segments.
this._line = [];
......@@ -58,6 +59,11 @@ class HKLLine extends TrajectoryLine {
iterator = new TrajectoryCircleIterator(this._center, this._start, this._end, this._intervals);
}
// Destroy the line segments.
for (let i = 0; i < this._line.length; i++) {
this._line[i].destroy();
}
// Empty the line.
this._line = [];
......@@ -92,9 +98,12 @@ class HKLLine extends TrajectoryLine {
}
// Define a sphere.
let stepSphere = new THREE.Mesh(this._sphereGeometry, this._sphereMaterial);
let stepSphere = new THREE.Mesh(this.sphereGeometry, this._sphereMaterial);
stepSphere.renderOrder = 3;
stepSphere.position.copy(iterator.value());
// Set the size of the sphere.
stepSphere.scale.multiplyScalar(1 / scale);
this._deltaSphereGroup.add(stepSphere);
// Set the previous point.
......@@ -128,12 +137,17 @@ class HKLLine extends TrajectoryLine {
* Remove this trajectory properly.
*/
destroy() {
// Remove from the parent.
this._parent.remove(this._group);
this._lineSphereGeometry.dispose();
// Dispose the materials.
this._lineMaterial.dispose();
this._sphereGeometry.dispose();
this._sphereMaterial.dispose();
// Destroy the line segments.
for (let i = 0; i < this._line.length; i++) {
this._line[i].destroy();
}
}
}
......
......@@ -38,7 +38,7 @@ class LineSegment {
}
destroy() {
this._material.dispose();
// Geometry is disposed but not material as it is created in the class.
this._geometry.dispose();
}
......
......@@ -2,6 +2,8 @@ const {scale} = require('../../utils/conversion');
const Color = require('../../utils/colors');
const THREE = require('three');
const commonSphereGeometry = new THREE.SphereGeometry(1, 8, 8);
/**
* Class defining the trajectory line in 3D.
*/
......@@ -27,6 +29,10 @@ class TrajectoryLine {
this._parent.add(this._group);
}
get sphereGeometry() {
return commonSphereGeometry;
}
_setIntervals() {
this._intervals = this._steps - 1;
if (this._intervals == 0) {
......
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