1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! `sdf-text` — a Rust port of lib3's `src/sdf-text/` module (signed-distance-
//! field text rendered from real font outlines) plus its `src/sdf/edt.js`
//! dependency.
//!
//! This is a `three-rs` addon, not a standalone text layout crate: steps 1–3
//! of the port (font metrics and outlines, the raster + EDT + atlas, and
//! layout — [`vector_font`], [`raster`], [`edt`], [`text_builder`]) are pure
//! CPU code with no `three-rs` dependency, but [`BatchedText`] — steps 4–5 —
//! depends on `three-rs` for the scene graph, the node material and the
//! `R32Float` atlas texture: it is an `InstancedMesh` whose
//! [`node()`](BatchedText::node) you add to a `three-rs` `Scene` like any
//! other object, and which the `three-rs` renderer then draws.
//!
//! The port is graded against golden data dumped from the JavaScript; see
//! `tests/golden/README.md` for the dump commands and `README.md` for the
//! deviation and skip registers.
//!
//! Ladder position: steps 1–3 of the plan (font metrics and outlines, the
//! raster + EDT + atlas, and layout) need no GPU and are graded against golden
//! data. [`batched_text::BatchedText`] is steps 4–5: it depends on `three-rs`
//! for the scene graph, the node material and the `R32Float` atlas texture, so
//! `cargo test -p sdf-text` covers it only where the packing can be checked on
//! the CPU; the pixel gates live in `three-rs`' own `tests/`.
//!
//! # Example
//!
//! Batching needs no font to compile against — an empty [`Text`] lays out to
//! nothing — so this shows the shape without pulling in a font file. `no_run`
//! only because [`BatchedText::node`] is meant to be added to a real scene,
//! which this snippet does not build.
//!
//! ```no_run
//! use sdf_text::{BatchedText, BatchedTextOptions, Text};
//! use three_rs::Scene;
//!
//! let mut batch = BatchedText::new(64, 1024, BatchedTextOptions::default());
//! let member_id = batch.add_text(Text::new());
//! batch.sync();
//!
//! let mut scene = Scene::new();
//! scene.add(batch.node());
//! # let _ = member_id;
//! ```
//!
//! # Member transforms
//!
//! A member's whole `matrix_world` reaches the GPU as its glyphs' instance
//! matrix, so rotation and scale work as well as position — a label laid flat
//! on a floor with `set_rotation( -PI / 2, 0, 0 )` on
//! [`BatchedText::member_node`] renders flat. Members are not billboarded and
//! are not position-only.
//!
//! # Frustum culling
//!
//! [`BatchedText::sync`] computes the batch's own bounding sphere over every
//! glyph quad of every member, in the batch node's space, and stores it on the
//! node — the way `BatchedMesh.computeBoundingSphere` does in three.js. The
//! frustum cull reads that sphere in preference to the geometry's, so a batch
//! node left at the origin with its members placed far away is culled on where
//! its glyphs actually are, not on where its node is. Members added or moved
//! after a `sync()` are only bounded by the next `sync()` (or by
//! [`BatchedText::set_matrix_at`], which updates the sphere as it goes), which
//! is the same contract as the attribute packing.
pub
pub
pub use ;
pub use ;
pub use Error;
pub use ;
pub use ;
pub use ;
pub use ;
/// The constant set used by lib3's *test* (`src/sdf/index.js`), which matches
/// neither `FontAtlas` (128/64/8/16) nor `VectorFontAtlas` (256/64/—/32). The
/// ported test layers 2–4 use these, so they are kept as their own namespace
/// rather than being folded into either atlas.