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