flutter3d
Showcase Changelog 62 packages API reference

Wireframe: the source

since 0.1.0 or earlier Shading and materials

Regions the guide quotes: mesh (line 26), settings (line 47), check (line 61).

1/// `RenderSettings.wireframe`: triangles drawn as lines, and what a device
2/// that cannot do that reports instead.
3///
4/// Quoted by `wireframe.md` and shown whole in the Source tab.
5library;
6
7import 'package:flutter3d/flutter3d.dart';
8import 'package:flutter3d_showcase/src/demo/demo.dart';
9
10/// The `wireframe` page: a knot drawn as lines. Its check is that a device
11/// that cannot draw wireframe says so.
12final class WireframeDemo extends ShowcaseDemo {
13 /// Whether the frame asks for wireframe.
14 bool wireframe = true;
16 @override
17 void configureView(DemoContext context) {
18 context.orbit
19 ..distance = 4.5
20 ..yaw = 0.5
21 ..pitch = 0.25;
22 }
24 @override
25 Scene build(DemoContext context) {
26 final MeshNode knot = MeshNode(
27 DeviceMesh.upload(
28 context.device,
29 const TorusShape(segments: 32, tubeSegments: 16).build(),
30 ),
31 RenderMaterial(
32 name: 'knot',
33 baseColor: LinearColor.fromSrgb(0.3, 0.65, 0.85, 1.0),
34 ),
35 name: 'knot',
36 );
37 return Scene()
38 ..add(knot)
39 ..add(
40 LightNode(name: 'sun', intensity: 3.0 * LightNode.legacyUnit)
41 ..setLocalForward(Vector3(-0.4, -0.7, -0.6)),
42 );
43 }
45 @override
46 RenderSettings settings(DemoContext context) => RenderSettings(
47 wireframe: wireframe,
48 );
50 @override
51 List<DemoControl> controls(DemoContext context) => <DemoControl>[
52 ToggleControl(
53 'Wireframe',
54 value: () => wireframe,
55 onChanged: (bool v) => wireframe = v,
56 ),
57 ];
59 @override
60 void verify(Scene scene, FrameResult frame) {
61 // The software rasteriser has no polygon-mode line primitive, so this
62 // page's own claim on this device is the refusal itself: asking for
63 // wireframe here still draws the model solid, and the frame says why.
64 if (wireframe && !frame.wireframeDeclined) {
65 throw StateError('this device drew wireframe; the claim below is stale');
66 }
67 if (frame.drawCalls < 1) {
68 throw StateError('the knot was not drawn');
69 }
70 }