Kemena3D
Loading...
Searching...
No Matches
kemena::kShaderGraph Struct Reference

A complete node-based shader graph: nodes, links, and identity. More...

#include <kshadernode.h>

Public Member Functions

int newId ()
 Allocates and returns a fresh unique id.
kShaderNodefindNode (int id)
 Finds a node by id.
const kShaderNodefindNode (int id) const
 Finds a node by id (const overload).
const kShaderLinkincomingLink (int nodeId, int pinId) const
 Finds the link feeding a given input pin.
bool isPinConnected (int nodeId, int pinId) const
 Tests whether a pin has any link attached.
void removeLinksByNode (int nodeId)
 Removes every link touching the given node.
void removeLinksByPin (int nodeId, int pinId)
 Removes every link touching the given pin.
kShaderNode makeNode (kShaderNodeType type, float x, float y)
 Creates a node of a given type with its default pins wired up.
nlohmann::json toJson () const
 Serializes the graph to JSON.
void fromJson (const nlohmann::json &j)
 Rebuilds the graph from a JSON representation.

Public Attributes

kString uuid
 Stable unique identifier for the graph asset.
kString name
 Display name of the graph.
std::vector< kShaderNodenodes
 All nodes in the graph.
std::vector< kShaderLinklinks
 All links between node pins.
int nextId = 1
 Next id to hand out via newId().
bool dirty = false
 True when the graph has unsaved changes.

Detailed Description

A complete node-based shader graph: nodes, links, and identity.

Owns its nodes and links, hands out unique ids, tracks a dirty flag for the editor, and provides queries, edits, a node factory, and JSON I/O.

Member Function Documentation

◆ findNode() [1/2]

kShaderNode * kemena::kShaderGraph::findNode ( int id)

Finds a node by id.

Parameters
idNode id to look up.
Returns
Pointer to the node, or nullptr if not found.

◆ findNode() [2/2]

const kShaderNode * kemena::kShaderGraph::findNode ( int id) const

Finds a node by id (const overload).

Parameters
idNode id to look up.
Returns
Const pointer to the node, or nullptr if not found.

◆ fromJson()

void kemena::kShaderGraph::fromJson ( const nlohmann::json & j)

Rebuilds the graph from a JSON representation.

Parameters
jJSON object previously produced by toJson().

◆ incomingLink()

const kShaderLink * kemena::kShaderGraph::incomingLink ( int nodeId,
int pinId ) const

Finds the link feeding a given input pin.

Parameters
nodeIdDestination node id.
pinIdDestination input pin id.
Returns
The link whose toNode/toPin match, or nullptr if the pin is unconnected.

◆ isPinConnected()

bool kemena::kShaderGraph::isPinConnected ( int nodeId,
int pinId ) const

Tests whether a pin has any link attached.

Parameters
nodeIdOwning node id.
pinIdPin id to test.
Returns
true if at least one link touches the pin.

◆ makeNode()

kShaderNode kemena::kShaderGraph::makeNode ( kShaderNodeType type,
float x,
float y )

Creates a node of a given type with its default pins wired up.

Parameters
typeNode type to construct.
xInitial canvas X position.
yInitial canvas Y position.
Returns
A fully initialized node (not yet added to the graph).

◆ newId()

int kemena::kShaderGraph::newId ( )
inline

Allocates and returns a fresh unique id.

Returns
The next sequential id.

◆ removeLinksByNode()

void kemena::kShaderGraph::removeLinksByNode ( int nodeId)

Removes every link touching the given node.

Parameters
nodeIdNode whose links should be removed.

◆ removeLinksByPin()

void kemena::kShaderGraph::removeLinksByPin ( int nodeId,
int pinId )

Removes every link touching the given pin.

Parameters
nodeIdOwning node id.
pinIdPin id whose links should be removed.

◆ toJson()

nlohmann::json kemena::kShaderGraph::toJson ( ) const

Serializes the graph to JSON.

Returns
JSON representation of the graph.

Member Data Documentation

◆ dirty

bool kemena::kShaderGraph::dirty = false

True when the graph has unsaved changes.

◆ links

std::vector<kShaderLink> kemena::kShaderGraph::links

All links between node pins.

◆ name

kString kemena::kShaderGraph::name

Display name of the graph.

◆ nextId

int kemena::kShaderGraph::nextId = 1

Next id to hand out via newId().

◆ nodes

std::vector<kShaderNode> kemena::kShaderGraph::nodes

All nodes in the graph.

◆ uuid

kString kemena::kShaderGraph::uuid

Stable unique identifier for the graph asset.


The documentation for this struct was generated from the following file: