Thomas Larsson's blender 2.5 importer

MakeHuman python API, python plugins, etc

Moderator: joepal

Re: Thomas Larsson's blender 2.5 importer

Postby m.e » Tue Apr 27, 2010 2:23 am

ThomasL wrote: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.


Thomas, I haven't been copying anything into the add-ons folder; everything has been done through the text editor.

Today, I tried loading a new model and Blender segfaulted (admittedly, segfaults in 2.5 svn are not an uncommon occurrence, but this was the first time your code has triggered it).

I put in some trace statements, and here are the last few lines of the output:
Code: Select all
key is matrix
default key, ext matrix, args /Matrix...
matrix
D ob.matrix
exec ob.matrix[0][0] = 1...
Segmentation fault (core dumped)


The crash is coming here in defaultKey:
Code: Select all
elif rnaType == 'Matrix':
        i = 0
        n = len(tokens)
        for (key, val, sub) in tokens:
            if key == 'row':
                for j in range(n):
                    expr = "%s[%d][%d] = %g" % (nvar, i, j, float(val[j]))
                    print('exec %s...' % (expr))
                    exec(expr, glbals, lcals)
                    print('exec done')
                i += 1
        return


For the record, here is the original output:

Code: Select all
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/ma-25.mhx
Tokenizing
clearScene 32 <bpy_struct, Scene("Scene")>
Parsing
Loading  /home/martin/mh/makehuman/data/textures/texture.tif  =  texture.tif
No file /home/martin/makehuman/exports/texture.png
No file /home/martin/makehuman/exports/texture.tif
No file /home/martin/mh/makehuman/data/textures/texture.png
Found file /home/martin/mh/makehuman/data/textures/texture.tif
Image <bpy_struct, Image("texture.tif")>
<bpy_struct, Image("texture.tif")>
Loading  /home/martin/mh/makehuman/data/textures/texture_ref.tif  =  texture_ref.tif
No file /home/martin/makehuman/exports/texture_ref.png
No file /home/martin/makehuman/exports/texture_ref.tif
No file /home/martin/mh/makehuman/data/textures/texture_ref.png
Found file /home/martin/mh/makehuman/data/textures/texture_ref.tif
Image <bpy_struct, Image("texture_ref.tif")>
<bpy_struct, Image("texture_ref.tif")>
Loading  /home/martin/mh/makehuman/data/textures/texture_opacity.tif  =  texture_opacity.tif
No file /home/martin/makehuman/exports/texture_opacity.png
No file /home/martin/makehuman/exports/texture_opacity.tif
No file /home/martin/mh/makehuman/data/textures/texture_opacity.png
Found file /home/martin/mh/makehuman/data/textures/texture_opacity.tif
Image <bpy_struct, Image("texture_opacity.tif")>
<bpy_struct, Image("texture_opacity.tif")>
<bpy_struct, ImageTexture("diffuse")>
<bpy_struct, ImageTexture("specularity")>
<bpy_struct, ImageTexture("alpha")>
<bpy_struct, CloudsTexture("normals")>
Ramp Element ['(0.569697,0.0276216,0.0473347,0.449231)', '0.0666667']
Ramp Element ['(1,0.990444,0.961778,1)', '0.525252']
Ramp interpolation ["'LINEAR'"]
Ramp Element ['(0.468774,0.306093,0.187666,0.2)', '0.2']
Ramp Element ['(1,0.925912,0.843177,0.5)', '0.8']
Ramp interpolation ["'LINEAR'"]
<bpy_struct, Material("SSS_skinshader")>
Struct done mat.strand
<bpy_struct, Material("Hair")>
<bpy_struct, Material("Invisio")>
<bpy_struct, Material("ProxySkin")>
<bpy_struct, Material("ProxyWhite")>
<bpy_struct, Material("ProxyRed")>
<bpy_struct, Material("ProxyGum")>
<bpy_struct, Material("ProxyBlue")>
<bpy_struct, Material("ProxyBlack")>
Linked
<bpy_struct, Armature("HumanRig")>
Segmentation fault (core dumped)


My system:
Code: Select all
~> ~/blender/blender/blender -v
Blender 2.52 (sub 5) Build
   build date: 2010-04-27
   build time: 09:47:57
   build revision: 28445M
   build platform: linux2
   build type: dynamic
~> uname -a
Linux edward.sunmoonstars 2.6.32.11-99.fc12.i686.PAE #1 SMP Mon Apr 5 16:15:03 EDT 2010 i686 i686 i386 GNU/Linux

No reason to believe that your code is the problem though.

I have looked a bit further at the code. I'm still working on this. But I'm not sur ewhy are you using exec everywhere. Why don't you just assign directly? like
Code: Select all
ob.matrix[i][j] =  float(val[j])
That doesn't help though; we still get a segfault.
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 » Tue Apr 27, 2010 12:51 pm

Now I also got a segfault, but thanks to your investigations I already knew where to look. Setting transformation matrices was never needed anyway, so I simply disabled the code.

execs are needed because the same code works whenever the data type is Matrix, irrespective of the name of the variable. The variable nvar could be eg. 'ob.matrix', 'bone.matrix', 'bone.matrix_local', 'posebone.matrix_channel', etc., and the same code works for all.
ThomasL
 
Posts: 1139
Joined: Tue Sep 15, 2009 2:46 am

Re: Thomas Larsson's blender 2.5 importer

Postby m.e » Tue Apr 27, 2010 1:26 pm

I've raised a bug in the Blender tracker https://projects.blender.org/tracker/in ... 9&atid=125

