sbsar_render.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # coding:utf-8
  2. #!/usr/bin/python
  3. #
  4. # Copyright (c) Contributors to the Open 3D Engine Project.
  5. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  6. #
  7. # SPDX-License-Identifier: Apache-2.0 OR MIT
  8. #
  9. # -- This line is 75 characters -------------------------------------------
  10. """Empty Doc String""" # To Do: add documentation
  11. # -------------------------------------------------------------------------
  12. # built-ins
  13. import os
  14. import sys
  15. import site
  16. # Lumberyard extensions
  17. from azpy.env_bool import env_bool
  18. from azpy.constants import ENVAR_DCCSI_GDEBUG
  19. from azpy.constants import ENVAR_DCCSI_DEV_MODE
  20. from azpy.constants import *
  21. # 3rdparty (we provide)
  22. from unipath import Path
  23. import click
  24. # -------------------------------------------------------------------------
  25. # -------------------------------------------------------------------------
  26. # substance automation toolkit (aka pysbs)
  27. # To Do: manage with dynaconf environment
  28. _PYSBS_DIR_PATH = Path(PATH_PROGRAMFILES_X64,
  29. 'Allegorithmic',
  30. 'Substance Automation Toolkit',
  31. 'Python API',
  32. 'install').resolve()
  33. site.addsitedir(str(_PYSBS_DIR_PATH)) # 'install' is the folder I created
  34. # Susbstance
  35. import pysbs.batchtools as pysbs_batch
  36. import pysbs.context as pysbs_context
  37. # -------------------------------------------------------------------------
  38. # -------------------------------------------------------------------------
  39. # set up global space, logging etc.
  40. _DCCSI_GDEBUG = env_bool(ENVAR_DCCSI_GDEBUG, False)
  41. _DCCSI_DEV_MODE = env_bool(ENVAR_DCCSI_DEV_MODE, False)
  42. _PACKAGENAME = __name__
  43. if _PACKAGENAME == '__main__':
  44. _PACKAGENAME = 'DCCsi.SDK.substance.builder.sbsar_render'
  45. import azpy
  46. _LOGGER = azpy.initialize_logger(_PACKAGENAME)
  47. _LOGGER.debug('Starting up: {0}.'.format({_PACKAGENAME}))
  48. # -------------------------------------------------------------------------
  49. # -------------------------------------------------------------------------
  50. # Defining CONSTANTS
  51. # To Do: shouldn't need this _BASE_ENVVAR_DICT (replace with dynaconf config)
  52. from collections import OrderedDict
  53. _SYNTH_ENV_DICT = OrderedDict()
  54. _SYNTH_ENV_DICT = azpy.synthetic_env.stash_env(_SYNTH_ENV_DICT)
  55. # grab a specific path from the base_env
  56. _PATH_DCCSI = _SYNTH_ENV_DICT[ENVAR_PATH_DCCSIG]
  57. _PATH_O3DE_PROJECT = _SYNTH_ENV_DICT[ENVAR_PATH_O3DE_PROJECT]
  58. # build some reuseable path parts
  59. _PATH_MOCK_ASSETS = Path(_PATH_O3DE_PROJECT, 'Assets').norm()
  60. _PATH_MOCK_SUBLIB = Path(_PATH_MOCK_ASSETS, 'SubstanceSource').norm()
  61. _PATH_MOCK_SBS = Path(_PATH_MOCK_SUBLIB, 'sbs').norm()
  62. _PATH_MOCK_SBSAR = Path(_PATH_MOCK_SUBLIB, 'sbsar').norm()
  63. _PATH_MOCK_MAT = Path(_PATH_MOCK_ASSETS, 'Textures').norm()
  64. _PATH_MOCK_MAT_SUB = Path(_PATH_MOCK_MAT, 'Substance').norm()
  65. # this will combine two parts into a single path (object)
  66. # It also returnd the fixed-up version (norm)
  67. _PATH_INPUT_SBS = Path(_PATH_MOCK_SBS, 'alien_rock_coral_formation','alien_rock_coral_formation.sbs').norm()
  68. _PATH_COOK_OUTPUT = _PATH_MOCK_SBSAR.norm()
  69. _PATH_RENDER_OUTPUT = _PATH_MOCK_MAT_SUB
  70. # quick test variables, will be removed
  71. _OUTPUT_SIZE = 9
  72. _user_preset = ['Red Coral', 'Red Sand', 'Grey Stone']
  73. integer1 = 0
  74. integer2 = [0, 0]
  75. float1 = 0.0
  76. float2 = [0.0, 0.0]
  77. _PYSBS_CONTEXT = pysbs_context.Context()
  78. # -------------------------------------------------------------------------
  79. # -------------------------------------------------------------------------
  80. @click.command()
  81. @click.option('--sbsar_path', default=_PATH_COOK_OUTPUT, help='Sbsar directory.')
  82. @click.option('--sbsar_name', default=_PATH_INPUT_SBS.stem, help='Sbsar name.')
  83. @click.option('--tex_path', default=_PATH_RENDER_OUTPUT, help='Texture output path.')
  84. @click.option('--output_size', default=9, help='512x512, 9 | 1024x1024, 10 | 2048x2048, 11')
  85. def sbsar_render(sbsar_path, sbsar_name, tex_path, output_size):
  86. """ Doc String"""
  87. pysbs_batch.sbsrender_render(inputs=os.path.join(sbsar_path, sbsar_name + '.sbsar'),
  88. # input_graph=_inputGraphPath,
  89. output_path=tex_path,
  90. output_name='{inputGraphUrl}_{outputNodeName}',
  91. output_format='tif',
  92. set_value=['$outputsize@%s,%s' % (output_size, output_size), '$randomseed@1'],
  93. # use_preset = _user_preset[0]
  94. no_report=True,
  95. verbose=True
  96. ).wait()
  97. # --------------------------------------------------------------------------
  98. ###########################################################################
  99. # Main Code Block, runs this script as main (testing)
  100. # -------------------------------------------------------------------------
  101. if __name__ == '__main__':
  102. """Run this file as main"""
  103. _LOGGER.debug("{0} :: if __name__ == '__main__':".format(_PACKAGENAME))
  104. _LOGGER.debug(sbsar_render())
  105. # remove the logger
  106. del _LOGGER
  107. # ---- END ---------------------------------------------------------------