collider property

ComponentSchema<Collider3D> get collider

Implementation

static ComponentSchema<Collider3D> get collider {
  bool shapeIs(Component c, Set<ColliderShape3D> shapes) =>
      shapes.contains((c as Collider3D).shape);
  return ComponentSchema<Collider3D>(
    type: 'Collider3D',
    id: 'collider_3d_1bf4c502',
    create: Collider3D.new,
    extent: const _ColliderExtent(),
    hints: ComponentHints(
      dimensions: Dimensions.threeD,
      name: 'Collider 3D',
      group: _group,
      description:
          'The shape of the entity\'s body; without a Rigid Body 3D, a static one.',
      icon: Icons.crop_square,
      accentColor: const Color(0xFF66BB6A),
      fieldGroups: const {
        'Shape': ['shape', 'size', 'radius', 'height', 'model', 'meshName'],
        'Height field': ['heightFieldSize', 'cellSize', 'heights'],
        'Placement': ['offset', 'rotation', 'scale'],
      },
      fields: {
        'shape': const FieldHint(
          label: 'Shape',
          description:
              'Match shape: the shape the entity is drawn as (a Cube, Stairs, …), following it.',
        ),
        'size': FieldHint(
          label: 'Size',
          visibleWhen: (c) => shapeIs(c, {ColliderShape3D.box}),
        ),
        'radius': FieldHint(
          label: 'Radius',
          scrub: _metres,
          visibleWhen: (c) => shapeIs(c, {
            ColliderShape3D.sphere,
            ColliderShape3D.capsule,
            ColliderShape3D.cylinder,
          }),
        ),
        'height': FieldHint(
          label: 'Height',
          scrub: _metres,
          visibleWhen: (c) =>
              shapeIs(c, {ColliderShape3D.capsule, ColliderShape3D.cylinder}),
        ),
        'model': FieldHint(
          label: 'Model',
          fileExtensions: const ['glb', 'gltf'],
          visibleWhen: (c) =>
              shapeIs(c, {ColliderShape3D.convexHull, ColliderShape3D.mesh}),
        ),
        'meshName': FieldHint(
          label: 'Mesh',
          description: 'Empty uses every mesh of the model.',
          visibleWhen: (c) =>
              shapeIs(c, {ColliderShape3D.convexHull, ColliderShape3D.mesh}),
        ),
        'heightFieldSize': FieldHint(
          label: 'Samples per side',
          visibleWhen: (c) => shapeIs(c, {ColliderShape3D.heightField}),
        ),
        'cellSize': FieldHint(
          label: 'Cell size',
          scrub: _metres,
          visibleWhen: (c) => shapeIs(c, {ColliderShape3D.heightField}),
        ),
        'heights': FieldHint(
          label: 'Heights',
          visibleWhen: (c) => shapeIs(c, {ColliderShape3D.heightField}),
        ),
        'offset': const FieldHint(label: 'Offset'),
        'rotation': const FieldHint(
          label: 'Rotation',
          unit: AngleUnit.degrees,
        ),
        'scale': const FieldHint(label: 'Scale'),
      },
    ),
    fields: [
      SchemaField(
        name: 'shape',
        kind: _colliderShape,
        read: (c) => (c as Collider3D).shape,
        write: (c, v) => (c as Collider3D).shape = v as ColliderShape3D,
      ),
      _vector<Collider3D>('size', (c) => c.size, (c, v) => c.size = v),
      _decimal<Collider3D>(
        'radius',
        (c) => c.radius,
        (c, v) => c.radius = v,
        min: 0,
      ),
      _decimal<Collider3D>(
        'height',
        (c) => c.height,
        (c, v) => c.height = v,
        min: 0,
      ),
      SchemaField(
        name: 'model',
        kind: FieldTypes.assetRef,
        read: (c) => (c as Collider3D).model,
        write: (c, v) => (c as Collider3D).model = v as String? ?? '',
      ),
      SchemaField(
        name: 'meshName',
        kind: FieldTypes.text,
        read: (c) => (c as Collider3D).meshName,
        write: (c, v) => (c as Collider3D).meshName = v as String? ?? '',
      ),
      SchemaField(
        name: 'heights',
        kind: FieldTypes.list,
        read: (c) => (c as Collider3D).heights,
        write: (c, v) => (c as Collider3D).heights = [
          if (v is List)
            for (final h in v) h is num ? h.toDouble() : 0.0,
        ],
      ),
      SchemaField(
        name: 'heightFieldSize',
        kind: FieldTypes.integer,
        read: (c) => (c as Collider3D).heightFieldSize,
        write: (c, v) =>
            (c as Collider3D).heightFieldSize = (v as num).toInt(),
        min: 0,
      ),
      _decimal<Collider3D>(
        'cellSize',
        (c) => c.cellSize,
        (c, v) => c.cellSize = v,
        min: 0,
      ),
      _vector<Collider3D>('offset', (c) => c.offset, (c, v) => c.offset = v),
      SchemaField(
        name: 'rotation',
        kind: FieldTypes.euler,
        read: (c) => (c as Collider3D).rotation,
        write: (c, v) => (c as Collider3D).rotation = v as Vector3,
      ),
      _vector<Collider3D>('scale', (c) => c.scale, (c, v) => c.scale = v),
    ],
  );
}