vec3<C extends Component> static method

ComponentField<C> vec3<C extends Component>(
  1. String name, {
  2. required Vector3 defaultValue(),
  3. Vector3 get(
    1. C component
    )?,
  4. void set(
    1. C component,
    2. Vector3 value
    )?,
  5. String? doc,
  6. String? group,
  7. List<PropertyConstraint<Object>> constraints = const [],
  8. List<String> formerNames = const [],
  9. bool transient = false,
})

A Vector3 property. Add an RgbColor constraint for linear RGB colors carried as vectors (byte-compatible with existing documents).

Implementation

static ComponentField<C> vec3<C extends Component>(
  String name, {
  required Vector3 Function() defaultValue,
  Vector3 Function(C component)? get,
  void Function(C component, Vector3 value)? set,
  String? doc,
  String? group,
  List<PropertyConstraint<Object>> constraints = const [],
  List<String> formerNames = const [],
  bool transient = false,
}) => ComponentField(
  ComponentPropertyDef(
    name,
    ComponentPropertyKind.vec3,
    defaultValue: Vec3Value(defaultValue()),
    doc: doc,
    group: group,
    constraints: constraints,
    formerNames: formerNames,
    transient: transient,
  ),
  read: get == null ? null : (c, _) => Vec3Value(get(c).clone()),
  write: set == null
      ? null
      : (c, v, _) {
          if (v is! Vec3Value) return;
          final vector = v.value.clone();
          if (constraints.any((constraint) => constraint is Normalized) &&
              vector.length2 > 0) {
            vector.normalize();
          }
          set(c, vector);
        },
);