From d94deb565d3d44834f8e0e3d4653fe721791eb4e Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Fri, 31 Oct 2025 20:27:57 -0700 Subject: Consolidate scene header --- include/gfx/scene.h | 215 +++++++++++++++++++++++++++++++++++++++++++-- include/gfx/scene/camera.h | 13 --- include/gfx/scene/model.h | 12 --- include/gfx/scene/node.h | 137 ----------------------------- include/gfx/scene/object.h | 39 -------- include/gfx/scene/scene.h | 19 ---- 6 files changed, 210 insertions(+), 225 deletions(-) delete mode 100644 include/gfx/scene/camera.h delete mode 100644 include/gfx/scene/model.h delete mode 100644 include/gfx/scene/node.h delete mode 100644 include/gfx/scene/object.h delete mode 100644 include/gfx/scene/scene.h (limited to 'include') diff --git a/include/gfx/scene.h b/include/gfx/scene.h index 3098221..740a948 100644 --- a/include/gfx/scene.h +++ b/include/gfx/scene.h @@ -1,7 +1,212 @@ #pragma once -#include -#include -#include -#include -#include +#include +#include + +#include +#include +#include + +typedef struct Anima Anima; +typedef struct Camera Camera; +typedef struct Light Light; +typedef struct Mesh Mesh; +typedef struct Model Model; +typedef struct Scene Scene; +/// A node in the scene graph. +/// +/// Scene nodes take ownership of the object they are associated with (Camera, +/// Light, SceneObject, etc), as well as of child nodes. +typedef struct SceneNode SceneNode; +typedef struct SceneObject SceneObject; +typedef struct Skeleton Skeleton; + +typedef struct ObjectDesc { + size_t num_meshes; + Mesh* meshes[GFX_MAX_NUM_MESHES]; +} ObjectDesc; + +/// Scene node type. +typedef enum NodeType { + LogicalNode, + AnimaNode, + CameraNode, + LightNode, + ModelNode, + ObjectNode, +} NodeType; + +// ----------------------------------------------------------------------------- +// Camera. +// ----------------------------------------------------------------------------- + +/// Create a new camera. +Camera* gfx_make_camera(void); + +/// Destroy the camera. +void gfx_destroy_camera(Camera**); + +// ----------------------------------------------------------------------------- +// Model. +// ----------------------------------------------------------------------------- + +/// Return the model's anima, or null if the model is not animated. +Anima* gfx_get_model_anima(Model*); + +/// Return the model's root node. +const SceneNode* gfx_get_model_root(const Model*); +SceneNode* gfx_get_model_root_mut(Model*); + +// ----------------------------------------------------------------------------- +// Object. +// ----------------------------------------------------------------------------- + +/// Create a new object. +SceneObject* gfx_make_object(const ObjectDesc*); + +/// Destroy the object. +/// +/// The object is conveniently removed from the scene graph and its parent scene +/// node is destroyed. +void gfx_destroy_object(SceneObject**); + +/// Set the object's skeleton. +void gfx_set_object_skeleton(SceneObject*, const Skeleton*); + +/// Get the object's skeleton. +/// Return null if the object has no skeleton. +const Skeleton* gfx_get_object_skeleton(const SceneObject*); + +/// Gets the object's bounding box. +/// +/// The object's bounding box is the bounding box of its mesh geometries. +aabb3 gfx_get_object_aabb(const SceneObject*); + +// ----------------------------------------------------------------------------- +// Scene. +// ----------------------------------------------------------------------------- + +/// Create a new scene. +Scene* gfx_make_scene(void); + +/// Destroy the scene. +/// +/// This function destroys the scene and all objects that it owns (scene +/// objects, cameras, lights, etc), but not objects that could be shared with +/// other scenes (meshes, materials, etc). +void gfx_destroy_scene(Scene**); + +/// Get the scene's root node. +const SceneNode* gfx_get_scene_root(const Scene*); +SceneNode* gfx_get_scene_root_mut(Scene*); + +// ----------------------------------------------------------------------------- +// Node constructors and destructor. +// ----------------------------------------------------------------------------- + +/// Create a new scene node. +/// +/// This node does not contain any camera, light, object, etc. and exists simply +/// as a logical and spatial construct. +SceneNode* gfx_make_node(void); + +/// Create an anima node. +SceneNode* gfx_make_anima_node(Anima*); + +/// Create a new camera node. +SceneNode* gfx_make_camera_node(Camera*); + +/// Create a new light node. +SceneNode* gfx_make_light_node(Light*); + +/// Create a new model node. +SceneNode* gfx_make_model_node(Model*); + +/// Create a new object node. +SceneNode* gfx_make_object_node(SceneObject*); + +/// Recursively destroy the scene node and its children. +/// +/// The scene node and its children are removed from the scene graph. +/// +/// Node resources -- cameras, lights, objects, etc. -- are also destroyed. +void gfx_destroy_node(SceneNode**); + +// ----------------------------------------------------------------------------- +// Node getters. +// ----------------------------------------------------------------------------- + +/// Get the node's type. +NodeType gfx_get_node_type(const SceneNode*); + +/// Get the node's anima. +/// +/// The node must be of type AnimaNode. +const Anima* gfx_get_node_anima(const SceneNode*); +Anima* gfx_get_node_anima_mut(SceneNode*); + +/// Get the node's camera. +/// +/// The node must be of type CameraNode. +const Camera* gfx_get_node_camera(const SceneNode* node); +Camera* gfx_get_node_camera_mut(SceneNode* node); + +/// Get the node's light. +/// +/// The node must be of type LightNode. +const Light* gfx_get_node_light(const SceneNode*); +Light* gfx_get_node_light_mut(SceneNode*); + +/// Get the node's model. +/// +/// The node must be of type ModelNode. +const Model* gfx_get_node_model(const SceneNode*); +Model* gfx_get_node_model_mut(SceneNode*); + +/// Get the node's scene object. +/// +/// The node must be of type ObjectNode. +const SceneObject* gfx_get_node_object(const SceneNode*); +SceneObject* gfx_get_node_object_mut(SceneNode*); + +/// Get the node's parent. +const SceneNode* gfx_get_node_parent(const SceneNode*); +SceneNode* gfx_get_node_parent_mut(SceneNode*); + +/// Get the node's first child. +const SceneNode* gfx_get_node_child(const SceneNode*); +SceneNode* gfx_get_node_child_mut(SceneNode*); + +/// Get the node's immediate sibling. +const SceneNode* gfx_get_node_sibling(const SceneNode*); +SceneNode* gfx_get_node_sibling_mut(SceneNode*); + +/// Get the node's (local) transform. +mat4 gfx_get_node_transform(const SceneNode*); + +/// Get the node's global transform. +mat4 gfx_get_node_global_transform(const SceneNode*); + +// ----------------------------------------------------------------------------- +// Node setters. +// ----------------------------------------------------------------------------- + +/// Set the node's parent. +/// +/// Pass in null to unwire from the existing parent, if one exists. +void gfx_set_node_parent(SceneNode*, SceneNode* parent_node); + +/// Set the node's (local) transform. +void gfx_set_node_transform(SceneNode*, const mat4* transform); + +/// Set the node's position. +void gfx_set_node_position(SceneNode*, const vec3* position); + +/// Set the node's rotation. +void gfx_set_node_rotation(SceneNode*, const quat* rotation); + +/// Set the node's rotation. +void gfx_set_node_rotation_mat(SceneNode*, const mat4* rotation); + +/// Log the node's hierarchy. +void gfx_log_node_hierarchy(const SceneNode*); diff --git a/include/gfx/scene/camera.h b/include/gfx/scene/camera.h deleted file mode 100644 index 873f780..0000000 --- a/include/gfx/scene/camera.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include - -typedef struct SceneNode SceneNode; - -typedef struct Camera Camera; - -/// Create a new camera. -Camera* gfx_make_camera(); - -/// Destroy the camera. -void gfx_destroy_camera(Camera**); diff --git a/include/gfx/scene/model.h b/include/gfx/scene/model.h deleted file mode 100644 index 42f85d4..0000000 --- a/include/gfx/scene/model.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -typedef struct Anima Anima; -typedef struct Model Model; -typedef struct SceneNode SceneNode; - -/// Return the model's anima, or null if the model is not animated. -Anima* gfx_get_model_anima(Model*); - -/// Return the model's root node. -const SceneNode* gfx_get_model_root(const Model*); -SceneNode* gfx_get_model_root_mut(Model*); diff --git a/include/gfx/scene/node.h b/include/gfx/scene/node.h deleted file mode 100644 index 215bbda..0000000 --- a/include/gfx/scene/node.h +++ /dev/null @@ -1,137 +0,0 @@ -#pragma once - -#include -#include - -typedef struct Anima Anima; -typedef struct Camera Camera; -typedef struct Light Light; -typedef struct Model Model; -typedef struct SceneObject SceneObject; - -/// Scene node type. -typedef enum NodeType { - LogicalNode, - AnimaNode, - CameraNode, - LightNode, - ModelNode, - ObjectNode, -} NodeType; - -/// A node in the scene graph. -/// -/// Scene nodes take ownership of the object they are associated with (Camera, -/// Light, SceneObject, etc), as well as of child nodes. -typedef struct SceneNode SceneNode; - -// ----------------------------------------------------------------------------- -// Constructors and destructor. -// ----------------------------------------------------------------------------- - -/// Create a new scene node. -/// -/// This node does not contain any camera, light, object, etc. and exists simply -/// as a logical and spatial construct. -SceneNode* gfx_make_node(void); - -/// Create an anima node. -SceneNode* gfx_make_anima_node(Anima*); - -/// Create a new camera node. -SceneNode* gfx_make_camera_node(Camera*); - -/// Create a new light node. -SceneNode* gfx_make_light_node(Light*); - -/// Create a new model node. -SceneNode* gfx_make_model_node(Model*); - -/// Create a new object node. -SceneNode* gfx_make_object_node(SceneObject*); - -/// Recursively destroy the scene node and its children. -/// -/// The scene node and its children are removed from the scene graph. -/// -/// Node resources -- cameras, lights, objects, etc. -- are also destroyed. -void gfx_destroy_node(SceneNode**); - -// ----------------------------------------------------------------------------- -// Getters. -// ----------------------------------------------------------------------------- - -/// Get the node's type. -NodeType gfx_get_node_type(const SceneNode*); - -/// Get the node's anima. -/// -/// The node must be of type AnimaNode. -const Anima* gfx_get_node_anima(const SceneNode*); -Anima* gfx_get_node_anima_mut(SceneNode*); - -/// Get the node's camera. -/// -/// The node must be of type CameraNode. -const Camera* gfx_get_node_camera(const SceneNode* node); -Camera* gfx_get_node_camera_mut(SceneNode* node); - -/// Get the node's light. -/// -/// The node must be of type LightNode. -const Light* gfx_get_node_light(const SceneNode*); -Light* gfx_get_node_light_mut(SceneNode*); - -/// Get the node's model. -/// -/// The node must be of type ModelNode. -const Model* gfx_get_node_model(const SceneNode*); -Model* gfx_get_node_model_mut(SceneNode*); - -/// Get the node's scene object. -/// -/// The node must be of type ObjectNode. -const SceneObject* gfx_get_node_object(const SceneNode*); -SceneObject* gfx_get_node_object_mut(SceneNode*); - -/// Get the node's parent. -const SceneNode* gfx_get_node_parent(const SceneNode*); -SceneNode* gfx_get_node_parent_mut(SceneNode*); - -/// Get the node's first child. -const SceneNode* gfx_get_node_child(const SceneNode*); -SceneNode* gfx_get_node_child_mut(SceneNode*); - -/// Get the node's immediate sibling. -const SceneNode* gfx_get_node_sibling(const SceneNode*); -SceneNode* gfx_get_node_sibling_mut(SceneNode*); - -/// Get the node's (local) transform. -mat4 gfx_get_node_transform(const SceneNode*); - -/// Get the node's global transform. -mat4 gfx_get_node_global_transform(const SceneNode*); - -// ----------------------------------------------------------------------------- -// Setters. -// ----------------------------------------------------------------------------- - -/// Set the node's parent. -/// -/// Pass in null to unwire from the existing parent, if one exists. -void gfx_set_node_parent(SceneNode*, SceneNode* parent_node); - -/// Set the node's (local) transform. -void gfx_set_node_transform(SceneNode*, const mat4* transform); - -/// Set the node's position. -void gfx_set_node_position(SceneNode*, const vec3* position); - -/// Set the node's rotation. -void gfx_set_node_rotation(SceneNode*, const quat* rotation); - -/// Set the node's rotation. -void gfx_set_node_rotation_mat(SceneNode*, const mat4* rotation); - -/// Log the node's hierarchy. -void gfx_log_node_hierarchy(const SceneNode*); diff --git a/include/gfx/scene/object.h b/include/gfx/scene/object.h deleted file mode 100644 index 7579d29..0000000 --- a/include/gfx/scene/object.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include - -#include - -#include - -typedef struct Mesh Mesh; -typedef struct SceneNode SceneNode; -typedef struct Skeleton Skeleton; - -typedef struct SceneObject SceneObject; - -typedef struct ObjectDesc { - size_t num_meshes; - Mesh* meshes[GFX_MAX_NUM_MESHES]; -} ObjectDesc; - -/// Create a new object. -SceneObject* gfx_make_object(const ObjectDesc*); - -/// Destroy the object. -/// -/// The object is conveniently removed from the scene graph and its parent scene -/// node is destroyed. -void gfx_destroy_object(SceneObject**); - -/// Set the object's skeleton. -void gfx_set_object_skeleton(SceneObject*, const Skeleton*); - -/// Get the object's skeleton. -/// Return null if the object has no skeleton. -const Skeleton* gfx_get_object_skeleton(const SceneObject*); - -/// Gets the object's bounding box. -/// -/// The object's bounding box is the bounding box of its mesh geometries. -aabb3 gfx_get_object_aabb(const SceneObject*); diff --git a/include/gfx/scene/scene.h b/include/gfx/scene/scene.h deleted file mode 100644 index 7386349..0000000 --- a/include/gfx/scene/scene.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -typedef struct SceneNode SceneNode; - -typedef struct Scene Scene; - -/// Create a new scene. -Scene* gfx_make_scene(void); - -/// Destroy the scene. -/// -/// This function destroys the scene and all objects that it owns (scene -/// objects, cameras, lights, etc), but not objects that could be shared with -/// other scenes (meshes, materials, etc). -void gfx_destroy_scene(Scene**); - -/// Get the scene's root node. -const SceneNode* gfx_get_scene_root(const Scene*); -SceneNode* gfx_get_scene_root_mut(Scene*); -- cgit v1.2.3