Ejemplo n.º 1
0
            def testLambda(self):
                sdPackage = tools.loadSDPackage(self.context, str(pathPackage))
                self.assertTrue(sdPackage,
                                f'Fail to load package from {pathPackage}')

                sdMDLGraph = next(
                    (sdResource
                     for sdResource in sdPackage.getChildrenResources(False)
                     if isinstance(sdResource, SDMDLGraph)), None)
                self.assertTrue(
                    sdMDLGraph,
                    'Could not find a MDL Graph in the package at depth 1')

                pathMDLE = Path(
                    tools.getTestOutputDir(__file__)
                ) / f'{pathPackage.stem}_{sdMDLGraph.getIdentifier()}.mdle'

                if pathMDLE.exists():
                    pathMDLE.unlink()

                if pathMDLE.parent.exists():
                    pathMDLE.parent.rmdir()

                SDMDLEExporter.sExportPreset(sdMDLGraph, str(pathMDLE))

                # Check results
                self.assertTrue(
                    pathMDLE.exists(),
                    f'Failed to export {sdMDLGraph.getIdentifier()} to {pathMDLE}'
                )

                logger.debug(
                    f'{sdMDLGraph.getIdentifier()} exported to {pathMDLE}')
    def runTest(self):
        context = sd.getContext()
        srcPackageFileName = 'test_export.sbs'
        sdPackage = tools.loadSDPackage(context, srcPackageFileName)
        self.assertTrue(sdPackage, 'Fail to load package')

        sbsarFilePath = os.path.join(tools.getTestOutputDir(__file__), 'test_new_content_output.sbsar')

        if os.path.isfile(sbsarFilePath):
            logger.debug('Remove existing file: ' + sbsarFilePath)
            os.remove(sbsarFilePath)
            self.assertFalse(os.path.isfile(sbsarFilePath))


        logger.debug('Export package to: ' + sbsarFilePath)
        sdSBSARExporter = SDSBSARExporter.sNew()
        sdSBSARExporter.setExposeRandomSeed(False)
        sdSBSARExporter.exportPackageToSBSAR(sdPackage, sbsarFilePath)

        # Check that sbsar file exist
        self.assertTrue(os.path.isfile(sbsarFilePath))

        # Check file size
        statinfo = os.stat(sbsarFilePath)
        self.assertTrue(statinfo.st_size > 0)
Ejemplo n.º 3
0
 def __test_File(self, aContext, aPackageFile, aResourceSuffixList):
     # Load Package
     sdPackage = tools.loadSDPackage(aContext, aPackageFile)
     self.assertTrue(sdPackage, 'Fail to load package')
     self.__test_SDMDLExporter_sExportPackage(sdPackage,
                                              aResourceSuffixList)
     self.__test_SDMDLExporter_sExportPreset(sdPackage, aResourceSuffixList)
Ejemplo n.º 4
0
 def __mainFlat(self, aContext):
     sdPackage = tools.loadSDPackage(aContext, '2_sbs_graphs.sbs')
     sdResources = sdPackage.getChildrenResources(True)
     for sdResource in sdResources:
         # Check if the resource is a SDGraph
         if issubclass(type(sdResource), sdgraph.SDGraph):
             sdNodes = sdResource.getNodes()
             for sdNode in sdNodes:
                 pos = sdNode.getPosition()
Ejemplo n.º 5
0
    def __mainArrays(self, aContext):
        sdPackage = tools.loadSDPackage(aContext, '2_sbs_graphs.sbs')
        firstResource = None
        for resource in sdPackage.getChildrenResources(True):
            firstResource = resource
            break
        logger.debug(firstResource.getIdentifier())
        logger.debug(firstResource.getType().getId())

        firstNode = None
        for node in firstResource.getNodes():
            firstNode = node
            break
        logger.debug('Pos: %dx%d' % (firstNode.getPosition().x, firstNode.getPosition().y))
