collider property
ComponentDefinition<Collider3DComponent>
get
collider
Implementation
static ComponentDefinition<Collider3DComponent> get collider {
bool shapeIs(Component c, Set<Collider3DShape> shapes) =>
shapes.contains((c as Collider3DComponent).shape);
return ComponentDefinition<Collider3DComponent>(
type: 'Collider3DComponent',
id: 'collider_3d_1bf4c502',
create: Collider3DComponent.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, {Collider3DShape.box}),
),
'radius': FieldHint(
label: 'Radius',
scrub: _metres,
visibleWhen: (c) => shapeIs(c, {
Collider3DShape.sphere,
Collider3DShape.capsule,
Collider3DShape.cylinder,
}),
),
'height': FieldHint(
label: 'Height',
scrub: _metres,
visibleWhen: (c) =>
shapeIs(c, {Collider3DShape.capsule, Collider3DShape.cylinder}),
),
'model': FieldHint(
label: 'Model',
fileExtensions: const ['glb', 'gltf'],
visibleWhen: (c) =>
shapeIs(c, {Collider3DShape.convexHull, Collider3DShape.mesh}),
),
'meshName': FieldHint(
label: 'Mesh',
description: 'Empty uses every mesh of the model.',
visibleWhen: (c) =>
shapeIs(c, {Collider3DShape.convexHull, Collider3DShape.mesh}),
),
'heightFieldSize': FieldHint(
label: 'Samples per side',
visibleWhen: (c) => shapeIs(c, {Collider3DShape.heightField}),
),
'cellSize': FieldHint(
label: 'Cell size',
scrub: _metres,
visibleWhen: (c) => shapeIs(c, {Collider3DShape.heightField}),
),
'heights': FieldHint(
label: 'Heights',
visibleWhen: (c) => shapeIs(c, {Collider3DShape.heightField}),
),
'offset': const FieldHint(label: 'Offset'),
'rotation': const FieldHint(
label: 'Rotation',
unit: AngleUnit.degrees,
),
'scale': const FieldHint(label: 'Scale'),
},
),
fields: [
FieldDefinition(
name: 'shape',
kind: _colliderShape,
read: (c) => (c as Collider3DComponent).shape,
write: (c, v) =>
(c as Collider3DComponent).shape = v as Collider3DShape,
),
_vector<Collider3DComponent>(
'size',
(c) => c.size,
(c, v) => c.size = v,
),
_decimal<Collider3DComponent>(
'radius',
(c) => c.radius,
(c, v) => c.radius = v,
min: 0,
),
_decimal<Collider3DComponent>(
'height',
(c) => c.height,
(c, v) => c.height = v,
min: 0,
),
FieldDefinition(
name: 'model',
kind: FieldTypes.assetRef,
read: (c) => (c as Collider3DComponent).model,
write: (c, v) =>
(c as Collider3DComponent).model = v as String? ?? '',
),
FieldDefinition(
name: 'meshName',
kind: FieldTypes.text,
read: (c) => (c as Collider3DComponent).meshName,
write: (c, v) =>
(c as Collider3DComponent).meshName = v as String? ?? '',
),
FieldDefinition(
name: 'heights',
kind: FieldTypes.list,
read: (c) => (c as Collider3DComponent).heights,
write: (c, v) => (c as Collider3DComponent).heights = [
if (v is List)
for (final h in v) h is num ? h.toDouble() : 0.0,
],
),
FieldDefinition(
name: 'heightFieldSize',
kind: FieldTypes.integer,
read: (c) => (c as Collider3DComponent).heightFieldSize,
write: (c, v) =>
(c as Collider3DComponent).heightFieldSize = (v as num).toInt(),
min: 0,
),
_decimal<Collider3DComponent>(
'cellSize',
(c) => c.cellSize,
(c, v) => c.cellSize = v,
min: 0,
),
_vector<Collider3DComponent>(
'offset',
(c) => c.offset,
(c, v) => c.offset = v,
),
FieldDefinition(
name: 'rotation',
kind: FieldTypes.euler,
read: (c) => (c as Collider3DComponent).rotation,
write: (c, v) => (c as Collider3DComponent).rotation = v as Vector3,
),
_vector<Collider3DComponent>(
'scale',
(c) => c.scale,
(c, v) => c.scale = v,
),
],
);
}