While thinking about a enhancing the design of DynamicTexture, I stumbled across the fact that I need controller individual parameters.
Let me explain on that exact example.
Situation
Just now Dynamic Texture allows to setup a texture source:
The Python controller tells what code to run. This code needs the path to the image file as input. The advantage is that this code can be used on any object with different filenames. The parameter (as property) is object individual. This means several objects can have different parameter content.
So far so nice.
Today I was looking at ImageMix (Due to a question regarding transition between textures). Implementing ImageMix is not a big deal - it has no initial parameters.
ImageMix is fed with parameters after creation (the texture sources to mix in). I would like to use the existing methods to create the sources. Unfortunately I need a way map the input parameters to code. Here is an example to do that by name by adding a suffix (.1, .2):
This is possible, but really no good design. It is not clear what parameter belongs to what controller. It also requires a huge impact on the implementation of the already existing sources. The design feels not good.
What if we had an option to setup
Logic brick individual parameters
This means it is possible to setup parameters at the logic brick. The above example could be configured like that:This has several advantages:
- easy to see relationship between logic brick and parameter
- no need to remember the parameter name
- visible default values
- correct value type
- more options to enter values (e.g. by file dialog, property name, selector …)
- fully backward compatible
- works in module and script mode
There are drawbacks too:
- does not exist
- currently no build in method to configure GUI for Logic bricks
- describing the GUI is Blender API, the executed code is BGE -> different scripts
Implementation
At the moment I have just a vague idea how that could be implemented.
The BGE player needs to be enhanced to read and apply the custom parameters when loading the scene.
The BGE API needs to be enhanced to allow access to the custom parameters. Examples:
call with additional arguments (module mode only):
def setup(controller, image):
print( "image file name:", image)
Parameter in context (script and module mode):
via controller attribute
import bge
controller = bge.logic.getCurrentController()
imageFileName = controller.image
print( "image file name:", imageFileName )
via controller item
import bge
controller = bge.logic.getCurrentController()
imageFileName = controller["image"]
print( "image file name:", imageFileName )
Blender already provides options to describe GUI elements. It needs to be enhanced to use it at Logic bricks (python controller).
The Brick Setup and the BGE code needs to be kept separately. You can see BGE code as “just another parameter” - which it already is.
Configuring gui elements could look like that:
imageProperty = bpy.props.StringProperty(name="Image", subtype = 'FILE_PATH')
...
def draw_buttons(self, context, layout):
layout.prop(self, "purposeProperty")
This snippet is taken from setting up elements of the node editor. So why not follow the same road?
What do you think?
Can such a design work?