khora_data/scene/definition.rs
1// Copyright 2025 eraflo
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Defines a stable, intermediate representation of a scene using serializable data types.
16
17use khora_core::ecs::entity::EntityId;
18use serde::{Deserialize, Serialize};
19
20use crate::ecs::{SerializableParent, SerializableTransform};
21
22/// The root container for a scene's intermediate representation.
23#[derive(Debug, Serialize, Deserialize)]
24pub struct SceneDefinition {
25 /// All entities in the scene.
26 pub entities: Vec<EntityDefinition>,
27}
28
29/// A serializable representation of a single entity and its components.
30#[derive(Debug, Serialize, Deserialize)]
31pub struct EntityDefinition {
32 /// The unique identifier for the entity.
33 pub id: EntityId,
34 /// The components attached to the entity.
35 pub components: Vec<ComponentDefinition>,
36}
37
38/// A serializable, type-erased representation of a single component.
39#[derive(Debug, Serialize, Deserialize)]
40pub enum ComponentDefinition {
41 /// The transform component, representing the entity's position, rotation, and scale.
42 Transform(SerializableTransform),
43 /// The parent component, representing the entity's parent-child relationship.
44 Parent(SerializableParent),
45}