polysmelt 0.15.1

Pure-Rust 3D asset interchange: glTF/GLB reading and writing, meshopt compression, and readers for common mesh formats, SketchUp included
Documentation
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
//! What a load keeps: [`Keep`], applied by [`Document::prune`].

use std::collections::BTreeSet;

use serde_json::{Map, Value};

use crate::document::Document;
use crate::mesh::{MAX_POINTS, MAX_TRIANGLES, TRIANGLE_CEILING};

/// Which parts of a model a load keeps. Meshes and the node hierarchy are always kept; each
/// switch here drops one kind of data on top of that. [`Keep::default`] keeps everything.
/// [`Keep::max_triangles`] caps how big a model a load takes at all, and [`Keep::max_points`]
/// how many points and lines [`Document::flatten`] draws.
///
/// Readers skip reading what isn't kept, so a narrow `Keep` also makes a load faster: no
/// texture files, embedded images or (without materials) material libraries and shaders are
/// read, nor animations, skins, morph targets, cameras or lights where the format keeps them
/// apart. What a reader did read and [`Document::prune`] then dropped leaves its buffer views
/// and accessors behind, unreferenced.
///
/// Without textures, a material's factors are its own: a reader that would have found a color
/// texture doesn't turn the base color white for it.
///
/// ```
/// use polysmelt::document::Keep;
/// // Static meshes for an engine that animates nothing, but still skins them.
/// let keep = Keep { animations: false, ..Keep::ALL };
/// # assert!(keep.skins);
/// // A 100-million-triangle scan, past the default limit.
/// let keep = Keep { max_triangles: 120_000_000, ..Keep::ALL };
/// // A 40-million-point lidar scan, drawn as points.
/// let keep = Keep { max_points: 40_000_000, ..Keep::ALL };
/// // Only the surfaces: no points or lines in the flattened mesh.
/// let keep = Keep { lines_and_points: false, ..Keep::ALL };
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[allow(clippy::struct_excessive_bools, reason = "independent switches")]
pub struct Keep {
    /// Animations.
    pub animations: bool,
    /// Skins: skeletons, their inverse bind matrices, and the joints and weights on vertices.
    /// The joint nodes stay either way, as part of the hierarchy.
    pub skins: bool,
    /// Morph targets and their weights (and animation channels that set them).
    pub morph_targets: bool,
    /// Materials; without them every primitive takes the default material, and textures go
    /// too.
    pub materials: bool,
    /// Textures, their images and samplers, and where materials use them.
    pub textures: bool,
    /// The images' bytes. Without them, kept textures' images are found but not read or
    /// converted: each is a glTF image with a `uri`, and [`Document::images`] has a handle on it
    /// that says where it is (its file, if it's in one) and reads it on request.
    /// [`Document::embed_images`] reads them all. [`Document::prune`] leaves images as they
    /// are: once read, they stay read. Images a reader must look into to make a texture (an OBJ's
    /// roughness and metalness maps packed into one) are read all the same, so the textures match.
    pub image_bytes: bool,
    /// Cameras.
    pub cameras: bool,
    /// Lights (`KHR_lights_punctual`).
    pub lights: bool,
    /// `extras` everywhere: custom properties and source metadata. The document's facts
    /// stay either way.
    pub extras: bool,
    /// The most triangles a load accepts, against hostile or runaway files: a model that draws
    /// more is refused (and [`Document::flatten`] refuses to draw more). Defaults to
    /// [`MAX_TRIANGLES`]; raise it for big scans. Values past [`TRIANGLE_CEILING`] are clamped
    /// to it.
    pub max_triangles: usize,
    /// Points and lines (glTF's `POINTS`, `LINES`, `LINE_LOOP` and `LINE_STRIP` primitives) in
    /// what [`Document::flatten`] draws: point clouds, wireframes, curves. Without them it draws
    /// only triangles, and a model of points and lines alone flattens to nothing. The document
    /// keeps them either way.
    pub lines_and_points: bool,
    /// The most points and line segments [`Document::flatten`] draws, against huge point clouds:
    /// a model that draws more is refused (unless [`Keep::lines_and_points`] leaves them out).
    /// Counted apart from triangles. Defaults to [`MAX_POINTS`]; raise it for big scans. Values
    /// past [`TRIANGLE_CEILING`] are clamped to it.
    pub max_points: usize,
    /// Threads a reader may split its work over, where it can: OBJ text and SPZ, so far. 1, the
    /// default, reads on the calling thread; 0 takes one per core. The model read is the same
    /// either way. Where threads can't be had (WebAssembly without shared memory, or a
    /// platform that refuses to start one), it reads on the calling thread.
    pub threads: usize,
}

