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
//! Pure-Rust 3D asset interchange, with glTF as the hub: 60-some formats read into a glTF 2.0
//! [`Document`], and written back out as GLB.
//!
//! # Quick start
//!
//! ```no_run
//! use polysmelt::document::Pose;
//!
//! // Any format Polysmelt reads: told by the extension, or else by the file's first bytes. The
//! // textures and libraries the model names are found beside it.
//! let doc = polysmelt::open("models/robot.fbx")?;
//!
//! // What the file says about itself (format, units, axes, the tool that wrote it), and what
//! // the reader converted to glTF's conventions.
//! let info = doc.source_info();
//! println!("{:?} {:?}, up {:?}", info.format, info.version, info.up_axis);
//!
//! // What it draws, counted from the JSON alone, or flattened into posed triangles.
//! println!("{} triangles", doc.triangles());
//! if let Some(mesh) = doc.flatten(Pose::Rest)? {
//! println!("{} vertices", mesh.prims.iter().map(|p| p.positions.len()).sum::<usize>());
//! }
//!
//! // And out as a GLB, everything it holds kept.
//! doc.write_glb(std::io::BufWriter::new(std::fs::File::create("robot.glb")?))?;
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! A model in memory is [`read`], and a [`Loader`] chooses what [`open`] and [`read`] don't:
//! what to [`Keep`], where the files a model names are found, and its [`Format`].
//!
//! ```
//! use polysmelt::{Keep, Loader, assets::Memory};
//!
//! let obj = "mtllib box.mtl\nusemtl red\nv 0 0 0\nv 1 0 0\nv 0 1 0\nf 1 2 3\n";
//! let mtl = "newmtl red\nKd 1 0 0\n";
//! let doc = Loader::new()
//! .assets(Memory::new().with("box.mtl", mtl.as_bytes()))
//! .keep(Keep::ALL.with_animations(false))
//! .read(obj.as_bytes(), "box.obj")?;
//! assert_eq!(doc.triangles(), 1);
//! assert_eq!(doc.json()["materials"][0]["name"], "red");
//! let glb: Vec<u8> = doc.to_glb()?;
//! # Ok::<(), polysmelt::Error>(())
//! ```
//!
//! # What's here
//!
//! - [`open`], [`read`] and [`Loader`]: the ways in. [`Format`] names what they read: STL, PLY,
//! `MagicaVoxel`, OBJ, FBX, 3DS, 3MF, USD, glTF, `SketchUp`, BVH, COLLADA, VRM, OFF,
//! X3D/VRML, DXF, LAS/LAZ, PCD, E57, text point clouds, AMF, `LightWave`, AC3D,
//! `OpenFlight`, `OpenGEX`, Irrlicht and XGL, and for game and animation assets
//! `MikuMikuDance` (PMX, PMD, VMD), `DirectX` `.x`, MD2, MD3, MD5, IQM, SMD, `MilkShape` 3D,
//! `Blitz3D`, ASF/AMC, C3D, TRC, HTR and OGRE, each behind a cargo feature.
//! - [`document`]: the [`Document`] they produce, a glTF 2.0 document (JSON and buffers)
//! written out as a GLB as it is, flattened into a posed [`Mesh`](mesh::Mesh) on demand, and
//! pruned to what a [`Keep`] asks for.
//! - [`mesh`]: the flat triangle-list model, written out as a GLB.
//! - [`rig`]: typed views of a document's node tree, skins and animations, for playing and
//! retargeting motion.
//! - [`source`]: what a file said about itself: units, axes, the tool that wrote it.
//! - [`assets`]: how readers find the textures and material libraries a model refers to.
//! - [`images`]: handles on a document's images, for those a load found but didn't read.
//! - [`gltf`]: GLB packing, and meshopt compression added to or decoded away from a GLB.
//! - [`meshopt`]: the `EXT_meshopt_compression` and `KHR_meshopt_compression` bitstreams.
/// The shared byte buffer [`mesh::Image`] holds, from the `bytes` crate: cloning or slicing one
/// doesn't copy its bytes.
pub use Bytes;
/// The JSON a [`Document`] is, from the `serde_json` crate, as [`Document::json`] hands it out.
pub use serde_json;
pub use ;
pub use open;
pub use ;
/// The README's examples, compiled as doc tests.
;
/// Returns an [`Error`] of an [`ErrorKind`] (named bare: `Corrupt`) with a message built from a
/// format string.
/// Bails with an error of the kind unless the condition holds.
/// An [`Error`] of an [`ErrorKind`] (named bare: `Corrupt`) with a message built from a format
/// string. A constant message isn't allocated.
pub use ;
pub use ;