Dev:2.4/Doc/How to/Node types

提供: wiki
< Dev:2.4‎ | Doc‎ | How to
移動先: 案内検索

Parts of the node

There are (at this time) 2 types of nodes: Shader nodes (for creating textures and materials), and composite nodes (for post-rendering processes). Both are the same, even though they are inteded for different functions. The image below shows the parts that make up the node.
ExampleNode.PNG
The first thing to do, is to create the input and output of the node. This function sets up the inputs to the node

static bNodeSocketType cmp_node_example_in[]= {
	{ SOCK_VALUE, 0, "Value Input",		1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
	{ SOCK_VECTOR, 0, "Vector Input",	1.0f, 1.0f, 1.0f, 1.0f, -10.0f, 10.0f},
	{ SOCK_RGBA, 0, "Color Input",		1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f},
	{ -1, 0, ""	}
};

The same thing goes for the outputs

static bNodeSocketType cmp_node_example_out[]= {
	{ SOCK_VALUE, 0, "Value Output",	1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
	{ SOCK_VECTOR, 0, "Vector Input",	0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
	{ SOCK_RGBA, 0, "Color Output",		0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
	{ -1, 0, ""	}
};

Let's take a look at the Sockets:

{ SOCK_VALUE, 0, "Value Output", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }

The socket is defined in BKE_node.h

typedef struct bNodeSocketType {
	int type, limit;
	char *name;
	float val1, val2, val3, val4;	/* default alloc value for inputs */
	float min, max;					/* default range for inputs */
	
	/* after this line is used internal only */
	struct bNodeSocket *sock;		/* used during verify_types */
	struct bNodeSocket *internsock;	/* group nodes, the internal socket counterpart */
	int own_index;					/* verify group nodes */
	
} bNodeSocketType;

Now let's break it down:

  • type - The type of data you're dealing with (SOCK_VALUE, SOCK_VECTOR, SOCK_RGBA)
  • limit - How many connections you can make to this socket. (0 means unlimited connections)
  • name - What you call the socket, how it's displayed in the node
  • val1 to val4 - Default values, used when socket is unconnected.
  • min, max - Range allowed for val1 to val4, used when socket is unconnected and user selects a value.