Exemple #1
0
def write_preview_shading():
    geoPaths = []
    this = hou.node('.')
    pxrMatPaths = []

    rawFile = this.parm("hi_abc_file").eval()

    if (rawFile != None):
        filename = rawFile.rsplit('.', 3)[0]
        fileNoPath = filename.split('/')[-1]
        dirPath = rawFile.rsplit('/', 1)[0]
        # we get all the unique paths as these are the prim paths in our USD file
        # if we find a unique path we also try to grab the shopmaterialpath, we'll
        # create and bind materials from these
        packNode = this.node('PACK_FOR_SHADERS')

        for prim in packNode.geometry().prims():
            gpath = prim.attribValue('path')
            if gpath is not '':
                if gpath not in geoPaths:
                    gmat = prim.attribValue('shop_materialpath')
                    geoPaths.append((gpath, gmat))

        # now we follow the material links building up shaders, if we've already built
        # the shader then we bind the existing one
        stage = Usd.Stage.Open(filename + '.usda')
        for gpath in geoPaths:
            matName = gpath[1].rsplit('/')[-1]
            if matName is not '':
                sshader = hou.node(gpath[1])

                if sshader:
                    matPath = '/Materials/' + matName
                    if matPath not in pxrMatPaths:
                        pxrMatPaths.append(matPath)
                        #newMaterial(shopShader, stage, matPath, Gf.Vec3f(0.73938,0.742392,0.72749), 0.336918, 0)
                        newMaterialViaShop(sshader, stage, matPath)
                        bindMaterial(stage, gpath[0], matPath)
                    else:
                        bindMaterial(stage, gpath[0], matPath)

        #editMaterial(stage, '/Materials/white_veneer')

    # CreateNewARKitUsdzPackage works with relative pathing, so we need to change our directory path to
    # the exported shaded usd path to sucessfully pull this together
    stage.Export(filename + '.usda')
    os.chdir(dirPath)
    UsdUtils.CreateNewARKitUsdzPackage(fileNoPath + '.usda',
                                       fileNoPath + '.usdz')
def write_arkit_usdz():
    this = hou.node('../../')
    rObj = hou.node(this.parm('obj').eval())
    
    rawDir = rObj.parm('model_dir').eval()
    rawFile = rObj.parm('model_file').eval()
        
    if(rawFile != None):
        filename = rawDir +'usd/' + rawFile
        
        # Let's write out our combined usd that layers the geo with the shading
        stage = Usd.Stage.CreateNew(filename + '.usda')
        
        if this.parm('trange').eval() > 0:
            stage.SetStartTimeCode(this.parm('f1').eval())
            stage.SetEndTimeCode(this.parm('f2').eval())

        rootLayer = stage.GetRootLayer()
        #Sdf.Layer.CreateNew(filename + '_shade.usda')
        #print 'Creating new layer ' + filename + '_shade.usda'
        #Sdf.Layer.CreateNew(filename + '_geo.usdc')
        #print 'Creating new layer ' + filename + '_geo.usdc'
        rootLayer.subLayerPaths.append(filename + '_shade.usda')
        rootLayer.subLayerPaths.append(filename + '_geo.usdc')
        #usdPrim = stage.DefinePrim('/'+rawFile)
        
        #usdPrim.GetReferences().AddReference(filename + '_geo.usdc')
        #usdPrim.GetReferences().AddReference(filename + '_shade.usda')
        
        stage.Export(filename + '.usda')
        #stage.Export(filename + '.usdc')

        # CreateNewARKitUsdzPackage works with relative pathing, so we need to change our directory path to
        # the exported shaded usd path to sucessfully pull this together                
        os.chdir(rawDir + '/usd')
        UsdUtils.CreateNewARKitUsdzPackage(rawFile + '.usda', rawFile + '.usdz')
        
        # remove files that compositied together the usdz
        # os.remove(rawFile + '_shade.usda')
        # os.remove(rawFile + '_geo.usdc')
        # os.remove(rawFile + '.usda')
        # os.remove(rawFile + '.usdc')
