Thomas Larsson's blender 2.5 importer

MakeHuman python API, python plugins, etc

Moderator: joepal

Thomas Larsson's blender 2.5 importer

Postby m.e » Tue Feb 23, 2010 4:56 am

Thomas Larsson's blender importer does not at present use the 2.5 interface; I'll try to update the code over the next few days and post the result here, if that would be felt useful. For technical reasons I can't post to the blog, so someone might want to post a link to this thread on the blog.
m.e
 
Posts: 56
Joined: Wed Jul 23, 2008 9:20 am
Location: Shenzhen/Hong Kong

Re: Thomas Larsson's blender 2.5 importer

Postby m.e » Tue Feb 23, 2010 12:46 pm

OK, I have had a look at the code. The script has some user interface code in it but it is commented out. I uncommented some of the code and loaded it into Blender and it worked (or at least did as far as I can see the same as the original script, but prompting the user for a file name). I have added the patch at the end of the post, but it just restores some of Thomas' code.

He did write in his post,
I have tried to make a user interface, but it currently messes up the code
but I cannot see the problem; perhaps you could explain a bit more, Thomas?

Code: Select all
diff --git a/blender/python/import_scene_mhx.py b/blender/python/import_scene_mhx.py
index 92caca9..36f514d 100644
--- a/blender/python/import_scene_mhx.py
+++ b/blender/python/import_scene_mhx.py
@@ -1483,10 +1483,11 @@ def clearScene():
 #

 #   User interface

 #

-"""
+
 DEBUG= False

 from bpy.props import *

 

+"""
 def check(flag):

    global toggle

    if toggle & flag:

@@ -1657,7 +1658,7 @@ bpy.types.register(OBJECT_OT_mhx_import)
 bpy.types.register(IMPORT_PT_makehuman_mhx)

 """

 

-"""

+
 class IMPORT_OT_makehuman_mhx(bpy.types.Operator):

    '''Import from MHX file format (.mhx)'''

    bl_idname = "import_scene.makehuman_mhx"

@@ -1690,12 +1691,12 @@ class IMPORT_OT_makehuman_mhx(bpy.types.Operator):
 bpy.types.register(IMPORT_OT_makehuman_mhx)

 menu_func = lambda self, context: self.layout.operator(IMPORT_OT_makehuman_mhx.bl_idname, text="MakeHuman (.mhx)...")

 bpy.types.INFO_MT_file_import.append(menu_func)