Ejemplo n.º 6
0
    def runTest(self):
        context = sd.getContext()
        srcPackageFileName = 'test_read_content.sbs'
        sdPackage = tools.loadSDPackage(context, srcPackageFileName)
        self.assertTrue(sdPackage, 'Fail to load package')

        # Check Serialization
        logFileDir = tools.getAssetsDir()
        currentFileBaseName = io.getFileBaseName(__file__)
        srcDumpFile = os.path.join(logFileDir, currentFileBaseName + '.txt')

        dumpLines = data_serializer.DataSerializer().serializeSDPackage(
            sdPackage)

        # ------------------------------------------------
        # For development only
        createSrcDumpFile = False
        if createSrcDumpFile:
            # test with file
            with open(srcDumpFile, 'wt', encoding='utf-8') as f:
                for line in dumpLines:
                    f.write(line + '\n')
                f.close()
        # ------------------------------------------------

        # Read src Dump File
        srcDumpFileLines = []

        with open(srcDumpFile, 'rt', encoding='utf-8') as rf:
            srcDumpFileLines = rf.readlines()
            rf.close()

        # Compare Lines
        for i in range(0, len(dumpLines)):
            srcLine = srcDumpFileLines[i]
            line = dumpLines[i]
            self.__compareLines(line, srcLine)

        # Check data coherency
        self.__checkSDPackage(sdPackage)

        # Check some MDL Data
        self.__checkMDL(sdPackage)

        # Check some Properties
        self.__checkGetProperties(sdPackage)
Ejemplo n.º 7
0
    def runTest(self):
        context = sd.getContext()

        # Load Package
        sdPackage = tools.loadSDPackage(context, 'test_export.sbs')
        self.assertTrue(sdPackage, 'Fail to load package')

        graphUrl = 'myGraph1'
        sdResource = sdPackage.findResourceFromUrl(graphUrl)
        self.assertTrue(sdResource, 'Graph \'%s\'not found' % graphUrl)
        # Check if the resource is a SDGraph
        if not issubclass(type(sdResource), sdgraph.SDGraph):
            self.assertTrue(sdResource,
                            'Resource \'%s\' is not a Graph' % graphUrl)
        self.__checkGraph(sdResource)

        outputDir = context.getTempDir(
            os.path.split(__file__)[1].split('.')[0])
        self.__exportGraph(sdResource, outputDir)
Ejemplo n.º 8
0
    def __mainNested(self, aContext):
        """
        This test is crafted to make sure objects are taken out of array and that they still
        are valid after the array goes out of scope
        """
        def __getResourceCount(package):
            return len(package.getChildrenResources(True))

        def __getResourceByIndex(package, index):
            return package.getChildrenResources(True)[index]

        sdPackage = tools.loadSDPackage(aContext, '2_sbs_graphs.sbs')
        for i in range(__getResourceCount(sdPackage)):
            # Check if the resource is a SDGraph
            sdResource = __getResourceByIndex(sdPackage, i)
            if issubclass(type(sdResource), sdgraph.SDGraph):
                sdNodes = sdResource.getNodes()
                for sdNode in sdNodes:
                    pos = sdNode.getPosition()
    def runTest(self):
        context = sd.getContext()
        srcPackageFileName = 'test_read_content.sbs'
        sdPackage = tools.loadSDPackage(context, srcPackageFileName)
        self.assertTrue(sdPackage, 'Fail to load package')

        # Get the graph
        sdSBSCompGraph = sdPackage.findResourceFromUrl(
            'sbs/compositing/sbs_comp_graph_outputs')
        self.assertTrue(sdSBSCompGraph)

        sdSBSCompGraph.compute()

        self.__checkValueProcessorNode(sdSBSCompGraph, '1343239036',
                                       SDValueBool.sNew(False))

        self.__checkValueProcessorNode(sdSBSCompGraph, '1343238354',
                                       SDValueInt.sNew(10))
        self.__checkValueProcessorNode(sdSBSCompGraph, '1343238355',
                                       SDValueInt2.sNew(int2(8, 4)))
        self.__checkValueProcessorNode(sdSBSCompGraph, '1343238353',
                                       SDValueInt3.sNew(int3(10, 8, 6)))
        self.__checkValueProcessorNode(sdSBSCompGraph, '1343238356',
                                       SDValueInt4.sNew(int4(18, 12, 8, 4)))

        self.__checkValueProcessorNode(sdSBSCompGraph, '1343233566',
                                       SDValueFloat.sNew(1.2))
        self.__checkValueProcessorNode(
            sdSBSCompGraph, '1343238020',
            SDValueFloat2.sNew(float2(0.552, 0.308)))
        self.__checkValueProcessorNode(
            sdSBSCompGraph, '1343238028',
            SDValueFloat3.sNew(float3(0.699, 0.401940047, 0.24966)))
        self.__checkValueProcessorNode(
            sdSBSCompGraph, '1343238035',
            SDValueFloat4.sNew(float4(0.81172, 0.58140003, 0.45955, 0.41952)))

        # Check Output that return a texture
        self.__checkOutputTexture(sdSBSCompGraph, '1343386302')
