scena 1.1.0

A Rust-native scene-graph renderer with typed scene state, glTF assets, and explicit prepare/render lifecycles.
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
use std::error;
use std::fmt;

use super::{
    AnimationError, AssetError, BuildError, Error, ImportError, InstantiateError, LookupError,
    NotPreparedReason, PrepareError, RenderError,
};

impl fmt::Display for Error {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Build(error) => error.fmt(formatter),
            Self::Asset(error) => error.fmt(formatter),
            Self::Import(error) => error.fmt(formatter),
            Self::Instantiate(error) => error.fmt(formatter),
            Self::Prepare(error) => error.fmt(formatter),
            Self::Render(error) => error.fmt(formatter),
            Self::Lookup(error) => error.fmt(formatter),
            Self::Animation(error) => error.fmt(formatter),
        }
    }
}

impl fmt::Display for BuildError {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::InvalidTargetSize { width, height } => {
                write!(formatter, "invalid render target size {width}x{height}")
            }
            Self::AsyncSurfaceRequired { backend } => {
                write!(
                    formatter,
                    "attached surface initialization for {backend:?} requires async construction"
                )
            }
            Self::CreateSurface { backend } => {
                write!(formatter, "failed to create GPU surface for {backend:?}")
            }
            Self::NoAdapter { backend } => {
                write!(formatter, "no compatible GPU adapter found for {backend:?}")
            }
            Self::RequestDevice { backend } => {
                write!(formatter, "failed to request GPU device for {backend:?}")
            }
            Self::SurfaceUnsupported { backend } => {
                write!(
                    formatter,
                    "no compatible surface configuration found for {backend:?}"
                )
            }
            Self::UnsupportedBackend { backend } => {
                write!(
                    formatter,
                    "backend {backend:?} is not supported on this target"
                )
            }
        }
    }
}

impl fmt::Display for AssetError {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::NotFound { path } => write!(formatter, "asset was not found: {path}"),
            Self::Io { path, reason } => {
                write!(formatter, "failed to read asset {path}: {reason}")
            }
            Self::Parse { path, reason } => {
                write!(formatter, "failed to parse asset {path}: {reason}")
            }
            Self::UnsupportedRequiredExtension { path, extension } => write!(
                formatter,
                "asset {path} requires unsupported extension {extension}"
            ),
            Self::UnsupportedOptionalExtensionUsed {
                path,
                extension,
                help,
            } => write!(
                formatter,
                "asset {path} uses unsupported optional extension {extension}: {help}"
            ),
            Self::MissingTexture {
                path,
                material_slot,
                texture_index,
                help,
            } => write!(
                formatter,
                "asset {path} references missing texture index {texture_index} in material slot {material_slot}: {help}"
            ),
            Self::UnsupportedTextureFormat { path, help } => {
                write!(
                    formatter,
                    "texture {path} uses an unsupported format: {help}"
                )
            }
            Self::Cancelled { path, help } => {
                write!(formatter, "asset load for {path} was cancelled: {help}")
            }
            Self::UnsupportedEnvironmentFormat { path, help } => {
                write!(
                    formatter,
                    "environment {path} uses an unsupported format: {help}"
                )
            }
            Self::ReloadRequiresRetain { path, help } => {
                write!(formatter, "asset {path} cannot be reloaded: {help}")
            }
            Self::GeometryHandleNotFound { geometry } => {
                write!(
                    formatter,
                    "geometry handle {geometry:?} was not found in Assets"
                )
            }
            Self::MaterialHandleNotFound { material } => {
                write!(
                    formatter,
                    "material handle {material:?} was not found in Assets"
                )
            }
            Self::TextureHandleNotFound { texture } => {
                write!(
                    formatter,
                    "texture handle {texture:?} was not found in Assets"
                )
            }
            Self::EnvironmentHandleNotFound { environment } => {
                write!(
                    formatter,
                    "environment handle {environment:?} was not found in Assets"
                )
            }
        }
    }
}

impl fmt::Display for ImportError {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Asset(error) => error.fmt(formatter),
            Self::Instantiate(error) => error.fmt(formatter),
        }
    }
}

impl From<AssetError> for ImportError {
    fn from(error: AssetError) -> Self {
        Self::Asset(error)
    }
}

impl From<InstantiateError> for ImportError {
    fn from(error: InstantiateError) -> Self {
        Self::Instantiate(error)
    }
}

