Пример #1
0
    def test_badPerFrameSolve(self):
        """
        This file solves wildly, with each frame good, then next bad. The
        animCurves created are very spikey, but we expect to solve a
        smooth curve.

        When opening the scene file manually using the GUI, and
        running the solver, the undo-ing the (bad) result, the
        timeline is traversed slowly. This shows issue #45.
        """
        # Open the Maya file
        file_name = 'mmSolverBasicSolveA_badSolve01.ma'
        path = self.get_data_path('scenes', file_name)
        maya.cmds.file(path, open=True, force=True, ignoreVersion=True)

        # Run solver!
        s = time.time()
        col = mmapi.Collection(node='collection1')
        lib_col.compile_collection(col)
        solres_list = col.execute()
        e = time.time()
        print 'total time:', e - s

        # save the output
        path = self.get_data_path('test_solve_badPerFrameSolve_after.ma')
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        self.checkSolveResults(solres_list)
        return
    def test_allFrameStrategySolve(self):
        """
        Solving only a 'all frames' solver step across multiple frames.
        """
        # Open the Maya file
        file_name = 'mmSolverBasicSolveA_badSolve02.ma'
        path = self.get_data_path('scenes', file_name)
        maya.cmds.file(path, open=True, force=True, ignoreVersion=True)

        # Run solver!
        s = time.time()
        col = mmapi.Collection(node='collection1')
        lib_col.compile_collection(col)
        solres_list = col.execute()
        e = time.time()
        print 'total time:', e - s

        # Set Deviation
        mkr_list = col.get_marker_list()
        mmapi.update_deviation_on_markers(mkr_list, solres_list)
        mmapi.update_deviation_on_collection(col, solres_list)

        # save the output
        path = self.get_data_path('test_solve_allFrameStrategySolve_after.ma')
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        self.checkSolveResults(solres_list)
        return
Пример #3
0
    def test_allFrameStrategySolve(self):
        """
        Solving only a 'all frames' solver step across multiple frames.
        """
        # Open the Maya file
        file_name = 'mmSolverBasicSolveA_badSolve02.ma'
        path = self.get_data_path('scenes', file_name)
        maya.cmds.file(path, open=True, force=True, ignoreVersion=True)

        # Collection
        col = mmapi.Collection(node='collection1')
        mkr_list = col.get_marker_list()

        # Frames
        #
        # Root Frames are automatically calculated from the markers.
        root_frm_list = []
        not_root_frm_list = []
        start_frame, end_frame = time_utils.get_maya_timeline_range_inner()
        min_frames_per_marker = 3
        frame_nums = mmapi.get_root_frames_from_markers(
            mkr_list, min_frames_per_marker, start_frame, end_frame)
        for f in frame_nums:
            frm = mmapi.Frame(f)
            root_frm_list.append(frm)
        for f in range(0, 41):
            frm = mmapi.Frame(f)
            not_root_frm_list.append(frm)

        # Define Solver
        sol_list = []
        sol = mmapi.SolverStandard()
        sol.set_root_frame_list(root_frm_list)
        sol.set_frame_list(not_root_frm_list)
        sol.set_only_root_frames(False)
        sol.set_global_solve(False)
        sol.set_single_frame(False)
        sol.set_root_frame_strategy(mmapi.ROOT_FRAME_STRATEGY_GLOBAL_VALUE)
        sol_list.append(sol)
        col.set_solver_list(sol_list)

        # Run solver!
        s = time.time()
        lib_col.compile_collection(col)
        solres_list = mmapi.execute(col)
        e = time.time()
        print 'total time:', e - s

        # Set Deviation
        mkr_list = col.get_marker_list()
        mmapi.update_deviation_on_markers(mkr_list, solres_list)
        mmapi.update_deviation_on_collection(col, solres_list)

        # save the output
        path = self.get_data_path('test_solve_allFrameStrategySolve_after.ma')
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        self.checkSolveResults(solres_list)
        return
Пример #4
0
    def test_solveAllFramesCausesStaticAnimCurves(self):
        """
        Solving with the scene file 'mmSolverBasicSolveB_before.ma', was
        reported to solve as static values, the same as the initial
        values. The DG did not evaluate some how and the solve was
        therefore useless.

        GitHub Issue #53.
        """
        # Open the Maya file
        file_name = 'mmSolverBasicSolveB_before.ma'
        path = self.get_data_path('scenes', file_name)
        maya.cmds.file(path, open=True, force=True, ignoreVersion=True)

        # Run solver!
        s = time.time()
        col = mmapi.Collection(node='collection1')
        lib_col.compile_collection(col)
        solres_list = col.execute()
        e = time.time()
        print 'total time:', e - s

        # save the output
        name = 'test_solve_solveAllFramesCausesStaticAnimCurves_after.ma'
        path = self.get_data_path(name)
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        self.checkSolveResults(solres_list)
        return
    def apply(self):
        self.setStatusLine(const.STATUS_EXECUTING)
        try:
            refresh_state = lib_state.get_refresh_viewport_state()
            log_level = lib_state.get_log_level()

            self.progressBar.setValue(0)
            self.progressBar.show()
            col = lib_state.get_active_collection()
            if col is None:
                msg = 'No active collection.'
                self.setStatusLine('ERROR: ' + msg)
                LOG.error(msg)
            ok = lib_collection.compile_collection(col)
            if ok is not True:
                msg = 'Cannot execute solver, collection is not valid.'
                msg += 'collection=%r'
                self.setStatusLine('Warning: ' + msg)
                LOG.warning(msg, col)
            else:
                lib_collection.execute_collection(
                    col,
                    log_level=log_level,
                    refresh=refresh_state,
                    prog_fn=self.progressBar.setValue,
                    status_fn=self.setStatusLine,
                )
        finally:
            self.progressBar.setValue(100)
            self.progressBar.hide()
            self.setStatusLine(const.STATUS_FINISHED)
        return
