예제 #1
0
파일: Runner.py 프로젝트: Dzess/ALFIRT
    initScene = parser.readX3DFile()

    rootFolder = "runner.output"
    inputFolder = os.path.join(rootFolder, gd.inputFolder).replace('\\', '\\\\').replace('\\\\\ ', '\\\ ')
    outputFolder = os.path.join(rootFolder, gd.outputFolder).replace('\\', '\\\\').replace('\\\\\  ', '\\\ ')


    logger.info("Successfully loaded the configuration file and model file")

    # Overall model mechanics for using the renderer
    # TODO: make those elements plug via factories 
    sg = DoubleAxisSceneGenerator(generatorDesc=gd,
                                  initCamera=initScene.camera,
                                  initAnchor=None)

    rg = BlenderGenerator(generatorDescription=gd,
                          inputFolder=inputFolder,
                          outputFolder=outputFolder)

    # BlenderRunner
    logger.info("Running generator")
    runner = BlenderRunner(generatorDescription=gd,
                           sceneGenerator=sg,
                           renderGenerator=rg,
                           rootFolder=rootFolder,
                           modelFileName=parser.x3dFile)

    runner.execute()

    logger.info("Finishing work with ALFIRT project.")
예제 #2
0
    def test_running_blender_case_1(self):
        '''
            Test if the blender script is invoked correctly with 
            corresponding runner. Generates SINGLE (one) file for the blender, and
            creates single scene.
        '''
        sGen = mock()

        # what kind of scenes are to be generated
        camera = ObjectPose([5, 0, 10], [0, 0, 0])
        anchor = ObjectPose([0, 0, 0], [0, 0, 0])

        scene1 = SceneDescription(camera, anchor)
        sceneList = [scene1]
        when(sGen, strict=True).prepareScenes().thenReturn(sceneList)


        #gDesc = self.__getGeneratorDescription()

        inputFileLocation = os.path.join("resources", "models", "cube_0.x3d")

        # use mock for generator description instead of class
        name = "some_expected_name"

        inputFolder = "models"
        outputFolder = "images"

        inputFormat = ".x3d"
        outputFormat = ".bmp"


        gDesc = mock(GeneratorDescription, strict=True)
        gDesc.inputFolder = inputFolder
        gDesc.outputFolder = outputFolder
        gDesc.inputFormat = inputFormat
        gDesc.outputFormat = outputFormat

        gDesc.inputFileName = name

        when(gDesc).getInputFilePath().thenReturn(inputFileLocation)

        inputFolderPath = os.path.join(self.root, inputFolder)
        outputFolderPath = os.path.join(self.root, outputFolder)
        bGen = BlenderGenerator(gDesc, inputFolder=inputFolderPath, outputFolder=outputFolderPath)

        runner = BlenderRunner(generatorDescription=gDesc,
                               sceneGenerator=sGen,
                               renderGenerator=bGen,
                               rootFolder=self.root,
                               modelFileName=inputFileLocation)

        # act
        runner.execute()


        verify(sGen, times=1, atleast=None, atmost=None, between=None)

        expected_name = name + "_0"

        input_path = os.path.join(self.root, gDesc.inputFolder, expected_name + gDesc.inputFormat)
        output_path = os.path.join(self.root, gDesc.outputFolder, expected_name + gDesc.outputFormat)
        script_path = os.path.join(self.root, "scripts", expected_name + ".py")

        print(os.path.abspath(input_path))
        print(os.path.abspath(output_path))
        print(os.path.abspath(script_path))

        # assertion about creating file the file should be created in order for rendering
        self.assertTrue(os.path.exists(input_path), "Expected .x3d file could not be found: " + input_path)

        # assertion about generated script
        self.assertTrue(os.path.exists(script_path), "Expected to find .py rendering script" + script_path)

        # assertion about generated scene
        self.assertTrue(os.path.exists(output_path), "Expected created .bmp file, could not be found: " + output_path)