-
Notifications
You must be signed in to change notification settings - Fork 27
Graph
FUDGE follows a standard model used in many game engines, mostly called the scenetree. Also the document object model, that represents websites in the browser, relies on the same structure. This is a directed graph consisting of so called nodes and edges. A node holds information about parts of the whole scenery to display. The edges connect nodes in a parent-child-relationship.
Edges are not separate entities in FUDGE, but simply references to children and parent owned by each node. One node can reference multiple child nodes, each of which own a back reference to this parent node. These references represent the edges of the graph, thus creating a hierarchy of nodes. Directed graph in this case means, that navigation along these edges can only go up and down in the hierarchy, there is no direct edge to sibling nodes or others built in.
Such a structure may be depicted as a tree.
Nodes contain all properties and methods to safely build such a tree. There must not be a child of a node referencing a different node as its parent. A node also contains a list of components that are attached to it, which actually comprise the information about visual and audible parts of the scene as well as behaviors of those and more. A node without components may simply serve to group its children.
As in the document object model, a node also serves as a transmitter for events. Information about an event, like a mouseclick or a collision, can travel up or down along the edges of the graph and be processed by listener-functions linked to a node in that path.
Since nodes represent parts of a three-dimensional scenery, they are positioned in world space. When rendering, FUDGE calculates the resulting matrix, describing the complete transformation of each node rendered, by concatenating the local transformations relative to the corresponding parents throughout the hierarchy.
FUDGE allows to render the information contained in a single branch of a graph in a viewport, or in multiple viewports e.g. from different perspectives.
A car may be constructed with one node holding the information to display the cars body, and four child nodes, each representing a wheel. This setup makes sense, since the wheels, being attached, move with the cars body, while also moving relative to it, rotating and being pushed in.
Despite being structurally identical, nodes are called depending on their position in the graph. A node with children but no parent may be called a root-node, since it is the starting point for a graph. A node with a parent but no child nodes is a leaf-node, since it is an end point of a graph. A node that has both, children and parent, is a branch-node.
- mostly such a tree is depicted upside down, since this it's easier to draw.
- easily create a representation of such a tree at runtime in the browser's console using Debug
.branch(...)
Every graph consists at least of one node. And one node, as root, may represent via its references to its descendants a whole graph. So there is some ambiguity. When working in FUDGE, try to stick to the following conventions.
When processing a single node, without including other nodes related to it, use the term node.
When processing a node including its descendants, use the term branch for that node.
A graph is a branch registered as a resource to be reused. So a graph describes an entity in a game consisting of multiple nodes and components and serves as a template. Many instances, respectively copies, of that graph may then populate the scene. The car of the example may be registered as a graph and then hundreds of car-instances be inserted into the scene graph to drive around the game world. Again, since there is a single root-node for any graph, this root can be attached as child to another node in a bigger graph an thus become a branch in that graph.