Exemplo n.º 1
0
 def onShow(self, event):
     RenderTaskView.onShow(self, event)
     self.renderButton.setFocus()
     if not mh.hasRenderToRenderbuffer() and self.firstTimeWarn:
         self.firstTimeWarn = False
         G.app.prompt('Lack of 3D hardware support',
             'Your graphics card lacks support for proper rendering.\nOnly limited functionality will be available.',
             'Ok', None, None, None, 'renderingGPUSupportWarning')
Exemplo n.º 2
0
 def onShow(self, event):
     RenderTaskView.onShow(self, event)
     self.renderButton.setFocus()
     if not mh.hasRenderToRenderbuffer() and self.firstTimeWarn:
         self.firstTimeWarn = False
         G.app.prompt('Lack of 3D hardware support',
             'Your graphics card lacks support for proper rendering.\nOnly limited functionality will be available.',
             'Ok', None, None, None, 'renderingGPUSupportWarning')
Exemplo n.º 3
0
def my_render(settings=None):
    if settings is None:
        settings = {'AA': True, 'lightmapSSS': False, 'scene': G.app.scene, 'dimensions': (230, 230)}

    if settings['lightmapSSS']:
        human = G.app.selectedHuman
        material_backup = material.Material(human.material)

        diffuse = imgop.Image(data=human.material.diffuseTexture)
        lmap = projection.mapSceneLighting(settings['scene'], border=human.material.sssRScale)
        lmapG = imgop.blurred(lmap, human.material.sssGScale, 13)
        lmapR = imgop.blurred(lmap, human.material.sssRScale, 13)
        lmap = imgop.compose([lmapR, lmapG, lmap])

        if not diffuse.isEmpty:
            lmap = imgop.resized(lmap, diffuse.width, diffuse.height, filter=image.FILTER_BILINEAR)
            lmap = imgop.multiply(lmap, diffuse)
            lmap.sourcePath = "Internal_Renderer_Lightmap_SSS_Texture"

        human.material.diffuseTexture = lmap
        human.configureShading(diffuse=True)
        human.shadeless = True

    if not mh.hasRenderToRenderbuffer():
        img = mh.grabScreen(0, 0, G.windowWidth, G.windowHeight)
        alphaImg = None
    else:
        width, height = settings['dimensions']
        if settings['AA']:
            width *= 2
            height *= 2

            img = mh.renderToBuffer(width, height)
            alphaImg = mh.renderAlphaMask(width, height)
            img = imgop.addAlpha(img, imgop.getChannel(alphaImg, 0))

        if settings['AA']:
            img = img.resized(width/2, height/2, filter=image.FILTER_BILINEAR)
            img.data[:, :, :] = img.data[:, :, (2, 1, 0, 3)]

    if settings['lightmapSSS']:
        human.material = material_backup

    return img
Exemplo n.º 4
0
    def __init__(self, category):
        RenderTaskView.__init__(self, category, 'Socket Render')

        # Declare settings
        G.app.addSetting('GL_RENDERER_SSS', False)
        G.app.addSetting('GL_RENDERER_AA', True)

        # Don't change shader for this RenderTaskView.
        self.taskViewShader = G.app.selectedHuman.material.shader

        settingsBox = self.addLeftWidget(gui.GroupBox('Settings'))

        self.renderButton = settingsBox.addWidget(gui.Button('Socket Render'))

        if not mh.hasRenderToRenderbuffer():
            self.firstTimeWarn = True

        @self.renderButton.mhEvent
        def onClicked(event):
            # do socket ops here
            mh_server.do_op()
Exemplo n.º 5
0
    def __init__(self, category):
        RenderTaskView.__init__(self, category, 'Render')

        # Declare settings
        G.app.addSetting('GL_RENDERER_SSS', False)
        G.app.addSetting('GL_RENDERER_AA', True)

        # Don't change shader for this RenderTaskView.
        self.taskViewShader = G.app.selectedHuman.material.shader

        settingsBox = self.addLeftWidget(gui.GroupBox('Settings'))
        settingsBox.addWidget(gui.TextView("Resolution"))
        self.resBox = settingsBox.addWidget(gui.TextEdit(
            "x".join([str(self.renderingWidth), str(self.renderingHeight)])))
        self.AAbox = settingsBox.addWidget(gui.CheckBox("Anti-aliasing"))
        self.AAbox.setSelected(G.app.getSetting('GL_RENDERER_AA'))
        self.renderButton = settingsBox.addWidget(gui.Button('Render'))

        self.lightmapSSS = gui.CheckBox("Lightmap SSS")
        self.lightmapSSS.setSelected(G.app.getSetting('GL_RENDERER_SSS'))

        self.optionsBox = self.addLeftWidget(gui.GroupBox('Options'))
        self.optionsWidgets = []

        renderMethodBox = self.addRightWidget(gui.GroupBox('Rendering methods'))
        self.renderMethodList = renderMethodBox.addWidget(gui.ListView())
        self.renderMethodList.setSizePolicy(
            gui.SizePolicy.Ignored, gui.SizePolicy.Preferred)

        # Rendering methods
        self.renderMethodList.addItem('Quick Render')
        self.renderMethodList.addItem('Advanced Render',
            data=[self.lightmapSSS])

        if not mh.hasRenderToRenderbuffer():
            self.firstTimeWarn = True
            # Can only use screen grabbing as fallback,
            # resolution option disabled
            self.resBox.setEnabled(False)
            self.AAbox.setEnabled(False)

        self.listOptions(None)

        @self.resBox.mhEvent
        def onChange(value):
            try:
                value = value.replace(" ", "")
                res = [int(x) for x in value.split("x")]
                self.renderingWidth = res[0]
                self.renderingHeight = res[1]
            except:  # The user hasn't typed the value correctly yet.
                pass

        @self.AAbox.mhEvent
        def onClicked(value):
            G.app.setSetting('GL_RENDERER_AA', self.AAbox.selected)

        @self.lightmapSSS.mhEvent
        def onClicked(value):
            G.app.setSetting('GL_RENDERER_SSS', self.lightmapSSS.selected)

        @self.renderMethodList.mhEvent
        def onClicked(item):
            self.listOptions(item.getUserData())

        @self.renderButton.mhEvent
        def onClicked(event):
            settings = dict()
            settings['scene'] = G.app.scene
            settings['AA'] = self.AAbox.selected
            settings['dimensions'] = (self.renderingWidth, self.renderingHeight)
            settings['lightmapSSS'] = self.lightmapSSS.selected and self.lightmapSSS in self.optionsWidgets

            mh2opengl.Render(settings)
