From 453a995351e94cca2bbaeebfea811e84b1dab816 Mon Sep 17 00:00:00 2001 From: HogJonny-AMZN Date: Thu, 21 Jul 2022 19:14:37 -0500 Subject: [PATCH] my hacks to run locallly in the way I wanted as a dev Signed-off-by: HogJonny-AMZN --- .../DCC/Maya/Tools/KitbashConversion/main.py | 86 ++++++++++++++++++- .../Tools/KitbashConversion/mps_readme.txt | 49 +++++++++++ .../KitbashConversion/process_fbx_file.py | 2 +- .../Tools/Dev/Windows/IDE/Env_Dev.bat.example | 37 +++++++- .../DccScriptingInterface/config.py | 15 +++- 5 files changed, 178 insertions(+), 11 deletions(-) create mode 100644 Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/Tools/DCC/Maya/Tools/KitbashConversion/mps_readme.txt diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/Tools/DCC/Maya/Tools/KitbashConversion/main.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/Tools/DCC/Maya/Tools/KitbashConversion/main.py index 0e6821f9a574..4557e5674627 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/Tools/DCC/Maya/Tools/KitbashConversion/main.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/Tools/DCC/Maya/Tools/KitbashConversion/main.py @@ -25,8 +25,45 @@ import sys import os import re +import site # azpy bootstrapping and extensions + +#### This would all occur in the maya/config.py #### +# so we'd only import one line of code to get all of this +# but I added this to make sure I could get to Qt / PySide2 +# maya has not yet been updated to the config.py patterns +# +# This ensures basic code access to the DCCsi +# /Gems/AtomLyIntegration/TechnicalArt/ +_MODULE_PATH = Path(__file__) +_PATH_DCCSIG = _MODULE_PATH.parents[5] +site.addsitedir(_PATH_DCCSIG.as_posix()) + +# now we know we will have known dccsi azpy api access +import azpy.config_utils + +# set envar with modules locally derived value +# to ensure we bootstrap with it (config.py) +from azpy.constants import ENVAR_PATH_DCCSIG +os.environ[ENVAR_PATH_DCCSIG] = _PATH_DCCSIG.as_posix() + +# this will bootstrap access to the dccsi managed package dependencies +# \3rdParty\Python\Lib\3.x\3.x.x (based on python version) +# know we know we'll have package dependancy access before other code runs +_PATH_DCCSI_PYTHON_LIB = azpy.config_utils.bootstrap_dccsi_py_libs() +site.addsitedir(_PATH_DCCSI_PYTHON_LIB.as_posix()) + +# This will import and retrieve the core /config.py and settings +_DCCSI_CORE_CONFIG = azpy.config_utils.get_dccsi_config(_PATH_DCCSIG) + +# now standalone we can validate the config, env, settings. +# I want to make sure that I am boostrapping Qt/PySide +_SETTINGS = _DCCSI_CORE_CONFIG.get_config_settings(enable_o3de_python=False, + enable_o3de_pyside2=True, + set_env=True) +#################################################### + from azpy.constants import FRMT_LOG_LONG # O3DE Qt/PySide2 @@ -63,6 +100,50 @@ # TODO - Add Blender support # TODO - Put in a better system for processing all available file types (blend, fbx, mb, ma). +#### I modified this code #### +# ideally all or most of this would just be pulled from settings like +# +# _all_properties_location = Path(settings.O3DE_CACHE, 'pc', 'materials', 'types', +# 'standardpbr_allproperties.material').resolve() +# +# But the cache was not previously considered, so not plumbed into config prior +# +# so I was hacking, I made a string of changes until the tool ran. +# and not that many... there are way more comments here then actual code changes. +# and some of these code changes I would actually streamline if I wasn't hacking. +# +# this would generally be your engine code repository, in fact it is (c:\o3de-ben\...) +# In my Env_Dev.bat this is: "set O3DE_DEV=c:\depot\o3de-ben" +_engine_root = Path(os.getenv('O3DE_DEV', _PATH_DCCSIG.parents[4])).resolve() + +# this would generally be your engine build binaries folder +# However, I switched this in the Env_Dev.bat to my already built engine bin folder +# In my Env_Dev.bat this is: set "PATH_O3DE_BIN=c:\depot\o3de-dev\build\bin\profile" +# if the envar key:value isn't set, it's gonna try a default location +# but if not set in Env_Dev.bat (or otherwise specified), the default fallback likely is wrong +# because engine-centric or project-centric build, +# or user specified build directory folder name for cmake, +# or the predetermined bin path for installer builds. +# the point is ... we don't know which engine, we don't know the bin path +# developers often work differently then downstream end user csutomers. +_engine_bin = Path(os.getenv('PATH_O3DE_BIN', Path(_engine_root, 'build/bin/profile'))).resolve() + +# I want to get to the cache, it used to be under the legacy engine ... +# now it's always under a project, but unless the user can specify which project +# we don't have a good way to know in a standalone tool which cache to access +# we would know if starting from the o3de editor, or a launcher that let them pick +# I am not doing either of those things, right now I just wanted to: +# 1) either start this tool from IDE +# 2) or start this tool from some command line, and then remote debug in IDE +# I just wanted a easy way to specify which cache and move on +# so this was set in my Env_Dev.bat files, so I didn't have to write new code +# set "PATH_O3DE_CACHE=C:\depot\MPS-test-project\Cache" +_PATH_O3DE_CACHE = Path(os.getenv('PATH_O3DE_CACHE')).resolve() + +_all_properties_location = Path(_PATH_O3DE_CACHE, 'pc', 'materials', 'types', + 'standardpbr_allproperties.material').resolve() + +############################## class KitbashConverter(QtWidgets.QDialog): def __init__(self, parent=None): @@ -77,8 +158,7 @@ def __init__(self, parent=None): self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowMinMaxButtonsHint) self.default_search_path = Path(__file__).as_posix() - self.all_properties_location = 'E:/Depot/EnginePythonTesting/Cache/pc/materials/types/' \ - 'standardpbr_allproperties.material' + self.all_properties_location = _all_properties_location.as_posix() self.autodesk_directory = Path(os.environ['ProgramFiles']) / 'Autodesk' self.default_material_definition = 'standardPBR.template.material' self.supported_file_extensions = ['.fbx', '.ma', '.mb'] @@ -1053,7 +1133,7 @@ def launch_kitbash_converter(): app.setStyle('Fusion') converter = KitbashConverter() converter.show() - sys.exit(app.exec_()) + sys.exit(app.exec_()) if __name__ == '__main__': diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/Tools/DCC/Maya/Tools/KitbashConversion/mps_readme.txt b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/Tools/DCC/Maya/Tools/KitbashConversion/mps_readme.txt new file mode 100644 index 000000000000..fa0932e70d4b --- /dev/null +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/Tools/DCC/Maya/Tools/KitbashConversion/mps_readme.txt @@ -0,0 +1,49 @@ +1. I unpacked the KB3D kit .zip file to here (source folder): + + C:\depot\o3de-multiplayersample-assets\Gems\kb3d_mps\.src\KB3D_HighTechStreets + +2. I copied the KB3DTextures to here (assets folder): + + C:\depot\o3de-multiplayersample-assets\Gems\kb3d_mps\Assets\KB3D_HighTechStreets\KB3DTextures + +3. I started Maya: + I set the project workspace, Maya > File > Set Project ... + C:\depot\o3de-multiplayersample-assets\Gems\kb3d_mps\ + +4. worked on the source scene to repath textures (from source to assets) + Maya > Windows > General Editors > Fiule path editor ... + + I repathed all textures, with relative paths to "../assets/KB3D_HighTechStreets/KB3DTextures" + +5. I worked on scene cleanup + - I set preferences: Z-up scene, Meter units + - I imported the native (.ma) from: + "C:\depot\o3de-multiplayersample-assets\Gems\kb3d_mps\.src\KB3D_HighTechStreets\KB3D_HiTechStreets-Native.ma" + - I placed all objects within a group, I set that group nodes pivot to the origin + - I rotated the parent group, so all models were Z-up + - I adjusted the parent groups pivot, to drop it to the bottom of the objects + - I moved the parent group up, so the adjusted pivot was at 0,0,0 + - I froze transforms on the parent group + - then I unparented all objects, so they are no longer under the parent group node + - I deleted the parent group node + +5. I saved the file (as a binary .mb) to: + "C:\depot\o3de-multiplayersample-assets\Gems\kb3d_mps\.src\KB3D_HighTechStreets\KB3D_HighTechStreets.mb" + +6. I cleaned up all the materials, I removed the _blinn from the material node names, then resaved the file + +7. I exported an SOURCE FBX: + "C:\depot\o3de-multiplayersample-assets\Gems\kb3d_mps\.src\KB3D_HighTechStreets\KB3D_HighTechStreets.fbx" + + also an ascii version (so I could inspect the paths): KB3D_HighTechStreets_ascii.fbx + +8. then ran Ben's tool + + I actually used the source .mb, and not the .fbx + input file: "C:\depot\o3de-multiplayersample-assets\Gems\kb3d_mps\.src\KB3D_HighTechStreets\KB3D_HighTechStreets.fbx" + + output directory: "C:\depot\o3de-multiplayersample-assets\Gems\kb3d_mps\" + +This mostly worked but I am seeing some other issues + +... to be continued \ No newline at end of file diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/Tools/DCC/Maya/Tools/KitbashConversion/process_fbx_file.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/Tools/DCC/Maya/Tools/KitbashConversion/process_fbx_file.py index cd746b05a804..c13bb5116d90 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/Tools/DCC/Maya/Tools/KitbashConversion/process_fbx_file.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/Tools/DCC/Maya/Tools/KitbashConversion/process_fbx_file.py @@ -339,7 +339,7 @@ def get_relative_path(self, full_path): path_parts = full_path.split('/') for index, part in enumerate(path_parts): if part == 'KB3DTextures': - return '/'.join(path_parts[(index-2):]) + return '/'.join(path_parts[(index - 1):]) return full_path ############################## diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/Tools/Dev/Windows/IDE/Env_Dev.bat.example b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/Tools/Dev/Windows/IDE/Env_Dev.bat.example index 4c26dcf268ae..8dec28c37b46 100644 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/Tools/Dev/Windows/IDE/Env_Dev.bat.example +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/Tools/Dev/Windows/IDE/Env_Dev.bat.example @@ -17,20 +17,49 @@ echo. echo ~ local env settings echo. -set O3DE_BUILD_FOO=True -echo O3DE_BUILD_FOO = %O3DE_BUILD_FOO% +:: set O3DE_BUILD_FOO=True +::echo O3DE_BUILD_FOO = %O3DE_BUILD_FOO% +:: this is your engine root locally, I pulled your branch - I did not build your branch +set O3DE_DEV=c:\depot\o3de-ben +echo O3DE_DEV = %O3DE_DEV% + +:: devs when they configuyre with cmake, can specify their build folder name +:: there is not a standard and could be entirely unknown, I use build, some people use build/windows2019 set O3DE_BUILD_FOLDER=build echo O3DE_BUILD_FOLDER = %O3DE_BUILD_FOLDER% -set DCCSI_GDEBUG=True +:: this assumes building in an engine centric way, which is how I work. +:: this is not the only way to work, there are project centric builds. +set "PATH_O3DE_BUILD=%O3DE_DEV%\%O3DE_BUILD_FOLDER%" +echo PATH_O3DE_BUILD = %PATH_O3DE_BUILD% + +:: +::set "PATH_O3DE_BIN=%PATH_O3DE_BUILD%\bin\profile" +::set "PATH_O3DE_BIN=%O3DE_DEV%\build\bin\profile" + +:: I didn't want to build the engine just so I could get to PySide2 and Qt .dlls +:: I already have the engine built, so I just pointed to mine other engine repo here +:: You can just point this directly to your build bin folder +set "PATH_O3DE_BIN=c:\depot\o3de-dev\build\bin\profile" +echo PATH_O3DE_BIN = %PATH_O3DE_BIN% + +:: and I just wanted a quick way to get to my cache for the standardpbr_allproperties.material +:: note: we should make the cache folder a legit thing to access from config.py / settings +:: you can set this to any cache folder you want to pull from +set "PATH_O3DE_CACHE=C:\depot\MPS-test-project\Cache" +echo PATH_O3DE_CACHE = %PATH_O3DE_CACHE% + +set DCCSI_GDEBUG=False echo DCCSI_GDEBUG = %DCCSI_GDEBUG% -set DCCSI_DEV_MODE=True +set DCCSI_DEV_MODE=False echo DCCSI_DEV_MODE = %DCCSI_DEV_MODE% set DCCSI_GDEBUGGER=WING echo DCCSI_GDEBUGGER = %DCCSI_GDEBUGGER% +:: even though I disable global debug flag, which does some additional checks/tests and is way more verbose. +:: I can still seperetly enable debug logging, so I can still important breadcrumbs. set DCCSI_LOGLEVEL=10 echo DCCSI_LOGLEVEL = %DCCSI_LOGLEVEL% diff --git a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/config.py b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/config.py index 342e625d8597..2a97ec2cda02 100755 --- a/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/config.py +++ b/Gems/AtomLyIntegration/TechnicalArt/DccScriptingInterface/config.py @@ -495,11 +495,20 @@ def init_o3de_core(engine_path=_O3DE_DEV, # There are numerous ways to build, e.g. project-centric or engine-centric # when using the installer with pre-built engine (CMakeCache doesn't exist) - _PATH_O3DE_BUILD = Path(azpy.config_utils.get_o3de_build_path(_O3DE_DEV, - 'CMakeCache.txt')) + # so this may not currently work with those builds if you don't set + # values in Env_Dev.bat files + _PATH_O3DE_BUILD = Path(os.getenv('PATH_O3DE_BUILD', + azpy.config_utils.get_o3de_build_path(_O3DE_DEV, + 'CMakeCache.txt'))).resolve() + # this ensure the locally derived default replaces the envar os.environ["DYNACONF_PATH_O3DE_BUILD"] = str(_PATH_O3DE_BUILD.as_posix()) - _PATH_O3DE_BIN = Path(STR_PATH_O3DE_BIN.format(_PATH_O3DE_BUILD)) + # this needs improved, it wasn't to assume this default + _PATH_O3DE_BIN = Path(STR_PATH_O3DE_BIN.format(_PATH_O3DE_BUILD)).resolve() + # but we want to let it be overridden if explicitly defined in external env + # if it's not externally defined, we accept the default and hope it works + _PATH_O3DE_BIN = Path(os.getenv('PATH_O3DE_BIN', + _PATH_O3DE_BIN)).resolve() os.environ["DYNACONF_PATH_O3DE_BIN"] = str(_PATH_O3DE_BIN.as_posix()) # hard check