setupGizmo static method

Mesh setupGizmo(
  1. Map<String, dynamic> gizmoMap
)

Implementation

static Mesh setupGizmo(Map<String,dynamic> gizmoMap) {
  final gizmo = Mesh();

  for (final name in gizmoMap.keys) {
    final len = gizmoMap[name].length;

    for (int i = (len - 1); i >= 0; i--) {
      final gi = gizmoMap[name][i];

      late Object3D object;
      if (gi.length > 0) {
        object = gi[0];
      }

      List<num>? position;
      if (gi.length > 1) {
        position = gi[1];
      }

      List<num>? rotation;
      if (gi.length > 2) {
        rotation = gi[2];
      }

      List<num>? scale;
      if (gi.length > 3) {
        scale = gi[3];
      }

      dynamic tag ;
      if (gi.length > 4) {
        tag = gi[4];
      }

      // name and tag properties are essential for picking and updating logic.
      object.name = name;
      object.tag = tag;

      if (position != null) {
        object.position.setValues(position[0].toDouble(), position[1].toDouble(), position[2].toDouble());
      }

      if (rotation != null) {
        object.rotation.set(rotation[0].toDouble(), rotation[1].toDouble(), rotation[2].toDouble());
      }

      if (scale != null) {
        object.scale.setValues(scale[0].toDouble(), scale[1].toDouble(), scale[2].toDouble());
      }

      object.updateMatrix();

      final tempGeometry = object.geometry?.clone();
      tempGeometry?.applyMatrix4(object.matrix);
      object.geometry = tempGeometry;
      object.renderOrder = double.maxFinite.toInt();

      object.position.setValues(0.0, 0.0, 0.0);
      object.rotation.set(0.0, 0.0, 0.0);
      object.scale.setValues(1.0, 1.0, 1.0);

      gizmo.add(object);
    }
  }

  return gizmo;
}