-
Notifications
You must be signed in to change notification settings - Fork 27
Component
In modern object oriented design, it's recommended to implement composition over inheritance. Instead of building a deep class hierarchy, it is preferred to use a flat hierarchy and extend objects by adding small components to them. That is why there is no mesh-node or audio-node in FUDGE, but simply nodes. A mesh or an audiosample and various other components are added to the node to turn it into what ever it is supposed to be.
To do so, FUDGE implements a superclass Component and various subclasses of it for different task. Each component instance added to a node keeps a back reference to the node it is attached to.
Some components are self contained, they add information or functionality to a node without refering to resources. The most common of this type of component is ComponentTransform, which adds spatial position and orientation to a node by using a local matrix that is contained within the component instance.
Other components refer to resources to be used when processing the node they are attached to. A very common example is ComponentMaterial, which ties a previously defined material to the node to be used when rendering the mesh attached.
Then some components do both, an example being ComponentMesh. It ties an existing mesh to a node but also contains a pivot matrix to define spatial position and orientation of the mesh relative to the nodes transform.
The following diagram displays the relationship of components, nodes and resources.
A special and very flexible kind of component is the script component. User may subclass this and create their own components via coding. Attached to a node, an instance of such a component can register its methods to the node as event-handlers that will automatically be called when an event is propagated to that node. Using the back reference, the script has easy access to the node.