flutter3d
Showcase Changelog 62 packages API reference

Describing the scene to a screen reader: the source

since 0.7.0 Widgets and the rest

Regions the guide quotes: announce (line 44), project (line 54), overlay (line 72).

1/// The scene, as something a screen reader can walk: one accessibility node
2/// per object, positioned where the camera actually projects it.
3///
4/// Quoted by `scene_semantics.md` and shown whole in the Source tab.
5library;
6
7import 'package:flutter/widgets.dart' show Size, SizedBox;
8import 'package:flutter3d/flutter3d.dart';
9import 'package:flutter3d_app/flutter3d_app.dart';
10import 'package:flutter3d_showcase/src/demo/demo.dart';
12/// The `scene-semantics` page: two wheels, each an accessibility node where
13/// the camera projects it. Its check is that both project to a node, left to
14/// the left, and that the overlay carries both.
15final class SceneSemanticsDemo extends ShowcaseDemo {
16 late final MeshNode _leftWheel;
17 late final MeshNode _rightWheel;
19 @override
20 Scene build(DemoContext context) {
21 final material = RenderMaterial(
22 name: 'wheel',
23 baseColor: LinearColor.fromSrgb(0.3, 0.3, 0.3, 1.0),
24 );
25 _leftWheel = MeshNode(
26 DeviceMesh.upload(context.device, SphereShape(segments: 16).build()),
27 material,
28 name: 'left-wheel',
29 )..setPosition(-0.6, 0, 0);
30 _rightWheel = MeshNode(
31 DeviceMesh.upload(context.device, SphereShape(segments: 16).build()),
32 material,
33 name: 'right-wheel',
34 )..setPosition(0.6, 0, 0);
35 return Scene()
36 ..add(_leftWheel)
37 ..add(_rightWheel)
38 ..add(
39 LightNode(name: 'sun', intensity: 3.0 * LightNode.legacyUnit)
40 ..setLocalForward(Vector3(-0.4, -1.0, -0.3)),
41 );
42 }
44 List<SceneAnnouncement> _announcements() => <SceneAnnouncement>[
45 SceneAnnouncement(id: 'left', label: 'left wheel', node: _leftWheel),
46 SceneAnnouncement(id: 'right', label: 'right wheel', node: _rightWheel),
47 ];
49 @override
50 void verify(Scene scene, FrameResult frame) {
51 if (frame.drawCalls < 1) {
52 throw StateError('the wheels were not drawn');
53 }
54 final camera = CameraNode()..setPosition(0, 0, 4);
55 final objects = semanticObjectsFor(
56 _announcements(),
57 camera: camera,
58 size: const Size(320, 180),
59 );
60 if (objects.length != 2) {
61 throw StateError('both wheels should project to a semantic object');
62 }
63 final left = objects.firstWhere((SemanticObject o) => o.id == 'left');
64 final right = objects.firstWhere((SemanticObject o) => o.id == 'right');
65 if (!(left.bounds.center.dx < right.bounds.center.dx)) {
66 throw StateError(
67 'the left wheel should project to the left of the '
68 'right one',
69 );
70 }
72 // The widget that publishes the objects to the platform. It is not
73 // pumped here, only built, since the claim above is about the numbers
74 // it would be given.
75 final overlay = SceneSemantics(
76 objects: objects,
77 child: const SizedBox.shrink(),
78 );
79 if (overlay.objects.length != 2 || !overlay.enabled) {
80 throw StateError(
81 'the overlay should carry both objects, enabled by '
82 'default',
83 );
84 }
85 }