# scene_tree_component.h ## Overview
The Scene Tree Component adds a "scene tree" hierarchy or "skeleton" to an entity. When an entity has a Scene Tree, child entities can be attached to specific nodes of the Scene Tree. If they are, their local position will be set relative to the transform of that Scene Tree node, rather than relative to the transform of the parent entity. See `tm_transform_component_api->set_parent()` for more information.
## Index
`TM_TT_TYPE__SCENE_TREE_COMPONENT`
`enum TM_TT_PROP__SCENE_TREE_COMPONENT`
`enum TM_SCENE_TREE_COMPONENT_ROOT_NODE`
`struct tm_scene_tree_node_t`
`struct tm_scene_tree_node_names_t`
`tm_scene_tree_component_t`
`tm_scene_tree_component_manager_o`
`TM_SCENE_TREE_COMPONENT_API_NAME`

`struct tm_scene_tree_component_api`
`setup_nodes()`
`node_names()`
`node_index_from_name()`
`node_debug_name_from_index()`
`world_matrices()`
`local_matrices()`
`local_transform()`
`world_transform()`
`set_local_transform()`
`set_local_matrix()`
`transform()`
`set_debug_color()`

## API
### `TM_TT_TYPE__SCENE_TREE_COMPONENT`
~~~c #define TM_TT_TYPE__SCENE_TREE_COMPONENT "tm_scene_tree_component" #define TM_TT_TYPE_HASH__SCENE_TREE_COMPONENT TM_STATIC_HASH("tm_scene_tree_component", 0x3dffa793f12d2b48ULL) ~~~
### `enum TM_TT_PROP__SCENE_TREE_COMPONENT`
~~~c enum { // Array of [[tm_scene_tree_node_t]] stored in a buffer. Array is assumed to be sorted with parent // nodes appearing before child nodes. TM_TT_PROP__SCENE_TREE_COMPONENT__NODES, // buffer // Array of full node names stored in a buffer for debugging. Node names are stored in the // buffer in the same order that nodes are stored in the `NODES` buffer and separate by `\0` // characters. Note that the hashes of these names must match the hashes in // `tm_scene_tree_node_t->name`. // // In earlier versions of The Machinery, this property didn't exist, so it might be missing for // old data. In that case, the hexadecimal hash will be displayed instead of the proper node // name. TM_TT_PROP__SCENE_TREE_COMPONENT__NODE_NAMES, // buffer // The asset from which this component was rigged. May not be set. TM_TT_PROP__SCENE_TREE_COMPONENT__ASSET, // reference [[TM_TT_TYPE__ASSET]] }; ~~~
### `enum TM_SCENE_TREE_COMPONENT_ROOT_NODE`
~~~c enum { TM_SCENE_TREE_COMPONENT_ROOT_NODE_PARENT = 0xffffffff }; ~~~
### `struct tm_scene_tree_node_t`
Represents a node in the scene tree. ~~~c typedef struct tm_scene_tree_node_t { // Hashed name of node. tm_strhash_t name; // Index of parent node or [[TM_SCENE_TREE_COMPONENT_ROOT_NODE_PARENT]] uint32_t parent_idx; // Local transform of node. tm_transform_t local_transform; TM_PAD(4); } tm_scene_tree_node_t; ~~~
### `struct tm_scene_tree_node_names_t`
Structure that provides information about the node names in the scene tree. This can be used to cache index translation tables between the scene tree, other scene trees or animation poses that lets us quickly pair objects/bones with matching names. ~~~c typedef struct tm_scene_tree_node_names_t { // A hash of all the node names in the scene tree. This uniquely identifies the "node setup" of // the scene tree. Two scene trees that have the same `hash` have the same nodes at the same // indices. // // This hash can also be used to match against the hash value in [[tm_animation_pose_t]] to test // if an animation pose has the same bone setup as the scene tree. uint64_t hash; // Number of nodes in the scene tree. uint32_t n; TM_PAD(4); // Pointer to array of hashed node names. const tm_strhash_t *node_names; } tm_scene_tree_node_names_t; ~~~
### `tm_scene_tree_component_t`
~~~c typedef struct tm_scene_tree_component_t tm_scene_tree_component_t; ~~~
### `tm_scene_tree_component_manager_o`
~~~c typedef struct tm_scene_tree_component_manager_o tm_scene_tree_component_manager_o; ~~~
### `TM_SCENE_TREE_COMPONENT_API_NAME`
~~~c #define TM_SCENE_TREE_COMPONENT_API_NAME "tm_scene_tree_component_api" ~~~
### `struct tm_scene_tree_component_api`
#### `setup_nodes()` ~~~c void (*setup_nodes)(tm_scene_tree_component_manager_o *manager, tm_scene_tree_component_t *st, const tm_scene_tree_node_t *nodes, uint32_t num_nodes, const char *debug_names); ~~~ Explicitly sets the nodes of the scene tree component. Note that the component will make its own copy of the `nodes` array. `debug_names` is a `\0` separated string of debug names for the nodes. You can pass NULL for this parameter if you don't want to use debug names. #### `node_names()` ~~~c tm_scene_tree_node_names_t (*node_names)(const tm_scene_tree_component_t *st); ~~~ Returns the node name information for the scene tree component. This can be used to match up node names with names from other systems, such as the animation system. #### `node_index_from_name()` ~~~c uint32_t (*node_index_from_name)(const tm_scene_tree_component_t *component, tm_strhash_t node_name, uint32_t not_found); ~~~ Returns the index of the node with hashed name `node_name` or `not_found` if no node with that name exists. #### `node_debug_name_from_index()` ~~~c const char *(*node_debug_name_from_index)(const tm_scene_tree_component_t *component, uint32_t node_idx); ~~~ Returns the debug name from the node at the specified index. This will only returns a valid string if `debug_names` was not NULL when `setup_nodes` was called, otherwise it will return NULL. #### `world_matrices()` ~~~c const tm_mat44_t *(*world_matrices)(const tm_scene_tree_component_t *component); ~~~ Returns `carray` of `tm_mat44_t` with local to world transforms. #### `local_matrices()` ~~~c const tm_mat44_t *(*local_matrices)(const tm_scene_tree_component_t *component); ~~~ Returns `carray` of `tm_mat44_t` with local to parent transforms. #### `local_transform()` ~~~c tm_transform_t (*local_transform)(const tm_scene_tree_component_t *component, uint32_t node_idx); ~~~ Return the local to parent `tm_transform_t` for `node_idx`. #### `world_transform()` ~~~c tm_transform_t (*world_transform)(const tm_scene_tree_component_t *component, uint32_t node_idx); ~~~ Return the local to world `tm_transform_t` for `node_idx`. #### `set_local_transform()` ~~~c void (*set_local_transform)(tm_scene_tree_component_t *component, uint32_t node_idx, const tm_transform_t *t); ~~~ Set the local to parent transform for `node_idx` to `t`. #### `set_local_matrix()` ~~~c void (*set_local_matrix)(tm_scene_tree_component_t *component, uint32_t node_idx, const tm_mat44_t *tm); ~~~ Set the local to parent matrix for `node_idx` to `tm`. #### `transform()` ~~~c void (*transform)(tm_scene_tree_component_t *st, const tm_transform_t *trans, uint64_t version); ~~~ Transform nodes with `trans`. `version` is a version number for the transform data. If it matches the current version, the transform will be ignored. #### `set_debug_color()` ~~~c void (*set_debug_color)(tm_scene_tree_component_t *st, const tm_color_srgb_t color); ~~~ Sets color for debug drawing.