Exemplo n.º 1
0
    def projectLighting(self):
        dstImg = projection.mapLighting()
        # dstImg.resize(128, 128)
        dstImg.save(os.path.join(mh.getPath(""), "data", "skins", "lighting.png"))

        gui3d.app.selectedHuman.setTexture(os.path.join(mh.getPath(""), "data", "skins", "lighting.png"))
        log.debug("Enabling shadeless rendering on body")
        gui3d.app.selectedHuman.mesh.setShadeless(1)  # Remember to reset this when lighting projection is done.
Exemplo n.º 2
0
    def export(self, human, filename):
        import projection

        dstImg = projection.mapLighting()
        filepath = filename("png")
        dstImg.save(filepath)

        if self.lightmapDisplay:
            import log
            human.setTexture(filepath)
            log.message("Enabling shadeless rendering on body")
            human.mesh.setShadeless(True)
    def projectLighting(self):
        dstImg = projection.mapLighting()
        #dstImg.resize(128, 128)
        texPath = os.path.join(mh.getPath(''), 'data', 'skins', 'lighting.png')
        if os.path.isfile(texPath):
            oldImg = mh.Image(texPath)
        else:
            oldImg = None

        gui3d.app.do(ProjectionAction("Change projected lighting texture",
                gui3d.app.selectedHuman.getTexture(),
                texPath,
                oldImg,
                dstImg))
        log.debug("Enabling shadeless rendering on body")
        self.shadelessButton.setChecked(True)
        gui3d.app.selectedHuman.mesh.setShadeless(1)
Exemplo n.º 4
0
    def export(self, human, filename):
        import projection

        dstImg = projection.mapLighting()
        filepath = filename("png")
        dstImg.save(filepath)
Exemplo n.º 5
0
    def projectLighting(self):

        dstImg = projection.mapLighting()
        #dstImg.resize(128, 128);

        dstImg.save(getPath('data/skins/lighting.png'))
Exemplo n.º 6
0
    def projectLighting(self):

            dstImg = projection.mapLighting()
            #dstImg.resize(128, 128);

            dstImg.save(getPath('data/skins/lighting.png'))
Exemplo n.º 7
0
    def export(self, human, filename):
        import projection

        dstImg = projection.mapLighting()
        filepath = filename("png")
        dstImg.save(filepath)
Exemplo n.º 8
0
    def projectLighting(self):

            dstImg = projection.mapLighting()
            #dstImg.resize(128, 128);

            dstImg.save(os.path.join(mh.getPath(''), 'data', 'skins', 'lighting.png'))
