In this Section we will write a basic sequence plugin and then go through the steps use a sequence plugin. The basics behind a sequence plugin are you are given some inputs; 1-3 input image buffers as well as some other information and you output a resulting image buffer.
All the files necessary to develop plugins as well as a few sample plugins can be found in the blender/plugins directory. You can alternately get a bunch of plugins from http://www.cs.umn.edu/~mein/blender/plugins
The Plugin System
Plugins are supported (loaded/called) in Blender using the dlopen() family of
calls. For those unfamiliar with the dlopen system it allows a program
(Blender) to use a compiled object as if it were part of the program itself,
similar to dynamically linked libraries, except the objects to load are
determined at runtime.
The advantage of using the dlopen system for plugins is that it is very fast to access a function, and there is no overhead in interfacing to the plugin, which is critical when (in the case of texture plugins) the plugin can be called several million times in a single render.
The disadvantage of the system is that the plugin code works just like it is part of Blender itself, if the plugin crashes, Blender crashes.
Provided functionality
The include files found in the plugin/include/ subdirectory of the Blender
installation document the Blender functionality provided to the plugins.
This includes the Imbuf library functions for loading and working with images
and image buffers, and noise and turbulence functions for consistent texturing.
Each VarStruct entry consists of a type, name, range information, and a tool tip.
The type defines the data type for each button entry, and the way to display the button. For number buttons this value should be a combination (ORed) of INT or FLO for the number format, and NUM, NUMSLI, or TOG, for the button type. Text buttons should have a type of LABEL.
The name is what will be displayed on (or beside) the button. This is limited to 15 characters.
The range information consists of three floats that define the default, minimum, and maximum values for the button. For TOG buttons the minimum is set in the pressed state, and the maximum is set in the depressed state.
The tip is a string that will be displayed
when the mouse is over this button (if the user has
tool tips on). This has a limit of 80 characters, and
should be set to the NULL string ("") if unused.
The cast should contain, in order, an integer
or float for every button defined in the varstr,
including text buttons. Typically these should
have the same name as the button for simple
reference.
#include "plugin.h"
char name[24]= "";
/* structure for buttons,
* butcode name default min max 0
*/
VarStruct varstr[]= {
{ LABEL, "In: X strips", 0.0, 0.0, 0.0, ""},
};
/* The cast struct is for input in the main doit function
Varstr and Cast must have the same variables in the same order */
typedef struct Cast {
int dummy; /* because of the 'label' button */
} Cast;
/* cfra: the current frame */
float cfra;
void plugin_seq_doit(Cast *, float, float, int, int,
ImBuf *, ImBuf *, ImBuf *, ImBuf *);
int plugin_seq_getversion(void) {
return B_PLUGIN_VERSION;
}
void plugin_but_changed(int but) {
}
void plugin_init() {
}
void plugin_getinfo(PluginInfo *info) {
info->name= name;
info->nvars= sizeof(varstr)/sizeof(VarStruct);
info->cfra= &cfra;
info->varstr= varstr;
info->init= plugin_init;
info->seq_doit= (SeqDoit) plugin_seq_doit;
info->callback= plugin_but_changed;
}
void plugin_seq_doit(Cast *cast, float facf0, float facf1, int xo, int yo,
ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *outbuf, ImBuf *use) {
char *in1= (char *)ibuf1->rect;
char *out=(char *)outbuf->rect;
}
Now we'll copy our generic plugin to simpfilt.c and will fill in the gaps.
Its always a good idea to add some comments. First off tell users
what the plugin does, where they can get a copy, who they should contact
for bugs/improvments, and any licensing restrictions on the code.
When using comments make sure you use /* */ style comments. The plugins
are in c and some c compilers do not accept // style comments.
/*
Description: This plugin is a sample sequence plugin that filters out lower
intensity pixels. I works on one strip as input.
Author: Kent Mein (mein@cs.umn.edu)
Website: http://www.cs.umn.edu/~mein/blender/plugins
Licensing: Public Domain
Last Modified: Sun Sep 7 23:41:35 CDT 2003
*/
Next we need to fill in the Name, you should really keep this the
same as your .c file. preferably descriptive, less than 23 chars, no
spaces, and all lowercase.
So we wind up with simpfilt.c
char name[24]= "simpfilt.c";
The Cast and varstr need to be in sync. We want one silder so we'll do the
folowing:
varStruct varstr[]= {
{ LABEL, "In: 1 strips", 0.0, 0.0, 0.0, ""},
{ NUM|INT, "Intensity", 10.0, 0.0, 255.0, "Our threshold value"},
};
typedef struct Cast {
int dummy; /* because of the 'label' button */
int intensity;
} Cast;
Now we need to fill in plugin_seq_doit. We basically want to loop
through each pixel and if RGB are all less than entensity set the output
pixel to: 0,0,0,255 else set it to the input values for that position.
int x,y;
for(y=0;y
If you are trying to develop plugins on a windows machine bmake may not work
for you in that case you should look into using lcc.
You can use the following to compile a plugin with lcc:
Assuming you have your plugins in c:\blender\plugins.
Here is an example of how you would compile the sequence plugin sweep.c Open
a dos prompt and do the following:
(Note: You'll want to make sure the lcc\bin directory is in your path)
cd c:\blender\plugins\sequence\sweep
lcc -Ic:\blender\plugins\include sweep.c
lcclnk -DLL sweep.obj c:\blender\plugins\include\seq.def
implib sweep.dll
Once you have the plugin loaded you can alter the order of the strips by hitting the c key and selecting swap a->b and or swap b->c. You can also alter the parameters you specified in varstr by selecting the plugin and hitting the n key. A menu will pop up where you can adjust your settings.