Exemplo n.º 6
0
    def __init__(self, category):
        RenderTaskView.__init__(self, category, 'Classification Images Render')

        # Declare settings
        G.app.addSetting('GL_RENDERER_SSS', False)
        G.app.addSetting('GL_RENDERER_AA', True)

        # Don't change shader for this RenderTaskView.
        self.taskViewShader = G.app.selectedHuman.material.shader

        settingsBox = self.addLeftWidget(gui.GroupBox('Settings'))
        settingsBox.addWidget(gui.TextView("Resolution"))
        self.resBox = settingsBox.addWidget(
            gui.TextEdit("x".join(
                [str(self.renderingWidth),
                 str(self.renderingHeight)])))
        self.AAbox = settingsBox.addWidget(gui.CheckBox("Anti-aliasing"))
        self.AAbox.setSelected(G.app.getSetting('GL_RENDERER_AA'))

        self.path = ""
        self.path_button = settingsBox.addWidget(
            gui.BrowseButton('dir', "Select an output directory"))
        self.pathBox = settingsBox.addWidget(gui.TextEdit(self.path))

        @self.path_button.mhEvent
        def onClicked(path):
            self.path = path
            self.pathBox.setText(self.path)

        self.renderButton = settingsBox.addWidget(gui.Button('Render'))

        self.lightmapSSS = gui.CheckBox("Lightmap SSS")
        self.lightmapSSS.setSelected(G.app.getSetting('GL_RENDERER_SSS'))

        self.optionsBox = self.addLeftWidget(gui.GroupBox('Options'))
        self.optionsWidgets = []

        renderMethodBox = self.addRightWidget(
            gui.GroupBox('Rendering methods'))
        self.renderMethodList = renderMethodBox.addWidget(gui.ListView())
        self.renderMethodList.setSizePolicy(gui.SizePolicy.Ignored,
                                            gui.SizePolicy.Preferred)

        # Rendering methods
        self.renderMethodList.addItem('Quick Render')
        self.renderMethodList.addItem('Advanced Render',
                                      data=[self.lightmapSSS])

        if not mh.hasRenderToRenderbuffer():
            self.firstTimeWarn = True
            # Can only use screen grabbing as fallback,
            # resolution option disabled
            self.resBox.setEnabled(False)
            self.AAbox.setEnabled(False)

        self.listOptions(None)

        classificationImagesSettingsBox = self.addRightWidget(
            gui.GroupBox('Classification Image Settings'))

        classificationImagesSettingsBox.addWidget(
            gui.TextView("The number of trials"))
        self.trialsBox = classificationImagesSettingsBox.addWidget(
            gui.TextEdit("10"))

        classificationImagesSettingsBox.addWidget(
            gui.TextView("Orbit Camera Y (left-right)"))
        self.camY = classificationImagesSettingsBox.addWidget(
            gui.TextEdit("0.0"))
        classificationImagesSettingsBox.addWidget(
            gui.TextView("Oribt Camera X (up-down)"))
        self.camX = classificationImagesSettingsBox.addWidget(
            gui.TextEdit("0.0"))

        classificationImagesSettingsBox.addWidget(
            gui.TextView("Fraction of Feature Range SD"))
        self.SDBox = classificationImagesSettingsBox.addWidget(
            gui.TextEdit("0.05"))

        classificationImagesSettingsBox.addWidget(
            gui.TextView("Material File"))
        self.materialBox = classificationImagesSettingsBox.addWidget(
            gui.TextEdit("young_caucasian_avg"))

        classificationImagesSettingsBox.addWidget(gui.TextView("Model File"))
        self.modelBox = classificationImagesSettingsBox.addWidget(
            gui.TextEdit(""))
        self.model_button = classificationImagesSettingsBox.addWidget(
            gui.BrowseButton('open', "Select a model file"))

        @self.model_button.mhEvent
        def onClicked(path):
            self.modelBox.setText(path)

        self.modelFeatureList = classificationImagesSettingsBox.addWidget(
            gui.ListView())
        classificationImagesSettingsBox.addWidget(gui.TextView("Features"))
        self.modelFeatureBox = classificationImagesSettingsBox.addWidget(
            gui.TextEdit(".*"))
        # recommended groups
        self.modelGroups = [
            "all", "nose", "head", "forehead", "eyebrow", "eyes", "mouth",
            "ear", "chin", "cheek"
        ]
        self.modelGroupBox = mhapi.ui.createComboBox(self.modelGroups,
                                                     self._onModelGroupChange)
        classificationImagesSettingsBox.addWidget(self.modelGroupBox)
        self.modelAddButton = classificationImagesSettingsBox.addWidget(
            gui.Button("Add"))
        self.modelRemoveButton = classificationImagesSettingsBox.addWidget(
            gui.Button("Remove"))

        self.expressionBox = classificationImagesSettingsBox.addWidget(
            gui.TextEdit(""))
        self.expression_button = classificationImagesSettingsBox.addWidget(
            gui.BrowseButton('open', "Select an expression file"))

        @self.expression_button.mhEvent
        def onClicked(path):
            self.expressionBox.setText(path)

        self.expressionFeatureList = classificationImagesSettingsBox.addWidget(
            gui.ListView())
        classificationImagesSettingsBox.addWidget(gui.TextView("Features"))
        self.expressionFeatureBox = classificationImagesSettingsBox.addWidget(
            gui.TextEdit(".*"))
        # recommended groups
        self.expressionGroups = [
            "all", "Nose", "Eyebrow", "Eye", "Mouth", "Chin", "Cheek",
            "Left Eyebrow", "Left Chin", "Left Eye", "Left Mouth",
            "Right Eyebrow", "Right Chin", "Right Eye", "Right Mouth"
        ]
        self.expressionGroupBox = mhapi.ui.createComboBox(
            self.expressionGroups, self._onExpressionGroupChange)
        classificationImagesSettingsBox.addWidget(self.expressionGroupBox)

        self.expressionAddButton = classificationImagesSettingsBox.addWidget(
            gui.Button("Add"))
        self.expressionRemoveButton = classificationImagesSettingsBox.addWidget(
            gui.Button("Remove"))

        @self.modelAddButton.mhEvent
        def onClicked(event):
            features = self.modelFeatureBox.getText()
            self.modelFeatureList.addItem('{0}'.format(features),
                                          data=dict(features=features))

        @self.modelRemoveButton.mhEvent
        def onClicked(event):
            selected_frame = self.modelFeatureList.selectedItems()
            if len(selected_frame) == 0:
                return
            selected_frame = selected_frame[0]
            new_items = [
                item for item in self.modelFeatureList.getItems()
                if item is not selected_frame
            ]
            self.reassign(self.modelFeatureList, new_items)

        @self.expressionAddButton.mhEvent
        def onClicked(event):
            features = self.expressionFeatureBox.getText()
            self.expressionFeatureList.addItem('{0}'.format(features),
                                               data=dict(features=features))

        @self.expressionRemoveButton.mhEvent
        def onClicked(event):
            selected_frame = self.expressionFeatureList.selectedItems()
            if len(selected_frame) == 0:
                return
            selected_frame = selected_frame[0]
            new_items = [
                item for item in self.expressionFeatureList.getItems()
                if item is not selected_frame
            ]
            self.reassign(self.expressionFeatureList, new_items)

        @self.resBox.mhEvent
        def onChange(value):
            try:
                value = value.replace(" ", "")
                res = [int(x) for x in value.split("x")]
                self.renderingWidth = res[0]
                self.renderingHeight = res[1]
            except:  # The user hasn't typed the value correctly yet.
                pass

        @self.AAbox.mhEvent
        def onClicked(value):
            G.app.setSetting('GL_RENDERER_AA', self.AAbox.selected)

        @self.lightmapSSS.mhEvent
        def onClicked(value):
            G.app.setSetting('GL_RENDERER_SSS', self.lightmapSSS.selected)

        @self.renderMethodList.mhEvent
        def onClicked(item):
            self.listOptions(item.getUserData())

        @self.renderButton.mhEvent
        def onClicked(event):
            settings = dict()
            settings['scene'] = G.app.scene
            settings['AA'] = self.AAbox.selected
            settings['dimensions'] = (self.renderingWidth,
                                      self.renderingHeight)
            settings[
                'lightmapSSS'] = self.lightmapSSS.selected and self.lightmapSSS in self.optionsWidgets
            # change the timing of the render
            # add path output
            # base_model, trials, shape_parameters, pose_parameters, SD=.3, rot_X=0, rot_Y=0, material_file="young_caucasian_avg"
            _, shape_parameters = self.get_data_labels(
                self.modelFeatureList.getItems())
            #log.message("Shape parameters "+shape_parameters)
            _, pose_parameters = self.get_data_labels(
                self.expressionFeatureList.getItems())
            CI_settings = dict(base_model=self.modelBox.getText(),
                               base_expression=self.expressionBox.getText(),
                               trials=int(self.trialsBox.getText()),
                               shape_parameters=shape_parameters,
                               pose_parameters=pose_parameters,
                               material_file=self.materialBox.getText(),
                               rot_X=float(self.camX.getText()),
                               rot_Y=float(self.camY.getText()),
                               SD=float(self.SDBox.getText()))
            classification_images.do_op(
                classification_image_settings=CI_settings,
                save_path=self.pathBox.getText(),
                render_function=(mh2opengl.Render, settings))