Ejemplo n.º 10
0
    def runTest(self):
        context = sd.getContext()

        # Load Package
        sdPackage = tools.loadSDPackage(context, '2_sbs_graphs.sbs')

        # Process all nodes
        for sdResource in sdPackage.getChildrenResources(True):
            # Check if the resource is a SDGraph
            if not issubclass(type(sdResource), sdgraph.SDGraph):
                continue
            res = graphlayout.alignSDNodes(
                sdResource.getNodes(),
                aAlignDirection=graphlayout.AlignmentDirection.Horizontal)
            self.assertTrue(res, 'Fail to align horizontally SDNodes')

            res = graphlayout.alignSDNodes(
                sdResource.getNodes(),
                aAlignDirection=graphlayout.AlignmentDirection.Vertical)
            self.assertTrue(res, 'Fail to align vertically SDNodes')

            res = graphlayout.snapSDNodes(sdResource.getNodes())
            self.assertTrue(res, 'Fail to snap SDNodes')
Ejemplo n.º 11
0
    def runTest(self):
        context = sd.getContext()
        srcPackageFileName = '2_sbs_graphs.sbs'
        sdPackage = tools.loadSDPackage(context, srcPackageFileName)
        self.assertTrue(sdPackage, 'Fail to load package')

        filePath = sdPackage.getFilePath()
        self.assertEqual(os.path.split(filePath)[1], srcPackageFileName, 'Fail to load package')

        sdResourceArray = sdPackage.getChildrenResources(True)
        self.assertTrue(sdResourceArray)

        # self.assertTrue(len(sbsGraphArray) == 2)
        sdGraphIndex = -1
        tab = '\t'
        for sdResource in sdResourceArray:
            sdResourceIdentifier = sdResource.getIdentifier()
            # Check if the resource is a SDGraph
            if not issubclass(type(sdResource), sdgraph.SDGraph):
                continue
            sdGraphIndex = sdGraphIndex + 1
            sdNodeArray = sdResource.getNodes()
            self.assertTrue(sdNodeArray, 'Fail to get Nodes from SD Graph')
            sdNodeArraySize = len(sdNodeArray)

            if sdGraphIndex == 0:
                self.assertEqual(sdResourceIdentifier, 'myGraph1', 'Graph identifier comparison failed')
                self.assertEqual(sdNodeArraySize, 7, 'Invalid Node count')
            elif sdGraphIndex == 1:
                self.assertEqual(sdResourceIdentifier, 'mySubGraph2', 'Graph identifier comparison failed')
                self.assertEqual(sdNodeArraySize, 5, 'Invalid Node count')
            # put nodes horizontally
            for sdNode in sdNodeArray:
                pos = sdNode.getPosition()
                self.assertTrue(pos, 'Fail to get node Position')

                # Check node position modification
                newPosX = 1234
                newPosY = -654
                sdNode.setPosition(float2(newPosX, newPosY))

                pos = sdNode.getPosition()
                self.assertTrue(pos, 'Fail to get node Position')
                self.assertEqual(pos.x, newPosX, 'Node Position X has not been set correctly')
                self.assertEqual(pos.y, newPosY, 'Node Position Y has not been set correctly')

                nodeDefinition = sdNode.getDefinition()
                inputProperties = nodeDefinition.getProperties(sdproperty.SDPropertyCategory.Input)
                logging.debug(tab + 'Node: ')
                for sdProperty in inputProperties:
                    name = sdProperty.getId()
                    sdType = sdProperty.getType()
                    category = sdProperty.getCategory()
                    logging.debug(tab*2 + '"%s" : "%s" (%s)' % (name, sdType.getId(), str(category)))
                    self.assertTrue(name, 'Empty property name')
                    # self.assertTrue(sdType, 'Empty property sdType for "' + name +'"')
                outputProperties = nodeDefinition.getProperties(sdproperty.SDPropertyCategory.Output)
                logging.debug(tab + 'Node: ')
                for sdProperty in outputProperties:
                    name = sdProperty.getId()
                    sdType = sdProperty.getType()
                    category = sdProperty.getCategory()
                    logging.debug(tab*2 + '"%s" : "%s" (%s)' % (name, sdType.getId(), str(category)))
                    self.assertTrue(name, 'Empty property name')
                    # self.assertTrue(sdType, 'Empty property sdType for "' + name +'"')

            # Save package to new file
            dstFileAbsPath = os.path.join(tools.getTestOutputDir(__file__), 'output.sbs')
            context.getSDApplication().getPackageMgr().savePackageAs(sdPackage, dstFileAbsPath)