-"""

+
 #

 #   Testing

 #
-toggle = T_Replace + T_ArmIK + T_LegIK + T_Face

-readMhxFile("/home/thomas/makehuman/exports/foo-classic-25.mhx")

+#toggle = T_Replace + T_ArmIK + T_LegIK + T_Face
+#readMhxFile("/home/thomas/makehuman/exports/foo-classic-25.mhx")
 #readMhxFile("C:/Documents and Settings/xxxxxxxxxxxxxxxxxxxx/Mina dokument/makehuman/exports/foo-classic-25.mhx")

 #readMhxFile("/home/thomas/mhx5/test1.mhx")

 #readMhxFile("/home/thomas/myblends/mhx4/test1.mhx")
m.e
 
Posts: 56
Joined: Wed Jul 23, 2008 9:20 am
Location: Shenzhen/Hong Kong

Re: Thomas Larsson's blender 2.5 importer

Postby ThomasL » Wed Feb 24, 2010 12:30 pm

I got an error message that I was trying to do something in the wrong context - the script was trying to define shape keys, if I remember correctly. When I executed the same code without a user interface, there were no problems. That is why I disabled the interface.

Generally I find context and operators in the new Blender API very confusing. I try to avoid them as far as possible, but some functionality only seems accessible through operators, at least at this time. If it works for you, it is either because you don't try to do the same thing (are you loading shape keys?), or because the Blender devs have fixed some bug.
ThomasL
 
Posts: 1139
Joined: Tue Sep 15, 2009 2:46 am

Re: Thomas Larsson's blender 2.5 importer

Postby m.e » Wed Feb 24, 2010 3:51 pm

Thomas,

I have just rerun the importer (as patched) with all the options ticked. I am not getting any context messages. I have copied the console trace at the end; some of the messages (eg "error: this CustomDataLayer...") are Blender alpha issues. I am getting much the same results as when I run the original importer (as found in the MH svn), except there is a user interface now. Note that I haven't enabled all your commented-out code, just enough to run readMhxFile.

I am running this with the new Blender 2.5 alpha 1 as released a few days ago on Linux 2.6.31.12-174.2.22.fc12.i686.PAE #1 SMP ... i686 i686 i386 GNU/Linux. The MH code was from svn a few days ago.

Regards,
Martin

error: this CustomDataLayer must not be written to file
error: this CustomDataLayer must not be written to file
error: this CustomDataLayer must not be written to file
error: this CustomDataLayer must not be written to file
error: this CustomDataLayer must not be written to file
error: this CustomDataLayer must not be written to file
error: this CustomDataLayer must not be written to file
RNA_string_set: IMPORT_SCENE_OT_makehuman_mhx.filename not found.
RNA_string_set: IMPORT_SCENE_OT_makehuman_mhx.directory not found.
Opening MHX file /home/martin/makehuman/exports/test-2010-0219-classic-25.mhx
Tokenizing
clearScene 32 <bpy_struct, Scene("Scene")>
Parsing
Parse Armature
Armature <bpy_struct, Armature("HumanRig.001")> <bpy_struct, Object("HumanRig")>
error: this CustomDataLayer must not be written to file
error: this CustomDataLayer must not be written to file
<bpy_struct, Armature("HumanRig.001")>
Parse Pose
<bpy_struct, Object("HumanRig")>
Parse Object
Found data
Parse Mesh
Mesh <bpy_struct, Mesh("Human.001")> <bpy_struct, Object("Human")>
Could not add material SSS_skinshader
Could not add material Invisio
Could not add material Hair
<bpy_struct, Mesh("Human.001")>
Parse Object
Found data
MOD Armature ARMATURE
MOD2 <bpy_struct, ArmatureModifier("Armature")>
<bpy_struct, Object("Human")> <bpy_struct, Object("Human")>
<bpy_collection[0], Object.particle_systems> []
error: this CustomDataLayer must not be written to file
<bpy_collection[1], Object.particle_systems> [<bpy_struct, ParticleSystem("ParticleSystem")>]
Psys <bpy_struct, ParticleSystem("ParticleSystem")>
Old structrna psys.settings <bpy_struct, ParticleSettings("ParticleSettings.001")>
Old structrna data.effector_weights <bpy_struct, EffectorWeights>
Struct done data.effector_weights
Struct done psys.settings
error: this CustomDataLayer must not be written to file
Parse Mesh
Mesh <bpy_struct, Mesh("MHBall.001")> <bpy_struct, Object("MHBall")>
<bpy_struct, Mesh("MHBall.001")>
Parse Object
Found data
Parse Mesh
Mesh <bpy_struct, Mesh("MHCircle03.001")> <bpy_struct, Object("MHCircle03")>
<bpy_struct, Mesh("MHCircle03.001")>
Parse Object
Found data
Parse Mesh
Mesh <bpy_struct, Mesh("MHCircle05.001")> <bpy_struct, Object("MHCircle05")>
<bpy_struct, Mesh("MHCircle05.001")>
Parse Object
Found data
Parse Mesh
Mesh <bpy_struct, Mesh("MHCircle10.001")> <bpy_struct, Object("MHCircle10")>
<bpy_struct, Mesh("MHCircle10.001")>
Parse Object
Found data
Parse Mesh
Mesh <bpy_struct, Mesh("MHCircle15.001")> <bpy_struct, Object("MHCircle15")>
<bpy_struct, Mesh("MHCircle15.001")>
Parse Object
Found data
Parse Mesh
Mesh <bpy_struct, Mesh("MHFace.001")> <bpy_struct, Object("MHFace")>
<bpy_struct, Mesh("MHFace.001")>
Parse Object
Found data
Failed: ob.active_material = loadedData['Material']['Hair']
Failed: ob.active_material = loadedData['Material']['Hair']
setinfl UpArm_L
setinfl LoArm_L
setinfl Hand_L
setinfl UpArm_R
setinfl LoArm_R
setinfl Hand_R
setinfl UpLeg_L
setinfl LoLeg_L
setinfl Foot_L
setinfl Toe_L
setinfl UpLeg_R
setinfl LoLeg_R
setinfl Foot_R
setinfl Toe_R
File /home/martin/makehuman/exports/test-2010-0219-classic-25.mhx loaded in 28.48 s but there where 2 errors.
m.e
 
Posts: 56
Joined: Wed Jul 23, 2008 9:20 am
Location: Shenzhen/Hong Kong

Re: Thomas Larsson's blender 2.5 importer

Postby m.e » Thu Feb 25, 2010 3:49 am

Here is an updated version of the patch. This version might actually pass the options that the user selects through to the main importer code. It also deletes some code that is not actually needed.

I'm not sure what "rigify" does (rig the model?) so maybe it should not appear as an option.

I'm still having some problems with the resulting rig (eg I cannot see the bones) but that seems to be an unrelated problem. We can deal with that later.

Code: Select all
diff --git a/blender/python/import_scene_mhx.py b/blender/python/import_scene_mhx.py
index 92caca9..1451a08 100644
--- a/blender/python/import_scene_mhx.py
+++ b/blender/python/import_scene_mhx.py
@@ -70,7 +70,7 @@ toggle = T_Replace + T_ArmIK + T_LegIK
 

 useMesh = 1

 doSmash = 1

-verbosity = 2

+verbosity = 3
 warnedTextureDir = False

 warnedVersion = False

 

@@ -158,16 +158,6 @@ def vertcolCreator(me, name):
 

 
 #

-#   loadMhx(filePath, context, flags):

-#

-

-def loadMhx(filePath, context, flags):

-   global toggle

-   toggle = flags

-   readMhxFile(filePath)

-   return

-

-#

 #   readMhxFile(filePath):

 #

 

@@ -1483,181 +1473,10 @@ def clearScene():
 #

 #   User interface

 #

-"""
+
 DEBUG= False

 from bpy.props import *

 