Exemplo n.º 7
0
    def __init__(self, category):
        RenderTaskView.__init__(self, category, 'Interpolation Render')

        # Declare settings
        G.app.addSetting('GL_RENDERER_SSS', False)
        G.app.addSetting('GL_RENDERER_AA', True)

        # Don't change shader for this RenderTaskView.
        self.taskViewShader = G.app.selectedHuman.material.shader

        settingsBox = self.addLeftWidget(gui.GroupBox('Settings'))
        settingsBox.addWidget(gui.TextView("Resolution"))
        self.resBox = settingsBox.addWidget(
            gui.TextEdit("x".join(
                [str(self.renderingWidth),
                 str(self.renderingHeight)])))
        self.AAbox = settingsBox.addWidget(gui.CheckBox("Anti-aliasing"))
        self.AAbox.setSelected(G.app.getSetting('GL_RENDERER_AA'))

        self.path = ""
        self.path_button = settingsBox.addWidget(
            gui.BrowseButton('dir', "Select an output directory"))
        self.pathBox = settingsBox.addWidget(gui.TextEdit(self.path))

        @self.path_button.mhEvent
        def onClicked(path):
            self.path = path
            self.pathBox.setText(self.path)

        self.renderButton = settingsBox.addWidget(gui.Button('Render'))

        self.lightmapSSS = gui.CheckBox("Lightmap SSS")
        self.lightmapSSS.setSelected(G.app.getSetting('GL_RENDERER_SSS'))

        self.optionsBox = self.addLeftWidget(gui.GroupBox('Options'))
        self.optionsWidgets = []

        renderMethodBox = self.addRightWidget(
            gui.GroupBox('Rendering methods'))
        self.renderMethodList = renderMethodBox.addWidget(gui.ListView())
        self.renderMethodList.setSizePolicy(gui.SizePolicy.Ignored,
                                            gui.SizePolicy.Preferred)

        # Rendering methods
        self.renderMethodList.addItem('Quick Render')
        self.renderMethodList.addItem('Advanced Render',
                                      data=[self.lightmapSSS])

        if not mh.hasRenderToRenderbuffer():
            self.firstTimeWarn = True
            # Can only use screen grabbing as fallback,
            # resolution option disabled
            self.resBox.setEnabled(False)
            self.AAbox.setEnabled(False)

        self.listOptions(None)

        # add interpolation settings to the right pane
        interpolateFrameBox = self.addRightWidget(gui.GroupBox('Total Frames'))
        interpolateFrameBox.addWidget(gui.TextView("Frames"))
        self.framesBox = interpolateFrameBox.addWidget(gui.TextEdit("120"))

        interpolatedFramesBox = self.addRightWidget(
            gui.GroupBox('Interpolated Frames'))
        self.interpolatedFramesList = interpolatedFramesBox.addWidget(
            gui.ListView())
        self.interpolatedFramesList.setSizePolicy(gui.SizePolicy.Ignored,
                                                  gui.SizePolicy.Preferred)
        self.interpolatedFramesList.setVerticalScrollingEnabled(True)
        self.addFrame = interpolatedFramesBox.addWidget(
            gui.Button('Add Frame'))
        self.removeFrame = interpolatedFramesBox.addWidget(
            gui.Button('Remove Frame'))
        self.save_button = interpolatedFramesBox.addWidget(
            gui.BrowseButton('save', "Save As.."))
        self.load_button = interpolatedFramesBox.addWidget(
            gui.BrowseButton('open', 'Load JSON'))

        self.key_frames = None

        @self.load_button.mhEvent
        def onClicked(path):
            with open(path, 'r') as f:
                self.key_frames = json.load(f)
                self.GUItize_key_frames()
                self.resort_frames()

        @self.save_button.mhEvent
        def onClicked(path):
            self.generate_key_frames()

            with open(path, 'w') as f:
                json.dump(self.key_frames, f)

        interpolateSettingsBox = self.addRightWidget(
            gui.GroupBox('Interpolation Settings'))
        interpolateSettingsBox.addWidget(
            gui.TextView(
                "Current Frame (integer frame # or float proportion)"))
        self.currentFramesBox = interpolateSettingsBox.addWidget(
            gui.TextEdit("0.0"))
        interpolateSettingsBox.addWidget(
            gui.TextView("Orbit Camera Y (left-right)"))
        self.camY = interpolateSettingsBox.addWidget(gui.TextEdit(""))
        interpolateSettingsBox.addWidget(
            gui.TextView("Oribt Camera X (up-down)"))
        self.camX = interpolateSettingsBox.addWidget(gui.TextEdit(""))
        interpolateSettingsBox.addWidget(gui.TextView("Model File"))

        self.modelBox = interpolateSettingsBox.addWidget(gui.TextEdit(""))
        self.model_button = interpolateSettingsBox.addWidget(
            gui.BrowseButton('open', "Select a model file"))

        @self.model_button.mhEvent
        def onClicked(path):
            self.modelBox.setText(path)

        interpolateSettingsBox.addWidget(
            gui.TextView("Model Extrapolation Percentage"))
        self.modelPercentageBox = interpolateSettingsBox.addWidget(
            gui.TextEdit("100"))

        interpolateSettingsBox.addWidget(
            gui.TextView("Expression file (or specify 'None')"))
        self.expressionBox = interpolateSettingsBox.addWidget(gui.TextEdit(""))
        self.expression_button = interpolateSettingsBox.addWidget(
            gui.BrowseButton('open', "Select an expression file"))
        interpolateSettingsBox.addWidget(
            gui.TextView("Expression Extrapolation Percentage"))
        self.expressionPercentageBox = interpolateSettingsBox.addWidget(
            gui.TextEdit("100"))

        @self.expression_button.mhEvent
        def onClicked(path):
            self.expressionBox.setText(path)

        self.updateFrame = interpolateSettingsBox.addWidget(
            gui.Button('Update Frame'))

        self.keybox = {
            "frame": self.currentFramesBox,
            "rot_Y": self.camY,
            "rot_X": self.camX,
            "model": self.modelBox,
            "expression": self.expressionBox
        }

        @self.framesBox.mhEvent
        def onChange(value):
            try:
                tmp = 1 / int(value)
                self.resort_frames()
            except:
                pass

        # save the values back to the selected frame
        @self.updateFrame.mhEvent
        def onClicked(event):
            selected_frame = self.interpolatedFramesList.selectedItems()
            if len(selected_frame) == 0:
                return
            selected_frame = selected_frame[0]
            selected_frame.setText('Frame {0}'.format(
                self.currentFramesBox.getText()))
            selected_frame.setUserData(
                data={
                    "frame":
                    self.num(self.currentFramesBox.getText()),
                    "rot_Y":
                    self.num(self.camY.getText()),
                    "rot_X":
                    self.num(self.camX.getText()),
                    "model":
                    self.modelBox.getText() + "|" +
                    self.modelPercentageBox.getText(),
                    "expression":
                    self.expressionBox.getText() + "|" +
                    self.expressionPercentageBox.getText()
                })
            self.resort_frames()

        @self.addFrame.mhEvent
        def onClicked(event):
            self.interpolatedFramesList.addItem(
                'Frame {0}'.format(self.currentFramesBox.getText()),
                data={
                    "frame":
                    self.num(self.currentFramesBox.getText()),
                    "rot_Y":
                    self.num(self.camY.getText()),
                    "rot_X":
                    self.num(self.camX.getText()),
                    "model":
                    self.modelBox.getText() + "|" +
                    self.modelPercentageBox.getText(),
                    "expression":
                    self.expressionBox.getText() + "|" +
                    self.expressionPercentageBox.getText()
                })
            self.resort_frames()

        @self.removeFrame.mhEvent
        def onClicked(event):
            selected_frame = self.interpolatedFramesList.selectedItems()
            if len(selected_frame) == 0:
                return
            selected_frame = selected_frame[0]
            new_items = [
                item for item in self.interpolatedFramesList.getItems()
                if item is not selected_frame
            ]
            self.reassign(new_items)

        @self.interpolatedFramesList.mhEvent
        def onClicked(item):
            self.listInterpolationFrameOptions(item.getUserData())

        @self.resBox.mhEvent
        def onChange(value):
            try:
                value = value.replace(" ", "")
                res = [int(x) for x in value.split("x")]
                self.renderingWidth = res[0]
                self.renderingHeight = res[1]
            except:  # The user hasn't typed the value correctly yet.
                pass

        @self.AAbox.mhEvent
        def onClicked(value):
            G.app.setSetting('GL_RENDERER_AA', self.AAbox.selected)

        @self.lightmapSSS.mhEvent
        def onClicked(value):
            G.app.setSetting('GL_RENDERER_SSS', self.lightmapSSS.selected)

        @self.renderMethodList.mhEvent
        def onClicked(item):
            self.listOptions(item.getUserData())

        @self.renderButton.mhEvent
        def onClicked(event):
            settings = dict()
            settings['scene'] = G.app.scene
            settings['AA'] = self.AAbox.selected
            settings['dimensions'] = (self.renderingWidth,
                                      self.renderingHeight)
            settings[
                'lightmapSSS'] = self.lightmapSSS.selected and self.lightmapSSS in self.optionsWidgets
            # change the timing of the render
            # add path output
            self.generate_key_frames()
            interpolate.do_op(self.key_frames,
                              "Front",
                              save_path=self.pathBox.getText(),
                              render_function=(mh2opengl.Render, settings))
