Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Want to load a stage in unreal with asset resolver context #22

Open
28Rohit opened this issue Sep 27, 2024 · 2 comments
Open

Want to load a stage in unreal with asset resolver context #22

28Rohit opened this issue Sep 27, 2024 · 2 comments
Assignees

Comments

@28Rohit
Copy link

28Rohit commented Sep 27, 2024

Hello!

This is not an issue, I want help to set a custom resolver before opening the stage in side unreal so that even some tries to load stage with the help of USD stage importer, the stage should open with that context.

Build for unreal asset resolver

REM build.bat

set AR_RESOLVER_NAME=pythonResolver
REM Define App
set AR_DCC_NAME=UNREAL
set UE_ENGINE_LOCATION=C:\Program Files\Epic Games\UE_5.3

REM Clear existing build data and invoke cmake
rmdir /S /Q build
rmdir /S /Q dist
REM Make sure to match the correct VS version the DCC was built with
cmake . -B build -G "Visual Studio 17 2022" -A x64 -T v143
cmake --build build  --clean-first --config Release
cmake --install build

CMakeList.txt

elseif("$ENV{AR_DCC_NAME}" STREQUAL "UNREAL")

    set(AR_UNREAL_ENGINE $ENV{UE_ENGINE_LOCATION}/Engine CACHE PATH "Unreal Engine install directory")
    set(UE_THIRD_PARTY_LOCATION ${AR_UNREAL_ENGINE}/Source/ThirdParty) 
    set(PYTHON_SOURCE_LOCATION ${UE_THIRD_PARTY_LOCATION}/Python3/Win64)

    # TBB 
    set( TBB_LOCATION ${UE_THIRD_PARTY_LOCATION}/Intel/TBB/IntelTBB-2019u8 )
    set( TBB_INCLUDE_LOCATION ${TBB_LOCATION}/include )
    include_directories(${TBB_INCLUDE_LOCATION}) 
    link_directories(${TBB_LOCATION}/lib/Win64/vc14) 

    # Python
    link_directories(${PYTHON_SOURCE_LOCATION}/libs)
    if (WIN32)
        set(AR_PYTHON_LIB python3.9)
        set(AR_PYTHON_LIB_NUMBER python39)       
        set(AR_PYTHON_EXECUTABLE ${AR_UNREAL_ENGINE}/Binaries/ThirdParty/Python3/Win64/python.exe )               
        set(AR_PYTHON_INCLUDE_DIR ${PYTHON_SOURCE_LOCATION}/include)
    else()
        message(FATAL_ERROR "LINUX Configuration pending!")
    endif()

    # Boost
    set(BOOST_LOCATION ${UE_THIRD_PARTY_LOCATION}/Boost/boost-1_80_0)
    set(AR_BOOST_NAMESPACE boost)
    if (WIN32)
        set(AR_BOOST_PYTHON_LIB ${AR_BOOST_NAMESPACE}_${AR_PYTHON_LIB_NUMBER}-mt-x64) #Done ( lib directory needs to add )
        set(AR_BOOST_INCLUDE_DIR ${BOOST_LOCATION}/include) #Done

        # Unreal has seperate link directory
        link_directories(${BOOST_LOCATION}/lib/Win64)

    else()
        message(FATAL_ERROR "LINUX Configuration pending!")
    endif()

    # Usd
    set(UE_USD_IMPORTER ${AR_UNREAL_ENGINE}/Plugins/Importers/USDImporter)
    set(UE_USD_RESOURCE ${UE_USD_IMPORTER}/Source/ThirdParty/USD)
    set(AR_PXR_INCLUDE_DIR ${UE_USD_RESOURCE}/include) #DONE
    set(AR_PXR_LIB_DIR ${UE_USD_RESOURCE}/lib)    #DONE
    set(AR_PXR_LIB_PREFIX "usd_") #Done
    if (WIN32)
        set(AR_PXR_PYTHON_LIB_SITEPACKAGES ${UE_USD_IMPORTER}/Content/Python/Lib/Win64/site-packages ) #DONE
    else()
        message(FATAL_ERROR "LINUX Configuration pending!")
    endif()

endif()

setup.bat

@echo off
REM Clear current session log 
cls
set AR_RESOLVER_NAME=pythonResolver
REM Define App
set AR_DCC_NAME=UNREAL

set REPO_ROOT=C:/path/to//VFX-UsdAssetResolver-main

set UE_PYTHONPATH=%REPO_ROOT%/dist/%AR_RESOLVER_NAME%/lib/python;%PYTHONPATH%
set PXR_PLUGINPATH_NAME=%REPO_ROOT%/dist/%AR_RESOLVER_NAME%/resources;%PXR_PLUGINPATH_NAME%
set LD_LIBRARY_PATH=%REPO_ROOT%/dist/%AR_RESOLVER_NAME%/lib;%LD_LIBRARY_PATH%

set AR_SEARCH_PATHS=%REPO_ROOT%/files/generic/workspace/shots;%REPO_ROOT%/files/generic/workspace/assets
set AR_SEARCH_REGEX_EXPRESSION="(bo)"
set AR_SEARCH_REGEX_FORMAT="Bo"
set TF_DEBUG=AR_RESOLVER_INIT

"C:\Program Files\Epic Games\UE_5.3\Engine\Binaries\Win64\UnrealEditor.exe" -log
@LucaScheller
Copy link
Owner

Hey, sorry for the late reply.
This is great!
I'll try to find some time to review this soon, so that we can add it to the repo.
Thanks for the documentation on what needs to be added.

@LucaScheller LucaScheller self-assigned this Oct 9, 2024
@28Rohit
Copy link
Author

28Rohit commented Oct 11, 2024

Hi @LucaScheller,
Thanks for the reply,
I was trying to load the stage with context which seems to be working fine,

Reference code that I have used:

from pxr import Usd , Ar , Sdf , UsdUtils
stage_cache = UsdUtils.StageCache.Get()
stage = stage_cache.GetAllStages()[0]
context_collection = stage.GetPathResolverContext()
pythonResolver_context = context_collection.Get()[0]
print(pythonResolver_context.GetData())

#LogPython: {"searchPaths": ["C:\\path\\to\\VFX-UsdAssetResolver-main\\files\\generic\\workspace\\shots", "C:\\path\\to\\VFX-UsdAssetResolver-main\\files\\generic\\workspace\\assets"], "mappingRegexExpression": "\"(bo)\"", "mappingRegexFormat": "\"Bo\"", "mappingPairs": {}}

I am still more curious for help or examples which can help to streamline the workflow and make production ready from Unreal side.
Many thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants