[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1111] trunk/py/scripts/addons/ io_import_scene_mhx.py: new make human import scripts/addons/ io_import_scene_mhx.py

Brendon Murphy meta.androcto1 at gmail.com
Sat Oct 23 15:32:59 CEST 2010


Revision: 1111
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1111
Author:   meta-androcto
Date:     2010-10-23 15:32:59 +0200 (Sat, 23 Oct 2010)

Log Message:
-----------
new make human import scripts/addons/io_import_scene_mhx.py
thanks to ThomasL for his patience.

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	2010-10-23 01:44:33 UTC (rev 1110)
+++ trunk/py/scripts/addons/io_import_scene_mhx.py	2010-10-23 13:32:59 UTC (rev 1111)
@@ -1,63 +1,47 @@
-# ##### 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 #####
-
-bl_addon_info = {
-    "name": "Import MakeHuman (.mhx)",
-    "author": "Thomas Larsson",
-    "version": (0,9,5),
-    "blender": (2, 5, 3),
-    "api": 31847,
-    "location": "File > Import",
-    "description": "Import files in the MakeHuman eXchange format (.mhx)",
-    "warning": "Alpha version",
-    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"
-        "Scripts/File_I-O/Make_Human",
-    "tracker_url": "https://projects.blender.org/tracker/index.php?"
-        "func=detail&aid=21872&group_id=153&atid=469",
-    "category": "Import/Export"}
-
 """ 
-**Project Name:**      MakeHuman
+**Project Name:**	  MakeHuman
 
 **Product Home Page:** http://www.makehuman.org/
 
-**Code Home Page:**    http://code.google.com/p/makehuman/
+**Code Home Page:**	http://code.google.com/p/makehuman/
 
-**Authors:**           Thomas Larsson
+**Authors:**		   Thomas Larsson
 
-**Copyright(c):**      MakeHuman Team 2001-2010
+**Copyright(c):**	  MakeHuman Team 2001-2010
 
-**Licensing:**         GPL3 (see also http://sites.google.com/site/makehumandocs/licensing)
+**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 0.9
+Version 1.0
 
 """
 
