Skip to content

Commit

Permalink
Add Arrow2 model that uses ArrowHelper from three.js (#186)
Browse files Browse the repository at this point in the history
add arrow2 model that uses arrow helper in three.js, Add dispose method in arrow model
  • Loading branch information
jihoonl authored Jul 28, 2017
1 parent 69eafed commit 0978eb4
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 2 deletions.
79 changes: 79 additions & 0 deletions build/ros3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -2405,6 +2405,85 @@ ROS3D.Arrow.prototype.setColor = function(hex) {
this.material.color.setHex(hex);
};

/*
* Free memory of elements in this marker.
*/
ROS3D.Arrow.prototype.dispose = function() {
if (this.geometry !== undefined) {
this.geometry.dispose();
}
if (this.material !== undefined) {
this.material.dispose();
}
};

/**
* @author Jihoon Lee - [email protected]
*/

/**
* A Arrow is a THREE object that can be used to display an arrow model using ArrowHelper
*
* @constructor
* @param options - object with following keys:
*
* * origin (optional) - the origin of the arrow
* * direction (optional) - the direction vector of the arrow
* * length (optional) - the length of the arrow
* * headLength (optional) - the head length of the arrow
* * shaftDiameter (optional) - the shaft diameter of the arrow
* * headDiameter (optional) - the head diameter of the arrow
* * material (optional) - the material to use for this arrow
*/
ROS3D.Arrow2 = function(options) {
options = options || {};
var origin = options.origin || new THREE.Vector3(0, 0, 0);
var direction = options.direction || new THREE.Vector3(1, 0, 0);
var length = options.length || 1;
var headLength = options.headLength || 0.2;
var shaftDiameter = options.shaftDiameter || 0.05;
var headDiameter = options.headDiameter || 0.1;
var material = options.material || new THREE.MeshBasicMaterial();

THREE.ArrowHelper.call(this, direction, origin, length, 0xff0000);

};

ROS3D.Arrow2.prototype.__proto__ = THREE.ArrowHelper.prototype;

/*
* Free memory of elements in this object.
*/
ROS3D.Arrow2.prototype.dispose = function() {
if (this.line !== undefined) {
this.line.material.dispose();
this.line.geometry.dispose();
}
if (this.cone!== undefined) {
this.cone.material.dispose();
this.cone.geometry.dispose();
}
};

/*
ROS3D.Arrow2.prototype.setLength = function ( length, headLength, headWidth ) {
if ( headLength === undefined ) {
headLength = 0.2 * length;
}
if ( headWidth === undefined ) {
headWidth = 0.2 * headLength;
}
this.line.scale.set( 1, Math.max( 0, length), 1 );
this.line.updateMatrix();
this.cone.scale.set( headWidth, headLength, headWidth );
this.cone.position.y = length;
this.cone.updateMatrix();
};
*/

/**
* @author David Gossow - [email protected]
*/
Expand Down
4 changes: 2 additions & 2 deletions build/ros3d.min.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions src/models/Arrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,15 @@ ROS3D.Arrow.prototype.setLength = function(length) {
ROS3D.Arrow.prototype.setColor = function(hex) {
this.material.color.setHex(hex);
};

/*
* Free memory of elements in this marker.
*/
ROS3D.Arrow.prototype.dispose = function() {
if (this.geometry !== undefined) {
this.geometry.dispose();
}
if (this.material !== undefined) {
this.material.dispose();
}
};
66 changes: 66 additions & 0 deletions src/models/Arrow2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* @author Jihoon Lee - [email protected]
*/

/**
* A Arrow is a THREE object that can be used to display an arrow model using ArrowHelper
*
* @constructor
* @param options - object with following keys:
*
* * origin (optional) - the origin of the arrow
* * direction (optional) - the direction vector of the arrow
* * length (optional) - the length of the arrow
* * headLength (optional) - the head length of the arrow
* * shaftDiameter (optional) - the shaft diameter of the arrow
* * headDiameter (optional) - the head diameter of the arrow
* * material (optional) - the material to use for this arrow
*/
ROS3D.Arrow2 = function(options) {
options = options || {};
var origin = options.origin || new THREE.Vector3(0, 0, 0);
var direction = options.direction || new THREE.Vector3(1, 0, 0);
var length = options.length || 1;
var headLength = options.headLength || 0.2;
var shaftDiameter = options.shaftDiameter || 0.05;
var headDiameter = options.headDiameter || 0.1;
var material = options.material || new THREE.MeshBasicMaterial();

THREE.ArrowHelper.call(this, direction, origin, length, 0xff0000);

};

ROS3D.Arrow2.prototype.__proto__ = THREE.ArrowHelper.prototype;

/*
* Free memory of elements in this object.
*/
ROS3D.Arrow2.prototype.dispose = function() {
if (this.line !== undefined) {
this.line.material.dispose();
this.line.geometry.dispose();
}
if (this.cone!== undefined) {
this.cone.material.dispose();
this.cone.geometry.dispose();
}
};

/*
ROS3D.Arrow2.prototype.setLength = function ( length, headLength, headWidth ) {
if ( headLength === undefined ) {
headLength = 0.2 * length;
}
if ( headWidth === undefined ) {
headWidth = 0.2 * headLength;
}
this.line.scale.set( 1, Math.max( 0, length), 1 );
this.line.updateMatrix();
this.cone.scale.set( headWidth, headLength, headWidth );
this.cone.position.y = length;
this.cone.updateMatrix();
};
*/

0 comments on commit 0978eb4

Please sign in to comment.