Plugin step-by-step:
1. Create a module file
This step is easy. Any Python file (with "py" extension) located in makehuman "plugin" sirectory and not strted with underscore ("_"), will be automatically loaded and executed. So lets create an empty file there.
2. Imports
To use makehuman functionality in your module, you need to make some imports. Depending on what you want to achive, exact list of imports may vary:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#GUI functions to alter user interface, used in most plugins:
import gui3d
Any python module from "mh_core" and "mh_plugins" could be imported here. You may also want to import some standard python modules.
It is recommended to finish imports with console output to track the proces and errors:
print 'example imported'
3. "Load" method
The only required methid for plugins is "load". It is called for plugin initialization. All initializations should be placed here:
def load(app):
4. Registering GUI
Any GUI elements could be added by the plugin. Lets make the most simplest operation - add a button. The buttons are organized by categories. Let's create a new category for the plugin and add a button there. We'll start before the "load" method:
#Global variables for our module to hold GUI controls
category = None
taskview = None
def load(app):
#Creating a category in GUI, using default button image
category = gui3d.Category(app, 'Example', app.getThemeResource('images', 'button_expressions.png'))
#Creating a task button, using default button image
taskview = gui3d.TaskView(category, 'Example', app.getThemeResource('images', 'button_expressions.png'))
5. Do some work
Our plugin need to do something. Let's make the button to change its image on pressing:
#Creating standard events
#Standard onShow:
@taskview.event
def onShow(event):
pass
#Standard onHide:
@taskview.event
def onHide(event):
pass
#Event for the button click:
@taskview.button.event
def onClicked(event):
taskview.button.setTexture(app.getThemeResource('images', 'button_about.png'))
It is recommended to finish initialization with console output to track the proces and errors:
print 'example loaded'
6. Going further
At this point you have a working plugin so you could start adding some real functionality here. Some tips to consider:
- It is often recommended to subclass TaskView, place your logic here and use the class for GUI initialization instead of TaskView. This approach helps to make the code more object-oriented.
- Plugins don't have to be called from main controls. If plugin affects some existing areas (i.e. Modelling), it is possible to navigate the area GUI. These GUI are created by core plugins from "mh_plugins" folder. All information could be found there.