Exemplo n.º 8
0
def Render(settings):
    progress = Progress.begin()

    if not mh.hasRenderToRenderbuffer():
        settings['dimensions'] = (G.windowWidth, G.windowHeight)

    if settings['lightmapSSS']:
        progress(0, 0.05, "Storing data")
        import material
        human = G.app.selectedHuman
        materialBackup = material.Material(human.material)

        progress(0.05, 0.1, "Projecting lightmaps")
        diffuse = imgop.Image(data=human.material.diffuseTexture)
        lmap = projection.mapSceneLighting(settings['scene'],
                                           border=human.material.sssRScale)
        progress(0.1, 0.4, "Applying medium scattering")
        lmapG = imgop.blurred(lmap, human.material.sssGScale, 13)
        progress(0.4, 0.7, "Applying high scattering")
        lmapR = imgop.blurred(lmap, human.material.sssRScale, 13)
        lmap = imgop.compose([lmapR, lmapG, lmap])
        if not diffuse.isEmpty:
            progress(0.7, 0.8, "Combining textures")
            lmap = imgop.resized(lmap,
                                 diffuse.width,
                                 diffuse.height,
                                 filter=image.FILTER_BILINEAR)
            progress(0.8, 0.9)
            lmap = imgop.multiply(lmap, diffuse)
        lmap.sourcePath = "Internal_Renderer_Lightmap_SSS_Texture"

        progress(0.9, 0.95, "Setting up renderer")
        human.material.diffuseTexture = lmap
        human.configureShading(diffuse=True)
        human.shadeless = True
        progress(0.95, 0.98, None)
    else:
        progress(0, 0.99, None)

    if not mh.hasRenderToRenderbuffer():
        # Limited fallback mode, read from screen buffer
        log.message("Fallback render: grab screen")
        img = mh.grabScreen(0, 0, G.windowWidth, G.windowHeight)
        alphaImg = None
    else:
        # Render to framebuffer object
        renderprog = Progress()
        renderprog(0, 0.99 - 0.59 * settings['AA'], "Rendering")
        width, height = settings['dimensions']
        log.message("Rendering at %sx%s", width, height)
        if settings['AA']:
            width = width * 2
            height = height * 2
        img = mh.renderToBuffer(width, height)
        alphaImg = mh.renderAlphaMask(width, height)
        img = imgop.addAlpha(img, imgop.getChannel(alphaImg, 0))

        if settings['AA']:
            renderprog(0.4, 0.99, "AntiAliasing")
            # Resize to 50% using bi-linear filtering
            img = img.resized(width / 2,
                              height / 2,
                              filter=image.FILTER_BILINEAR)
            # TODO still haven't figured out where components get swapped, but this hack appears to be necessary
            img.data[:, :, :] = img.data[:, :, (2, 1, 0, 3)]
        renderprog.finish()

    if settings['lightmapSSS']:
        progress(0.98, 0.99, "Restoring data")
        human.material = materialBackup

    progress(1, None, 'Rendering complete')

    gui3d.app.getCategory('Rendering').getTaskByName('Viewer').setImage(img)
    mh.changeTask('Rendering', 'Viewer')
    gui3d.app.statusPersist('Rendering complete')
Exemplo n.º 9
0
    def __init__(self, category):
        RenderTaskView.__init__(self, category, 'Render')

        # Don't change shader for this RenderTaskView.
        self.taskViewShader = G.app.selectedHuman.material.shader

        settingsBox = self.addLeftWidget(gui.GroupBox('Settings'))
        settingsBox.addWidget(gui.TextView("Resolution"))
        self.resBox = settingsBox.addWidget(gui.TextEdit(
            "x".join([str(self.renderingWidth), str(self.renderingHeight)])))
        self.AAbox = settingsBox.addWidget(gui.CheckBox("Anti-aliasing"))
        self.AAbox.setSelected(G.app.settings.get('GL_RENDERER_AA', True))
        self.renderButton = settingsBox.addWidget(gui.Button('Render'))

        self.lightmapSSS = gui.CheckBox("Lightmap SSS")
        self.lightmapSSS.setSelected(
            G.app.settings.get('GL_RENDERER_SSS', False))

        self.optionsBox = self.addLeftWidget(gui.GroupBox('Options'))
        self.optionsWidgets = []

        renderMethodBox = self.addRightWidget(gui.GroupBox('Rendering methods'))
        self.renderMethodList = renderMethodBox.addWidget(gui.ListView())
        self.renderMethodList.setSizePolicy(
            gui.SizePolicy.Ignored, gui.SizePolicy.Preferred)

        # Rendering methods
        self.renderMethodList.addItem('Quick Render')
        self.renderMethodList.addItem('Advanced Render',
            data=[self.lightmapSSS])

        if not mh.hasRenderToRenderbuffer():
            self.firstTimeWarn = True
            # Can only use screen grabbing as fallback,
            # resolution option disabled
            self.resBox.setEnabled(False)
            self.AAbox.setEnabled(False)

        self.listOptions(None)

        @self.resBox.mhEvent
        def onChange(value):
            try:
                value = value.replace(" ", "")
                res = [int(x) for x in value.split("x")]
                self.renderingWidth = res[0]
                self.renderingHeight = res[1]
            except:  # The user hasn't typed the value correctly yet.
                pass

        @self.AAbox.mhEvent
        def onClicked(value):
            G.app.settings['GL_RENDERER_AA'] = self.AAbox.selected

        @self.lightmapSSS.mhEvent
        def onClicked(value):
            G.app.settings['GL_RENDERER_SSS'] = self.lightmapSSS.selected

        @self.renderMethodList.mhEvent
        def onClicked(item):
            self.listOptions(item.getUserData())

        @self.renderButton.mhEvent
        def onClicked(event):
            settings = dict()
            settings['scene'] = G.app.scene
            settings['AA'] = self.AAbox.selected
            settings['dimensions'] = (self.renderingWidth, self.renderingHeight)
            settings['lightmapSSS'] = self.lightmapSSS.selected and self.lightmapSSS in self.optionsWidgets

            mh2opengl.Render(settings)
