[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1594] trunk/py/scripts/addons/ io_import_scene_mhx.py: Mhx importer: new registration and changed license to GPL 2+
Thomas Larsson
thomas_larsson_01 at hotmail.com
Mon Feb 14 06:55:04 CET 2011
Revision: 1594
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1594
Author: thomasl
Date: 2011-02-14 05:55:03 +0000 (Mon, 14 Feb 2011)
Log Message:
-----------
Mhx importer: new registration and changed license to GPL 2+
Modified Paths:
--------------
trunk/py/scripts/addons/io_import_scene_mhx.py
Modified: trunk/py/scripts/addons/io_import_scene_mhx.py
===================================================================
--- trunk/py/scripts/addons/io_import_scene_mhx.py 2011-02-13 11:46:54 UTC (rev 1593)
+++ trunk/py/scripts/addons/io_import_scene_mhx.py 2011-02-14 05:55:03 UTC (rev 1594)
@@ -1,30 +1,49 @@
-"""
-**Project Name:** MakeHuman
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
-**Product Home Page:** http://www.makehuman.org/
+# <pep8 compliant>
-**Code Home Page:** http://code.google.com/p/makehuman/
+# Project Name: MakeHuman
+# Product Home Page: http://www.makehuman.org/
+# Code Home Page: http://code.google.com/p/makehuman/
+# Authors: Thomas Larsson
+# Script copyright (C) MakeHuman Team 2001-2011
+# Coding Standards: See http://sites.google.com/site/makehumandocs/developers-guide
-**Authors:** Thomas Larsson
-
-**Copyright(c):** MakeHuman Team 2001-2010
-
-**Licensing:** GPL3 (see also http://sites.google.com/site/makehumandocs/licensing)
-
-**Coding Standards:** See http://sites.google.com/site/makehumandocs/developers-guide
-
+"""
Abstract
MHX (MakeHuman eXchange format) importer for Blender 2.5x.
-Version 1.0.4
+Version 1.2.7
+This script should be distributed with Blender.
+If not, place it in the .blender/scripts/addons dir
+Activate the script in the "Add-Ons" tab (user preferences).
+Access from the File > Import menu.
+
+Alternatively, run the script in the script editor (Alt-P), and access from the File > Import menu
"""
bl_info = {
'name': 'Import: MakeHuman (.mhx)',
'author': 'Thomas Larsson',
- 'version': (1, 0, 4),
- 'blender': (2, 5, 6),
- 'api': 34326,
+ 'version': (1, 2, 7),
+ 'blender': (2, 5, 7),
+ 'api': 34786,
'location': "File > Import",
'description': 'Import files in the MakeHuman eXchange format (.mhx)',
'warning': '',
@@ -34,15 +53,9 @@
'func=detail&aid=21872',
'category': 'Import-Export'}
-"""
-Place this file in the .blender/scripts/addons dir
-You have to activated the script in the "Add-Ons" tab (user preferences).
-Access from the File > Import menu.
-"""
-
MAJOR_VERSION = 1
-MINOR_VERSION = 0
-SUB_VERSION = 4
+MINOR_VERSION = 2
+SUB_VERSION = 7
BLENDER_VERSION = (2, 56, 0)
#
@@ -101,13 +114,22 @@
T_Cage = 0x800
T_Rigify = 0x1000
-T_Preset = 0x2000
+T_Opcns = 0x2000
T_Symm = 0x4000
-T_MHX = 0x8000
toggle = T_EnforceVersion + T_Replace + T_Mesh + T_Armature + T_Face + T_Shape + T_Proxy + T_Clothes
#
+# Blender versions
+#
+
+BLENDER_GRAPHICALL = 0
+BLENDER_256a = 1
+
+BlenderVersions = ['Graphicall', 'Blender256a']
+theBlenderVersion = BLENDER_GRAPHICALL
+
+#
# setFlagsAndFloats(rigFlags):
#
# Global floats
@@ -240,16 +262,15 @@
return
#
-# readMhxFile(filePath, scale):
+# readMhxFile(filePath):
#
-def readMhxFile(filePath, scale):
+def readMhxFile(filePath):
global todo, nErrors, theScale, defaultScale, One, toggle
- checkBlenderVersion()
+ #checkBlenderVersion()
- theScale = scale
- defaultScale = scale
+ defaultScale = theScale
One = 1.0/theScale
fileName = os.path.expanduser(filePath)
@@ -343,10 +364,6 @@
nErrors += 1
#raise NameError(msg)
- print("Postprocess")
- postProcess()
- print("HideLayers")
- hideLayers()
time2 = time.clock()
print("toggle = %x" % toggle)
msg = "File %s loaded in %g s" % (fileName, time2-time1)
@@ -374,7 +391,7 @@
def checkMhxVersion(major, minor):
global warnedVersion
- if major != MAJOR_VERSION or minor != MINOR_VERSION:
+ if major != MAJOR_VERSION or (major == MAJOR_VERSION and minor > MINOR_VERSION):
if warnedVersion:
return
else:
@@ -403,7 +420,7 @@
global MHX249, ifResult, theScale, defaultScale, One
for (key, val, sub) in tokens:
- # print("Parse %s" % key)
+ print("Parse %s" % key)
data = None
if key == 'MHX':
checkMhxVersion(int(val[0]), int(val[1]))
@@ -457,8 +474,15 @@
data = parseWorld(val, sub)
elif key == "Scene":
data = parseScene(val, sub)
+ elif key == "DefineProperty":
+ parseDefineProperty(val, sub)
elif key == "Process":
parseProcess(val, sub)
+ elif key == "PostProcess":
+ postProcess(val)
+ hideLayers(val)
+ elif key == "CorrectRig":
+ correctRig(val)
elif key == 'AnimationData':
try:
ob = loadedData['Object'][val[0]]
@@ -484,7 +508,7 @@
raise NameError("ShapeKeys object %s does not exist" % val[0])
if ob:
bpy.context.scene.objects.active = ob
- parseShapeKeys(ob, ob.data, val, sub)
+ parseShapeKeys(ob, ob.data, val, sub)
else:
data = parseDefaultType(key, val, sub)
@@ -502,9 +526,9 @@
name = args[0]
data = None
expr = "bpy.data.%s.new('%s')" % (Plural[typ], name)
- print(expr)
+ # print(expr)
data = eval(expr)
- print(" ok", data)
+ # print(" ok", data)
bpyType = typ.capitalize()
print(bpyType, name, data)
@@ -668,22 +692,24 @@
def parseAnimationData(rna, args, tokens):
if not eval(args[1]):
return
+ print("Parse Animation data")
if rna.animation_data == None:
rna.animation_data_create()
adata = rna.animation_data
for (key, val, sub) in tokens:
if key == 'FCurve':
- fcu = parseAnimDataFCurve(adata, rna, val, sub)
+ fcu = parseAnimDataFCurve(adata, rna, val, sub)
else:
defaultKey(key, val, sub, 'adata', [], globals(), locals())
+ print(adata)
return adata
def parseAnimDataFCurve(adata, rna, args, tokens):
+ global theBlenderVersion
if invalid(args[2]):
return
dataPath = args[0]
index = int(args[1])
- # print("parseAnimDataFCurve", adata, dataPath, index)
n = 1
for (key, val, sub) in tokens:
if key == 'Driver':
@@ -693,7 +719,10 @@
elif key == 'FModifier':
parseFModifier(fcu, val, sub)
elif key == 'kp':
- pt = fcu.keyframe_points.insert(n, 0)
+ if theBlenderVersion >= BLENDER_256a:
+ pt = fcu.keyframe_points.add(n, 0)
+ else:
+ pt = fcu.keyframe_points.insert(n, 0)
pt.interpolation = 'LINEAR'
pt = parseKeyFramePoint(pt, val, sub)
n += 1
@@ -712,7 +741,7 @@
expr = "rna." + words[0] + ']'
pwords = words[1].split('"')
prop = pwords[1]
- # print("prop", expr, prop)
+ #print("prop", expr, prop)
bone = eval(expr)
return None
else:
@@ -726,7 +755,9 @@
#print("expr", rna, expr)
fcu = eval(expr)
drv = fcu.driver
+ #print(" Driver type", drv, args[0])
drv.type = args[0]
+ #print(" ->", drv.type)
for (key, val, sub) in tokens:
if key == 'DriverVariable':
var = parseDriverVariable(drv, rna, val, sub)
@@ -737,9 +768,10 @@
def parseDriverVariable(drv, rna, args, tokens):
var = drv.variables.new()
var.name = args[0]
+ #print(" Var type", var, args[1])
var.type = args[1]
+ #print(" ->", var.type)
nTarget = 0
- # print("var", var, var.name, var.type)
for (key, val, sub) in tokens:
if key == 'Target':
parseDriverTarget(var, nTarget, rna, val, sub)
@@ -764,7 +796,10 @@
"""
def parseDriverTarget(var, nTarget, rna, args, tokens):
targ = var.targets[nTarget]
- targ.id = loadedData['Object'][args[0]]
+ ob = loadedData['Object'][args[0]]
+ #print(" targ id", targ, ob)
+ targ.id = ob
+ #print(" ->", targ.id)
for (key, val, sub) in tokens:
defaultKey(key, val, sub, 'targ', [], globals(), locals())
return targ
@@ -1047,7 +1082,7 @@
if key == 'Modifier':
parseModifier(ob, val, sub)
elif key == 'Constraint':
- parseConstraint(ob.constraints, val, sub)
+ parseConstraint(ob.constraints, None, val, sub)
elif key == 'AnimationData':
parseAnimationData(ob, val, sub)
elif key == 'ParticleSystem':
@@ -1108,6 +1143,7 @@
# parseModifier(ob, args, tokens):
#
+
def parseModifier(ob, args, tokens):
name = args[0]
typ = args[1]
@@ -1115,9 +1151,36 @@
return None
mod = ob.modifiers.new(name, typ)
for (key, val, sub) in tokens:
- defaultKey(key, val, sub, 'mod', [], globals(), locals())
+ if key == 'HookAssignNth':
+ if val[0] == 'CURVE':
+ hookAssignNth(mod, int(val[1]), True, ob.data.splines[0].points)
+ elif val[0] == 'LATTICE':
+ hookAssignNth(mod, int(val[1]), False, ob.data.points)
+ elif val[0] == 'MESH':
+ hookAssignNth(mod, int(val[1]), True, ob.data.vertices)
+ else:
+ raise NameError("Unknown hook %s" % val)
+ else:
+ defaultKey(key, val, sub, 'mod', [], globals(), locals())
return mod
+def hookAssignNth(mod, n, select, points):
+ if select:
+ for pt in points:
+ pt.select = False
+ points[n].select = True
+ sel = []
+ for pt in points:
+ sel.append(pt.select)
+ #print(mod, sel, n, points)
+
+ bpy.ops.object.mode_set(mode='EDIT')
+ bpy.ops.object.hook_reset(modifier=mod.name)
+ bpy.ops.object.hook_select(modifier=mod.name)
+ bpy.ops.object.hook_assign(modifier=mod.name)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list