[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1418] extern/py/scripts/addons/ makehuman/1.0.4/io_import_scene_mhx.py: Mhx importer: Previous commit did not start from the file in Blender trunk, with modifications by Cambell Barton.
Thomas Larsson
thomas_larsson_01 at hotmail.com
Mon Jan 17 11:47:27 CET 2011
Revision: 1418
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1418
Author: thomasl
Date: 2011-01-17 10:47:26 +0000 (Mon, 17 Jan 2011)
Log Message:
-----------
Mhx importer: Previous commit did not start from the file in Blender trunk, with modifications by Cambell Barton. In particular, bl_addons_info -> bl_info.
Modified Paths:
--------------
extern/py/scripts/addons/makehuman/1.0.4/io_import_scene_mhx.py
Modified: extern/py/scripts/addons/makehuman/1.0.4/io_import_scene_mhx.py
===================================================================
--- extern/py/scripts/addons/makehuman/1.0.4/io_import_scene_mhx.py 2011-01-17 10:06:50 UTC (rev 1417)
+++ extern/py/scripts/addons/makehuman/1.0.4/io_import_scene_mhx.py 2011-01-17 10:47:26 UTC (rev 1418)
@@ -1,2480 +1,2480 @@
-"""
-**Project Name:** MakeHuman
-
-**Product Home Page:** http://www.makehuman.org/
-
-**Code Home Page:** http://code.google.com/p/makehuman/
-
-**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
-
-"""
-
-bl_addon_info = {
- 'name': 'Import: MakeHuman (.mhx)',
- 'author': 'Thomas Larsson',
- 'version': (1, 0, 4),
- 'blender': (2, 5, 6),
- 'api': 34326,
- '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
-SUB_VERSION = 4
-BLENDER_VERSION = (2, 56, 0)
-
-#
-#
-#
-
-import bpy
-import os
-import time
-import mathutils
-from mathutils import *
-#import geometry
-#import string
-
-MHX249 = False
-Blender24 = False
-Blender25 = True
-TexDir = "~/makehuman/exports"
-
-#
-#
-#
-
-theScale = 1.0
-One = 1.0/theScale
-useMesh = 1
-verbosity = 2
-warnedTextureDir = False
-warnedVersion = False
-
-true = True
-false = False
-Epsilon = 1e-6
-nErrors = 0
-theTempDatum = None
-
-todo = []
-
-#
-# toggle flags
-#
-
-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_Cage = 0x800
-
-T_Rigify = 0x1000
-T_Preset = 0x2000
-T_Symm = 0x4000
-T_MHX = 0x8000
-
-toggle = T_EnforceVersion + T_Replace + T_Mesh + T_Armature + T_Face + T_Shape + T_Proxy + T_Clothes
-
-#
-# setFlagsAndFloats(rigFlags):
-#
-# Global floats
-#fFingerPanel = 0.0
-#fFingerIK = 0.0
-fNoStretch = 0.0
-
-# rigLeg and rigArm flags
-T_Toes = 0x0001
-#T_GoboFoot = 0x0002
-
-#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
-
-def setFlagsAndFloats():
- '''
- global toggle, rigLeg, rigArm
-
- (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
-
- rigArm = 0
- if fingerRig == 'Panel': rigArm |= T_FingerPanel
- elif fingerRig == 'Rotation': rigArm |= T_FingerRot
- elif fingerRig == 'IK': rigArm |= T_FingerIK
-
- toggle |= T_Panel
- '''
- global fNoStretch
- if toggle&T_Stretch: fNoStretch == 0.0
- else: fNoStretch = 1.0
-
- return
-
-
-#
-# Dictionaries
-#
-
-loadedData = {
- 'NONE' : {},
-
- 'Object' : {},
- 'Mesh' : {},
- 'Armature' : {},
- 'Lamp' : {},
- 'Camera' : {},
- 'Lattice' : {},
- 'Curve' : {},
- 'Text' : {},
-
- 'Material' : {},
- 'Image' : {},
- 'MaterialTextureSlot' : {},
- 'Texture' : {},
-
- 'Bone' : {},
- 'BoneGroup' : {},
- 'Rigify' : {},
-
- 'Action' : {},
- 'Group' : {},
-
- 'MeshTextureFaceLayer' : {},
- 'MeshColorLayer' : {},
- 'VertexGroup' : {},
- 'ShapeKey' : {},
- 'ParticleSystem' : {},
-
- 'ObjectConstraints' : {},
- 'ObjectModifiers' : {},
- 'MaterialSlot' : {},
-}
-
-Plural = {
- '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',
-}
-
-#
-# checkBlenderVersion()
-#
-
-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
-
-#
-# readMhxFile(filePath, scale):
-#
-
-def readMhxFile(filePath, scale):
- global todo, nErrors, theScale, defaultScale, One, toggle
-
- checkBlenderVersion()
-
- theScale = scale
- defaultScale = scale
- One = 1.0/theScale
-
- 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
- comment = 0
- nesting = 0
-
- 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][0] == '#':
- if lineSplit[0] == '#if':
- if comment == nesting:
- try:
- res = eval(lineSplit[1])
- except:
- res = False
- if res:
- comment += 1
- nesting += 1
- elif lineSplit[0] == '#else':
- if comment == nesting-1:
- comment += 1
- elif comment == nesting:
- comment -= 1
- elif lineSplit[0] == '#endif':
- if comment == nesting:
- comment -= 1
- nesting -= 1
- elif comment < nesting:
- pass
- elif lineSplit[0] == 'end':
- try:
- sub = tokens
- tokens = stack.pop()
- if tokens:
- tokens[-1][2] = sub
- level -= 1
- except:
- print( "Tokenizer error at or before line %d" % lineNo )
- print( line )
- dummy = stack.pop()
- elif lineSplit[-1] == ';':
- if lineSplit[0] == '\\':
- key = lineSplit[1]
- tokens.append([key,lineSplit[2:-1],[]])
- else:
- key = lineSplit[0]
- tokens.append([key,lineSplit[1:-1],[]])
- else:
- key = lineSplit[0]
- tokens.append([key,lineSplit[1:],[]])
- stack.append(tokens)
- level += 1
- tokens = []
- file.close()
-
- if level != 0:
- raise NameError("Tokenizer out of kilter %d" % level)
- clearScene()
- print( "Parsing" )
- parse(tokens)
-
- for (expr, glbals, lcals) in todo:
- try:
- print("Doing %s" % expr)
- exec(expr, glbals, lcals)
- except:
- msg = "Failed: "+expr
- print( msg )
- 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)
- if nErrors:
- msg += " but there where %d errors. " % (nErrors)
- print(msg)
- return
-
-#
-# getObject(name, var, glbals, lcals):
-#
-
-def getObject(name, var, glbals, lcals):
- try:
- ob = loadedData['Object'][name]
- except:
- if name != "None":
- pushOnTodoList(None, "ob = loadedData['Object'][name]" % globals(), locals())
- ob = None
- return ob
-
-#
-# checkMhxVersion(major, minor):
-#
-
-def checkMhxVersion(major, minor):
- global warnedVersion
- if major != MAJOR_VERSION or minor != MINOR_VERSION:
- if warnedVersion:
- return
- else:
- msg = (
-"Wrong MHX version\n" +
-"Expected MHX %d.%d but the loaded file has version MHX %d.%d\n" % (MAJOR_VERSION, MINOR_VERSION, major, minor) +
-"You can disable this error message by deselecting the Enforce version option when importing. " +
-"Alternatively, you can try to download the most recent nightly build from www.makehuman.org. " +
-"The current version of the import script is located in the importers/mhx/blender25x folder and is called import_scene_mhx.py. " +
-"The version distributed with Blender builds from www.graphicall.org may be out of date.\n"
-)
- if toggle & T_EnforceVersion:
- raise NameError(msg)
- else:
- print(msg)
- warnedVersion = True
- return
-
-#
-# parse(tokens):
-#
-
-ifResult = False
-
-def parse(tokens):
- global MHX249, ifResult, theScale, defaultScale, One
-
- for (key, val, sub) in tokens:
- # print("Parse %s" % key)
- data = None
- if key == 'MHX':
- checkMhxVersion(int(val[0]), int(val[1]))
- elif key == 'MHX249':
- MHX249 = eval(val[0])
- print("Blender 2.49 compatibility mode is %s\n" % MHX249)
- elif MHX249:
- pass
- elif key == 'print':
- msg = concatList(val)
- print(msg)
- elif key == 'warn':
- msg = concatList(val)
- print(msg)
- elif key == 'error':
- msg = concatList(val)
- raise NameError(msg)
- elif key == 'NoScale':
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list