Sending user defined texture to the Burster

It is common practice to allow users to set various information via web-form and send it to another component. It is possible with Burster plugin too.



Get the user data

You can gather data from user using web form, for example you can allow the user to specify a texture of your game object. To do this just use standard form to get the texture file:

<form enctype="multipart/form-data" action="uploader.php" method="POST">
Upload your own texture: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />

The uploader.php file moves uploaded file to the server, to the directory available to the Burster plugin.

$sid = session_id();

$target_path = "uploads/$sid.jpg";

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
} else{
 die("There was an error uploading the file, please try again!");

header("location: blends/test.php");

The code firstly gets the session id - this identifier is latter used as a filename. The possibility that the session identifier is very low, so users have low chances to overwrite their files. After the file was moved to the directory accessible by Burster, the browser is redirected to the site with blend file embeded (see: embeding blends article).

Receiving data in blend

The most important thing is receiving the data in blend file. Before the Burster player will start you need to create valid parameters list - the example test.php file is listed below:


 $sid = session_id();

 echo "
 <body style=\"background: #000\">    <OBJECT classid=\"CLSID:8318DE8B-B213-426b-B1B6-0A2589859898\"
 <PARAM name=\"type\" value=\"application/x-burster\"/> 
 <PARAM name=\"src\" value=\"test.blend\"/> 
 <strong><PARAM name=\"session\" value=\"$sid\"/> </strong>
 <embed type=\"application/x-burster\"

The additional parameter - session - is filed with user session identifier. As you remember from previous section, this parameter was used to create the file name that your blend should use. The rest of code is standard embeding code.

Now, in blend file i added to the logic bricks element that runs folowing Python code:
obj = GameLogic.getCurrentController().owner
 # Check if the texture was set

 print "----- Loading and setting the user defined testure  ----"

 import sys
 session = None
 # sys.argv contains all parameters passed to the Burster player.
 # parameters are passed as "name=value" - so you need to 
# find the '=' sign and read the parameter name and value.
 # After standard parameters passed to the plugin the '-' sign is passed. 
#This sign marks that following parameters are custom parameters.

 for arg in sys.argv:
 if session=="read":
 param = arg
 eqs = param.find("=")
 name = param[0:eqs]
 value = param[eqs+1:]
 if name=="session":
 session = value
 print name, value
 if arg=="-":
 session = "read"    

 print session        
 import VideoTexture        

 matID = VideoTexture.materialID(obj, "MAdisplayer")

 texture = VideoTexture.Texture(obj, matID, 0)

 fname = ""+str(session)+".jpg"
 print "Fname: ", fname
 texture.source = VideoTexture.ImageFFmpeg(fname)


 obj["Texture"] = texture

The script firstly checks if it is executed first time (the obj["Texture"] property is set to the user texture). Then the script finds parameter named "session". The value of the session parameter is the file name of the texture. After that, the script reads the texture from url and sets it to the object in scene.

You can download the source blend file here.

Following link shows how it works in practice.



0 #2 Przemysław Króliszewski 2010-11-15 14:38
The Game Actuator allows to save and load GameLogic.globalDict

So you can set the game state into GameLogic object using python: GameLogic.someVariable = value.

Then you could load the GameLogic.globalDict and all variables you have stored will be reloaded.

For whole blender files this will be possibly harder to do. I don't know if there is "save blend" function in game api...
0 #1 chris 2010-11-11 04:37
is it possible to do this with whole models as well? having a placeholder blender file- then using a "save file" or form to populate the blender file... then at the end of the game a "save" function notes the position and state of the current blend...