Exemple #3
0
def main():
    parser = argparse.ArgumentParser(
        description='Utility for creating a .usdz '
        'file containging USD assets and for inspecting existing .usdz files.')

    parser.add_argument('usdzFile',
                        type=str,
                        nargs='?',
                        help='Name of the .usdz file to create or to inspect '
                        'the contents of.')

    parser.add_argument('inputFiles',
                        type=str,
                        nargs='*',
                        help='Files to include in the .usdz file.')
    parser.add_argument('-r',
                        '--recurse',
                        dest='recurse',
                        action='store_true',
                        help='If specified, files in sub-directories are '
                        'recursively added to the package.')

    parser.add_argument(
        '-a',
        '--asset',
        dest='asset',
        type=str,
        help='Resolvable asset path pointing to the root layer '
        'of the asset to be isolated and copied into the '
        'package.')
    parser.add_argument("--arkitAsset",
                        dest="arkitAsset",
                        type=str,
                        help="Similar to the --asset option, the --arkitAsset "
                        "option packages all of the dependencies of the named "
                        "scene file.  Assets targeted at the initial usdz "
                        "implementation in ARKit operate under greater "
                        "constraints than usdz files for more general 'in "
                        "house' uses, and this option attempts to ensure that "
                        "these constraints are honored; this may involve more "
                        "transformations to the data, which may cause loss of "
                        "features such as VariantSets.")

    parser.add_argument(
        '-c',
        '--checkCompliance',
        dest='checkCompliance',
        action='store_true',
        help='Perform compliance checking '
        'of the input files. If the input asset or \"root\" '
        'layer fails any of the compliance checks, the package '
        'is not created and the program fails.')

    parser.add_argument(
        '-l',
        '--list',
        dest='listTarget',
        type=str,
        nargs='?',
        default=None,
        const='-',
        help='List contents of the specified usdz file. If '
        'a file-path argument is provided, the list is output '
        'to a file at the given path. If no argument is '
        'provided or if \'-\' is specified as the argument, the'
        ' list is output to stdout.')
    parser.add_argument(
        '-d',
        '--dump',
        dest='dumpTarget',
        type=str,
        nargs='?',
        default=None,
        const='-',
        help='Dump contents of the specified usdz file. If '
        'a file-path argument is provided, the contents are '
        'output to a file at the given path. If no argument is '
        'provided or if \'-\' is specified as the argument, the'
        ' contents are output to stdout.')

    parser.add_argument('-v',
                        '--verbose',
                        dest='verbose',
                        action='store_true',
                        help='Enable verbose mode, which causes messages '
                        'regarding files being added to the package to be '
                        'output to stdout.')

    args = parser.parse_args()
    usdzFile = args.usdzFile
    inputFiles = args.inputFiles

    if args.asset and args.arkitAsset:
        parser.error("Specify either --asset or --arkitAsset, not both.")

    elif (args.arkitAsset or args.asset) and len(inputFiles) > 0:
        parser.error("Specify either inputFiles or an asset (via --asset or "
                     "--arkitAsset, not both.")

    # If usdzFile is not specified directly as an argument, check if it has been
    # specified as an argument to the --list or --dump options. In these cases,
    # output the list or the contents to stdout.
    if not usdzFile:
        if args.listTarget and args.listTarget != '-' and \
           args.listTarget.endswith('.usdz') and \
           os.path.exists(args.listTarget):
            usdzFile = args.listTarget
            args.listTarget = '-'
        elif args.dumpTarget and args.dumpTarget != '-' and \
           args.dumpTarget.endswith('.usdz') and \
           os.path.exists(args.dumpTarget):
            usdzFile = args.dumpTarget
            args.dumpTarget = '-'
        else:
            parser.error("No usdz file specified!")

    # Check if we're in package creation mode and verbose mode is enabled,
    # print some useful information.
    if (args.asset or args.arkitAsset or len(inputFiles) > 0):
        # Ensure that the usdz file has the right extension.
        if not usdzFile.endswith('.usdz'):
            usdzFile += '.usdz'

        if args.verbose:
            if os.path.exists(usdzFile):
                print("File at path '%s' already exists. Overwriting file." %
                      usdzFile)

            if args.inputFiles:
                print('Creating package \'%s\' with files %s.' %
                      (usdzFile, inputFiles))

            if args.asset or args.arkitAsset:
                Tf.Debug.SetDebugSymbolsByName("USDUTILS_CREATE_USDZ_PACKAGE",
                                               1)

            if not args.recurse:
                print('Not recursing into sub-directories.')
    else:
        if args.checkCompliance:
            parser.error(
                "--checkCompliance should only be specified when "
                "creatinga usdz package. Please use 'usdchecker' to check "
                "compliance of an existing .usdz file.")

    success = True
    if len(inputFiles) > 0:
        success = _CreateUsdzPackage(usdzFile, inputFiles, args.recurse,
                                     args.checkCompliance,
                                     args.verbose) and success

    elif args.asset:
        r = Ar.GetResolver()
        resolvedAsset = r.Resolve(args.asset)
        if args.checkCompliance:
            success = _CheckCompliance(resolvedAsset, arkit=False) and success

        context = r.CreateDefaultContextForAsset(resolvedAsset)
        with Ar.ResolverContextBinder(context):
            # Create the package only if the compliance check was passed.
            success = success and UsdUtils.CreateNewUsdzPackage(
                Sdf.AssetPath(args.asset), usdzFile)

    elif args.arkitAsset:
        r = Ar.GetResolver()
        resolvedAsset = r.Resolve(args.arkitAsset)
        if args.checkCompliance:
            success = _CheckCompliance(resolvedAsset, arkit=True) and success

        context = r.CreateDefaultContextForAsset(resolvedAsset)
        with Ar.ResolverContextBinder(context):
            # Create the package only if the compliance check was passed.
            success = success and UsdUtils.CreateNewARKitUsdzPackage(
                Sdf.AssetPath(args.arkitAsset), usdzFile)

    if args.listTarget or args.dumpTarget:
        if os.path.exists(usdzFile):
            zipFile = Usd.ZipFile.Open(usdzFile)
            if zipFile:
                if args.dumpTarget:
                    if args.dumpTarget == usdzFile:
                        _Err("The file into which to dump the contents of the "
                             "usdz file '%s' must be different from the file "
                             "itself." % usdzFile)
                        return 1
                    _DumpContents(args.dumpTarget, zipFile)
                if args.listTarget:
                    if args.listTarget == usdzFile:
                        _Err("The file into which to list the contents of the "
                             "usdz file '%s' must be different from the file "
                             "itself." % usdzFile)
                        return 1
                    _ListContents(args.listTarget, zipFile)
            else:
                _Err("Failed to open usdz file at path '%s'." % usdzFile)
        else:
            _Err("Can't find usdz file at path '%s'." % usdzFile)

    return 0 if success else 1
