Shop Forum More Submit  Join Login
About Deviant Cary SemarMale/United States Group :iconthemoviesgroup: TheMoviesGroup
 
Recent Activity
Deviant for 3 Years
Needs Core Membership
Statistics 74 Deviations 147 Comments 1,916 Pageviews
×

Favourites

No Favourites yet.

Groups

Activity


Some of us have been kicking around the idea of using Graphical User Interfaces (GUI's) to help structure and improve the work flow (at least in part) of modifying content in the The Movies Game.  Recently, I decided to put some effort into studying the way GUI's can be implemented in Blender (2.49) using python.  This article describes my first attempt to put together a GUI to perform some basic tasks; it is not complete and will probably need to be redone in the future, but it is a work in progress and represents an opportunity to explore some of the capabilities and pitfalls of GUI's in Blender.

The script is called "tmg_gui.py" and you start it by opening the file in the text window and executing it as a python script.  The first screen shot shows the GUI running in an empty scene.

Ss Gui 01 by lefty2016
Figure 1:  The GUI is started in an empty scene.

The GUI script draws a bunch of buttons and labels in the python console window, then sits there waiting for something to happen, such as a mouse or keyboard event.  As you can see, there are currently 10 buttons.  The current blender directory is displayed as text above the buttons.  The first four buttons allow you to choose one of four predefined directories as the current blender directory.  The idea is to save some of the tedium of navigating around your hard drive in the File Selector looking for files.

The remaining buttons are there to perform a function by running some python code.  For example, if you press "Import Mesh" the GUI will run a script to import a movies game mesh file (MSH).  The script used here is virtually identical to msh_import_2009.py, but a few lines of code were changed to make it a module which can be imported into the GUI program.  With the current directory set as shown, if you press "Import Mesh" the file selector window will open in the Blender program directory and you would then have to navigate to the folder where your meshes are stored.  Instead, you can press one of the first two buttons under "Default Folders" to set the Blender directory to one of your default mesh folders.

I have the Game Meshes button pointing to "C:/TMBlender/data/meshes" which is where I keep a copy of all the mesh files extracted from the game.  The Modified Meshes button points to "C:/The Movies/data/meshes" which is where you place your modified meshes to make them available in the game.  Let's import Woody to simulate an action we might take in creating a mod.  First, press "Game Meshes."

Ss Gui 02 by lefty2016
Figure 2: Press Games Meshes sets the Current Directory to folder containing unmodified game meshes

Nothing much happens except the window now indicates the Current Directory is "C:/TMBlender/data/meshes."


Ss Gui 03 by lefty2016
Figure 3: Pressing Import Mesh causes the file selector to open in the current directory.

Let's just type in "woodenman.msh" and get on with it.

Ss Gui 04 by lefty2016
Figure 4: Select the MSH file to import just as you normally would


Ss Gui 05 by lefty2016
Figure 5: It worked!  So far so good.

Now let's try the TM Preflight test.

Ss Gui 06 by lefty2016
Figure 6: TM Preflight Test results displayed in the browser.

This is basically the standard tm_preflight.py script, slightly modified to be run as a module inside the GUI.

Ss Gui 07 by lefty2016
Figure 7: Pressing the "Game animations" button sets the working current blender directory to our animations folder.

Ss Gui 08 by lefty2016
Figure 8: Press "Import ANM" button and the file selector opens in the current directory.

We select the idle_male.anm file for import.

Ss Gui 09 by lefty2016
Figure 9: The idle male animation is imported.

What you have seen is no more than a crude prototype, a test module, intended to illustrate some of the possibilities for use of Blender GUI's for managing and modifying The Movies Game digital assets.  I don't plan to distribute this very early version but I would like to hear from potential users of such a tool and find out what ideas and suggestions they might have for future development.

Thank you for reading.

PS:
I am including a copy of the "gui_example.py" script which demonstrates basic functionality in Blender GUI's such as a toggle button or a text input capability.  This is the template I used in starting the development of the prototype described in this journal article.
#---------beginning of code
import Blender
from Blender import Draw, BGL

mystring = ""
mymsg = ""
toggle = 0

def event(evt, val):    # the function to handle input events
    global mystring, mymsg

    if not val:  # val = 0: it's a key/mbutton release
      if evt in [Draw.LEFTMOUSE, Draw.MIDDLEMOUSE, Draw.RIGHTMOUSE]:
        mymsg = "You released a mouse button."
        Draw.Redraw(1)
      return

    if evt == Draw.ESCKEY:
      Draw.Exit()                 # exit when user presses ESC
      return

    elif Draw.AKEY <= evt <= Draw.ZKEY: mystring += chr(evt)
    elif evt == Draw.SPACEKEY: mystring += ' '
    elif evt == Draw.BACKSPACEKEY and len(mystring):
      mystring = mystring[:-1]
    else: return # no need to redraw if nothing changed

    Draw.Redraw(1)

  def button_event(evt):  # the function to handle Draw Button events
    global mymsg, toggle
    if evt == 1:
      mymsg = "You pressed the toggle button."
      toggle = 1 - toggle
      Draw.Redraw(1)

def gui():              # the function to draw the screen
    global mystring, mymsg, toggle
    if len(mystring) > 90: mystring = ""
    BGL.glClearColor(0,0,1,1)
    BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
    BGL.glColor3f(1,1,1)
    Draw.Toggle("Toggle", 1, 10, 10, 55, 20, toggle,"A toggle button")
    BGL.glRasterPos2i(72, 16)
    if toggle: toggle_state = "down"
    else: toggle_state = "up"
    Draw.Text("The toggle button is %s." % toggle_state, "small")
    BGL.glRasterPos2i(10, 230)
    Draw.Text("Type letters from a to z, ESC to leave.")
    BGL.glRasterPos2i(20, 200)
    Draw.Text(mystring)
    BGL.glColor3f(1,0.4,0.3)
    BGL.glRasterPos2i(340, 70)
    Draw.Text(mymsg, "tiny")

Draw.Register(gui, event, button_event)  # registering the 3 callbacks
#----------- end of code

Run the script in a text window so see what it does.
Squadron
Six Jn-4B (B for Beowulf),  the blue one is Lima 2016, my signature airplane.
Loading...
KateWilson by lefty2016

"Kate Wilson" is a Blender implementation of one of my "Starmaker" heads.  I used the the head import script from Sexymaria to import the mesh, but all that gives you is the mesh shape and armature; you need to reapply the materials and textures yourself.  The hair is a a separate mesh, which you have to import using the standard mesh import script.  You can find out the mesh for the hair by viewing the starmaker info file that comes with the head in a hex editor and you can look at the star.hd file in your hex editor to find out what texture is used for the face.

I deleted the "eyelids" mesh for the head; no one has figured out how to make that work as far as I know.  The first real problem was the eyebrows because the basic face texture had none.  I found the eyebrows textures in the data/textures/makeup folder, but the starmaker files did not have any reference to a makeup texture, as far as I could see.  The makeup is probably an integer entry in the starmaker file, but the format of the file is not completely been decoded.  However, there is a slider on the "facial features" page that selects the facial hair and eyebrows.  The first position appears to be "no eyebrows" but slider was set for the second slot when I checked it, so that is probably the first of the eyebrows makeup textures, which is named "mup_feyebrow_v00.dds." 

One way to apply the eyebrows in blender is to use texture stacking in which you add an additional texture layer to your material.  The "mup" texture is transparent except where the facial hair goes, so if you apply it over the face texture, you get nice eyebrows.  I tried that and it works fine, but I decided it was easier to just create a texture externally that already had the facial hair applied.  You can do that in "paint.net" rather simply.  The face and mup textures are exactly the same size, so if you open the face texture in paint.net, you can import the mup texture as a second layer.  You then merge the layers and save the result as a single layered texture with the eyebrows applied and use that in blender to texture the face.

The UVW map for the eyes was edited to change the eye color from the default brown to blue.

Finally, I added some lamps to erase unwanted shadows, set up the rotation and exported the animation using AVI CodeC option in the render window.  I used the free version of Camtasia to convert the AVI file into a GIF. 

Good fun for a leisurely Sunday.
When creating an animation in Blender, it is convenient to parent a prop such
as a gun or sword to the hand bone so the prop will automatically move as the pose of
the figure changes.  The Movies Game, however, does not do things that way.  The animation
of the armature and the animation of the carriable prop are separate blocks of data treated
independently and called Bone Animations and Static Animations respectively.  In order to
export your animation from Blender to The Movies game, you must convert your completed
animation to the same structure.

This can be done using a python script I found in the Blender2.4 manual and adapted for this purpose.

A detailed description of the method is available at lefty2000 (The Movies Game)

Click on the link and read the article "Converting a Bone Animation to a Prop Animation."

Acknowledgement:
Thanks to TheMoviesGame and Beowulf71 for their valuable contributions to this development.
Apparently good lighting is crucial to get nice scene renders in Blender.  What I would like to be able to do is produce renders in Blender that are similar to the results you get in The Movies.  This would allow one to mix media between The Movies and Blender without it being too obvious.  One trick that I stumbled on uses the "emit" adjustment for blender materials.  The following images show a similar scene rendered in two ways:  One with the materials for the main figures set to Emit=0 and, using the same lighting, adjusting to Emit in the range .4-.5 for each of the materials in the figures.


Horse Walk.00 by lefty2016
Emit = 0.
The lighting scheme is really simple: there is a single spot light to give a nice solid ground shadow.  The ambient light parameter (Amb) was cranked up to around .5 for each of the materials in the figures, but it seems to have no effect that I can see.  Maybe something else is not set.





Horse Walk by lefty2016

Emit ~ .4 to .5
The other light settings are unchanged, but just cranking up the Emit parameter on each material brightens up the figures and softens the shadows.  No single setting worked best for all materials; the setting varies a little for each material.

This scene was created by importing the movies animation wes_horse_rider_walk.anm using importanm(5.1).py.  This is one of those animation files that imports very easily; it includes an animation for the human actor and the horse prop.  I used the append setting in the ID property browser and imported enough copies to yield about 5 seconds of video at 25 frames per second.  One tricky problem is that the actor costume must be loaded first,followed by the horse prop.  The script processes the armatures in the order they are stored in blender data.  If you import the horse first, the script will try to apply the animation data to the wrong armature.  I need to fix this someday.

The animation produces a "walk in place" but if you look in the ID property browser and look at the "destination" location, it will tell you how far the container empties need to move for each cycle to produce a nice walk with no foot slipping.

I made three clips at different ranges and spliced them together to make a 40 second video of the rider walking her horse through the forest.  The forest texture is from the game; I attached it to a plane for a backdrop.  The texture for the ground plane is also from the game, it is one of the standard grass textures.

The Video

The video was edited together in Camtasia.  I borrowed the forest ambience sound from the game and added a soft Gaelic themed mp3 I had on my hard drive.
Some of us have been kicking around the idea of using Graphical User Interfaces (GUI's) to help structure and improve the work flow (at least in part) of modifying content in the The Movies Game.  Recently, I decided to put some effort into studying the way GUI's can be implemented in Blender (2.49) using python.  This article describes my first attempt to put together a GUI to perform some basic tasks; it is not complete and will probably need to be redone in the future, but it is a work in progress and represents an opportunity to explore some of the capabilities and pitfalls of GUI's in Blender.

The script is called "tmg_gui.py" and you start it by opening the file in the text window and executing it as a python script.  The first screen shot shows the GUI running in an empty scene.

Ss Gui 01 by lefty2016
Figure 1:  The GUI is started in an empty scene.

The GUI script draws a bunch of buttons and labels in the python console window, then sits there waiting for something to happen, such as a mouse or keyboard event.  As you can see, there are currently 10 buttons.  The current blender directory is displayed as text above the buttons.  The first four buttons allow you to choose one of four predefined directories as the current blender directory.  The idea is to save some of the tedium of navigating around your hard drive in the File Selector looking for files.

The remaining buttons are there to perform a function by running some python code.  For example, if you press "Import Mesh" the GUI will run a script to import a movies game mesh file (MSH).  The script used here is virtually identical to msh_import_2009.py, but a few lines of code were changed to make it a module which can be imported into the GUI program.  With the current directory set as shown, if you press "Import Mesh" the file selector window will open in the Blender program directory and you would then have to navigate to the folder where your meshes are stored.  Instead, you can press one of the first two buttons under "Default Folders" to set the Blender directory to one of your default mesh folders.

I have the Game Meshes button pointing to "C:/TMBlender/data/meshes" which is where I keep a copy of all the mesh files extracted from the game.  The Modified Meshes button points to "C:/The Movies/data/meshes" which is where you place your modified meshes to make them available in the game.  Let's import Woody to simulate an action we might take in creating a mod.  First, press "Game Meshes."

Ss Gui 02 by lefty2016
Figure 2: Press Games Meshes sets the Current Directory to folder containing unmodified game meshes

Nothing much happens except the window now indicates the Current Directory is "C:/TMBlender/data/meshes."


Ss Gui 03 by lefty2016
Figure 3: Pressing Import Mesh causes the file selector to open in the current directory.

Let's just type in "woodenman.msh" and get on with it.

Ss Gui 04 by lefty2016
Figure 4: Select the MSH file to import just as you normally would


Ss Gui 05 by lefty2016
Figure 5: It worked!  So far so good.

Now let's try the TM Preflight test.

Ss Gui 06 by lefty2016
Figure 6: TM Preflight Test results displayed in the browser.

This is basically the standard tm_preflight.py script, slightly modified to be run as a module inside the GUI.

Ss Gui 07 by lefty2016
Figure 7: Pressing the "Game animations" button sets the working current blender directory to our animations folder.

Ss Gui 08 by lefty2016
Figure 8: Press "Import ANM" button and the file selector opens in the current directory.

We select the idle_male.anm file for import.

Ss Gui 09 by lefty2016
Figure 9: The idle male animation is imported.

What you have seen is no more than a crude prototype, a test module, intended to illustrate some of the possibilities for use of Blender GUI's for managing and modifying The Movies Game digital assets.  I don't plan to distribute this very early version but I would like to hear from potential users of such a tool and find out what ideas and suggestions they might have for future development.

Thank you for reading.

PS:
I am including a copy of the "gui_example.py" script which demonstrates basic functionality in Blender GUI's such as a toggle button or a text input capability.  This is the template I used in starting the development of the prototype described in this journal article.
#---------beginning of code
import Blender
from Blender import Draw, BGL

mystring = ""
mymsg = ""
toggle = 0

def event(evt, val):    # the function to handle input events
    global mystring, mymsg

    if not val:  # val = 0: it's a key/mbutton release
      if evt in [Draw.LEFTMOUSE, Draw.MIDDLEMOUSE, Draw.RIGHTMOUSE]:
        mymsg = "You released a mouse button."
        Draw.Redraw(1)
      return

    if evt == Draw.ESCKEY:
      Draw.Exit()                 # exit when user presses ESC
      return

    elif Draw.AKEY <= evt <= Draw.ZKEY: mystring += chr(evt)
    elif evt == Draw.SPACEKEY: mystring += ' '
    elif evt == Draw.BACKSPACEKEY and len(mystring):
      mystring = mystring[:-1]
    else: return # no need to redraw if nothing changed

    Draw.Redraw(1)

  def button_event(evt):  # the function to handle Draw Button events
    global mymsg, toggle
    if evt == 1:
      mymsg = "You pressed the toggle button."
      toggle = 1 - toggle
      Draw.Redraw(1)

def gui():              # the function to draw the screen
    global mystring, mymsg, toggle
    if len(mystring) > 90: mystring = ""
    BGL.glClearColor(0,0,1,1)
    BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
    BGL.glColor3f(1,1,1)
    Draw.Toggle("Toggle", 1, 10, 10, 55, 20, toggle,"A toggle button")
    BGL.glRasterPos2i(72, 16)
    if toggle: toggle_state = "down"
    else: toggle_state = "up"
    Draw.Text("The toggle button is %s." % toggle_state, "small")
    BGL.glRasterPos2i(10, 230)
    Draw.Text("Type letters from a to z, ESC to leave.")
    BGL.glRasterPos2i(20, 200)
    Draw.Text(mystring)
    BGL.glColor3f(1,0.4,0.3)
    BGL.glRasterPos2i(340, 70)
    Draw.Text(mymsg, "tiny")

Draw.Register(gui, event, button_event)  # registering the 3 callbacks
#----------- end of code

Run the script in a text window so see what it does.

deviantID

lefty2016's Profile Picture
lefty2016
Cary Semar
United States
Interests

Comments


Add a Comment:
 
:iconbeowulf71:
Beowulf71 Featured By Owner May 7, 2016  Hobbyist
Welcome to the group!
Reply