A lesson through the rig: the source
Open the live demo · Read the guide · View on GitHub
Regions the guide quotes: steps (line 20), view (line 63), apply (line 75).
1/// The same lesson document a step panel authors, played back through a
2/// stereo rig with a Previous and a Next button instead of a keyboard.
3///
4/// Quoted by `stereo_lesson.md` and shown whole in the Source tab.
5library;
7import 'package:flutter/widgets.dart';
8import 'package:flutter3d/flutter3d.dart' hide Material;
9import 'package:flutter3d/flutter3d.dart' as f3d show Material;
10import 'package:flutter3d_showcase/src/demo/demo.dart';
11import 'package:flutter3d_sim/flutter3d_sim.dart';
12import 'package:flutter3d_stereo/flutter3d_stereo.dart';
13import 'package:vector_math/vector_math.dart';
15final class StereoLessonDemo extends ShowcaseDemo {
16 final StereoRig _rig = StereoRig();
17 late Scene _scene;
18 late MeshNode _detail;
20 late final LessonPlayer _player = LessonPlayer(<EntityDef>[
21 EntityDef(
22 type: 'edu_step',
23 position: Vector3(0, 0, 0),
24 properties: const <String, Object?>{
25 'hidden': <String>['detail'],
26 },
27 ),
28 EntityDef(
29 type: 'edu_step',
30 position: Vector3(0.5, 0, 0),
31 properties: const <String, Object?>{
32 'visible': <String>['detail'],
33 },
34 ),
35 ]);
38 Scene build(DemoContext context) {
39 final material = f3d.Material(
40 name: 'ball',
41 baseColor: Vector4(0.8, 0.5, 0.3, 1.0),
42 );
43 final ball = MeshNode(
44 DeviceMesh.upload(context.device, SphereShape(segments: 24).build()),
45 material,
46 )..setPosition(0, 0, -2);
47 _detail = MeshNode(
48 DeviceMesh.upload(context.device, SphereShape(segments: 12).build()),
49 f3d.Material(name: 'detail', baseColor: Vector4(0.9, 0.9, 0.2, 1.0)),
50 name: 'detail',
51 )..setPosition(0.4, 0, -2);
52 _scene = Scene()
53 ..add(_rig.stage)
54 ..add(ball)
55 ..add(_detail)
56 ..add(
57 LightNode(name: 'sun', intensity: 3.0)
58 ..setLocalForward(Vector3(-0.4, -1.0, -0.3)),
59 );
60 return _scene;
61 }
64 Widget? customBody(BuildContext buildContext, DemoContext context) =>
65 LessonStereoView(
66 renderer: context.renderer,
67 scene: _scene,
68 rig: _rig,
69 player: _player,
70 nodes: <String, SceneNode>{'detail': _detail},
71 );
74 void verify(Scene scene, FrameResult frame) {
75 // The first step hides the detail node; stepping forward shows it.
76 _player.applyCurrent(_rig, nodes: <String, SceneNode>{'detail': _detail});
77 final hiddenAtStart = !_detail.visible;
78 _player.next();
79 _player.applyCurrent(_rig, nodes: <String, SceneNode>{'detail': _detail});
80 final shownAtStepTwo = _detail.visible;
81 if (!hiddenAtStart || !shownAtStepTwo) {
82 throw StateError(
83 'the detail node should be hidden on the first step '
84 'and shown on the second',
85 );
86 }
87 }
88}