--- Horde3DExport.py.orig Wed Jun 16 18:00:30 2010 +++ Horde3DExport.py Wed Jun 16 17:58:03 2010 @@ -80,6 +80,7 @@ # GUI buttons : fileButton = Draw.Create('') +baseButton = Draw.Create('') shaderButton = Draw.Create('') textureButton = Draw.Create('') materialButton = Draw.Create('') @@ -96,12 +97,13 @@ exitButton = Draw.Create('') def updateRegistry(): - global fileButton, shaderButton, textureButton, materialButton, animationButton, texPathButton + global fileButton, baseButton, shaderButton, textureButton, materialButton, animationButton, texPathButton global exportMaterialsButton, exportAnimationsButton, exportGeometryButton, exportSceneButton global consoleWarningsButton hordeReg = {} hordeReg['path'] = fileButton.val + hordeReg['base'] = baseButton.val hordeReg['shader'] = shaderButton.val hordeReg['texSub'] = textureButton.val hordeReg['matPath'] = materialButton.val @@ -117,7 +119,7 @@ Blender.Registry.SetKey('horde', hordeReg, True) def draw(): - global fileButton, shaderButton, textureButton, materialButton, animationButton, texPathButton + global fileButton, baseButton, shaderButton, textureButton, materialButton, animationButton, texPathButton global exportMaterialsButton, exportAnimationsButton, exportGeometryButton, exportSceneButton global consoleWarningsButton @@ -136,10 +138,13 @@ glRasterPos2d(8, 83) # Text entry buttons : - Draw.Label('Export filename:', 10, size[1]/2+100, 100, 20) - fileButton = Draw.String('', EVENT_BUTTONCHANGE, 210, size[1]/2+100, 400, 20, fileButton.val, 255, 'Filename') - Draw.Button('...', EVENT_BROWSE, 610, size[1]/2+100, 30, 20) + Draw.Label('Export filename:', 10, size[1]/2+140, 100, 20) + fileButton = Draw.String('', EVENT_BUTTONCHANGE, 210, size[1]/2+140, 400, 20, fileButton.val, 255, 'Filename') + Draw.Button('...', EVENT_BROWSE, 610, size[1]/2+140, 30, 20) + Draw.Label('Base path:', 10, size[1]/2+100, 200, 20) + baseButton = Draw.String('', EVENT_BUTTONCHANGE, 210, size[1]/2+100, 200, 20, baseButton.val, 255, 'Base path') + Draw.Label('Shader:', 10, size[1]/2+60, 100, 20) shaderButton = Draw.String('', EVENT_BUTTONCHANGE, 210, size[1]/2+60, 200, 20, shaderButton.val, 255, 'Shader') @@ -179,7 +184,7 @@ Draw.Exit() def bevent(evt): - global fileButton, shaderButton, textureButton, materialButton, animationButton, texPathButton + global fileButton, baseButton, shaderButton, textureButton, materialButton, animationButton, texPathButton global exportMaterialsButton, exportAnimationsButton, exportGeometryButton, exportSceneButton global consoleWarningsButton global EVENT_NOEVENT, EVENT_EXPORT, EVENT_EXIT, EVENT_BROWSE, EVENT_BUTTONCHANGE @@ -201,7 +206,7 @@ startTime = Blender.sys.time() - success = Export(fileButton.val, shaderButton.val, textureButton.val, + success = Export(fileButton.val, baseButton.val, shaderButton.val, textureButton.val, texPathButton.val, materialButton.val, animationButton.val, exportMaterialsButton.val, exportAnimationsButton.val, exportGeometryButton.val, exportSceneButton.val) @@ -231,7 +236,7 @@ def main(): if not _ERROR: - global fileButton, shaderButton, textureButton, materialButton, animationButton, texPathButton + global fileButton, baseButton, shaderButton, textureButton, materialButton, animationButton, texPathButton global exportMaterialsButton, exportAnimationsButton, exportGeometryButton, exportSceneButton global consoleWarningsButton @@ -243,6 +248,8 @@ # - text entry buttons : if not 'path' in hordeReg: hordeReg['path'] = Blender.sys.dirname(Blender.sys.progname) + Blender.sys.sep + DEFAULT_SCENE_NAME + if not 'base' in hordeReg: + hordeReg['base'] = '..' if not 'shader' in hordeReg: hordeReg['shader'] = DEFAULT_SHADER_NAME if not 'texSub' in hordeReg: @@ -267,6 +274,7 @@ hordeReg['consoleWarnings'] = 1 fileButton.val = hordeReg['path'] + baseButton.val = hordeReg['base'] shaderButton.val = hordeReg['shader'] textureButton.val = hordeReg['texSub'] materialButton.val = hordeReg['matPath'] @@ -293,7 +301,7 @@ ###################################################### # Export Main ###################################################### -def Export(path, defShader, texturesub, texPath, matPath, animPath, exportMat, exportAnim, exportGeo, exportScene): +def Export(path, basePath, defShader, texturesub, texPath, matPath, animPath, exportMat, exportAnim, exportGeo, exportScene): # Show the wait cursor in blender and stop editing mode Blender.Window.WaitCursor(1) @@ -310,6 +318,7 @@ texSubPath = texturesub + Blender.sys.sep # Get absolute pathes + basePath = os.path.realpath(os.path.join(dir, basePath)) + Blender.sys.sep if texPath != '': texPath = dir+texPath+Blender.sys.sep+texSubPath if matPath != '': @@ -339,7 +348,7 @@ # Get current scene and objects scn = Blender.Scene.GetCurrent() - converter = Converter(path, texSubPath, texPath, matPath, animPath) + converter = Converter(path, basePath, texSubPath, texPath, matPath, animPath) print "Converting model..." if converter.convertModel( scn ) == False: @@ -470,7 +479,7 @@ ###################################################### class Converter(): - def __init__(self, path, sub, texPath, matPath, animPath): + def __init__(self, path, basePath, sub, texPath, matPath, animPath): self.__vertices = [] self.__meshes = [] self.__joints = [] @@ -482,6 +491,7 @@ self.__bObjects = [] self.__materials = {} self.__filePath = path + self.__basePath = basePath self.__texSubPath = sub self.__texPath = texPath self.__matPath = matPath @@ -1048,7 +1058,7 @@ if exportScene: # Write model header - sceneFile.write('\n' % (fileName, fileName) ) + sceneFile.write('\n' % (fileName, os.path.relpath(fileName, self.__basePath) ) ) # Write morph target names as comment if len(self.__morphTargets) > 0: @@ -1290,7 +1300,7 @@ t = roundVec(mesh.matRel.translationPart()) mat = ' ' if mesh.material != None: - mat = fileName+'/'+self.__materials[mesh.material]['name']+".material.xml" + mat = os.path.relpath(self.__matPath + fileName+'/'+self.__materials[mesh.material]['name']+".material.xml", self.__basePath) else: printWarning("no material found for mesh: "+mesh.name) @@ -1368,7 +1378,7 @@ matFile.write('\n') matFile.write('\t\n\n' % defShader) for tex in self.__materials[mat]['textures']: - matFile.write('\t\n' % tex[1]) + matFile.write('\t\n' % os.path.relpath(self.__texPath + tex[1], self.__basePath)) if self.__materials[mat]['uniform'] != None: color = tuple(self.__materials[mat]['uniform']) name = [self.__materials[mat]['name']+'col']