+bl_addon_info = {
+	'name': 'Import: MakeHuman (.mhx)',
+	'author': 'Thomas Larsson',
+	'version': '1.0',
+	'blender': (2, 5, 4),
+    "api": 31913,
+	"location": "File > Import",
+	"description": "Import files in the MakeHuman eXchange format (.mhx)",
+	"warning": "",
+	"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/File_I-O/Make_Human",
+	"tracker_url": "https://projects.blender.org/tracker/index.php?func=detail&aid=21872&group_id=153&atid=469",
+	"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
+BLENDER_VERSION = (2, 54, 0)
+
 #
 #
 #
@@ -70,8 +54,6 @@
 import geometry
 import string
 
-MAJOR_VERSION = 0
-MINOR_VERSION = 9
 MHX249 = False
 Blender24 = False
 Blender25 = True
@@ -82,8 +64,8 @@
 #
 
 theScale = 1.0
+One = 1.0/theScale
 useMesh = 1
-doSmash = 1
 verbosity = 2
 warnedTextureDir = False
 warnedVersion = False
@@ -97,2149 +79,2387 @@
 todo = []
 
 #
-#    toggle flags
+#	toggle flags
 #
 
-T_ArmIK = 0x01
-T_LegIK = 0x02
+T_EnforceVersion = 0x01
+T_Clothes = 0x02
+T_Stretch = 0x04
+T_Bend = 0x08
+
+T_Diamond = 0x10
 T_Replace = 0x20
 T_Face = 0x40
 T_Shape = 0x80
+
 T_Mesh = 0x100
 T_Armature = 0x200
 T_Proxy = 0x400
-T_Panel = 0x800
+T_Cage = 0x800
 
 T_Rigify = 0x1000
 T_Preset = 0x2000
 T_Symm = 0x4000
 T_MHX = 0x8000
 
-toggle = T_Replace + T_ArmIK + T_LegIK + T_Mesh + T_Armature + T_Face
+toggle = T_EnforceVersion + T_Replace + T_Mesh + T_Armature + T_Face + T_Shape + T_Proxy + T_Clothes
 
 #
-#    setFlagsAndFloats(rigFlags):
+#	setFlagsAndFloats(rigFlags):
 #
-#    Global floats
-fLegIK = 0.0
-fArmIK = 0.0
-fFingerPanel = 0.0
-fFingerIK = 0.0
-fFingerCurl = 0.0
+#	Global floats
+#fFingerPanel = 0.0
+#fFingerIK = 0.0
+fNoStretch = 0.0
 
-#    rigLeg and rigArm flags
+#	rigLeg and rigArm flags
 T_Toes = 0x0001
-T_GoboFoot = 0x0002
-T_InvFoot = 0x0004
+#T_GoboFoot = 0x0002
 
-T_FingerPanel = 0x100
-T_FingerCurl = 0x0200
-T_FingerIK = 0x0400
+#T_InvFoot = 0x0010
+#T_InvFootPT = 0x0020
+#T_InvFootNoPT = 0x0040
 
+#T_FingerPanel = 0x100
+#T_FingerRot = 0x0200
+#T_FingerIK = 0x0400
 
-T_LocalFKIK = 0x8000
 
-rigLeg = 0
-rigArm = 0
+#T_LocalFKIK = 0x8000
 
-def setFlagsAndFloats(rigFlags):
-    global toggle, rigLeg, rigArm
+#rigLeg = 0
+#rigArm = 0
 
-    (footRig, fingerRig) = rigFlags
-    rigLeg = 0
-    rigArm = 0
-    if footRig == 'Reverse foot': rigLeg |= T_InvFoot
-    elif footRig == 'Gobo': rigLeg |= T_GoboFoot
+def setFlagsAndFloats():
+	'''
+	global toggle, rigLeg, rigArm
 
-    if fingerRig == 'Panel': rigArm |= T_FingerPanel
-    elif fingerRig == 'IK': rigArm |= T_FingerIK
-    elif fingerRig == 'Curl': rigArm |= T_FingerCurl
+	(footRig, fingerRig) = rigFlags
+	rigLeg = 0
+	if footRig == 'Reverse foot': 
+		rigLeg |= T_InvFoot
+		if toggle & T_PoleTar:
+			rigLeg |= T_InvFootPT
+		else:
+			rigLeg |= T_InvFootNoPT
+	elif footRig == 'Gobo': rigLeg |= T_GoboFoot		
 
-    toggle |= T_Panel
+	rigArm = 0
+	if fingerRig == 'Panel': rigArm |= T_FingerPanel
+	elif fingerRig == 'Rotation': rigArm |= T_FingerRot
+	elif fingerRig == 'IK': rigArm |= T_FingerIK
 
-    # Global floats, used as influences
-    global fFingerCurl, fLegIK, fArmIK, fFingerIK
+	toggle |= T_Panel
+	'''
+	global fNoStretch
+	if toggle&T_Stretch: fNoStretch == 0.0
+	else: fNoStretch = 1.0
 
-    fFingerCurl = 1.0 if rigArm&T_FingerCurl else 0.0
-    fLegIK = 1.0 if toggle&T_LegIK else 0.0
-    fArmIK = 1.0 if toggle&T_ArmIK else 0.0
-    fFingerIK = 1.0 if rigArm&T_FingerIK else 0.0
+	return
 
-    return
 
-
 #
-#    Dictionaries
+#	Dictionaries
 #
 
 loadedData = {
-    'NONE' : {},
+	'NONE' : {},
 
-    'Object' : {},
-    'Mesh' : {},
-    'Armature' : {},
-    'Lamp' : {},
-    'Camera' : {},
-    'Lattice' : {},
-    'Curve' : {},
+	'Object' : {},
+	'Mesh' : {},
+	'Armature' : {},
+	'Lamp' : {},
+	'Camera' : {},
+	'Lattice' : {},
+	'Curve' : {},
+	'Text' : {},
 
-    'Material' : {},
-    'Image' : {},
-    'MaterialTextureSlot' : {},
-    'Texture' : {},
-    
-    'Bone' : {},
-    'BoneGroup' : {},
-    'Rigify' : {},
+	'Material' : {},
+	'Image' : {},
+	'MaterialTextureSlot' : {},
+	'Texture' : {},
+	
+	'Bone' : {},
+	'BoneGroup' : {},
+	'Rigify' : {},
 
-    'Action' : {},
-    'Group' : {},
+	'Action' : {},
+	'Group' : {},
 
-    'MeshTextureFaceLayer' : {},
-    'MeshColorLayer' : {},
-    'VertexGroup' : {},
-    'ShapeKey' : {},
-    'ParticleSystem' : {},
+	'MeshTextureFaceLayer' : {},
+	'MeshColorLayer' : {},
+	'VertexGroup' : {},
+	'ShapeKey' : {},
+	'ParticleSystem' : {},
 
-    'ObjectConstraints' : {},
-    'ObjectModifiers' : {},
-    'MaterialSlot' : {},
+	'ObjectConstraints' : {},
+	'ObjectModifiers' : {},
+	'MaterialSlot' : {},
 }
 
 Plural = {
-    'Object' : 'objects',
-    'Mesh' : 'meshes',
-    'Lattice' : 'lattices',
-    'Curve' : 'curves',
-    'Group' : 'groups',
-    'Empty' : 'empties',
-    'Armature' : 'armatures',
-    'Bone' : 'bones',
-    'BoneGroup' : 'bone_groups',
-    'Pose' : 'poses',
-    'PoseBone' : 'pose_bones',
-    'Material' : 'materials',
-    'Texture' : 'textures',
-    'Image' : 'images',
-    'Camera' : 'cameras',
-    'Lamp' : 'lamps',
-    'World' : 'worlds',
+	'Object' : 'objects',
+	'Mesh' : 'meshes',
+	'Lattice' : 'lattices',
+	'Curve' : 'curves',
+	'Text' : 'texts',
+	'Group' : 'groups',
+	'Empty' : 'empties',
+	'Armature' : 'armatures',
+	'Bone' : 'bones',
+	'BoneGroup' : 'bone_groups',
+	'Pose' : 'poses',
+	'PoseBone' : 'pose_bones',
+	'Material' : 'materials',
+	'Texture' : 'textures',
+	'Image' : 'images',
+	'Camera' : 'cameras',
+	'Lamp' : 'lamps',
+	'World' : 'worlds',
 }
 
 #
-#    Creators
+#	checkBlenderVersion()
 #
 
-def uvtexCreator(me, name):
-    print("uvtexCreator", me, name)
-    return me.uv_textures.new(name)
+def checkBlenderVersion():
+	print("Found Blender", bpy.app.version)
+	(A, B, C) = bpy.app.version
+	(a, b, c) = BLENDER_VERSION
+	if a <= A: return
+	if b <= B: return
+	if c <= C: return
+	msg = (
+"This version of the MHX importer only works with Blender (%d, %d, %d) or later. " % (a, b, c) +
+"Download a more recent Blender from www.blender.org or www.graphicall.org.\n"
+	)
+	raise NameError(msg)
+	return
 
-
-def vertcolCreator(me, name):
-    print("vertcolCreator", me, name)
-    return me.vertex_colors.new(name)
-
-
 #
-#    loadMhx(filePath, context, flags):
+#	readMhxFile(filePath, scale):
 #
 
-def loadMhx(filePath, context, flags):
-    global toggle
-    toggle = flags
-    readMhxFile(filePath)
-    return
+def readMhxFile(filePath, scale):
+	global todo, nErrors, theScale, defaultScale, One, toggle
 
-#
-#    readMhxFile(filePath, rigFlags):
-#
+	checkBlenderVersion()	
+	
+	theScale = scale
+	defaultScale = scale
+	One = 1.0/theScale
 
-def readMhxFile(filePath, rigFlags):
-    global todo, nErrors
-    
-    fileName = os.path.expanduser(filePath)
-    (shortName, ext) = os.path.splitext(fileName)
-    if ext != ".mhx":
-        print("Error: Not a mhx file: " + fileName)
-        return
-    print( "Opening MHX file "+ fileName )
-    time1 = time.clock()
+	fileName = os.path.expanduser(filePath)
+	(shortName, ext) = os.path.splitext(fileName)
+	if ext.lower() != ".mhx":
+		print("Error: Not a mhx file: " + fileName)
+		return
+	print( "Opening MHX file "+ fileName )
+	time1 = time.clock()
 
-    ignore = False
-    stack = []
-    tokens = []
-    key = "toplevel"
-    level = 0
-    nErrors = 0
+	ignore = False
+	stack = []
+	tokens = []
+	key = "toplevel"
+	level = 0
+	nErrors = 0
+	comment = 0
+	nesting = 0
 
-    setFlagsAndFloats(rigFlags)
+	setFlagsAndFloats()
 
-    file= open(fileName, "rU")
-    print( "Tokenizing" )
-    lineNo = 0
-    for line in file: 
-        # print(line)
-        lineSplit= line.split()
-        lineNo += 1
-        if len(lineSplit) == 0:
-            pass
-        elif lineSplit[0] == '#':
-            pass
-        elif lineSplit[0] == 'end':
-            try:
-                sub = tokens
-                tokens = stack.pop()
-                if tokens:

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list