Commit e3455c83 authored by legoc's avatar legoc
Browse files

Replaced line with cylinder in Energy line

parent 71b43491
......@@ -14,9 +14,9 @@ class Arrow3D {
this.cylinder = new THREE.Mesh( this.geometry, this.material );
this.cylinder.position.y = 10;
//radius, height, radialSegments, heightSegements
//radius, height, radialSegments, heightSegments
this.coneHeight = this.cylinderHeight/6;
//radius, height, radialSegments, heightSegements
//radius, height, radialSegments, heightSegments
this.geometry = new THREE.ConeGeometry(1, this.coneHeight, 500);
this.cone = new THREE.Mesh(this.geometry, this.material);
this.cone.position.y = this.cylinderHeight;
......
......@@ -10,11 +10,16 @@ class EnergyLine extends TrajectoryLine {
this._data = [];
// Define the line that will be a cylinder.
this._line = null;
// Create a group for the data.
this._dataGroup = new THREE.Group();
this._group.add(this._dataGroup);
this._dataGroup.add(this._trajectoryLine);
this._lineGroup = new THREE.Group();
this._lineGroup.rotateX(Math.PI/2);
this._dataGroup.add(this._lineGroup);
this._deltaSphereGroup = new THREE.Group();
this._dataGroup.add(this._deltaSphereGroup);
......@@ -33,7 +38,7 @@ class EnergyLine extends TrajectoryLine {
updateDataGroup() {
// Change the group.
// Reset the group transform.
let inv = new THREE.Matrix4();
inv.getInverse(this._dataGroup.matrix);
this._dataGroup.applyMatrix(inv);
......@@ -47,13 +52,15 @@ class EnergyLine extends TrajectoryLine {
this._deltaSphereGroup.remove(this._deltaSphereGroup.children[i]);
}
// Calculate delta between spheres.
// Calculate length of the segment.
let length = this._end.clone().sub(this._start).length();
// 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(0.25/scale, 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++) {
......@@ -78,9 +85,6 @@ class EnergyLine extends TrajectoryLine {
sphere.renderOrder = 4;
sphere.position.copy(position);
this._deltaSphereGroup.add(sphere);
// Add a vertex for the trajectory line.
this._trajectoryLine.geometry.vertices.push(position.clone());
}
}
......@@ -89,22 +93,24 @@ class EnergyLine extends TrajectoryLine {
*/
updateLine() {
// Remove the line from the scene before rebuilding it.
// Indeed trying to update the line by updating the vertices does not work.
this._dataGroup.remove(this._trajectoryLine);
// Create the line.
let lineMaterial = new THREE.LineBasicMaterial({ color: Color.Q, linewidth: 5, depthTest: true, transparent: false});
this._trajectoryLine = new THREE.Line(new THREE.Geometry(), lineMaterial);
this._trajectoryLine.geometry.verticesNeedUpdate = true;
this._trajectoryLine.renderOrder = 2;
// Set the color.
this.highlight(true);
// Add the newly created line.
this._dataGroup.add(this._trajectoryLine);
// Remove the line from the line group.
this._lineGroup.remove(this._line);
// Calculate length of the segment.
let length = this._end.clone().sub(this._start).length();
// Define the line as a cylinder.
let geometry = new THREE.CylinderGeometry(0.5/scale, 0.5/scale, length, 32);
this._line = new THREE.Mesh(geometry, lineMaterial);
// As the line group is rotated on the x axis, we translate the cylinder on the y axis.
this._line.position.y = 0.5 * length;
this._lineGroup.add(this._line);
// Update the data.
this.updateDataGroup();
......@@ -114,7 +120,7 @@ class EnergyLine extends TrajectoryLine {
* Set line visibility.
*/
setVisibility(visibility) {
this._trajectoryLine.visible = visibility;
this._line.visible = visibility;
//this._dataGroup.visible = visibility;
}
......@@ -122,8 +128,8 @@ class EnergyLine extends TrajectoryLine {
* Remove this trajectory properly.
*/
destroy() {
this._trajectoryLine.geometry.dispose();
this._trajectoryLine.material.dispose();
this._line.geometry.dispose();
this._line.material.dispose();
for (let d of this._deltaSphereGroup.children) {
d.geometry.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