Exemplo n.º 10
0
    def __init__(self, category):
        RenderTaskView.__init__(self, category, 'Classification Images Motion Render')

        # Declare settings
        G.app.addSetting('GL_RENDERER_SSS', False)
        G.app.addSetting('GL_RENDERER_AA', True)

        # Don't change shader for this RenderTaskView.
        self.taskViewShader = G.app.selectedHuman.material.shader

        settingsBox = self.addLeftWidget(gui.GroupBox('Settings'))
        settingsBox.addWidget(gui.TextView("Resolution"))
        self.resBox = settingsBox.addWidget(gui.TextEdit(
            "x".join([str(self.renderingWidth), str(self.renderingHeight)])))
        self.AAbox = settingsBox.addWidget(gui.CheckBox("Anti-aliasing"))
        self.AAbox.setSelected(G.app.getSetting('GL_RENDERER_AA'))
        
        self.path = ""
        self.path_button = settingsBox.addWidget(gui.BrowseButton('dir', "Select an output directory"))
        self.pathBox = settingsBox.addWidget(gui.TextEdit(self.path))

        @self.path_button.mhEvent
        def onClicked(path):
            self.path = path
            self.pathBox.setText(self.path)
        
        
        self.renderButton = settingsBox.addWidget(gui.Button('Render'))

        self.lightmapSSS = gui.CheckBox("Lightmap SSS")
        self.lightmapSSS.setSelected(G.app.getSetting('GL_RENDERER_SSS'))

        self.optionsBox = self.addLeftWidget(gui.GroupBox('Options'))
        self.optionsWidgets = []

        renderMethodBox = self.addRightWidget(gui.GroupBox('Rendering methods'))
        self.renderMethodList = renderMethodBox.addWidget(gui.ListView())
        self.renderMethodList.setSizePolicy(
            gui.SizePolicy.Ignored, gui.SizePolicy.Preferred)

        # Rendering methods
        self.renderMethodList.addItem('Quick Render')
        self.renderMethodList.addItem('Advanced Render',
            data=[self.lightmapSSS])

        if not mh.hasRenderToRenderbuffer():
            self.firstTimeWarn = True
            # Can only use screen grabbing as fallback,
            # resolution option disabled
            self.resBox.setEnabled(False)
            self.AAbox.setEnabled(False)

        self.listOptions(None)
        
        
        
        
        classificationImagesSettingsBox = self.addRightWidget(gui.GroupBox('Classification Image Settings'))

        classificationImagesSettingsBox.addWidget(gui.TextView("The number of trials"))
        self.trialsBox = classificationImagesSettingsBox.addWidget(gui.TextEdit("1"))

        classificationImagesSettingsBox.addWidget(gui.TextView("The number of frames per trial"))
        self.framesBox = classificationImagesSettingsBox.addWidget(gui.TextEdit("30"))

        classificationImagesSettingsBox.addWidget(gui.TextView("Orbit Camera Y (left-right)"))
        self.camY = classificationImagesSettingsBox.addWidget(gui.TextEdit("0.0"))
        classificationImagesSettingsBox.addWidget(gui.TextView("Oribt Camera X (up-down)"))
        self.camX = classificationImagesSettingsBox.addWidget(gui.TextEdit("0.0"))

        classificationImagesSettingsBox.addWidget(gui.TextView("Oribt Camera Z (out-int)"))
        self.camZ = classificationImagesSettingsBox.addWidget(gui.TextEdit("8.7"))

        classificationImagesSettingsBox.addWidget(gui.TextView("Frame Rate"))
        self.frameRateBox = classificationImagesSettingsBox.addWidget(gui.TextEdit("30"))

        classificationImagesSettingsBox.addWidget(gui.TextView("Material File"))
        self.materialBox = classificationImagesSettingsBox.addWidget(gui.TextEdit("young_caucasian_avg"))

        classificationImagesSettingsBox.addWidget(gui.TextView("Start Model File"))
        self.modelBox = classificationImagesSettingsBox.addWidget(gui.TextEdit(""))
        self.model_button = classificationImagesSettingsBox.addWidget(gui.BrowseButton('open', "Select a model file"))
        @self.model_button.mhEvent
        def onClicked(path):
            self.modelBox.setText(path)

        classificationImagesSettingsBox.addWidget(gui.TextView("End Model File"))
        self.modelBox2 = classificationImagesSettingsBox.addWidget(gui.TextEdit("None"))
        self.model_button2 = classificationImagesSettingsBox.addWidget(gui.BrowseButton('open', "Select a model file"))
        
        @self.model_button2.mhEvent
        def onClicked(path):
            self.modelBox2.setText(path)



        self.modelFeatureList = classificationImagesSettingsBox.addWidget(gui.ListView())
        classificationImagesSettingsBox.addWidget(gui.TextView("Features"))
        self.modelFeatureBox = classificationImagesSettingsBox.addWidget(gui.TextEdit(".*"))
        # recommended groups
        self.modelGroups = ["all", "nose", "head", "forehead", "eyebrow", "eyes", "mouth", "ear", "chin", "cheek"]
        self.modelGroupBox = mhapi.ui.createComboBox(self.modelGroups, self._onModelGroupChange)
        classificationImagesSettingsBox.addWidget(self.modelGroupBox)
        classificationImagesSettingsBox.addWidget(gui.TextView("Mode and SD"))
        self.modelAlphaBox = classificationImagesSettingsBox.addWidget(gui.TextEdit("0.5"))
        self.modelAlphaSDBox = classificationImagesSettingsBox.addWidget(gui.TextEdit("0.1667"))
        classificationImagesSettingsBox.addWidget(gui.TextView("Concentration and SD"))
        self.modelBetaBox = classificationImagesSettingsBox.addWidget(gui.TextEdit("25.0"))
        self.modelBetaSDBox = classificationImagesSettingsBox.addWidget(gui.TextEdit("7.6667"))
        self.modelAddButton = classificationImagesSettingsBox.addWidget(gui.Button("Add"))
        self.modelRemoveButton = classificationImagesSettingsBox.addWidget(gui.Button("Remove"))
        
        classificationImagesSettingsBox.addWidget(gui.TextView("Start Expression File"))
        self.expressionBox = classificationImagesSettingsBox.addWidget(gui.TextEdit("None"))
        self.expression_button = classificationImagesSettingsBox.addWidget(gui.BrowseButton('open', "Select an expression"))
        @self.expression_button.mhEvent
        def onClicked(path):
            self.expressionBox.setText(path)

        classificationImagesSettingsBox.addWidget(gui.TextView("End Expression File"))
        self.expressionBox2 = classificationImagesSettingsBox.addWidget(gui.TextEdit(""))
        self.expression_button2 = classificationImagesSettingsBox.addWidget(gui.BrowseButton('open', "Select an expression"))
        @self.expression_button2.mhEvent
        def onClicked(path):
            self.expressionBox2.setText(path)


        self.expressionFeatureList = classificationImagesSettingsBox.addWidget(gui.ListView())

        # add the default CCNLab NSF groups
        alpha = 0.5
        alpha_sd = .5/3
        beta = 25.0
        beta_sd = 7 + 1/3.
        
        # between the brows
        features = "NoseWrinkler"
        self.expressionFeatureList.addItem('{0}: ({1:0.2f}, {2:0.2f})'.format(features, alpha, beta), data=dict(features=features, alpha=alpha, alpha_sd=alpha_sd, beta=beta, beta_sd=beta_sd))
        
        # the nose
        features = "Nose,Naso"
        self.expressionFeatureList.addItem('{0}: ({1:0.2f}, {2:0.2f})'.format(features, alpha, beta), data=dict(features=features, alpha=alpha, alpha_sd=alpha_sd, beta=beta, beta_sd=beta_sd))
        
        # left brow
        features = "Left.*Brow"
        self.expressionFeatureList.addItem('{0}: ({1:0.2f}, {2:0.2f})'.format(features, alpha, beta), data=dict(features=features, alpha=alpha, alpha_sd=alpha_sd, beta=beta, beta_sd=beta_sd))

        # left eyelid
        features = "Left.*Eye,Left.*Lid"
        self.expressionFeatureList.addItem('{0}: ({1:0.2f}, {2:0.2f})'.format(features, alpha, beta), data=dict(features=features, alpha=alpha, alpha_sd=alpha_sd, beta=beta, beta_sd=beta_sd))

        # right brow
        features = "Right.*Brow"
        self.expressionFeatureList.addItem('{0}: ({1:0.2f}, {2:0.2f})'.format(features, alpha, beta), data=dict(features=features, alpha=alpha, alpha_sd=alpha_sd, beta=beta, beta_sd=beta_sd))

        # right eyelid
        features = "Right.*Eye,Right.*Lid"
        self.expressionFeatureList.addItem('{0}: ({1:0.2f}, {2:0.2f})'.format(features, alpha, beta), data=dict(features=features, alpha=alpha, alpha_sd=alpha_sd, beta=beta, beta_sd=beta_sd))
        
        # chin and jaw
        features = "Chin,Jaw"
        self.expressionFeatureList.addItem('{0}: ({1:0.2f}, {2:0.2f})'.format(features, alpha, beta), data=dict(features=features, alpha=alpha, alpha_sd=alpha_sd, beta=beta, beta_sd=beta_sd))

        # left mouth and cheek
        features = "Mouth.*Left,TongueLeft,Left.*Cheek"
        self.expressionFeatureList.addItem('{0}: ({1:0.2f}, {2:0.2f})'.format(features, alpha, beta), data=dict(features=features, alpha=alpha, alpha_sd=alpha_sd, beta=beta, beta_sd=beta_sd))

        # right mouth and cheek
        features = "Mouth.*Right,TongueRight,Right.*Cheek"
        self.expressionFeatureList.addItem('{0}: ({1:0.2f}, {2:0.2f})'.format(features, alpha, beta), data=dict(features=features, alpha=alpha, alpha_sd=alpha_sd, beta=beta, beta_sd=beta_sd))

        # center mouth
        features = "Tongue,Lip"
        self.expressionFeatureList.addItem('{0}: ({1:0.2f}, {2:0.2f})'.format(features, alpha, beta), data=dict(features=features, alpha=alpha, alpha_sd=alpha_sd, beta=beta, beta_sd=beta_sd))

        classificationImagesSettingsBox.addWidget(gui.TextView("Features"))
        self.expressionFeatureBox = classificationImagesSettingsBox.addWidget(gui.TextEdit(".*"))
        # recommended groups
        self.expressionGroups = ["all", "Nose", "Eyebrow", "Eye", "Mouth", "Chin", "Cheek", "Left Eyebrow", "Left Chin", "Left Eye", "Left Mouth", "Right Eyebrow", "Right Chin", "Right Eye", "Right Mouth"]
        self.expressionGroupBox = mhapi.ui.createComboBox(self.expressionGroups, self._onExpressionGroupChange)
        classificationImagesSettingsBox.addWidget(self.expressionGroupBox)
        
        classificationImagesSettingsBox.addWidget(gui.TextView("Mode and SD"))
        self.expressionAlphaBox = classificationImagesSettingsBox.addWidget(gui.TextEdit("0.5"))
        self.expressionAlphaSDBox = classificationImagesSettingsBox.addWidget(gui.TextEdit("0.1667"))
        classificationImagesSettingsBox.addWidget(gui.TextView("Concentration and SD"))
        self.expressionBetaBox = classificationImagesSettingsBox.addWidget(gui.TextEdit("25.0"))
        self.expressionBetaSDBox = classificationImagesSettingsBox.addWidget(gui.TextEdit("7.6667"))

        self.expressionAddButton = classificationImagesSettingsBox.addWidget(gui.Button("Add"))
        self.expressionRemoveButton = classificationImagesSettingsBox.addWidget(gui.Button("Remove"))

        @self.modelAddButton.mhEvent
        def onClicked(event):
            features = self.modelFeatureBox.getText()
            alpha = float(self.modelAlphaBox.getText())
            alpha_sd = float(self.modelAlphaSDBox.getText())
            beta = float(self.modelBetaBox.getText())
            beta_sd = float(self.modelBetaSDBox.getText())
            self.modelFeatureList.addItem('{0}: ({1:0.2f}, {2:0.2f})'.format(features, alpha, beta), data=dict(features=features, alpha=alpha, alpha_sd=alpha_sd, beta=beta, beta_sd=beta_sd))

        @self.modelRemoveButton.mhEvent
        def onClicked(event):
            selected_frame = self.modelFeatureList.selectedItems()
            if len(selected_frame) == 0:
                return
            selected_frame = selected_frame[0]
            new_items = [item for item in self.modelFeatureList.getItems() if item is not selected_frame]
            self.reassign(self.modelFeatureList, new_items)

        @self.expressionAddButton.mhEvent
        def onClicked(event):
            features = self.expressionFeatureBox.getText()
            alpha = float(self.expressionAlphaBox.getText())
            alpha_sd = float(self.expressionAlphaSDBox.getText())
            beta = float(self.expressionBetaBox.getText())
            beta_sd = float(self.expressionBetaSDBox.getText())
            self.expressionFeatureList.addItem('{0}: ({1:0.2f}, {2:0.2f})'.format(features, alpha, beta), data=dict(features=features, alpha=alpha, alpha_sd=alpha_sd, beta=beta, beta_sd=beta_sd))

        @self.expressionRemoveButton.mhEvent
        def onClicked(event):
            selected_frame = self.expressionFeatureList.selectedItems()
            if len(selected_frame) == 0:
                return
            selected_frame = selected_frame[0]
            new_items = [item for item in self.expressionFeatureList.getItems() if item is not selected_frame]
            self.reassign(self.expressionFeatureList, new_items)


            
            
        @self.resBox.mhEvent
        def onChange(value):
            try:
                value = value.replace(" ", "")
                res = [int(x) for x in value.split("x")]
                self.renderingWidth = res[0]
                self.renderingHeight = res[1]
            except:  # The user hasn't typed the value correctly yet.
                pass

        @self.AAbox.mhEvent
        def onClicked(value):
            G.app.setSetting('GL_RENDERER_AA', self.AAbox.selected)

        @self.lightmapSSS.mhEvent
        def onClicked(value):
            G.app.setSetting('GL_RENDERER_SSS', self.lightmapSSS.selected)
            
        @self.renderMethodList.mhEvent
        def onClicked(item):
            self.listOptions(item.getUserData())

        @self.renderButton.mhEvent
        def onClicked(event):
            settings = dict()
            settings['scene'] = G.app.scene
            settings['AA'] = self.AAbox.selected
            settings['dimensions'] = (self.renderingWidth, self.renderingHeight)
            settings['lightmapSSS'] = self.lightmapSSS.selected and self.lightmapSSS in self.optionsWidgets
            # change the timing of the render
            # add path output
            # base_model, trials, shape_parameters, pose_parameters, SD=.3, rot_X=0, rot_Y=0, material_file="young_caucasian_avg"
            shape_data,shape_parameters = self.get_data_labels(self.modelFeatureList.getItems())
            #log.message("Shape parameters "+shape_parameters)
            pose_data,pose_parameters = self.get_data_labels(self.expressionFeatureList.getItems())
            frame_rate = float(self.frameRateBox.getText())
            CI_settings = dict(base_model = self.modelBox.getText(),
                                end_model = self.modelBox2.getText(),
                                base_expression = self.expressionBox.getText(),
                                end_expression = self.expressionBox2.getText(),
                                trials = int(self.trialsBox.getText()),
                                frames = int(self.framesBox.getText()),
                                shape_parameters = shape_parameters,
                                pose_parameters=pose_parameters,
                                shape_data=shape_data,
                                pose_data=pose_data,
                                material_file = self.materialBox.getText(),
                                rot_X = float(self.camX.getText()),
                                rot_Y = float(self.camY.getText()),
                                cam_Z = float(self.camZ.getText()))
            classification_images_motion.do_op(classification_image_settings=CI_settings, 
            save_path = self.pathBox.getText(), 
            frame_rate = frame_rate, render_function = (mh2opengl.Render, settings))
