flutter3d
Showcase Changelog 38 packages API reference

Wireframe

since 0.1.0 or earlier Shading and materials

RenderSettings.wireframe asks the renderer to draw the scene's triangles as lines instead of filled surfaces. It is a polygon mode, and only one of the three backends this engine draws through actually has one: Impeller. WebGL2 has no glPolygonMode, and neither does the software rasteriser this page's own test runs on.

That refusal is not silent. FrameResult.wireframeDeclined is true exactly when a frame asked for wireframe and could not be given it, so a caller can tell "nothing drew" apart from "the device cannot do this."

Step 1: Something with edges worth seeing #

A torus shows its wireframe better than a sphere does: the tube reveals how the two rings of segments cross each other.

final MeshNode knot = MeshNode(
  DeviceMesh.upload(
    context.device,
    const TorusShape(segments: 32, tubeSegments: 16).build(),
  ),
  Material(name: 'knot', baseColor: Vector4(0.3, 0.65, 0.85, 1.0)),
  name: 'knot',
);
return Scene()
  ..add(knot)
  ..add(
    LightNode(name: 'sun', intensity: 3.0)
      ..setLocalForward(Vector3(-0.4, -0.7, -0.6)),
  );

Step 2: Ask for it #

One field, read every frame.

wireframe: wireframe,

Step 3: What actually happened #

On a device that can draw lines, the knot now looks like a wire model. On the software rasteriser, the knot still comes back solid, and wireframeDeclined says why: the request was heard and could not be met.

// The software rasteriser has no polygon-mode line primitive, so this
// page's own claim on this device is the refusal itself: asking for
// wireframe here still draws the model solid, and the frame says why.
if (wireframe && !frame.wireframeDeclined) {
  throw StateError('this device drew wireframe; the claim below is stale');
}
if (frame.drawCalls < 1) {
  throw StateError('the knot was not drawn');
}

Note. This is the one page in this set that leans on Need.wireframe. A device that lacks it still opens the page, with a note that part of what it describes will not show.