-def check(flag):

-   global toggle

-   if toggle & flag:

-      return "CHECKBOX_HLT"

-   else:

-      return "CHECKBOX_DEHLT"

-

-class IMPORT_PT_makehuman_mhx(bpy.types.Panel):

-   bl_label = "Import MHX"

-   bl_space_type = "PROPERTIES"

-   bl_region_type = "WINDOW"

-   bl_context = "scene"

-

-   def draw(self, context):

-      row = self.layout.row()

-      col = []

-      split = row.split(percentage = 1.0/3)

-      col.append(split.column())

-      col[0].operator("mhxArmIK", icon=check(T_ArmIK))

-      col.append(split.column())

-      col[1].operator("mhxLegIK", icon=check(T_LegIK))

-      col.append(split.column())

-      col[2].operator("mhxFingerIK", icon=check(T_FingerIK))

-

-      row = self.layout.row()

-      col = []

-      split = row.split(percentage = 1.0/3)

-      col.append(split.column())

-      col[0].operator("mhxFKIK", icon=check(T_FKIK))

-      col.append(split.column())

-      col[1].operator("mhxDispObs", icon=check(T_DispObs))

-      col.append(split.column())

-      col[2].operator("mhxReplace", icon=check(T_Replace))

-

-      row = self.layout.row()

-      col = []

-      split = row.split(percentage = 1.0/3)

-      col.append(split.column())

-      col[0].operator("mhxShapes", icon=check(T_Face))

-      col.append(split.column())

-      col[1].operator("mhxRot90", icon=check(T_Rot90))

-      col.append(split.column())

-      col[2].operator("mhxTexDir")

-

-      row = self.layout.row()

-      row.operator("mhxImport")

-

-      return

-

-class OBJECT_OT_mhx_arm_ik(bpy.types.Operator):

-   bl_label = "Arm IK"

-   bl_idname = "mhxArmIK"

-   bl_description = "Arm IK"

-

-   def invoke(self, context, event):

-      global toggle

-      toggle ^= T_ArmIK

-      return{'FINISHED'}

-

-class OBJECT_OT_mhx_leg_ik(bpy.types.Operator):

-   bl_label = "Leg IK"

-   bl_idname = "mhxLegIK"

-   bl_description = "Leg IK"

-

-   def invoke(self, context, event):

-      global toggle

-      toggle ^= T_LegIK

-      return{'FINISHED'}

-

-class OBJECT_OT_mhx_finger_ik(bpy.types.Operator):

-   bl_label = "Finger IK"

-   bl_idname = "mhxFingerIK"

-   bl_description = "Finger IK"

-

-   def invoke(self, context, event):

-      global toggle

-      toggle ^= T_FingerIK

-      return{'FINISHED'}

-

-class OBJECT_OT_mhx_fkik(bpy.types.Operator):

-   bl_label = "FK/IK"

-   bl_idname = "mhxFKIK"

-   bl_description = "FK/IK switch"

-

-   def invoke(self, context, event):

-      global toggle

-      toggle ^= T_FKIK

-      return{'FINISHED'}

-

-class OBJECT_OT_mhx_dispobs(bpy.types.Operator):