Exemple #4
0
                        dest='numErrors',
                        default=0,
                        type=int,
                        action='store')

    args = parser.parse_args()

    context = Ar.GetResolver().CreateDefaultContextForAsset(args.assetPath)
    with Ar.ResolverContextBinder(context):
        if not args.arkit:
            assert UsdUtils.CreateNewUsdzPackage(
                Sdf.AssetPath(args.assetPath), args.usdzFile,
                args.rename if args.rename else '')
        else:
            assert UsdUtils.CreateNewARKitUsdzPackage(
                Sdf.AssetPath(args.assetPath), args.usdzFile,
                args.rename if args.rename else '')

    zipFile = Usd.ZipFile.Open(args.usdzFile)
    assert zipFile

    with stream(args.outfile, 'w') as ofp:
        for fileName in zipFile.GetFileNames():
            print >> ofp, fileName

    # Validate that the usdz file can be opened on a stage.
    stage = Usd.Stage.Open(args.usdzFile)
    assert stage

    if args.check:
        rootLayerPath = stage.GetRootLayer().realPath
Exemple #5
0
from helpers.DataManager import get_closing_info
from helpers.DataManager import get_percentage_difference
from modelGenerations.generateModel import generate_chart_model
from pxr import Usd, UsdUtils

if __name__ == '__main__':
    stage = Usd.Stage.CreateNew('assets/Final.usd')
    ticker_symbols = ['MSFT', 'AAPL', 'TSLA', 'GOOGL']

    for ticker_position in range(0, len(ticker_symbols)):
        dates, prices = get_closing_info(ticker_symbols[ticker_position])
        percentage_difference = get_percentage_difference(prices)
        percentage_difference = [0] + percentage_difference
        generate_chart_model(stage, ticker_position,
                             ticker_symbols[ticker_position], prices[:20],
                             percentage_difference[:20])

    stage.Save()
    UsdUtils.CreateNewARKitUsdzPackage('assets/Final.usd', 'assets/Final.usdz')
Exemple #6
0
    parser.add_argument('assetPath')
    parser.add_argument('-l',
                        '--listContents',
                        type=str,
                        default='-',
                        dest='outfile')
    parser.add_argument('-n',
                        '--firstLayerName',
                        type=str,
                        default='',
                        dest='rename')
    parser.add_argument('--arkit', dest="arkit", action="store_true")

    args = parser.parse_args()

    context = Ar.GetResolver().CreateDefaultContextForAsset(args.assetPath)
    with Ar.ResolverContextBinder(context):
        if not args.arkit:
            assert UsdUtils.CreateNewUsdzPackage(
                Sdf.AssetPath(args.assetPath), args.usdzFile,
                args.rename if args.rename else "")
        else:
            assert UsdUtils.CreateNewARKitUsdzPackage(
                Sdf.AssetPath(args.assetPath), args.usdzFile)

    zipFile = Usd.ZipFile.Open(args.usdzFile)
    assert zipFile

    with stream(args.outfile, 'w') as ofp:
        for fileName in zipFile.GetFileNames():
            print >> ofp, fileName