Exemplo n.º 11
0
    def __init__(self, category):
        RenderTaskView.__init__(self, category, 'Interpolation Render')

        # Declare settings
        G.app.addSetting('GL_RENDERER_SSS', False)
        G.app.addSetting('GL_RENDERER_AA', True)

        # Don't change shader for this RenderTaskView.
        self.taskViewShader = G.app.selectedHuman.material.shader

        settingsBox = self.addLeftWidget(gui.GroupBox('Settings'))
        settingsBox.addWidget(gui.TextView("Resolution"))
        self.resBox = settingsBox.addWidget(
            gui.TextEdit("x".join(
                [str(self.renderingWidth),
                 str(self.renderingHeight)])))
        self.AAbox = settingsBox.addWidget(gui.CheckBox("Anti-aliasing"))
        self.AAbox.setSelected(G.app.getSetting('GL_RENDERER_AA'))

        self.path = ""
        self.path_button = settingsBox.addWidget(
            gui.BrowseButton('dir', "Select an output directory"))
        self.pathBox = settingsBox.addWidget(gui.TextEdit(self.path))

        self.save_models = gui.CheckBox("Save a Model per Frame")
        settingsBox.addWidget(self.save_models)

        @self.path_button.mhEvent
        def onClicked(path):
            self.path = path
            self.pathBox.setText(self.path)

        self.renderButton = settingsBox.addWidget(gui.Button('Render'))

        self.lightmapSSS = gui.CheckBox("Lightmap SSS")
        self.lightmapSSS.setSelected(G.app.getSetting('GL_RENDERER_SSS'))

        self.optionsBox = self.addLeftWidget(gui.GroupBox('Options'))
        self.optionsWidgets = []

        renderMethodBox = self.addRightWidget(
            gui.GroupBox('Rendering methods'))
        self.renderMethodList = renderMethodBox.addWidget(gui.ListView())
        self.renderMethodList.setSizePolicy(gui.SizePolicy.Ignored,
                                            gui.SizePolicy.Preferred)

        # Rendering methods
        self.renderMethodList.addItem('Quick Render')
        self.renderMethodList.addItem('Advanced Render',
                                      data=[self.lightmapSSS])

        if not mh.hasRenderToRenderbuffer():
            self.firstTimeWarn = True
            # Can only use screen grabbing as fallback,
            # resolution option disabled
            self.resBox.setEnabled(False)
            self.AAbox.setEnabled(False)

        self.listOptions(None)

        # add interpolation settings to the right pane
        interpolateFrameBox = self.addRightWidget(gui.GroupBox('Total Frames'))
        interpolateFrameBox.addWidget(gui.TextView("Frames"))
        self.framesBox = interpolateFrameBox.addWidget(gui.TextEdit("120"))

        interpolatedFramesBox = self.addRightWidget(
            gui.GroupBox('Interpolated Frames'))
        self.interpolatedFramesList = interpolatedFramesBox.addWidget(
            gui.ListView())
        self.interpolatedFramesList.setSizePolicy(gui.SizePolicy.Ignored,
                                                  gui.SizePolicy.Preferred)
        self.interpolatedFramesList.setVerticalScrollingEnabled(True)
        self.addFrame = interpolatedFramesBox.addWidget(
            gui.Button('Add Frame'))
        self.removeFrame = interpolatedFramesBox.addWidget(
            gui.Button('Remove Frame'))
        self.save_button = interpolatedFramesBox.addWidget(
            gui.BrowseButton('save', "Save As.."))
        self.load_button = interpolatedFramesBox.addWidget(
            gui.BrowseButton('open', 'Load JSON'))

        self.key_frames = None

        @self.load_button.mhEvent
        def onClicked(path):
            with open(path, 'r') as f:
                self.key_frames = json.load(f)
                self.GUItize_key_frames()
                self.resort_frames()

        @self.save_button.mhEvent
        def onClicked(path):
            self.generate_key_frames()

            with open(path, 'w') as f:
                json.dump(self.key_frames, f)

        interpolateSettingsBox = self.addRightWidget(
            gui.GroupBox('Interpolation Settings'))
        interpolateSettingsBox.addWidget(
            gui.TextView(
                "Current Frame (integer frame # or float proportion)"))
        self.currentFramesBox = interpolateSettingsBox.addWidget(
            gui.TextEdit("0.0"))
        interpolateSettingsBox.addWidget(
            gui.TextView("Orbit Camera Y (left-right)"))
        self.camY = interpolateSettingsBox.addWidget(gui.TextEdit(""))
        interpolateSettingsBox.addWidget(
            gui.TextView("Oribt Camera X (up-down)"))
        self.camX = interpolateSettingsBox.addWidget(gui.TextEdit(""))

        interpolateSettingsBox.addWidget(
            gui.TextView("Zoom Factor (8.7 for default face cam)"))
        self.camZ = interpolateSettingsBox.addWidget(gui.TextEdit(""))

        interpolateSettingsBox.addWidget(gui.TextView("Model File"))
        self.modelBox = interpolateSettingsBox.addWidget(gui.TextEdit(""))
        self.model_button = interpolateSettingsBox.addWidget(
            gui.BrowseButton('open', "Select a model file"))

        @self.model_button.mhEvent
        def onClicked(path):
            self.modelBox.setText(path)

        interpolateSettingsBox.addWidget(
            gui.TextView("Model Extrapolation Percentage"))
        self.modelPercentageBox = interpolateSettingsBox.addWidget(
            gui.TextEdit("100"))
        # allow alpha beta parameters
        self.modelAlphaBetaList = interpolateSettingsBox.addWidget(
            gui.ListView())
        interpolateSettingsBox.addWidget(gui.TextView("Features"))
        self.modelFeatureBox = interpolateSettingsBox.addWidget(
            gui.TextEdit(".*"))
        # recommended groups
        self.modelGroups = [
            "all", "nose", "head", "forehead", "eyebrow", "eyes", "mouth",
            "ear", "chin", "cheek"
        ]
        self.modelGroupBox = mhapi.ui.createComboBox(self.modelGroups,
                                                     self._onModelGroupChange)
        interpolateSettingsBox.addWidget(self.modelGroupBox)

        interpolateSettingsBox.addWidget(gui.TextView("Alpha"))
        self.modelAlphaBox = interpolateSettingsBox.addWidget(
            gui.TextEdit("1.0"))
        interpolateSettingsBox.addWidget(gui.TextView("Beta"))
        self.modelBetaBox = interpolateSettingsBox.addWidget(
            gui.TextEdit("1.0"))
        self.modelAddButton = interpolateSettingsBox.addWidget(
            gui.Button("Add"))
        self.modelRemoveButton = interpolateSettingsBox.addWidget(
            gui.Button("Remove"))

        interpolateSettingsBox.addWidget(
            gui.TextView("Expression file (or specify 'None')"))
        self.expressionBox = interpolateSettingsBox.addWidget(gui.TextEdit(""))
        self.expression_button = interpolateSettingsBox.addWidget(
            gui.BrowseButton('open', "Select an expression file"))
        interpolateSettingsBox.addWidget(
            gui.TextView("Expression Extrapolation Percentage"))
        self.expressionPercentageBox = interpolateSettingsBox.addWidget(
            gui.TextEdit("100"))
        # alphas and betas for expressions
        self.expressionAlphaBetaList = interpolateSettingsBox.addWidget(
            gui.ListView())
        interpolateSettingsBox.addWidget(gui.TextView("Features"))
        self.expressionFeatureBox = interpolateSettingsBox.addWidget(
            gui.TextEdit(".*"))
        # recommended groups
        self.expressionGroups = [
            "all", "Nose", "Eyebrow", "Eye", "Mouth", "Chin", "Cheek",
            "Left Eyebrow", "Left Chin", "Left Eye", "Left Mouth",
            "Right Eyebrow", "Right Chin", "Right Eye", "Right Mouth"
        ]
        self.expressionGroupBox = mhapi.ui.createComboBox(
            self.expressionGroups, self._onExpressionGroupChange)
        interpolateSettingsBox.addWidget(self.expressionGroupBox)

        interpolateSettingsBox.addWidget(gui.TextView("Alpha"))
        self.expressionAlphaBox = interpolateSettingsBox.addWidget(
            gui.TextEdit("1.0"))
        interpolateSettingsBox.addWidget(gui.TextView("Beta"))
        self.expressionBetaBox = interpolateSettingsBox.addWidget(
            gui.TextEdit("1.0"))
        self.expressionAddButton = interpolateSettingsBox.addWidget(
            gui.Button("Add"))
        self.expressionRemoveButton = interpolateSettingsBox.addWidget(
            gui.Button("Remove"))

        @self.modelAddButton.mhEvent
        def onClicked(event):
            features = self.modelFeatureBox.getText()
            alpha = float(self.modelAlphaBox.getText())
            beta = float(self.modelBetaBox.getText())
            self.modelAlphaBetaList.addItem('{0}: ({1:0.2f}, {2:0.2f})'.format(
                features, alpha, beta),
                                            data=dict(features=features,
                                                      alpha=alpha,
                                                      beta=beta))

        @self.modelRemoveButton.mhEvent
        def onClicked(event):
            selected_frame = self.modelAlphaBetaList.selectedItems()
            if len(selected_frame) == 0:
                return
            selected_frame = selected_frame[0]
            new_items = [
                item for item in self.modelAlphaBetaList.getItems()
                if item is not selected_frame
            ]
            self.reassign(self.modelAlphaBetaList, new_items)

        @self.expressionAddButton.mhEvent
        def onClicked(event):
            features = self.expressionFeatureBox.getText()
            alpha = float(self.expressionAlphaBox.getText())
            beta = float(self.expressionBetaBox.getText())
            self.expressionAlphaBetaList.addItem(
                '{0}: ({1:0.2f}, {2:0.2f})'.format(features, alpha, beta),
                data=dict(features=features, alpha=alpha, beta=beta))

        @self.expressionRemoveButton.mhEvent
        def onClicked(event):
            selected_frame = self.expressionAlphaBetaList.selectedItems()
            if len(selected_frame) == 0:
                return
            selected_frame = selected_frame[0]
            new_items = [
                item for item in self.expressionAlphaBetaList.getItems()
                if item is not selected_frame
            ]
            self.reassign(self.expressionAlphaBetaList, new_items)

        @self.expression_button.mhEvent
        def onClicked(path):
            self.expressionBox.setText(path)

        self.updateFrame = interpolateSettingsBox.addWidget(
            gui.Button('Update Frame'))

        self.keybox = {
            "frame": self.currentFramesBox,
            "rot_Y": self.camY,
            "rot_X": self.camX,
            "cam_Z": self.camZ,
            "model": self.modelBox,
            "expression": self.expressionBox
        }

        @self.framesBox.mhEvent
        def onChange(value):
            try:
                tmp = 1 / int(value)
                self.resort_frames()
            except:
                pass

        # save the values back to the selected frame
        @self.updateFrame.mhEvent
        def onClicked(event):
            selected_frame = self.interpolatedFramesList.selectedItems()
            if len(selected_frame) == 0:
                return
            selected_frame = selected_frame[0]
            selected_frame.setText('Frame {0}'.format(
                self.currentFramesBox.getText()))

            # each item has a Regular expression and the alpha beta values
            model_extra = {}
            for item in self.modelAlphaBetaList.getItems():
                d = item.getUserData()
                model_extra[d['features']] = (d['alpha'], d['beta'])

            expression_extra = {}
            for item in self.expressionAlphaBetaList.getItems():
                d = item.getUserData()
                expression_extra[d['features']] = (d['alpha'], d['beta'])

            selected_frame.setUserData(
                data={
                    "frame":
                    self.num(self.currentFramesBox.getText()),
                    "rot_Y":
                    self.num(self.camY.getText()),
                    "rot_X":
                    self.num(self.camX.getText()),
                    "cam_Z":
                    self.num(self.camZ.getText()),
                    "model": (self.modelBox.getText(),
                              self.num(self.modelPercentageBox.getText()),
                              model_extra),
                    "expression": (
                        self.expressionBox.getText(),
                        self.num(self.expressionPercentageBox.getText()),
                        expression_extra)
                })
            self.resort_frames()
            self.generate_key_frames()

        @self.addFrame.mhEvent
        def onClicked(event):
            # each item has a Regular expression and the alpha beta values
            model_extra = {}
            for item in self.modelAlphaBetaList.getItems():
                d = item.getUserData()
                model_extra[d['features']] = (d['alpha'], d['beta'])

            expression_extra = {}
            for item in self.expressionAlphaBetaList.getItems():
                d = item.getUserData()
                expression_extra[d['features']] = (d['alpha'], d['beta'])

            self.interpolatedFramesList.addItem(
                'Frame {0}'.format(self.currentFramesBox.getText()),
                data={
                    "frame":
                    self.num(self.currentFramesBox.getText()),
                    "rot_Y":
                    self.num(self.camY.getText()),
                    "rot_X":
                    self.num(self.camX.getText()),
                    "cam_Z":
                    self.num(self.camZ.getText()),
                    "model":
                    (self.modelBox.getText(),
                     self.num(self.modelPercentageBox.getText()), model_extra),
                    "expression":
                    (self.expressionBox.getText(),
                     self.num(self.expressionPercentageBox.getText()),
                     expression_extra)
                })
            self.resort_frames()

        @self.removeFrame.mhEvent
        def onClicked(event):
            selected_frame = self.interpolatedFramesList.selectedItems()
            if len(selected_frame) == 0:
                return
            selected_frame = selected_frame[0]
            new_items = [
                item for item in self.interpolatedFramesList.getItems()
                if item is not selected_frame
            ]
            self.reassign(self.interpolatedFramesList, new_items)

        @self.interpolatedFramesList.mhEvent
        def onClicked(item):
            self.listInterpolationFrameOptions(item.getUserData())

        @self.resBox.mhEvent
        def onChange(value):
            try:
                value = value.replace(" ", "")
                res = [int(x) for x in value.split("x")]
                self.renderingWidth = res[0]
                self.renderingHeight = res[1]
            except:  # The user hasn't typed the value correctly yet.
                pass

        @self.AAbox.mhEvent
        def onClicked(value):
            G.app.setSetting('GL_RENDERER_AA', self.AAbox.selected)

        @self.lightmapSSS.mhEvent
        def onClicked(value):
            G.app.setSetting('GL_RENDERER_SSS', self.lightmapSSS.selected)

        @self.renderMethodList.mhEvent
        def onClicked(item):
            self.listOptions(item.getUserData())

        @self.renderButton.mhEvent
        def onClicked(event):
            settings = dict()
            settings['scene'] = G.app.scene
            settings['AA'] = self.AAbox.selected
            settings['dimensions'] = (self.renderingWidth,
                                      self.renderingHeight)
            settings[
                'lightmapSSS'] = self.lightmapSSS.selected and self.lightmapSSS in self.optionsWidgets
            settings['saveModels'] = self.save_models.selected
            # change the timing of the render
            # add path output
            self.generate_key_frames()
            interpolate.do_op(self.key_frames,
                              "Front",
                              save_path=self.pathBox.getText(),
                              render_function=(mh2opengl.Render, settings))
