예제 #1
0
def writeTextures(stuffs, outDir, progressCallback = None):
    def progress(prog):
        if progressCallback == None:
            gui3d.app.progress(prog)
        else:
            progressCallback(prog)
    progress(0)
    
    i = 0.0
    stuffnum = float(len(stuffs))
    for stuff in stuffs:
        if stuff.textureImage:
            teximg = stuff.textureImage
        elif stuff.texture:
            teximg = mh.Image(path = collect.getpath(stuff.texture))
        # Export diffuse texture, with subtextures.
        teximg.save(os.path.join(
            outDir,"%s_texture.png" % stuff.name))
        progress((i+0.4)/stuffnum)
        # Export transparency map.
        imgop.getAlpha(teximg).save(path = os.path.join(outDir,"%s_alpha.png" % stuff.name))
        progress((i+0.8)/stuffnum)
        # Export bump map.
        if stuff.bump:
            collect.copy(stuff.bump, os.path.join(
                outDir, "%s_bump.%s" % (stuff.name,(
                    stuff.bump[1].split("."))[1])))
        elif stuff.displacement:
            collect.copy(stuff.displacement, os.path.join(
                outDir, "%s_bump.%s" % (stuff.name,(
                    stuff.displacement[1].split("."))[1])))
        i += 1.0
        progress(i/stuffnum)
예제 #2
0
def writeTextures(stuffs, outDir, progressCallback=None):
    def progress(prog):
        if progressCallback == None:
            gui3d.app.progress(prog)
        else:
            progressCallback(prog)

    progress(0)

    i = 0.0
    stuffnum = float(len(stuffs))
    for stuff in stuffs:
        if stuff.textureImage:
            teximg = stuff.textureImage
        elif stuff.texture:
            teximg = mh.Image(path=collect.getpath(stuff.texture))
        # Export diffuse texture, with subtextures.
        teximg.save(os.path.join(outDir, "%s_texture.png" % stuff.name))
        progress((i + 0.4) / stuffnum)
        # Export transparency map.
        imgop.getAlpha(teximg).save(
            path=os.path.join(outDir, "%s_alpha.png" % stuff.name))
        progress((i + 0.8) / stuffnum)
        # Export bump map.
        if stuff.bump:
            collect.copy(
                stuff.bump,
                os.path.join(
                    outDir, "%s_bump.%s" % (stuff.name,
                                            (stuff.bump[1].split("."))[1])))
        elif stuff.displacement:
            collect.copy(
                stuff.displacement,
                os.path.join(
                    outDir,
                    "%s_bump.%s" % (stuff.name,
                                    (stuff.displacement[1].split("."))[1])))
        i += 1.0
        progress(i / stuffnum)
예제 #3
0
def povrayExportArray(obj, camera, path, settings):
    """
    This function exports data in the form of arrays of data the can be used to 
    reconstruct a humanoid object using some very simple POV-Ray macros. These macros 
    can build this data into a variety of different POV-Ray objects, including a
    mesh2 object that represents the human figure much as it was displayed in MakeHuman. 

    These macros can also generate a union of spheres at the vertices and a union of 
    cylinders that follow the edges of the mesh. A parameter on the mesh2 macro can be 
    used to generate a slightly inflated or deflated mesh. 

    The generated output file always starts with a standard header, is followed by a set 
    of array definitions containing the object data and is ended by a standard set of 
    POV-Ray object definitions. 

    Parameters
    ----------

    obj:
      *3D object*. The object to export. This should be the humanoid object with
      uv-mapping data and Face Groups defined.

    camera:
      *Camera object*. The camera to render from. 

    path:
      *string*. The file system path to the output files that need to be generated. 
    """

    # Certain files and blocks of SDL are mostly static and can be copied directly
    # from reference files into the generated output directories or files.

    headerFile = 'data/povray/headercontent.inc'
    staticFile = 'data/povray/staticcontent.inc'
    sceneFile = 'data/povray/makehuman.pov'
    groupingsFile = 'data/povray/makehuman_groupings.inc'
    pigmentMap = gui3d.app.selectedHuman.mesh.texture

    # Define some additional file related strings

    outputSceneFile = path.replace('.inc', '.pov')
    baseName = os.path.basename(path)
    nameOnly = string.replace(baseName, '.inc', '')
    underScores = ''.ljust(len(baseName), '-')
    outputDirectory = os.path.dirname(path)

    # Make sure the directory exists

    if not os.path.isdir(outputDirectory):
        try:
            os.makedirs(outputDirectory)
        except:
            log.error('Error creating export directory.')
            return 0

# Open the output file in Write mode

    try:
        outputFileDescriptor = open(path, 'w')
    except:
        log.error('Error opening file to write data.')
        return 0