impl Default for Keep {
    fn default() -> Self {
        Self::ALL
    }
}

impl Keep {
    /// Everything.
    pub const ALL: Keep = Keep {
        animations: true,
        skins: true,
        morph_targets: true,
        materials: true,
        textures: true,
        image_bytes: true,
        cameras: true,
        lights: true,
        extras: true,
        max_triangles: MAX_TRIANGLES,
        lines_and_points: true,
        max_points: MAX_POINTS,
        threads: 1,
    };

    /// The meshes and what shapes or shades them (skins, morph targets, materials, textures,
    /// extras), without animations, cameras or lights.
    pub const MESHES: Keep = Keep {
        animations: false,
        cameras: false,
        lights: false,
        ..Keep::ALL
    };

    /// [`Keep::MESHES`] without reading the images: textures stay, as references to their
    /// images (see [`Keep::image_bytes`]).
    pub const LIGHT: Keep = Keep {
        image_bytes: false,
        ..Keep::MESHES
    };

    /// [`Keep::max_triangles`], clamped to [`TRIANGLE_CEILING`].
    pub(crate) fn triangles(self) -> usize {
        self.max_triangles.min(TRIANGLE_CEILING)
    }

    /// [`Keep::max_points`], clamped to [`TRIANGLE_CEILING`].
    pub(crate) fn points(self) -> usize {
        self.max_points.min(TRIANGLE_CEILING)
    }

    /// [`Keep::threads`]: how many to use here, at least 1. WebAssembly without shared memory
    /// has no threads; elsewhere, a reader whose threads can't be started reads on one.
    #[cfg_attr(
        not(any(
            feature = "obj",
            feature = "spz",
            feature = "las",
            feature = "pcd",
            feature = "xyz",
            feature = "e57",
            feature = "ac3d"
        )),
        allow(dead_code, reason = "only the OBJ and SPZ readers take threads")
    )]
    pub(crate) fn threads(self) -> usize {
        if cfg!(all(target_family = "wasm", not(target_feature = "atomics"))) {
            1
        } else if self.threads == 0 {
            std::thread::available_parallelism().map_or(1, std::num::NonZero::get)
        } else {
            self.threads
        }
    }
}

#[cfg(test)]
thread_local! {
    /// For tests: thread starts fail, as on a platform without threads.
    pub(crate) static NO_THREADS: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
}

/// `f` started on a thread of `s`; false, and `f` dropped, where no thread can be started.
#[cfg_attr(
    not(any(
        feature = "obj",
        feature = "spz",
        feature = "las",
        feature = "pcd",
        feature = "xyz",
        feature = "e57",
        feature = "ac3d"
    )),
    allow(dead_code, reason = "only the OBJ and SPZ readers take threads")
)]
pub(crate) fn spawn<'s>(s: &'s std::thread::Scope<'s, '_>, f: impl FnOnce() + Send + 's) -> bool {
    #[cfg(test)]
    if NO_THREADS.get() {
        return false;
    }
    std::thread::Builder::new().spawn_scoped(s, f).is_ok()
}