Exemplo n.º 12
0
def Render(settings):
    progress = Progress.begin()

    if not mh.hasRenderToRenderbuffer():
        settings['dimensions'] = (G.windowWidth, G.windowHeight)

    if settings['lightmapSSS']:
        progress(0, 0.05, "Storing data")
        import material
        human = G.app.selectedHuman
        materialBackup = material.Material(human.material)

        progress(0.05, 0.1, "Projecting lightmaps")
        diffuse = imgop.Image(data=human.material.diffuseTexture)
        lmap = projection.mapSceneLighting(settings['scene'],
                                           border=human.material.sssRScale)
        progress(0.1, 0.4, "Applying medium scattering")
        lmapG = imgop.blurred(lmap, human.material.sssGScale, 13)
        progress(0.4, 0.7, "Applying high scattering")
        lmapR = imgop.blurred(lmap, human.material.sssRScale, 13)
        lmap = imgop.compose([lmapR, lmapG, lmap])
        if not diffuse.isEmpty:
            progress(0.7, 0.8, "Combining textures")
            lmap = imgop.resized(lmap, diffuse.width, diffuse.height)
            progress(0.8, 0.9)
            lmap = imgop.multiply(lmap, diffuse)
        lmap.sourcePath = "Internal_Renderer_Lightmap_SSS_Texture"

        progress(0.9, 0.95, "Setting up renderer")
        human.material.diffuseTexture = lmap
        human.mesh.configureShading(diffuse=True)
        human.mesh.shadeless = True
        progress(0.95, 0.98, None)
    else:
        progress(0, 0.99, None)

    if not mh.hasRenderToRenderbuffer():
        # Limited fallback mode, read from screen buffer
        log.message("Fallback render: grab screen")
        img = mh.grabScreen(0, 0, G.windowWidth, G.windowHeight)
        alphaImg = None
    else:
        # Render to framebuffer object
        renderprog = Progress()
        renderprog(0, 0.99 - 0.59 * settings['AA'], "Rendering")
        width, height = settings['dimensions']
        log.message("Rendering at %sx%s", width, height)
        if settings['AA']:
            width = width * 2
            height = height * 2
        img = mh.renderToBuffer(width, height)
        alphaImg = mh.renderAlphaMask(width, height)
        img = imgop.addAlpha(img, imgop.getChannel(alphaImg, 0))

        if settings['AA']:
            renderprog(0.4, 0.99, "AntiAliasing")
            # Resize to 50% using Qt image class
            qtImg = img.toQImage()
            del img
            # Bilinear filtered resize for anti-aliasing
            scaledImg = qtImg.scaled(
                width / 2,
                height / 2,
                transformMode=gui.QtCore.Qt.SmoothTransformation)
            del qtImg
            img = scaledImg
            #img = image.Image(scaledImg)    # Convert back to MH image
            #del scaledImg
        renderprog.finish()

    if settings['lightmapSSS']:
        progress(0.98, 0.99, "Restoring data")
        human.material = materialBackup

    progress(1, None, 'Rendering complete')

    gui3d.app.getCategory('Rendering').getTaskByName('Viewer').setImage(img)
    mh.changeTask('Rendering', 'Viewer')
    gui3d.app.statusPersist('Rendering complete.')
