ArrowHelper constructor

ArrowHelper([
  1. Vector3? dir,
  2. Vector3? origin,
  3. double? length,
  4. int? color,
  5. double? headLength,
  6. double? headWidth,
])

dir -- direction from origin. Must be a unit vector.

origin -- Point at which the arrow starts.

length -- length of the arrow. Default is 1.

color -- hexadecimal value to define color. Default is 0xffff00.

headLength -- The length of the head of the arrow. Default is 0.2 * length.

headWidth -- The width of the head of the arrow. Default is 0.2 * headLength.

Implementation

ArrowHelper([Vector3? dir, Vector3? origin, double? length, int? color, double? headLength, double? headWidth]) : super() {
  // dir is assumed to be normalized

  type = 'ArrowHelper';

  dir ??= Vector3(0, 0, 1);
  origin ??= Vector3(0, 0, 0);
  length ??= 1;
  color ??= 0xffff00;
  headLength ??= 0.2 * length;
  headWidth ??= 0.2 * headLength;

  if (_lineGeometry == null) {
    _lineGeometry = BufferGeometry();
    _lineGeometry!.setAttributeFromString('position',Float32BufferAttribute.fromList([0, 0, 0, 0, 1, 0], 3, false));

    _coneGeometry = CylinderGeometry(0, 0.5, 1, 5, 1);
    _coneGeometry!.translate(0, -0.5, 0);
  }

  position.setFrom(origin);

  line = Line(_lineGeometry,
      LineBasicMaterial.fromMap({"color": color, "toneMapped": false}));
  line.matrixAutoUpdate = false;
  add(line);

  cone = Mesh(_coneGeometry,
      MeshBasicMaterial.fromMap({"color": color, "toneMapped": false}));
  cone.matrixAutoUpdate = false;
  add(cone);

  setDirection(dir);
  setLength(length, headLength, headWidth);
}