sumo plugin code example

the cube plugin will just show a very simple rotating cube, which can be textured.
you can find the full source of this example in the source code at sumo.plugins.cube.Cube.

configuration

every plugin is configured in /application/plugins.xml
<plugin name="test cube" class="sumo.plugins.cube.Cube" icon="3dbox.png">
	<description>
	super cube!
	</description>
	<variables title="default">
		<variable name="image" type="resource" resourceType="sumo.resource.types.textureFile" />
		<variable name="size" type="float" />
	</variables>
</plugin>
most important is to specify the correct classname (<plugin class="...">)

also the you define which variables are visible to the user.
this definition will look like this :

cubeplugin

code

declaration of variables
public class Cube extends Plugin
{
	public KeyframedResource image;
	public KeyframedFloat size;
at first you declare some variables you need. these are the variables we also defined in plugins.xml.


initializing
public void init()
{
	image.setResource(new textureFile());
	image.addKeysChangedListener(new KeyFramesChangedListener()
	{
		public void keysChanged()
		{
			currenTexture=(textureFile)image.getResource();
		}
	});
}
the init function will be called only once, when a plugin is instanced by the user.
in the example we add a "keychangedlistener".
a keychangedlistener will evoke the local function "keyschanged" when the keys have changed.
in this case we want to update our texture after the user choose an image.


rendering
public void render()
{
	GL11.glLoadIdentity();
	GL11.glTranslatef(0,0,-4.0f-2.0f);

	scale=size.getValue()*1.3f;
	GL11.glScalef(scale,scale,scale);

	if(currenTexture!=null)
	{
		currenTexture.enable();
		currenTexture.bind();
	}
	else
	{
		textureFile.disable();
	}

	GL11.glRotatef(Project.getProject().getTime()*180.0f,1,1,1);
	GL11.glColor3f(1.0f,1.0f,1.0f);

	drawCube();
}
the render function will be called at every frame.
everything is painted with the usual opengl commands. sumo uses lwjgl as interface to native opengl.
most interesting parts of the render example:
scale=size.getValue()*1.3f;
KeyframedInt, KeyframedFloat and KeyframedBoolean have the function getValue() which will return their keyframed value at the current time (current time= where the time marker at the moment).
Project.getProject().getTime()
this will give you the current time as a float.