Exemplo n.º 13
0
def Render(settings):
    progress = Progress.begin()
    
    if not mh.hasRenderToRenderbuffer():
        settings['dimensions'] = (G.windowWidth, G.windowHeight)

    if settings['lightmapSSS']:
        progress(0, 0.05, "Storing data")
        import material
        human = G.app.selectedHuman
        materialBackup = material.Material(human.material)

        progress(0.05, 0.1, "Projecting lightmaps")
        diffuse = imgop.Image(data = human.material.diffuseTexture)
        lmap = projection.mapSceneLighting(
            settings['scene'], border = human.material.sssRScale)
        progress(0.1, 0.4, "Applying medium scattering")
        lmapG = imgop.blurred(lmap, human.material.sssGScale, 13)
        progress(0.4, 0.7, "Applying high scattering")
        lmapR = imgop.blurred(lmap, human.material.sssRScale, 13)
        lmap = imgop.compose([lmapR, lmapG, lmap])
        if not diffuse.isEmpty:
            progress(0.7, 0.8, "Combining textures")
            lmap = imgop.resized(lmap, diffuse.width, diffuse.height, filter=image.FILTER_BILINEAR)
            progress(0.8, 0.9)
            lmap = imgop.multiply(lmap, diffuse)
        lmap.sourcePath = "Internal_Renderer_Lightmap_SSS_Texture"

        progress(0.9, 0.95, "Setting up renderer")
        human.material.diffuseTexture = lmap
        human.configureShading(diffuse = True)
        human.shadeless = True
        progress(0.95, 0.98, None)
    else:
        progress(0, 0.99, None)
        
    if not mh.hasRenderToRenderbuffer():
        # Limited fallback mode, read from screen buffer
        log.message("Fallback render: grab screen")
        img = mh.grabScreen(0, 0, G.windowWidth, G.windowHeight)
        alphaImg = None
    else:
        # Render to framebuffer object
        renderprog = Progress()
        renderprog(0, 0.99 - 0.59 * settings['AA'], "Rendering")
        width, height = settings['dimensions']
        log.message("Rendering at %sx%s", width, height)
        if settings['AA']:
            width = width * 2
            height = height * 2
        img = mh.renderToBuffer(width, height)
        alphaImg = mh.renderAlphaMask(width, height)
        img = imgop.addAlpha(img, imgop.getChannel(alphaImg, 0))

        if settings['AA']:
            renderprog(0.4, 0.99, "AntiAliasing")
            # Resize to 50% using bi-linear filtering
            img = img.resized(width/2, height/2, filter=image.FILTER_BILINEAR)
            # TODO still haven't figured out where components get swapped, but this hack appears to be necessary
            img.data[:,:,:] = img.data[:,:,(2,1,0,3)]
        renderprog.finish()

    if settings['lightmapSSS']:
        progress(0.98, 0.99, "Restoring data")
        human.material = materialBackup

    progress(1, None, 'Rendering complete')

    gui3d.app.getCategory('Rendering').getTaskByName('Viewer').setImage(img)
    mh.changeTask('Rendering', 'Viewer')
    gui3d.app.statusPersist('Rendering complete')