impl fmt::Display for InstantiateError {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::InvalidChildIndex { parent, child } => write!(
                formatter,
                "glTF node {parent} references invalid child node index {child}"
            ),
            Self::InvalidSkinIndex { node, skin } => {
                write!(
                    formatter,
                    "glTF node {node} references invalid skin index {skin}"
                )
            }
            Self::InvalidSkinJointIndex { skin, joint } => write!(
                formatter,
                "glTF skin {skin} references invalid joint node index {joint}"
            ),
            Self::InvalidAnchorExtras { node, reason } => {
                write!(
                    formatter,
                    "glTF node {node} has invalid anchor extras: {reason}"
                )
            }
            Self::UnsupportedCoordinateSystem {
                coordinate_system,
                reason,
            } => write!(
                formatter,
                "source coordinate system {coordinate_system:?} is not supported for this import: {reason}"
            ),
        }
    }
}

impl fmt::Display for PrepareError {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::InvalidTargetSize { width, height } => {
                write!(formatter, "invalid render target size {width}x{height}")
            }
            Self::AssetsRequired { node } => {
                write!(
                    formatter,
                    "node {node:?} references asset handles; call prepare_with_assets"
                )
            }
            Self::GeometryNotFound { node, geometry } => {
                write!(
                    formatter,
                    "node {node:?} references missing geometry handle {geometry:?}"
                )
            }
            Self::MaterialNotFound { node, material } => {
                write!(
                    formatter,
                    "node {node:?} references missing material handle {material:?}"
                )
            }
            Self::TextureNotFound {
                node,
                material,
                texture,
                slot,
            } => {
                write!(
                    formatter,
                    "node {node:?} material {material:?} references missing texture handle {texture:?} in slot {slot}"
                )
            }
            Self::EnvironmentAssetsRequired { environment } => {
                write!(
                    formatter,
                    "environment handle {environment:?} requires prepare_with_assets"
                )
            }
            Self::EnvironmentNotFound { environment } => {
                write!(
                    formatter,
                    "active environment handle {environment:?} was not found in assets"
                )
            }
            Self::UnsupportedGeometryTopology { node, topology } => {
                write!(
                    formatter,
                    "node {node:?} uses unsupported geometry topology {topology:?}"
                )
            }
            Self::UnsupportedMaterialKind { node, kind } => {
                write!(
                    formatter,
                    "node {node:?} uses unsupported material kind {kind:?}"
                )
            }
            Self::UnsupportedAlphaMode { node, alpha_mode } => {
                write!(
                    formatter,
                    "node {node:?} uses unsupported alpha mode {alpha_mode:?}"
                )
            }
            Self::UnsupportedModelNode { node } => {
                write!(
                    formatter,
                    "node {node:?} is a model node; model preparation is not implemented"
                )
            }
            Self::MultipleShadowedDirectionalLights { first, second } => write!(
                formatter,
                "only one shadowed directional light is supported; nodes {first:?} and {second:?} both cast shadows"
            ),
            Self::InvalidSkinGeometry { node, reason } => {
                write!(
                    formatter,
                    "node {node:?} has invalid skin geometry: {reason}"
                )
            }
            Self::BackendCapabilityMismatch {
                feature,
                backend,
                help,
            } => {
                write!(
                    formatter,
                    "backend {backend:?} cannot provide required feature {feature}: {help}"
                )
            }
            Self::GpuResourceUpload { backend, reason } => {
                write!(
                    formatter,
                    "backend {backend:?} failed during explicit GPU resource upload: {reason}"
                )
            }
        }
    }
}

impl fmt::Display for RenderError {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::NotPrepared { reason } => write!(formatter, "renderer is not prepared: {reason}"),
            Self::NoActiveCamera => write!(formatter, "scene has no active camera"),
            Self::CameraNotFound(_) => write!(formatter, "camera key does not exist in the scene"),
            Self::InvalidSurfaceSize { width, height } => {
                write!(formatter, "invalid surface size {width}x{height}")
            }
            Self::SurfaceLost { recoverable } => {
                write!(
                    formatter,
                    "render surface was lost; recoverable={recoverable}"
                )
            }
            Self::ContextLost { recoverable } => {
                write!(
                    formatter,
                    "render context was lost; recoverable={recoverable}"
                )
            }
            Self::GpuDeviceLost { recoverable } => {
                write!(formatter, "GPU device was lost; recoverable={recoverable}")
            }
            Self::GpuResourcesNotPrepared { backend } => {
                write!(formatter, "GPU resources for {backend:?} were not prepared")
            }
            Self::GpuReadback { backend } => {
                write!(formatter, "failed to read rendered output for {backend:?}")
            }
        }
    }
}