/// Calls `f` on each item of `obj[key]` that's an object.
fn each(obj: &mut Map<String, Value>, key: &str, mut f: impl FnMut(&mut Map<String, Value>)) {
    let items = obj.get_mut(key).and_then(Value::as_array_mut);
    for item in items.into_iter().flatten().filter_map(Value::as_object_mut) {
        f(item);
    }
}

/// Calls `f` on every primitive.
fn primitives(json: &mut Map<String, Value>, mut f: impl FnMut(&mut Map<String, Value>)) {
    each(json, "meshes", |m| each(m, "primitives", &mut f));
}

/// Removes extension `name` from `obj`, and its `extensions` if that leaves it empty.
fn remove_extension(obj: &mut Map<String, Value>, name: &str) {
    if let Some(exts) = obj.get_mut("extensions").and_then(Value::as_object_mut) {
        exts.remove(name);
        if exts.is_empty() {
            obj.remove("extensions");
        }
    }
}

/// Removes extension `name` wherever it is.
fn remove_extension_everywhere(v: &mut Value, name: &str) {
    match v {
        Value::Object(obj) => {
            remove_extension(obj, name);
            obj.values_mut().for_each(|v| remove_extension_everywhere(v, name));
        }
        Value::Array(a) => a.iter_mut().for_each(|v| remove_extension_everywhere(v, name)),
        _ => {}
    }
}

/// Removes every `key` member, at any depth.
fn remove_key_everywhere(v: &mut Value, key: &str) {
    match v {
        Value::Object(obj) => {
            obj.remove(key);
            obj.values_mut().for_each(|v| remove_key_everywhere(v, key));
        }
        Value::Array(a) => a.iter_mut().for_each(|v| remove_key_everywhere(v, key)),
        _ => {}
    }
}

/// Removes the texture references (`...Texture` objects) in a material, its extensions'
/// included.
fn remove_textures(obj: &mut Map<String, Value>) {
    obj.retain(|k, v| !(k.ends_with("Texture") && v.is_object()));
    for v in obj.values_mut() {
        if let Value::Object(o) = v {
            remove_textures(o);
        }
    }
}

/// The names of every extension the JSON uses an object for.
fn extensions_present(v: &Value, out: &mut BTreeSet<String>) {
    match v {
        Value::Object(obj) => {
            if let Some(exts) = obj.get("extensions").and_then(Value::as_object) {
                out.extend(exts.keys().cloned());
            }
            obj.values().for_each(|v| extensions_present(v, out));
        }
        Value::Array(a) => a.iter().for_each(|v| extensions_present(v, out)),
        _ => {}
    }
}

