CameraHelper constructor

CameraHelper(
  1. dynamic camera
)

Implementation

factory CameraHelper(camera) {
  var geometry = BufferGeometry();
  var material = LineBasicMaterial(
      {"color": 0xffffff, "vertexColors": true, "toneMapped": false});

  List<double> vertices = [];
  List<double> colors = [];

  Map<String, dynamic> pointMap = {};

  // colors

  var colorFrustum = Color.fromHex(0xffaa00);
  var colorCone = Color.fromHex(0xff0000);
  var colorUp = Color.fromHex(0x00aaff);
  var colorTarget = Color.fromHex(0xffffff);
  var colorCross = Color.fromHex(0x333333);

  addPoint(id, color) {
    vertices.addAll([0, 0, 0]);
    colors.addAll([color.r, color.g, color.b]);

    if (pointMap[id] == null) {
      pointMap[id] = [];
    }

    pointMap[id].add(vertices.length ~/ 3.0 - 1);
  }

  addLine(a, b, color) {
    addPoint(a, color);
    addPoint(b, color);
  }

  // near

  addLine('n1', 'n2', colorFrustum);
  addLine('n2', 'n4', colorFrustum);
  addLine('n4', 'n3', colorFrustum);
  addLine('n3', 'n1', colorFrustum);

  // far

  addLine('f1', 'f2', colorFrustum);
  addLine('f2', 'f4', colorFrustum);
  addLine('f4', 'f3', colorFrustum);
  addLine('f3', 'f1', colorFrustum);

  // sides

  addLine('n1', 'f1', colorFrustum);
  addLine('n2', 'f2', colorFrustum);
  addLine('n3', 'f3', colorFrustum);
  addLine('n4', 'f4', colorFrustum);

  // cone

  addLine('p', 'n1', colorCone);
  addLine('p', 'n2', colorCone);
  addLine('p', 'n3', colorCone);
  addLine('p', 'n4', colorCone);

  // up

  addLine('u1', 'u2', colorUp);
  addLine('u2', 'u3', colorUp);
  addLine('u3', 'u1', colorUp);

  // target

  addLine('c', 't', colorTarget);
  addLine('p', 'c', colorCross);

  // cross

  addLine('cn1', 'cn2', colorCross);
  addLine('cn3', 'cn4', colorCross);

  addLine('cf1', 'cf2', colorCross);
  addLine('cf3', 'cf4', colorCross);

  geometry.setAttribute(
      'position',
      Float32BufferAttribute(Float32Array.from(vertices), 3, false));
  geometry.setAttribute(
      'color',
      Float32BufferAttribute(Float32Array.from(colors), 3, false));

  CameraHelper cameraHelper = CameraHelper.create(geometry, material);
  cameraHelper.camera = camera;

  cameraHelper.camera.updateProjectionMatrix();

  cameraHelper.matrix = camera.matrixWorld;
  cameraHelper.matrixAutoUpdate = false;

  cameraHelper.pointMap = pointMap;

  cameraHelper.update();

  return cameraHelper;
}