# Write the file name into the top of the comment block that starts the file.

    outputFileDescriptor.write('// %s\n' % baseName)
    outputFileDescriptor.write('// %s\n' % underScores)

    # Copy the header file SDL straight across to the output file

    try:
        headerFileDescriptor = open(headerFile, 'r')
    except:
        log.error('Error opening file to read standard headers.')
        return 0
    headerLines = headerFileDescriptor.read()
    outputFileDescriptor.write(headerLines)
    outputFileDescriptor.write('''

''')
    headerFileDescriptor.close()

    # Declare POV_Ray variables containing the current makehuman camera.

    povrayCameraData(camera, resolution, outputFileDescriptor)

    outputFileDescriptor.write('#declare MakeHuman_TranslateX      = %s;\n' %
                               -obj.x)
    outputFileDescriptor.write('#declare MakeHuman_TranslateY      = %s;\n' %
                               obj.y)
    outputFileDescriptor.write('#declare MakeHuman_TranslateZ      = %s;\n\n' %
                               obj.z)

    outputFileDescriptor.write('#declare MakeHuman_RotateX         = %s;\n' %
                               obj.rx)
    outputFileDescriptor.write('#declare MakeHuman_RotateY         = %s;\n' %
                               -obj.ry)
    outputFileDescriptor.write('#declare MakeHuman_RotateZ         = %s;\n\n' %
                               obj.rz)

    # Calculate some useful values and add them to the output as POV-Ray variable
    # declarations so they can be readily accessed from a POV-Ray scene file.

    povraySizeData(obj, outputFileDescriptor)

    # Collect and prepare all objects.
    stuffs = collect.setupObjects(settings['name'],
                                  gui3d.app.selectedHuman,
                                  helpers=False,
                                  hidden=False,
                                  eyebrows=False,
                                  lashes=False,
                                  subdivide=settings['subdivide'])

    # Write array data for the object.
    povrayWriteArray(outputFileDescriptor, stuffs)

    # Copy macro and texture definitions straight across to the output file.

    try:
        staticContentFileDescriptor = open(staticFile, 'r')
    except:
        log.error('Error opening file to read static content.')
        return 0
    staticContentLines = staticContentFileDescriptor.read()
    outputFileDescriptor.write(staticContentLines)
    outputFileDescriptor.write('\n')
    staticContentFileDescriptor.close()

    # The POV-Ray include file is complete

    outputFileDescriptor.close()
    log.message("POV-Ray '#include' file generated.")

    # Copy a sample scene file across to the output directory

    try:
        sceneFileDescriptor = open(sceneFile, 'r')
    except:
        log.error('Error opening file to read standard scene file.')
        return 0
    try:
        outputSceneFileDescriptor = open(outputSceneFile, 'w')
    except:
        log.error('Error opening file to write standard scene file.')
        return 0
    sceneLines = sceneFileDescriptor.read()
    sceneLines = string.replace(sceneLines, 'xxFileNamexx', nameOnly)
    sceneLines = string.replace(sceneLines, 'xxUnderScoresxx', underScores)
    sceneLines = string.replace(sceneLines, 'xxLowercaseFileNamexx',
                                nameOnly.lower())
    outputSceneFileDescriptor.write(sceneLines)

    # Copy the skin texture file into the output directory
    collect.copy(pigmentMap, os.path.join(outputDirectory, "texture.png"))

    # Copy the makehuman_groupings.inc file into the output directory

    try:
        shutil.copy(groupingsFile, outputDirectory)
    except (IOError, os.error), why:
        log.error("Can't copy %s" % str(why))