impl Document<'_> {
    /// Drops what `keep` doesn't keep. The JSON stays valid glTF: references to what went are
    /// removed with it, and extensions no longer used are unlisted. Extensions Polysmelt doesn't
    /// know that refer to dropped materials, textures or cameras may be left pointing at them.
    /// [`Keep::max_triangles`] and [`Keep::threads`] play no part here. Points and lines stay in
    /// the JSON: [`Keep::lines_and_points`] and [`Keep::max_points`] are recorded for
    /// [`Document::flatten`] (see [`Document::set_lines_and_points`] and
    /// [`Document::set_max_points`]).
    pub fn prune(&mut self, keep: Keep) {
        self.lines_and_points = keep.lines_and_points;
        self.max_points = keep.points();
        if (Keep {
            image_bytes: true,
            max_triangles: Keep::ALL.max_triangles,
            lines_and_points: true,
            max_points: Keep::ALL.max_points,
            threads: Keep::ALL.threads,
            ..keep
        }) == Keep::ALL
        {
            return;
        }
        let mut before = BTreeSet::new();
        let mut root = Value::Object(std::mem::take(&mut self.json));
        extensions_present(&root, &mut before);
        let Value::Object(json) = &mut root else { unreachable!() };
        // Animation pointers (`KHR_animation_pointer`) into what goes, go with it.
        let mut dead: Vec<&str> = Vec::new();
        if !keep.animations {
            json.remove("animations");
        }
        if !keep.cameras {
            json.remove("cameras");
            each(json, "nodes", |n| {
                n.remove("camera");
            });
            dead.push("/cameras/");
        }
        if !keep.lights {
            remove_extension_everywhere(&mut root, "KHR_lights_punctual");
            dead.push("/extensions/KHR_lights_punctual/");
        }
        let Value::Object(json) = &mut root else { unreachable!() };
        if !keep.skins {
            json.remove("skins");
            each(json, "nodes", |n| {
                n.remove("skin");
            });
            primitives(json, |p| {
                let skinning = |k: &String| k.starts_with("JOINTS_") || k.starts_with("WEIGHTS_");
                if let Some(a) = p.get_mut("attributes").and_then(Value::as_object_mut) {
                    a.retain(|k, _| !skinning(k));
                }
                let draco = p
                    .get_mut("extensions")
                    .and_then(|e| e.get_mut("KHR_draco_mesh_compression"))
                    .and_then(|d| d.get_mut("attributes"))
                    .and_then(Value::as_object_mut);
                if let Some(a) = draco {
                    a.retain(|k, _| !skinning(k));
                }
            });
        }
        if !keep.morph_targets {
            primitives(json, |p| {
                p.remove("targets");
            });
            each(json, "meshes", |m| {
                m.remove("weights");
                if let Some(x) = m.get_mut("extras").and_then(Value::as_object_mut) {
                    x.remove("targetNames");
                }
            });
            each(json, "nodes", |n| {
                n.remove("weights");
            });
            each(json, "animations", |a| {
                if let Some(ch) = a.get_mut("channels").and_then(Value::as_array_mut) {
                    ch.retain(|c| c.pointer("/target/path").and_then(Value::as_str) != Some("weights"));
                }
            });
            dead.extend(["/meshes/*/weights", "/nodes/*/weights"]);
        }
        let textures = keep.textures && keep.materials;
        if !keep.materials {
            json.remove("materials");
            primitives(json, |p| {
                p.remove("material");
            });
            dead.push("/materials/");
        }
        if !keep.materials {
            remove_extension_everywhere(&mut root, "KHR_materials_variants");
        }
        let Value::Object(json) = &mut root else { unreachable!() };
        if !textures {
            for key in ["textures", "images", "samplers"] {
                json.remove(key);
            }
            each(json, "materials", remove_textures);
            dead.push("/textures/");
            self.refs.clear();
        }
        if !keep.extras {
            remove_key_everywhere(&mut root, "extras");
        }
        let Value::Object(json) = &mut root else { unreachable!() };
        if !dead.is_empty() {
            each(json, "animations", |a| {
                if let Some(ch) = a.get_mut("channels").and_then(Value::as_array_mut) {
                    ch.retain(|c| {
                        let pointer = c
                            .pointer("/target/extensions/KHR_animation_pointer/pointer")
                            .and_then(Value::as_str);
                        !pointer.is_some_and(|p| dead.iter().any(|d| matches_pointer(p, d)))
                    });
                }
            });
        }
        // An animation needs a channel.
        if let Some(anims) = json.get_mut("animations").and_then(Value::as_array_mut) {
            anims.retain(|a| {
                a.get("channels")
                    .and_then(Value::as_array)
                    .is_some_and(|c| !c.is_empty())
            });
            if anims.is_empty() {
                json.remove("animations");
            }
        }
        let mut after = BTreeSet::new();
        extensions_present(&root, &mut after);
        let Value::Object(json) = &mut root else { unreachable!() };
        for key in ["extensionsUsed", "extensionsRequired"] {
            if let Some(list) = json.get_mut(key).and_then(Value::as_array_mut) {
                list.retain(|e| e.as_str().is_none_or(|e| !before.contains(e) || after.contains(e)));
                if list.is_empty() {
                    json.remove(key);
                }
            }
        }
        let Value::Object(json) = root else { unreachable!() };
        self.json = json;
    }
}

