This repository was archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Writing Node Libraries
fdb edited this page Oct 29, 2010
·
4 revisions
The appeal of creative coding is that you can make your own nodes, of course. Nodes are package in node libraries. Writing your own nodes within the application is not supported yet. You'll have to use command-line tools or an IDE such as Eclipse to prepare the code.
To get you started, we've created a fully self-contained demonstration library.
The basic structure of a node looks like this:
package nodebox.graphics.nodes;
import nodebox.node.*;
@Description("Generate a line based on a starting point and angle/distance.")
@Category("Geometry")
public class LineNode extends Node {
public final GeometryPort pOutput = new GeometryPort(this, "output", Port.Direction.OUTPUT);
@Override
public void execute(Context context, float time) {
Geometry geometry = doSomethingToGenerateGeometry();
pOutput.set(geometry);
}
}
- Description: Always in active form ("generate", not "generates"), ending with a period.
- Category: Important for the node taxonomy.
- execute: Base method. This method should not cause any side effects. If your node needs to draw something on the canvas, override the draw() method. See the technical architecture for more details.
The manifest contains the metadata for the node library, such as the name, version, and a list of exported nodes. Here's the one from nodebox.graphics:
Manifest-Version: 1
Bundle-ManifestVersion: 2
Bundle-SymbolicName: nodebox.graphics
Bundle-Name: NodeBox-Graphics
Bundle-Version: 1.0.0
Import-Package: org.osgi.framework, processing.core, nodebox.node, nodebox.util
Export-Package: nodebox.graphics
Export-Node: nodebox.graphics.nodes.ColorNode,
nodebox.graphics.nodes.LineNode
- Manifest-Version: Indicates to Java that this is a standard manifest file. Required, and is always "1".
- Bundle-ManifestVersion: Indicates that this is an OSGi manifest. Required, and is always "2".
- Bundle-SymbolicName: A unique name that identifies this library. Use the package name. Required.
- Bundle-Name: A freeform name that identifies the library to the user. You can use spaces here. Required.
- Bundle-Version: The version number for the library. Use major.minor.revision format, such as "3.2.4". Required.
- Import-Package: A list of packages this library needs. If you import other packages in your source, add them here as well, otherwise you get ClassNotFound exceptions. Required.
- Export-Package: If your node also makes other packages available, add them here. Optional.
- Export-Node: A comma-separated list of all your node classes. The system will read this list and extract the metadata, such as description an category. Required.