flutter3d
Showcase Changelog 38 packages API reference

Wireframe: the source

since 0.1.0 or earlier Shading and materials

Regions the guide quotes: mesh (line 24), settings (line 42), check (line 56).

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';
9import 'package:vector_math/vector_math.dart';
11final class WireframeDemo extends ShowcaseDemo {
12 bool wireframe = true;
14 @override
15 void configureView(DemoContext context) {
16 context.orbit
17 ..distance = 4.5
18 ..yaw = 0.5
19 ..pitch = 0.25;
20 }
22 @override
23 Scene build(DemoContext context) {
24 final MeshNode knot = MeshNode(
25 DeviceMesh.upload(
26 context.device,
27 const TorusShape(segments: 32, tubeSegments: 16).build(),
28 ),
29 Material(name: 'knot', baseColor: Vector4(0.3, 0.65, 0.85, 1.0)),
30 name: 'knot',
31 );
32 return Scene()
33 ..add(knot)
34 ..add(
35 LightNode(name: 'sun', intensity: 3.0)
36 ..setLocalForward(Vector3(-0.4, -0.7, -0.6)),
37 );
38 }
40 @override
41 RenderSettings settings(DemoContext context) => RenderSettings(
42 wireframe: wireframe,
43 );
45 @override
46 List<DemoControl> controls(DemoContext context) => <DemoControl>[
47 ToggleControl(
48 'Wireframe',
49 value: () => wireframe,
50 onChanged: (bool v) => wireframe = v,
51 ),
52 ];
54 @override
55 void verify(Scene scene, FrameResult frame) {
56 // The software rasteriser has no polygon-mode line primitive, so this
57 // page's own claim on this device is the refusal itself: asking for
58 // wireframe here still draws the model solid, and the frame says why.
59 if (wireframe && !frame.wireframeDeclined) {
60 throw StateError('this device drew wireframe; the claim below is stale');
61 }
62 if (frame.drawCalls < 1) {
63 throw StateError('the knot was not drawn');
64 }
65 }