I have now managed to load my model successfully,
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 Apr 29, 2010 5:51 am

Thomas,

Another change to the Blender API: Vector now only takes a list of 3 elements, not 3 floats ie you need to replace Vector(x,y,z) with Vector([x,y,z]) throughout eg import_hair_obj lines 137 and 184.

Also. and this may be a touch picky, the 'addons' directory does not have a hyphen.

Another, unrelated issue - I'm not getting any hair exported. --- that one was me; I think I had not generated the hair properly. But it would be nice if the exporter panel in MH itself could indicate that there is no hair to export, when that is the case.

Martin
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 » Wed May 05, 2010 3:59 pm

It's me again, with another Blender segfault and a general question.

With gobo rig, segfault
If I try to import the gobo rig I get a segfault. I enabled some trace statements in the code, and here are the last few lines of what I got.
Code: Select all
D fmod.poly_order
fmod poly_order 1
extrapolation
D fcu.extrapolation
fcu extrapolation 'CONSTANT'
locked
D fcu.locked
fcu locked False
selected
D fcu.selected
fcu selected False
Doing tex.interpolation = 'LINEAR'
Failed #d: tex.interpolation = 'LINEAR'
Doing tex.interpolation = 'LINEAR'
Failed #d: tex.interpolation = 'LINEAR'
Doing bone.parent = loadedData['Bone']['FootGobo_L']
Segmentation fault (core dumped)


With the other rig, some warnings
I got a few warnings when I imported with the non-gobo rig, but Blender survived the adventure.
Code: Select all
Doing tex.interpolation = 'LINEAR'
Failed #d: tex.interpolation = 'LINEAR'
Doing tex.interpolation = 'LINEAR'
Failed #d: tex.interpolation = 'LINEAR'
...
Doing cns.keep_axis = 'X'
Failed #d: cns.keep_axis = 'X'
Doing cns.keep_axis = 'X'
Failed #d: cns.keep_axis = 'X'
Postprocess


Comment
If we have more than one 'human' in a scene, it gets a bit confusing. Is there anything to be done about this? There are all these MHxxx objects and Goboxxx objects, and they (a) take up conceptual space in the outliner and (b) make it hard to guess which is attached to which 'human'. Is it possible for example to parent them to the 'human'? Then they will be hidden except when we are looking into that particular human. Or can something be done with groups? I'm not really that familiar with the code so I can't say definitely what the consequences would be of doing so, but I would have thought something like that would still keep the code working.
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 May 07, 2010 4:26 am

The segfaults are not specific to the Gobo feet. Blender usually crashes on me when I load a second character. This happens at random places, but usually towards the end of the load phase. I am pretty sure that this is a garbage collection/memory allocation bug. And even if Blender does not crash, it often writes something like "Error TotBlocks = 2" when I quit, which should be an indication that the heap is corrupt.

However, I don't think that this is time to report this kind of bug. Better to find well-isolated and reproducible bugs that the devs can fix more easily first.

I will parent all custom shapes under an empty. In that way they won't take up space in the outliner.
ThomasL
 
Posts: 1139
Joined: Tue Sep 15, 2009 2:46 am

Re: Thomas Larsson's blender 2.5 importer

Postby m.e » Fri May 07, 2010 4:43 am

ThomasL wrote:The segfaults are not specific to the Gobo feet. Blender usually crashes on me when I load a second character. ...
I have also found that Blender crashes on the second import, as you say, but I can start with a new Blender and load the gobo rig, and it still crashes. What seems to happen is that some invalid python causes the segfault when it should give an error such as 'None does not have an attribute xyz' or the like. So maybe execing "bone.parent = loadedData['Bone']['FootGobo_L']" causes the problem. I haven't checked yet, so maybe you have fixed it already. I have now built the latest svn Blender and MH, exported a model and tried to import it into a clean instance of Blender using the gobo rig, and it segfaults as I previously described.
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 » Sat May 08, 2010 4:41 am

Now I think that I have fixed the crashes. I have loaded four characters (two Gobos and two Reverse feet) into the same scene without problems.

The objects in an mhx file are loaded sequentially into Blender. However, it may happen that some attribute cannot be set because it refers to an object that has not yet been loaded. If this happens, the statement together with its entire context is saved on the todo list. The todo list is then evaluated after the entire file has been loaded.

This works in principle, but in practice we have found that evaluating the todo list is crash prone, due to bugs in Blender or perhaps in python itself. The mhx file has now been rearranged so it is not necessary to put things on the todo list. This seems to have done the trick.

The Gobo problem was that a bone was defined before its parent. Hence setting bone.parent failed and was put on the todo list, which caused the crash.
ThomasL
 
Posts: 1139
Joined: Tue Sep 15, 2009 2:46 am

Re: Thomas Larsson's blender 2.5 importer

Postby m.e » Mon May 24, 2010 4:42 am

m.e wrote:Today, I tried loading a new model and Blender segfaulted ... I put in some trace statements, and here are the last few lines of the output:
Code: Select all
...exec ob.matrix[0][0] = 1...
Segmentation fault (core dumped)
...


Blender has now fixed the matrix segfault. (see http://projects.blender.org/tracker/?func=detail&atid=498&aid=22183&group_id=9 if you need the details).
m.e
 
Posts: 56
Joined: Wed Jul 23, 2008 9:20 am
Location: Shenzhen/Hong Kong

Previous

Return to Python scripts

Who is online

Users browsing this forum: No registered users and 1 guest

cron