impl fmt::Display for NotPreparedReason {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::NeverPrepared => write!(formatter, "prepare has not been called"),
            Self::DifferentScene => write!(formatter, "prepare was called for a different scene"),
            Self::SceneChanged {
                prepared_revision,
                current_revision,
                change,
            }
            | Self::EnvironmentChanged {
                prepared_revision,
                current_revision,
                change,
            } => write!(
                formatter,
                "prepared state changed after prepare ({prepared_revision} -> {current_revision}, {change:?})"
            ),
            Self::TargetChanged {
                prepared_revision,
                current_revision,
                change,
            } => write!(
                formatter,
                "render target changed after prepare ({prepared_revision} -> {current_revision}, {change:?})"
            ),
            Self::RendererChanged {
                prepared_revision,
                current_revision,
                change,
            } => write!(
                formatter,
                "renderer setting changed after prepare ({prepared_revision} -> {current_revision}, {change:?}); call prepare again"
            ),
        }
    }
}

impl fmt::Display for LookupError {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::NodeNotFound(_) => write!(formatter, "node key does not exist in the scene"),
            Self::NodeNameNotFound { name } => {
                write!(formatter, "imported scene has no node named '{name}'")
            }
            Self::AmbiguousNodeName { name, matches } => write!(
                formatter,
                "imported scene node name '{name}' is ambiguous across {} nodes",
                matches.len()
            ),
            Self::AnchorNotFound { name } => {
                write!(formatter, "imported scene has no anchor named '{name}'")
            }
            Self::AmbiguousAnchorName { name, hosts } => write!(
                formatter,
                "imported scene anchor name '{name}' is ambiguous across {} host nodes",
                hosts.len()
            ),
            Self::ConnectorNotFound { name } => {
                write!(formatter, "imported scene has no connector named '{name}'")
            }
            Self::AmbiguousConnectorName { name, hosts } => write!(
                formatter,
                "imported scene connector name '{name}' is ambiguous across {} host nodes",
                hosts.len()
            ),
            Self::ClipNotFound { name } => {
                write!(
                    formatter,
                    "imported scene has no animation clip named '{name}'"
                )
            }
            Self::VariantNotFound { name } => write!(
                formatter,
                "imported scene has no KHR_materials_variants variant named '{name}'"
            ),
            Self::AmbiguousClipName { name, matches } => write!(
                formatter,
                "imported scene animation clip name '{name}' is ambiguous across {} clips",
                matches.len()
            ),
            Self::PathNotFound { path } => {
                write!(formatter, "imported scene path '{path}' was not found")
            }
            Self::InvalidViewport { width, height } => {
                write!(
                    formatter,
                    "viewport {width}x{height} is invalid; width and height must be non-zero"
                )
            }
            Self::ImportHasNoBounds => {
                write!(
                    formatter,
                    "imported scene has no renderable bounds to frame"
                )
            }
            Self::StaleImport => write!(formatter, "scene import has been invalidated"),
            Self::NodeIsNotMesh { node } => write!(formatter, "node {node:?} is not a mesh node"),
            Self::NonInvertibleParentTransform { node, parent } => write!(
                formatter,
                "node {node:?} cannot be placed in world space because parent {parent:?} has a non-invertible transform"
            ),
            Self::GeometryNotFound { node, .. } => {
                write!(
                    formatter,
                    "geometry for mesh node {node:?} was not found in Assets"
                )
            }
            Self::CameraNotFound(_) => write!(formatter, "camera key does not exist in the scene"),
            Self::ClippingPlaneNotFound(_) => {
                write!(formatter, "clipping plane key does not exist in the scene")
            }
            Self::InstanceSetNotFound(_) => {
                write!(formatter, "instance set key does not exist in the scene")
            }
            Self::LabelNotFound(_) => write!(formatter, "label key does not exist in the scene"),
        }
    }
}

impl fmt::Display for AnimationError {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::ClipNotFound { name } => {
                write!(
                    formatter,
                    "imported scene has no animation clip named '{name}'"
                )
            }
            Self::MixerNotFound(_) => write!(formatter, "animation mixer key does not exist"),
            Self::StaleMixer(_) => write!(
                formatter,
                "animation mixer is stale because its source import was replaced"
            ),
        }
    }
}

impl error::Error for Error {}
impl error::Error for BuildError {}
impl error::Error for AssetError {}
impl error::Error for ImportError {}
impl error::Error for InstantiateError {}
impl error::Error for PrepareError {}
impl error::Error for RenderError {}
impl error::Error for LookupError {}
impl error::Error for AnimationError {}