/// Whether JSON pointer `p` starts with `prefix`, where `*` in the prefix stands for one
/// segment.
fn matches_pointer(p: &str, prefix: &str) -> bool {
    let mut segs = p.split('/');
    let pre: Vec<&str> = prefix.trim_end_matches('/').split('/').collect();
    pre.iter()
        .all(|want| segs.next().is_some_and(|s| *want == "*" || s == *want))
}

#[cfg(test)]
mod tests {
    use serde_json::json;

    use super::*;

    fn doc(v: Value) -> Document<'static> {
        let Value::Object(json) = v else { unreachable!() };
        let mut d = Document::empty(Map::new());
        d.json = json;
        d
    }

    #[test]
    fn keeps_everything_by_default() {
        let v = json!({ "asset": { "version": "2.0" }, "animations": [{ "channels": [{}] }], "extras": { "a": 1 } });
        let mut d = doc(v.clone());
        d.prune(Keep::default());
        assert_eq!(Value::Object(d.json), v);
    }

    #[test]
    fn a_triangle_limit_alone_prunes_nothing() {
        // Pruning drops animations without channels, whatever it keeps: a limit alone mustn't start it.
        let v = json!({ "asset": { "version": "2.0" }, "animations": [{ "channels": [] }] });
        let mut d = doc(v.clone());
        d.prune(Keep {
            max_triangles: 10,
            image_bytes: false,
            ..Keep::ALL
        });
        assert_eq!(Value::Object(d.json), v);
        let mut d = doc(v);
        d.prune(Keep {
            extras: false,
            ..Keep::ALL
        });
        assert!(!d.json.contains_key("animations"));
    }

    #[test]
    fn point_settings_prune_nothing_but_reach_flatten() {
        let v = json!({ "asset": { "version": "2.0" }, "animations": [{ "channels": [] }] });
        let mut d = doc(v.clone());
        d.prune(Keep {
            lines_and_points: false,
            max_points: usize::MAX,
            ..Keep::ALL
        });
        assert_eq!(Value::Object(d.json.clone()), v);
        assert!(!d.lines_and_points());
        assert_eq!(d.max_points(), TRIANGLE_CEILING);
        d.prune(Keep::LIGHT);
        assert!(d.lines_and_points());
        assert_eq!(d.max_points(), MAX_POINTS);
    }

    #[test]
    fn the_triangle_limit_is_clamped() {
        assert_eq!(Keep::ALL.triangles(), MAX_TRIANGLES);
        assert_eq!(Keep::LIGHT.max_triangles, MAX_TRIANGLES);
        let keep = |max_triangles| Keep {
            max_triangles,
            ..Keep::ALL
        };
        assert_eq!(keep(12_000_000).triangles(), 12_000_000);
        assert_eq!(keep(usize::MAX).triangles(), TRIANGLE_CEILING);
    }

    #[test]
    fn drops_animations_but_keeps_skins() {
        let mut d = doc(json!({
            "asset": { "version": "2.0" },
            "nodes": [{ "mesh": 0, "skin": 0 }, { "camera": 0 }],
            "skins": [{ "joints": [1] }],
            "cameras": [{ "type": "perspective" }],
            "meshes": [{ "primitives": [{ "attributes": { "POSITION": 0, "JOINTS_0": 1, "WEIGHTS_0": 2 } }] }],
            "animations": [{ "channels": [{ "sampler": 0, "target": { "node": 1, "path": "rotation" } }] }],
            "extensions": { "KHR_lights_punctual": { "lights": [{ "type": "point" }] } },
            "extensionsUsed": ["KHR_lights_punctual", "KHR_mesh_quantization"],
        }));
        d.prune(Keep::MESHES);
        assert_eq!(
            Value::Object(d.json),
            json!({
                "asset": { "version": "2.0" },
                "nodes": [{ "mesh": 0, "skin": 0 }, {}],
                "skins": [{ "joints": [1] }],
                "meshes": [{ "primitives": [{ "attributes": { "POSITION": 0, "JOINTS_0": 1, "WEIGHTS_0": 2 } }] }],
                "extensionsUsed": ["KHR_mesh_quantization"],
            })
        );
    }

    #[test]
    fn drops_skins_morphs_and_textures() {
        let mut d = doc(json!({
            "asset": { "version": "2.0" },
            "nodes": [{ "mesh": 0, "skin": 0, "weights": [0.5] }],
            "skins": [{ "joints": [0] }],
            "meshes": [{
                "weights": [0.0],
                "extras": { "targetNames": ["smile"], "keep": true },
                "primitives": [{ "attributes": { "POSITION": 0, "JOINTS_0": 1 }, "targets": [{ "POSITION": 2 }], "material": 0 }],
            }],
            "materials": [{
                "pbrMetallicRoughness": { "baseColorTexture": { "index": 0 }, "baseColorFactor": [1, 1, 1, 1] },
                "extensions": { "KHR_materials_clearcoat": { "clearcoatTexture": { "index": 0 }, "clearcoatFactor": 1 } },
            }],
            "textures": [{ "source": 0 }],
            "images": [{ "uri": "a.png" }],
            "animations": [
                { "channels": [{ "sampler": 0, "target": { "node": 0, "path": "weights" } }] },
                { "channels": [{ "sampler": 0, "target": { "node": 0, "path": "translation" } }] },
            ],
            "extensionsUsed": ["KHR_materials_clearcoat"],
        }));
        d.prune(Keep {
            skins: false,
            morph_targets: false,
            textures: false,
            ..Keep::ALL
        });
        assert_eq!(
            Value::Object(d.json),
            json!({
                "asset": { "version": "2.0" },
                "nodes": [{ "mesh": 0 }],
                "meshes": [{ "extras": { "keep": true }, "primitives": [{ "attributes": { "POSITION": 0 }, "material": 0 }] }],
                "materials": [{
                    "pbrMetallicRoughness": { "baseColorFactor": [1, 1, 1, 1] },
                    "extensions": { "KHR_materials_clearcoat": { "clearcoatFactor": 1 } },
                }],
                "animations": [{ "channels": [{ "sampler": 0, "target": { "node": 0, "path": "translation" } }] }],
                "extensionsUsed": ["KHR_materials_clearcoat"],
            })
        );
    }

    #[test]
    fn drops_extras_and_pointer_channels() {
        let mut d = doc(json!({
            "asset": { "version": "2.0", "extras": 1 },
            "materials": [{ "extras": { "x": 1 } }],
            "animations": [{ "channels": [
                { "sampler": 0, "target": { "path": "pointer", "extensions": { "KHR_animation_pointer": { "pointer": "/materials/0/emissiveFactor" } } } },
                { "sampler": 0, "target": { "path": "pointer", "extensions": { "KHR_animation_pointer": { "pointer": "/nodes/0/translation" } } } },
            ] }],
        }));
        d.prune(Keep {
            materials: false,
            extras: false,
            ..Keep::ALL
        });
        assert_eq!(
            Value::Object(d.json),
            json!({
                "asset": { "version": "2.0" },
                "animations": [{ "channels": [
                    { "sampler": 0, "target": { "path": "pointer", "extensions": { "KHR_animation_pointer": { "pointer": "/nodes/0/translation" } } } },
                ] }],
            })
        );
    }

    #[test]
    fn pointer_prefixes() {
        assert!(matches_pointer("/meshes/3/weights", "/meshes/*/weights"));
        assert!(matches_pointer("/meshes/3/weights/1", "/meshes/*/weights"));
        assert!(!matches_pointer("/meshes/3/primitives", "/meshes/*/weights"));
        assert!(matches_pointer("/cameras/0/perspective/yfov", "/cameras/"));
        assert!(!matches_pointer("/camerasx/0", "/cameras/"));
    }
}