appcore_render/asset_frame.rs
1// =============================================================================
2// #######
3// ### ### F: asset_frame.rs
4// ## ## ## ## P: AppCore-Runtime
5// ## ##
6// C: 2026/10/14 17:50:33 by dnettoRaw
7// ## ## ## ## U: 2026/10/15 10:24:40 by dnettoRaw
8// ########### S: 0.1.0-alpha.1
9// =============================================================================
10
11use crate::{
12 asset_data::{world_bounds, AssetLease, Material},
13 BoundingSphere, EntityId, MeshAsset, ResourceId, SceneSnapshot, Transform,
14};
15use std::sync::Arc;
16/// Instance with resolved immutable asset ownership; no lookup or fallback is deferred to shaders.
17pub struct PreparedInstance {
18 pub(crate) entity: EntityId,
19 pub(crate) transform: Transform,
20 pub(crate) mesh_id: ResourceId,
21 pub(crate) mesh: Arc<MeshAsset>,
22 pub(crate) material: Arc<Material>,
23 pub(crate) tint: [f32; 4],
24}
25impl PreparedInstance {
26 /// Extracted stable entity identity.
27 pub fn entity(&self) -> EntityId {
28 self.entity
29 }
30 /// Validated local transform.
31 pub fn transform(&self) -> Transform {
32 self.transform
33 }
34 /// Mesh identity for batching; its immutable payload remains owned by this frame.
35 pub fn mesh_id(&self) -> ResourceId {
36 self.mesh_id
37 }
38 /// Shared mesh payload.
39 pub fn mesh(&self) -> &MeshAsset {
40 &self.mesh
41 }
42 /// Validated combined linear material/tint color.
43 pub fn color(&self) -> [f32; 4] {
44 std::array::from_fn(|i| self.material.color[i] * self.tint[i])
45 }
46 /// Conservative transformed sphere, including nonuniform scale and quaternion tolerance.
47 pub fn world_bounds(&self) -> BoundingSphere {
48 world_bounds(self.mesh.bounds(), self.transform)
49 }
50}
51/// Owned resolved frame, retaining snapshot admission and CPU assets through registry retirement.
52/// GPU upload/retirement remains a separate submission-completion boundary.
53pub struct PreparedScene {
54 pub(crate) instances: Vec<PreparedInstance>,
55 pub(crate) _snapshot: SceneSnapshot,
56 pub(crate) _lease: AssetLease,
57}
58impl PreparedScene {
59 /// Resolved immutable instances; prepared payload capacity is accounted by the registry.
60 pub fn instances(&self) -> &[PreparedInstance] {
61 &self.instances
62 }
63}