VFX-UsdAssetResolver icon indicating copy to clipboard operation
VFX-UsdAssetResolver copied to clipboard

Want to load a stage in unreal with asset resolver context

Open 28Rohit opened this issue 1 year ago • 3 comments

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

28Rohit avatar Sep 27 '24 05:09 28Rohit

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 avatar Oct 09 '24 05:10 LucaScheller

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.

28Rohit avatar Oct 11 '24 05:10 28Rohit

@28Rohit and @LucaScheller, thank you so much for the reference code!
I followed your steps to build the PythonResolver for UE 5.3.1, but I’m hitting this error:

Cannot open include file: 'python.hpp': No such file or directory
[C:\Users\kei\Documents\GitHub\VFX-UsdAssetResolver\build\src\PythonResolver\_pythonResolver.vcxproj]

I double-checked and AR_BOOST_INCLUDE_DIR is correctly set to
C:\Program Files\Epic Games\UE_5.3\Engine\Source\ThirdParty\Boost\boost-1_80_0\include.

Any idea what might be missing? I’d really appreciate your thoughts. Thanks again for the help!

kikeda-falcons avatar Nov 03 '25 15:11 kikeda-falcons