Пример #6
0
    def updateSolveValidState(self):
        self.setStatusLine(const.STATUS_COMPILING)
        v = True
        col = lib_state.get_active_collection()
        if col is None:
            v = False
        else:
            v = lib_col.compile_collection(col)
        assert isinstance(v, bool) is True

        # TODO: Sometimes the apply button is falsely disabled,
        #   therefore we shouldn't disable it until it's fixed.
        # # if self._parentObject is not None:
        # #     self._parentObject.applyBtn.setEnabled(v)

        if v is True:
            self.setStatusLine(const.STATUS_READY)
        else:
            self.setStatusLine(const.STATUS_SOLVER_NOT_VALID)
        return
Пример #7
0
    def test_solveAllFramesCausesStaticAnimCurves(self):
        """
        Solving with the scene file 'mmSolverBasicSolveB_before.ma', was
        reported to solve as static values, the same as the initial
        values. The DG did not evaluate some how and the solve was
        therefore useless.

        GitHub Issue #53.
        """
        # Open the Maya file
        file_name = 'mmSolverBasicSolveB_before.ma'
        path = self.get_data_path('scenes', file_name)
        maya.cmds.file(path, open=True, force=True, ignoreVersion=True)

        # NOTE: We leave these nodes along, since these are already in
        # the 'correct' position, we are treating these as surveyed.
        # When we have less than 3 points as survey the solve goes
        # crazy.
        dont_touch_these_nodes = [
            '|bundle_12_BND', '|bundle_13_BND', '|bundle_14_BND'
        ]

        # Triangulate all 3D points.
        nodes = maya.cmds.ls(type='transform') or []
        bnd_nodes = mmapi.filter_bundle_nodes(nodes)
        bnd_list = [mmapi.Bundle(node=n) for n in bnd_nodes]
        for bnd in bnd_list:
            bnd_node = bnd.get_node()
            if bnd_node in dont_touch_these_nodes:
                continue
            attrs = ['translateX', 'translateY', 'translateZ']
            for attr_name in attrs:
                plug = bnd_node + '.' + attr_name
                maya.cmds.setAttr(plug, lock=False)
            lib_triangulate.triangulate_bundle(bnd)

        # Get Bundle attributes to compute.
        bnd_attr_list = []
        for bnd in bnd_list:
            node = bnd.get_node()
            attrs = ['translateX', 'translateY', 'translateZ']
            for attr_name in attrs:
                attr = mmapi.Attribute(node=node, attr=attr_name)
                bnd_attr_list.append(attr)

        # Camera attributes
        cam_tfm = 'stA_1_1'
        cam_attr_list = []
        attrs = [
            'translateX', 'translateY', 'translateZ', 'rotateX', 'rotateY',
            'rotateZ'
        ]
        for attr_name in attrs:
            attr = mmapi.Attribute(node=cam_tfm, attr=attr_name)
            cam_attr_list.append(attr)

        # Run solver!
        s = time.time()
        # Solve camera transform based on triangulated bundle
        # positions.
        col = mmapi.Collection(node='collection1')
        col.set_attribute_list(cam_attr_list)
        lib_col.compile_collection(col)
        solres_list = col.execute()
        print 'time (solve #1):', time.time() - s

        # Refine the bundle positions only
        s2 = time.time()
        col.set_attribute_list(bnd_attr_list)
        lib_col.compile_collection(col)
        solres_list = col.execute()
        print 'time (solve #2):', time.time() - s2

        # # Solve both camera transform and bundle positions together.
        # s3 = time.time()
        # col.set_attribute_list(cam_attr_list + bnd_attr_list)
        # lib_col.compile_collection(col)
        # solres_list = col.execute()
        e = time.time()
        # print 'time (solve #3):', e - s3
        print 'total time:', e - s

        # save the output
        name = 'test_solve_solveAllFramesCausesStaticAnimCurves_after.ma'
        path = self.get_data_path(name)
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        self.checkSolveResults(solres_list)
        return