Exemplo n.º 9
0
def povrayExportMesh2_TL(obj, camera, resolution, path, settings, progressCallback = None):
    """
    This function exports data in the form of a mesh2 humanoid object. The POV-Ray 
    file generated is fairly inflexible, but is highly efficient. 

    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.

    settings:
      *dictionary*. Settings passed from the GUI.
    """

    progbase = 0
    def progress (base, prog, desc):
        if progressCallback == None:
            gui3d.app.progress(base + prog, desc)
        else:
            progressCallback(base + prog, desc)

    # Certain blocks of SDL are mostly static and can be copied directly from reference
    # files into the output files.
    progress (progbase,0,"Parsing data")
    progbase = progbase + 0.05
    headerFile = 'data/povray/headercontent_mesh2only.inc'
    staticFile = 'data/povray/staticcontent_mesh2only_fsss.inc' if settings['SSS'] == True else 'data/povray/staticcontent_mesh2only_tl.inc'
    sceneFile = 'data/povray/makehuman_mesh2only_tl.pov'
    pigmentMap = gui3d.app.selectedHuman.mesh.texture

    # Define some additional file locations
    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

    # If fake SSS is enabled, render lightmaps there. # TODO: if they aren't already rendered.
    if settings['SSS'] == True:
        # calculate resolution of each cannel, according to settings
        resred = float(settings['SSSA'])
        resgreen = int(2.0**(10-resred/2))
        resred = int(2.0**(10-resred))
        # blue channel
        lmap = projection.mapLighting(progressCallback = lambda p: progress(progbase,p*(0.55-progbase),"Rendering lightmaps"))
        log.debug('SSS: Hi-Res lightmap resolution: %s', lmap.width)
        lmap.save(os.path.join(outputDirectory, 'lighthi.png'))
        # green channel
        lmap.resize(resgreen,resgreen)
        log.debug('SSS: Mid-Res lightmap resolution: %s', lmap.width)
        lmap.save(os.path.join(outputDirectory, 'lightmid.png'))
        # red channel
        lmap.resize(resred,resred)
        log.debug('SSS: Low-Res lightmap resolution: %s', lmap.width)
        lmap.save(os.path.join(outputDirectory, 'lightlo.png'))
        progbase = 0.55

    # Open the output file in Write mode
    progress(progbase,0,"Writing code")
    progbase = progbase + 0.5
    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, settings)
    
    # Declare POV Ray variables containing the current object position and rotation.
    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)

    stuffs = object_collection.setupObjects("MakeHuman", gui3d.app.selectedHuman, helpers=False, hidden=False,
                                            eyebrows=False, lashes=False, subdivide = settings['subdivide'],
                                            progressCallback = lambda p: progress(progbase,p*(0.75-progbase),"Preparing Objects"))
    progbase = 0.75

    # Mesh2 Object - Write the initial part of the mesh2 object declaration
    progress(progbase,0,"Writing objects")
    for stuff in stuffs:

        outputFileDescriptor.write('// Humanoid mesh2 definition\n')
        outputFileDescriptor.write('#declare %s_Mesh2Object = mesh2 {\n' % stuff.name)

        # Vertices - Write a POV-Ray array to the output stream
        outputFileDescriptor.write('  vertex_vectors {\n  ')
        outputFileDescriptor.write('    %s\n  ' % len(stuff.meshInfo.verts))

        for v in stuff.meshInfo.verts:
            outputFileDescriptor.write('<%s,%s,%s>' % (-v[0],v[1],v[2]))
        outputFileDescriptor.write('''
  }

''')

        # Normals - Write a POV-Ray array to the output stream
        outputFileDescriptor.write('  normal_vectors {\n  ')
        outputFileDescriptor.write('    %s\n  ' % len(stuff.meshInfo.verts))
        for vno in stuff.meshInfo.vnormals:
            outputFileDescriptor.write('<%s,%s,%s>' % (-vno[0],vno[1],vno[2]))

        outputFileDescriptor.write('''
  }

''')
    
        # UV Vectors - Write a POV-Ray array to the output stream
        outputFileDescriptor.write('  uv_vectors {\n  ')
        outputFileDescriptor.write('    %s\n  ' % len(stuff.meshInfo.uvValues))
        for uv in stuff.meshInfo.uvValues:
            outputFileDescriptor.write('<%s,%s>' % tuple(uv))        

        outputFileDescriptor.write('''
  }

''')

        # Faces - Write a POV-Ray array of arrays to the output stream
        nTriangles = 0
        for f in stuff.meshInfo.faces:
            nTriangles += len(f)-2

        outputFileDescriptor.write('  face_indices {\n  ')
        outputFileDescriptor.write('    %s\n  ' % nTriangles)

        for f in stuff.meshInfo.faces:
            verts = []
            for v,vt in f:
                verts.append(v)
            outputFileDescriptor.write('<%s,%s,%s>' % (verts[0], verts[1], verts[2]))
            if len(verts) == 4:
                outputFileDescriptor.write('<%s,%s,%s>' % (verts[2], verts[3], verts[0]))

        outputFileDescriptor.write('''
  }

''')


        # UV Indices for each face - Write a POV-Ray array to the output stream
        outputFileDescriptor.write('  uv_indices {\n  ')
        outputFileDescriptor.write('    %s\n  ' % nTriangles)

        for f in stuff.meshInfo.faces:
            vts = []
            for v,vt in f:
                vts.append(vt)        
            outputFileDescriptor.write('<%s,%s,%s>' % (vts[0], vts[1], vts[2]))
            if len(vts) == 4:
                outputFileDescriptor.write('<%s,%s,%s>' % (vts[2], vts[3], vts[0]))

        outputFileDescriptor.write('''
  }
''')

        # Mesh2 Object - Write the end squiggly bracket for the mesh2 object declaration
        outputFileDescriptor.write('''
      uv_mapping
''')
        outputFileDescriptor.write('''}

''')
    progbase = 0.85
                                            
    # Copy texture definitions to the output file.
    progress(progbase,0,"Writing Materials")
    try:
        staticContentFileDescriptor = open(staticFile, 'r')
    except:
        log.error('Error opening file to read static content.')
        return 0
    staticContentLines = staticContentFileDescriptor.read()
    staticContentLines = string.replace(staticContentLines, '%%skinoil%%', str(settings['skinoil']))    
    staticContentLines = string.replace(staticContentLines, '%%rough%%', str(settings['rough']))    
    staticContentLines = string.replace(staticContentLines, '%%wrinkles%%', str(settings['wrinkles']))    
    outputFileDescriptor.write(staticContentLines)
    outputFileDescriptor.write('\n')
    staticContentFileDescriptor.close()
    
    # Write items' materials 
    writeItemsMaterials(outputFileDescriptor, stuffs, settings, outputDirectory)
             
    # The POV-Ray include file is complete
    outputFileDescriptor.close()
    log.message("POV-Ray '#include' file generated.")
    progbase = 0.95

    # Copy a sample scene file across to the output directory
    progress(progbase,0,"Writing Scene file")
    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)
    
    for stuff in stuffs:
        outputSceneFileDescriptor.write(
            "object { \n" +
            "   %s_Mesh2Object \n" % stuff.name +
            "   rotate <0, 0, MakeHuman_RotateZ> \n" +
            "   rotate <0, MakeHuman_RotateY, 0> \n" +
            "   rotate <MakeHuman_RotateX, 0, 0> \n" +
            "   translate <MakeHuman_TranslateX, MakeHuman_TranslateY, MakeHuman_TranslateZ> \n" +
            "   material {%s_Material} \n" % stuff.name +
            "}  \n")

    # Job done, clean up
    outputSceneFileDescriptor.close()
    sceneFileDescriptor.close()
    progbase = 1

    # Copy the skin texture file into the output directory
    progress(progbase,0,"Finishing")
    copyFile(pigmentMap, os.path.join(outputDirectory, "texture.png"))

    for stuff in stuffs[1:]:
        if stuff.texture:
            copyFile(stuff.texture, outputDirectory)
        """
        if proxy.normal:
            copyFile(proxy.normal, outputDirectory)
        if proxy.bump:
            copyFile(proxy.bump, outputDirectory)
        if proxy.displacement:
            copyFile(proxy.displacement, outputDirectory)
        if proxy.transparency:
            copyFile(proxy.transparency, outputDirectory)
        """

    log.message('Sample POV-Ray scene file generated')
    progress(0,0,"Finished. Pov-Ray project exported successfully at %s" % outputDirectory)