2
0

materialgen.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/env python
  2. # -*- Coding: UTF-8 -*-
  3. # ---------------------------------------------------------------------------
  4. # Open Asset Import Library (ASSIMP)
  5. # ---------------------------------------------------------------------------
  6. #
  7. # Copyright (c) 2006-2020, ASSIMP Development Team
  8. #
  9. # All rights reserved.
  10. #
  11. # Redistribution and use of this software in source and binary forms,
  12. # with or without modification, are permitted provided that the following
  13. # conditions are met:
  14. #
  15. # * Redistributions of source code must retain the above
  16. # copyright notice, this list of conditions and the
  17. # following disclaimer.
  18. #
  19. # * Redistributions in binary form must reproduce the above
  20. # copyright notice, this list of conditions and the
  21. # following disclaimer in the documentation and/or other
  22. # materials provided with the distribution.
  23. #
  24. # * Neither the name of the ASSIMP team, nor the names of its
  25. # contributors may be used to endorse or promote products
  26. # derived from this software without specific prior
  27. # written permission of the ASSIMP Development Team.
  28. #
  29. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  32. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  36. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  37. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. # ---------------------------------------------------------------------------
  41. """Update PyAssimp's texture type constants C/C++ headers.
  42. This script is meant to be executed in the source tree, directly from
  43. port/PyAssimp/gen
  44. """
  45. import os
  46. import re
  47. REenumTextureType = re.compile(r''
  48. r'enum\saiTextureType' # enum aiTextureType
  49. r'[^{]*?\{' # {
  50. r'(?P<code>.*?)' # code
  51. r'\};' # };
  52. , re.IGNORECASE + re.DOTALL + re.MULTILINE)
  53. # Replace comments
  54. RErpcom = re.compile(r''
  55. r'\s*(/\*+\s|\*+/|\B\*\s?|///?!?)' # /**
  56. r'(?P<line>.*?)' # * line
  57. , re.IGNORECASE + re.DOTALL)
  58. # Remove trailing commas
  59. RErmtrailcom = re.compile(r',$', re.IGNORECASE + re.DOTALL)
  60. # Remove #ifdef __cplusplus
  61. RErmifdef = re.compile(r''
  62. r'#ifndef SWIG' # #ifndef SWIG
  63. r'(?P<code>.*)' # code
  64. r'#endif(\s*//\s*!?\s*SWIG)*' # #endif
  65. , re.IGNORECASE + re.DOTALL)
  66. path = '../../../include/assimp'
  67. files = os.listdir (path)
  68. enumText = ''
  69. for fileName in files:
  70. if fileName.endswith('.h'):
  71. text = open(os.path.join(path, fileName)).read()
  72. for enum in REenumTextureType.findall(text):
  73. enumText = enum
  74. text = ''
  75. for line in enumText.split('\n'):
  76. line = line.lstrip().rstrip()
  77. line = RErmtrailcom.sub('', line)
  78. text += RErpcom.sub('# \g<line>', line) + '\n'
  79. text = RErmifdef.sub('', text)
  80. file = open('material.py', 'w')
  81. file.write(text)
  82. file.close()
  83. print("Generation done. You can now review the file 'material.py' and merge it.")