-   bl_label = "Dispobs"

-   bl_idname = "mhxDispObs"

-   bl_description = "Display objects"

-

-   def invoke(self, context, event):

-      global toggle

-      toggle ^= T_DispObs

-      return{'FINISHED'}

-

-class OBJECT_OT_mhx_replace(bpy.types.Operator):

-   bl_label = "Replace scene"

-   bl_idname = "mhxReplace"

-   bl_description = "Replace scene"

-

-   def invoke(self, context, event):

-      global toggle

-      toggle ^= T_Replace

-      return{'FINISHED'}

-

-

-class OBJECT_OT_mhx_shapes(bpy.types.Operator):

-   bl_label = "Shapes"

-   bl_idname = "mhxShapes"

-   bl_description = "Shape keys"

-

-   def invoke(self, context, event):

-      global toggle

-      toggle ^= T_Face

-      return{'FINISHED'}

-

-class OBJECT_OT_mhx_rot90(bpy.types.Operator):

-   bl_label = "Rot 90"

-   bl_idname = "mhxRot90"

-   bl_description = "Rotate 90 degrees (Y up)"

-

-   def invoke(self, context, event):

-      global toggle

-      toggle ^= T_Rot90

-      return{'FINISHED'}

-

-class OBJECT_OT_mhx_texdir(bpy.types.Operator):

-   bl_label = "Tex dir"

-   bl_idname = "mhxTexDir"

-   bl_description = "Choose texture directory"

-

-   def invoke(self, context, event):

-      return{'FINISHED'}

-

-class OBJECT_OT_mhx_import(bpy.types.Operator):

-   bl_label = "Import MHX file"

-   bl_idname = "mhxImport"

-   bl_description = "Import MHX file"

-   bl_space_type = "PROPERTIES"

-   bl_region_type = "WINDOW"

-

-   path = StringProperty(name="File Path", description="File path used for importing the MHX file", maxlen= 1024, default= "")

-

-   def execute(self, context):

-      readMhxFile(self.properties.path)

-      return {'FINISHED'}

-

-   def invoke(self, context, event):

-      wm = context.manager

-      wm.add_fileselect(self)

-      return {'RUNNING_MODAL'}

-

-

-bpy.types.register(OBJECT_OT_mhx_arm_ik)

-bpy.types.register(OBJECT_OT_mhx_leg_ik)

-bpy.types.register(OBJECT_OT_mhx_finger_ik)

-bpy.types.register(OBJECT_OT_mhx_fkik)

-bpy.types.register(OBJECT_OT_mhx_dispobs)

-bpy.types.register(OBJECT_OT_mhx_replace)

-bpy.types.register(OBJECT_OT_mhx_shapes)

-bpy.types.register(OBJECT_OT_mhx_rot90)

-bpy.types.register(OBJECT_OT_mhx_texdir)

-bpy.types.register(OBJECT_OT_mhx_import)

-bpy.types.register(IMPORT_PT_makehuman_mhx)

-"""

-

-"""

 class IMPORT_OT_makehuman_mhx(bpy.types.Operator):

    '''Import from MHX file format (.mhx)'''

    bl_idname = "import_scene.makehuman_mhx"

@@ -1677,8 +1496,21 @@ class IMPORT_OT_makehuman_mhx(bpy.types.Operator):
    face = BoolProperty(name="Face shapes", description="Include facial shapekeys", default= True)

    shape = BoolProperty(name="Body shapes", description="Include body shapekeys", default= False)

    rot90 = BoolProperty(name="Rot 90", description="Rotate X 90.", default= False)

+        rigify = BoolProperty(name="Rigify", description="Rigify.", default= False)
 

    def execute(self, context):

+                global toggle
+                O_ArmIK = T_ArmIK if self.properties.armik else 0
+                O_LegIK = T_LegIK if self.properties.legik else 0
+                O_FKIK = T_FKIK if self.properties.armik else 0
+                O_FingerIK = T_FingerIK if self.properties.fkik else 0
+                O_DispObs = T_DispObs if self.properties.dispobs else 0
+                O_Replace = T_Replace if self.properties.replace else 0
+                O_Face = T_Face if self.properties.face else 0
+                O_Shape = T_Shape if self.properties.shape else 0
+                O_Rot90 = T_Rot90 if self.properties.rot90 else 0
+                O_Rigify = T_Rigify if self.properties.rigify else 0
+                toggle =  O_ArmIK | O_LegIK | O_FKIK | O_FingerIK | O_DispObs | O_Replace | O_Face | O_Shape | O_Rot90 | O_Rigify
       readMhxFile(self.properties.path)

       return {'FINISHED'}

 

