model property

Implementation

static ComponentSchema<ModelComponent> get model =>
    ComponentSchema<ModelComponent>(
      type: 'ModelComponent',
      id: 'model_3d_7c21e4b9',
      create: ModelComponent.new,
      extent: const _ModelExtent(),
      hints: const ComponentHints(
        dimensions: Dimensions.threeD,
        name: 'Model',
        group: '3D',
        description: 'Draws a glTF model (.glb or .gltf).',
        icon: Icons.view_in_ar,
        accentColor: Color(0xFF42A5F5),
        fields: {
          'model': FieldHint(label: 'Model', fileExtensions: ['glb', 'gltf']),
          'materials': FieldHint(
            label: 'Materials',
            description:
                'Material files drawn instead of its own: by material name, '
                '#index, or * for every one.',
          ),
          'castShadows': FieldHint(label: 'Casts shadows'),
          'visible': FieldHint(label: 'Visible'),
        },
      ),
      fields: [
        SchemaField(
          name: 'model',
          kind: FieldTypes.assetRef,
          read: (c) => (c as ModelComponent).model,
          write: (c, v) => (c as ModelComponent).model = v as String? ?? '',
        ),
        SchemaField(
          name: 'materials',
          kind: FieldTypes.map,
          read: (c) => Map<Object?, Object?>.of((c as ModelComponent).materials),
          write: (c, v) => (c as ModelComponent).materials = {
            if (v is Map)
              for (final e in v.entries)
                if (e.value is String && (e.value as String).isNotEmpty)
                  '${e.key}': e.value as String,
          },
        ),
        SchemaField(
          name: 'castShadows',
          kind: FieldTypes.boolean,
          read: (c) => (c as ModelComponent).castShadows,
          write: (c, v) => (c as ModelComponent).castShadows = v as bool,
        ),
        SchemaField(
          name: 'visible',
          kind: FieldTypes.boolean,
          read: (c) => (c as ModelComponent).visible,
          write: (c, v) => (c as ModelComponent).visible = v as bool,
        ),
      ],
    );