예제 #4
0
def povrayExportArray(obj, camera, path, settings):
    """
    This function exports data in the form of arrays of data the can be used to
    reconstruct a humanoid object using some very simple POV-Ray macros. These macros
    can build this data into a variety of different POV-Ray objects, including a
    mesh2 object that represents the human figure much as it was displayed in MakeHuman.

    These macros can also generate a union of spheres at the vertices and a union of
    cylinders that follow the edges of the mesh. A parameter on the mesh2 macro can be
    used to generate a slightly inflated or deflated mesh.

    The generated output file always starts with a standard header, is followed by a set
    of array definitions containing the object data and is ended by a standard set of
    POV-Ray object definitions.

    Parameters
    ----------

    obj:
      *3D object*. The object to export. This should be the humanoid object with
      uv-mapping data and Face Groups defined.

    camera:
      *Camera object*. The camera to render from.

    path:
      *string*. The file system path to the output files that need to be generated.
    """

  # Certain files and blocks of SDL are mostly static and can be copied directly
  # from reference files into the generated output directories or files.

    headerFile = mh.getSysDataPath('povray/headercontent.inc')
    staticFile = mh.getSysDataPath('povray/staticcontent.inc')
    sceneFile = mh.getSysDataPath('povray/makehuman.pov')
    groupingsFile = mh.getSysDataPath('povray/makehuman_groupings.inc')
    pigmentMap = gui3d.app.selectedHuman.mesh.texture

  # Define some additional file related strings

    outputSceneFile = path.replace('.inc', '.pov')
    baseName = os.path.basename(path)
    nameOnly = string.replace(baseName, '.inc', '')
    underScores = ''.ljust(len(baseName), '-')
    outputDirectory = os.path.dirname(path)

  # Make sure the directory exists

    if not os.path.isdir(outputDirectory):
        try:
            os.makedirs(outputDirectory)
        except:
            log.error('Error creating export directory.')
            return 0

  # Open the output file in Write mode

    try:
        outputFileDescriptor = open(path, 'w')
    except:
        log.error('Error opening file to write data.')
        return 0

  # Write the file name into the top of the comment block that starts the file.

    outputFileDescriptor.write('// %s\n' % baseName)
    outputFileDescriptor.write('// %s\n' % underScores)

  # Copy the header file SDL straight across to the output file

    try:
        headerFileDescriptor = open(headerFile, 'r')
    except:
        log.error('Error opening file to read standard headers.')
        return 0
    headerLines = headerFileDescriptor.read()
    outputFileDescriptor.write(headerLines)
    outputFileDescriptor.write('''

''')
    headerFileDescriptor.close()

  # Declare POV_Ray variables containing the current makehuman camera.

    povrayCameraData(camera, resolution, outputFileDescriptor)

    outputFileDescriptor.write('#declare MakeHuman_TranslateX      = %s;\n' % -obj.x)
    outputFileDescriptor.write('#declare MakeHuman_TranslateY      = %s;\n' % obj.y)
    outputFileDescriptor.write('#declare MakeHuman_TranslateZ      = %s;\n\n' % obj.z)

    outputFileDescriptor.write('#declare MakeHuman_RotateX         = %s;\n' % obj.rx)
    outputFileDescriptor.write('#declare MakeHuman_RotateY         = %s;\n' % -obj.ry)
    outputFileDescriptor.write('#declare MakeHuman_RotateZ         = %s;\n\n' % obj.rz)

  # Calculate some useful values and add them to the output as POV-Ray variable
  # declarations so they can be readily accessed from a POV-Ray scene file.

    povraySizeData(obj, outputFileDescriptor)

    # Collect and prepare all objects.
    rmeshes,_amt = collect.setupObjects(settings['name'], gui3d.app.selectedHuman, helpers=False, hidden=False,
                                            eyebrows=False, lashes=False, subdivide = settings['subdivide'])

    # Write array data for the object.
    povrayWriteArray(outputFileDescriptor, rmeshes)

  # Copy macro and texture definitions straight across to the output file.

    try:
        staticContentFileDescriptor = open(staticFile, 'r')
    except:
        log.error('Error opening file to read static content.')
        return 0
    staticContentLines = staticContentFileDescriptor.read()
    outputFileDescriptor.write(staticContentLines)
    outputFileDescriptor.write('\n')
    staticContentFileDescriptor.close()

  # The POV-Ray include file is complete

    outputFileDescriptor.close()
    log.message("POV-Ray '#include' file generated.")

  # Copy a sample scene file across to the output directory

    try:
        sceneFileDescriptor = open(sceneFile, 'r')
    except:
        log.error('Error opening file to read standard scene file.')
        return 0
    try:
        outputSceneFileDescriptor = open(outputSceneFile, 'w')
    except:
        log.error('Error opening file to write standard scene file.')
        return 0
    sceneLines = sceneFileDescriptor.read()
    sceneLines = string.replace(sceneLines, 'xxFileNamexx', nameOnly)
    sceneLines = string.replace(sceneLines, 'xxUnderScoresxx', underScores)
    sceneLines = string.replace(sceneLines, 'xxLowercaseFileNamexx', nameOnly.lower())
    outputSceneFileDescriptor.write(sceneLines)

    # Copy the skin texture file into the output directory
    collect.copy(pigmentMap, os.path.join(outputDirectory, "texture.png"))


  # Copy the makehuman_groupings.inc file into the output directory

    try:
        shutil.copy(groupingsFile, outputDirectory)
    except (IOError, os.error) as why:
        log.error("Can't copy %s" % str(why))

  # Job done

    outputSceneFileDescriptor.close()
    sceneFileDescriptor.close()
    log.message('Sample POV-Ray scene file generated.')