@@ -1690,12 +1522,12 @@ class IMPORT_OT_makehuman_mhx(bpy.types.Operator):
 bpy.types.register(IMPORT_OT_makehuman_mhx)

 menu_func = lambda self, context: self.layout.operator(IMPORT_OT_makehuman_mhx.bl_idname, text="MakeHuman (.mhx)...")

 bpy.types.INFO_MT_file_import.append(menu_func)

-"""

+
 #

 #   Testing

 #
-toggle = T_Replace + T_ArmIK + T_LegIK + T_Face

-readMhxFile("/home/thomas/makehuman/exports/foo-classic-25.mhx")

+#toggle = T_Replace + T_ArmIK + T_LegIK + T_Face
+#readMhxFile("/home/thomas/makehuman/exports/foo-classic-25.mhx")
 #readMhxFile("C:/Documents and Settings/xxxxxxxxxxxxxxxxxxxx/Mina dokument/makehuman/exports/foo-classic-25.mhx")

 #readMhxFile("/home/thomas/mhx5/test1.mhx")

 #readMhxFile("/home/thomas/myblends/mhx4/test1.mhx")
m.e
 
Posts: 56
Joined: Wed Jul 23, 2008 9:20 am
Location: Shenzhen/Hong Kong

Re: Thomas Larsson's blender 2.5 importer

Postby ThomasL » Fri Feb 26, 2010 5:07 am

Thank you, Martin. I didn't notice that the checkboxes actually appeared on the shelf to the left. Your code has been incorporated into a commit that I'm making now.
ThomasL
 
Posts: 1139
Joined: Tue Sep 15, 2009 2:46 am

Re: Thomas Larsson's blender 2.5 importer

Postby meta-androcto » Thu Mar 04, 2010 2:35 am

Hi,
great work. thank you all very much.
currently I'm setting up/have set up a new system for Blender Scripts.
If you get a version of Blender from Graphicall.org, latest revisions,
you will see in User Preferences the Add-Ons menu.
Press this to see how external scripts are now handled.
The Registration system (for the menu) is quite simple.
You will see the Raw mesh IO script there.
it's in .blender/scripts/add-ons/io_mesh_raw folder.
this will help you understand the system used for Import Export scripts.

I am running http://projects.blender.org/projects/bf-extensions/
also we have a svn set up for external scripts. https://svn.blender.org/svnroot/bf-extensions/
Some of this is mirrored with Blender Trunk,
It would not require much work from you guys & I can set every thing up & release your script in Blender Add-Ons Menu.

Keep up the good work.
I can be contacted on IRC Freenode #blenderwiki for discussion or email at
meta.androcto1 (at the domain) gmail.com.

Personally this would be Great!
As I have watched MH dev since it's beginning.
thanks again.

Brendon.
Blender Add-Ons Script Management Team
Project Manager.
meta-androcto
 
Posts: 5
Joined: Fri Feb 15, 2008 3:41 pm

Blender API changes again

Postby m.e » Thu Apr 15, 2010 3:32 pm

Thomas, in the current Blender svn, mathutils and geometry are all lower case, so you may want to fix your script. Martin
m.e
 
Posts: 56
Joined: Wed Jul 23, 2008 9:20 am
Location: Shenzhen/Hong Kong

Current error

Postby m.e » Sun Apr 25, 2010 3:04 pm

Thomas,

at present I'm getting the following

Code: Select all
Opening MHX file /home/martin/makehuman/exports/test20100415b-25.mhx
Tokenizing
Traceback (most recent call last):
  File "import_scene_mhx.py", line 2106, in execute

then nothing more happens (it jumps back to the 3D screen with no changes). I re-exported my model using the current MH and still got the same results when I tried to load it.
m.e
 
Posts: 56
Joined: Wed Jul 23, 2008 9:20 am
Location: Shenzhen/Hong Kong

Re: Thomas Larsson's blender 2.5 importer

Postby ThomasL » Mon Apr 26, 2010 8:42 am

Strange, I have no problems here (Win32 XP, Blender r28413), nor on Ubuntu yesterday. However, one thing I have noticed is that Blender may be confused if I execute one version of the importer in a script window and have another one in the add-ons folder.
ThomasL
 
Posts: 1139
Joined: Tue Sep 15, 2009 2:46 am

Next

Return to Python scripts

Who is online

Users browsing this forum: No registered users and 1 guest