Please separate user interface code from the data handling c

Tech support and suggestions forum. If you only have a basic question on how to get started, please use the "newbies" forum in the community section.

Moderator: joepal

Re: Please separate user interface code from the data handling c

Postby Zurbarah » Thu Sep 03, 2009 2:06 pm

Manuel wrote:...we should write an official script that correctly imports the full MH character, including an automatically generated skeleton and linked in the blender scene, with precalculated weights (and even with facial rigging). This is a very important feature, a lot of users are waiting for it...

Bingo! IMHO, this is #1 task. ;)
Zurbarah
 
Posts: 2
Joined: Wed Apr 29, 2009 2:43 pm

What I am trying to do

Postby m.e » Thu Sep 03, 2009 2:18 pm

Manuel, good question. My interest here is in animation. If I just want to do a single frame (a still picture) then I can pose the figure in MH and then import it into Blender. That was possible in the old MH, and there were several tutorials out there on how to do it.

For animation there was the option of using the Blender animation system, namely armatures for overall posing and shape keys. Using what MH provided and some work, it was possible to set up an armature. There were tutorials available, and I wrote a script once to automate much of the process. MH however did not provide any basis for expressions (shape keys). Also Blender's armature system is not as good as MH's pose system (the MH pose system knows about human anatomy, blender's armatures are just a general purpose system that can be used for anything).

So what I want to do is to be able to animate using the MH pose and expression systems. The figure's pose and expression will generally change from frame to frame so it is necessary to recalculate the mesh for each frame. So there are several options for this:

  • pose each frame in MH and export separately to Blender (very slow)
  • use the MH animation system and export the animated figure to Blender (not sure when MH animation will be available, and difficult to coordinate MH figures with Blender objects)
  • just use MH animation for everything (lose Blender altogether)
  • work out some way of integrating MH and Blender (getting MH to recalculate the Blender mesh for each frame, based somehow on data sent from Blender)

To integrate MH with Blender I could
  • work out some way of running MH and Blender simultaneously (in different address spaces) and exchanging data between (rather like Microsoft's OLE), or
  • make parts of MH callable from Blender

The first of those would I suspect -- I could be wrong -- require major changes to both Blender and MH, and a lot of deep knowledge of both programs (and a lot of work and major political skills). I am trying for the second of those options.

So there are counter arguments and alternatives, but I think what I am trying to do is the simplest way of getting there. I'm not sure that it is part of the MH's team's vision for the system (indeed, I am rather sure it is not), and realistically it is a hack, but really I am trying to demonstrate feasibility of an approach. I am expecting that others will come along and develop a better approach later on.
m.e
 
Posts: 56
Joined: Wed Jul 23, 2008 9:20 am
Location: Shenzhen/Hong Kong

Re: Please separate user interface code from the data handling c

Postby Manuel » Thu Sep 03, 2009 9:57 pm

Make parts of MH callable from Blender is interesting, but I'm not sure it's the best solution for animation.
The sequence will be completely separated from Blender keyframes editor, and it will need the full MH data library to run.
It will be difficult, for example, to integrate a MH animation in a existent Blender scene. Besides, users will forced to use 2 interfaces to handle one animation: MH one and Blender one.

In my opinion, we should think about a more general solution.
In example, we can code an exporter that write a special Blender exchange file format, that store all info about human and animation. This format can store each keyframe morph (yes, it will be not so small). Then we can code a Blender importer that read the file above, and make a Blender vertex animation key for each frame. So, at the end, the blend file will store all info about animation, without need extra knowledge (MH) and without need extra packages: all will be perfectly integrated in Blender using the IPO curve and the absolute vertex key mechanism. The animation can be shared with other Blender users, and they can even improve and refine the verts key (later we can write an importer Blender->MH).

How it sound?

Regards,

Manuel

PS:: In any case, we will need an exporter that write an accurately rigged character, as requested by many Blender users.
Manuel
 

To export a figure that can be given poses and expressions

Postby m.e » Fri Sep 04, 2009 3:52 am

I don't want to export an animation; I want to export a figure that can be given poses and expressions. The actual animation would be done in Blender. MH will have the pose and expression code (several releases in the future). MH 0.9 for example had a muscle model, and there was the LOOXIS code (as far as I know this never made it into production). Presumably this will all reappear in MH 1.0. I want to be able to access all this from Blender.

I see the workflow as:
  • use MH standalone to model a figure (gender, ethnicity, details), save to file;
  • use Blender to import and animate the figure (poses and expressions).

For the animation side I had envisaged using Blender's GUI (and keyframing) not MH's. For each frame, Blender would
  • pull the values from an IPO [called Actions in Blender 2.5],
  • call routines like human.setMuscle() [or rather the pose/expression equivalent] to poke the values into MH for each frame,
  • call human.applyAllTargets() [I suppose] to calculate the new mesh values, and then
  • pull the mesh vertex locations back into Blender,
To create the animation, there would be a GUI in Blender with lots of sliders (not the MH API) that would keyframe the values into the IPO/Action.

It may be best to wait until MH has poses; then I could code up what I mean and show you; that would be clearer than just talking about it.

My focus though is on the result. If there is another way to achieve this, I am quite happy to go with it.
m.e
 
Posts: 56
Joined: Wed Jul 23, 2008 9:20 am
Location: Shenzhen/Hong Kong

Experiment

Postby m.e » Sat Sep 05, 2009 5:23 pm

I have now done a bit of an experiment, and put the result on my site at http://thereisnoend.org/Animation/Experiments/mh1.html (maybe I could post it here but this will save your bandwidth). This is a Flash video of an animation generated by a script.

What my new script does is push a Blender-generated value into MH and then update the mesh based on the results. I am using age but only because poses are not yet available in MH; when poses are available I can change this to make the figure move its arms or something instead.

Also I am not using Blender's IPOs or any blender user interface to generate the values (that are pushed into MH) but that is easy to change.

At the end I have put most of the new code, if you want the details. I have not posted the rest which is almost the same as the code that I previously posted. Half of the new code sets up what Blnder calls a 'script link' that is called when the frame is changed, ie for each frame of the animation. The rest of the code is the script that gets called, and as can be seen it
  • calculates an age value
  • pushes the age to MH using setAge
  • recalculates the mesh using applyAllTargets
  • pulls the new mesh coordinates back into blender

In conclusion,
  • As can be seen from the video, this all does work.
  • I make no claims for the visual quality (I am a programmer not an artist).
  • If anyone can think of a better way to achieve the same result, please let the forum know.

Code: Select all
# code derived from the Camera Changer script (http://cybercreator.free.fr)
scriptName = 'animate.py'
scriptText = '''import Blender
import module3d
import human
import sys
def main():
   scn = Blender.Scene.GetCurrent()
   frame = Blender.Get('curframe')
   startFrame = scn.render.startFrame()
   endFrame = scn.render.endFrame()
   age =  (frame - startFrame) * 1.0 / (endFrame - startFrame)
   ageInYears = age * 58 + 12
   print 'starting frame %d age %d...'%(frame, ageInYears)
 #   mhScene = module3d.Scene3D()
   humanData = Blender.theHuman
   if humanData == None: print 'no human data found'
   meshData = humanData.meshData
   humanData.setAge(age)
   print 'applying targets...'
   humanData.applyAllTargets()   
   for obj in scn.objects:
      if obj.name[:9] == 'MakeHuman':
         blenderMesh = Blender.Mesh.Get(obj.getData(1))
         print 'using %s...'%(obj.name)
   blenderVerts = blenderMesh.verts
   print 'pulling vert locations...'
   for v in meshData.verts:
      for i in range(3):
         blenderMesh.verts[v.idx].co[i] = v.co[i]
   print 'updating mesh...'
   blenderMesh.update()   
   print 'updating text...'
   ageText = Blender.Text3d.Get('AgeInfo')
   if ageText == None: print 'no age text'
   ageText.setText('Age %d'%(ageInYears))
   Blender.Object.Get('AgeInfo').makeDisplayList()
   print 'frame %d done.'%(frame)
main()
'''
try:   
   animate_text = Blender.Text.Get(scriptName)
   if animate_text:
      animate_text = None   
except:   animate_text = None

scripting=Blender.Text.New(scriptName)
scripting.write(scriptText)
scriptlinks = scene.getScriptLinks('FrameChanged')
if not scriptlinks or (scriptName not in scriptlinks):
   scene.addScriptLink(scriptName,'FrameChanged')
   Blender.Window.RedrawAll()

print 'all done'    
m.e
 
Posts: 56
Joined: Wed Jul 23, 2008 9:20 am
Location: Shenzhen/Hong Kong

Previous

Return to Bugs, problems and feature requests

Who is online

Users browsing this forum: No registered users and 1 guest

cron