3
0

LegacyPointLightComponentConverter.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. Lumberyard Legacy Point Light Component to Atom Point Light Component Conversion Script
  6. """
  7. from LegacyConversionHelpers import *
  8. from LegacyMaterialComponentConverter import *
  9. class Point_Light_Component_Converter(Component_Converter):
  10. """
  11. Converts point lights
  12. """
  13. def __init__(self, assetCatalogHelper, statsCollector, _):
  14. Component_Converter.__init__(self, assetCatalogHelper, statsCollector)
  15. self.color = ""
  16. self.diffuse_multiplier = ""
  17. self.point_max_distance = ""
  18. def convert_legacy_light_intensity_to_atom_intensity(self, diffuse_multiplier: str) -> str:
  19. return str(float(diffuse_multiplier) * 100)
  20. def is_this_the_component_im_looking_for(self, xmlElement, parent):
  21. if "name" in xmlElement.keys() and xmlElement.get("name") == "EditorPointLightComponent":
  22. return True
  23. return False
  24. def gather_info_for_conversion(self, xmlElement, _):
  25. # First, get the data that we need
  26. # <Class name="EditorPointLightComponent" field="element" version="1" type="{00818135-138D-42AD-8657-FF3FD38D9E7A}">
  27. # <Class name="EditorLightComponent" field="BaseClass1" version="2" type="{7C18B273-5BA3-4E0F-857D-1F30BD6B0733}">
  28. # <Class name="EditorComponentBase" field="BaseClass1" version="1" type="{D5346BD4-7F20-444E-B370-327ACD03D4A0}">
  29. # <Class name="AZ::Component" field="BaseClass1" type="{EDFCB2CF-F75D-43BE-B26B-F35821B29247}">
  30. # <Class name="AZ::u64" field="Id" value="14732701159327458740" type="{D6597933-47CD-4FC8-B911-63F3E2B0993A}"/>
  31. # </Class>
  32. # </Class>
  33. # <Class name="EditorLightConfiguration" field="EditorLightConfiguration" version="1" type="{1D3B114F-8FB2-47BD-9C21-E089F4F37861}">
  34. # <Class name="LightConfiguration" field="BaseClass1" version="8" type="{F4CC7BB4-C541-480C-88FC-C5A8F37CC67F}">
  35. # <Class name="unsigned int" field="LightType" value="0" type="{43DA906B-7DEF-4CA8-9790-854106D3F983}"/>
  36. # <Class name="bool" field="Visible" value="false" type="{A0CA880C-AFE4-43CB-926C-59AC48496112}"/>
  37. # <Class name="bool" field="OnInitially" value="false" type="{A0CA880C-AFE4-43CB-926C-59AC48496112}"/>
  38. # <Class name="Color" field="Color" value="1.0000000 1.0000000 1.0000000 1.0000000" type="{7894072A-9050-4F0F-901B-34B1A0D29417}"/>
  39. # <Class name="float" field="DiffuseMultiplier" value="50000.0000000" type="{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"/>
  40. # <Class name="float" field="SpecMultiplier" value="1.0000000" type="{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"/>
  41. # <Class name="bool" field="Ambient" value="false" type="{A0CA880C-AFE4-43CB-926C-59AC48496112}"/>
  42. # <Class name="float" field="PointMaxDistance" value="500.0000000" type="{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"/>
  43. # <Class name="float" field="PointAttenuationBulbSize" value="0.0500000" type="{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"/>
  44. # <Class name="float" field="AreaWidth" value="5.0000000" type="{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"/>
  45. # <Class name="float" field="AreaHeight" value="5.0000000" type="{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"/>
  46. # <Class name="float" field="AreaMaxDistance" value="2.0000000" type="{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"/>
  47. # <Class name="float" field="AreaFOV" value="45.0000000" type="{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"/>
  48. # <Class name="float" field="ProjectorDistance" value="5.0000000" type="{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"/>
  49. # <Class name="float" field="ProjectorAttenuationBulbSize" value="0.0500000" type="{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"/>
  50. # <Class name="float" field="ProjectorFOV" value="90.0000000" type="{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"/>
  51. # <Class name="float" field="ProjectorNearPlane" value="0.0000000" type="{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"/>
  52. # ...
  53. for editorPointLightComponentChild in xmlElement:
  54. #print("Editor Point Light Component Config")
  55. for editorLightComponentChild in editorPointLightComponentChild:
  56. #print("Editor Light Component Config")
  57. #print(f"Name: {editorLightComponentChild.get('name')}, Field: {editorLightComponentChild.get('field')}")
  58. if "name" in editorLightComponentChild.keys() and editorLightComponentChild.get("name") == "EditorLightConfiguration":
  59. #print(f"Editor Light Config. {editorLightComponentChild.get('name')}, {editorLightComponentChild.get('field')}")
  60. for editorLightConfigurationChild in editorLightComponentChild:
  61. for lightConfigurationChild in editorLightConfigurationChild:
  62. #print(f"Name: {lightConfigurationChild.get('name')}, Field: {lightConfigurationChild.get('field')}")
  63. if "field" in lightConfigurationChild.keys() and lightConfigurationChild.get("field") == "Color":
  64. self.color = lightConfigurationChild.get("value")
  65. elif "field" in lightConfigurationChild.keys() and lightConfigurationChild.get("field") == "DiffuseMultiplier":
  66. self.diffuse_multiplier = lightConfigurationChild.get("value")
  67. elif "field" in lightConfigurationChild.keys() and lightConfigurationChild.get("field") == "PointMaxDistance":
  68. self.point_max_distance = lightConfigurationChild.get("value")
  69. #print(f"Color: {self.color}")
  70. #print(f"Diffuse: {self.diffuse_multiplier}")
  71. #print(f"Attenuation Dist.: {self.point_max_distance}")
  72. print('Editor Light Component was touched!')
  73. def __create_adapter_xml(self, color, intensity, attenuationRadius):
  74. # <Class name="AZ::Render::EditorPointLightComponent" field="element" version="1" type="{C4D354BE-5247-41FD-9A8D-550C6772EE5B}">
  75. # <Class name="EditorRenderComponentAdapter&lt;AZ::Render::PointLightComponentController AZ::Render::PointLightComponent PointLightComponentConfi" field="BaseClass1" type="{B09B7A31-789F-5996-AD50-EF71942A5271}">
  76. # <Class name="EditorComponentAdapter&lt;AZ::Render::PointLightComponentController AZ::Render::PointLightComponent PointLightComponentConfig &gt;" field="BaseClass1" version="1" type="{DC9066D5-4557-52C7-B901-4B5626C4F35A}">
  77. # <Class name="EditorComponentBase" field="BaseClass1" version="1" type="{D5346BD4-7F20-444E-B370-327ACD03D4A0}">
  78. # <Class name="AZ::Component" field="BaseClass1" type="{EDFCB2CF-F75D-43BE-B26B-F35821B29247}">
  79. # <Class name="AZ::u64" field="Id" value="12988262800448744331" type="{D6597933-47CD-4FC8-B911-63F3E2B0993A}"/>
  80. # </Class>
  81. # </Class>
  82. # <Class name="AZ::Render::PointLightComponentController" field="Controller" version="1" type="{23F82E30-2E1F-45FE-A9A7-B15632ED9EBD}">
  83. # <Class name="PointLightComponentConfig" field="Configuration" version="2" type="{B6FC35BA-D22F-4C20-BFFC-3FE7A48858FA}">
  84. # <Class name="ComponentConfig" field="BaseClass1" version="1" type="{0A7929DF-2932-40EA-B2B3-79BC1C3490D0}"/>
  85. # <Class name="Color" field="Color" value="1.0000000 1.0000000 1.0000000 1.0000000" type="{7894072A-9050-4F0F-901B-34B1A0D29417}"/>
  86. # <Class name="char" field="ColorIntensityMode" value="0" type="{3AB0037F-AF8D-48CE-BCA0-A170D18B2C03}"/>
  87. # <Class name="float" field="Intensity" value="800.0000000" type="{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"/>
  88. # <Class name="unsigned char" field="AttenuationRadiusMode" value="1" type="{72B9409A-7D1A-4831-9CFE-FCB3FADD3426}"/>
  89. # <Class name="float" field="AttenuationRadius" value="89.4427185" type="{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"/>
  90. # <Class name="float" field="BulbRadius" value="0.0500000" type="{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"/>
  91. # </Class>
  92. # </Class>
  93. # </Class>
  94. # </Class>
  95. # </Class>
  96. editorRenderComponentAdapter = xml.etree.ElementTree.Element("Class", {
  97. 'name': "EditorRenderComponentAdapter<AZ::Render::PointLightComponentController AZ::Render::PointLightComponent PointLightComponentConfig >",
  98. 'field': "BaseClass1", 'type': "{B09B7A31-789F-5996-AD50-EF71942A5271}"
  99. })
  100. editorComponentAdapter = xml.etree.ElementTree.Element("Class", {
  101. 'name': "EditorComponentAdapter<AZ::Render::PointLightComponentController AZ::Render::PointLightComponent PointLightComponentConfig >",
  102. 'field': "BaseClass1", 'version': "1", 'type': "{DC9066D5-4557-52C7-B901-4B5626C4F35A}"
  103. })
  104. editorComponentBase = xml.etree.ElementTree.Element("Class", {
  105. 'name': "EditorComponentBase",
  106. 'field': "BaseClass1",
  107. 'version': "1",
  108. 'type': "{D5346BD4-7F20-444E-B370-327ACD03D4A0}"
  109. })
  110. component = xml.etree.ElementTree.Element("Class", {
  111. 'name': "AZ::Component",
  112. 'field': "BaseClass1",
  113. 'type': "{EDFCB2CF-F75D-43BE-B26B-F35821B29247}"
  114. })
  115. u64 = xml.etree.ElementTree.Element("Class", {
  116. 'name': "AZ::u64",
  117. 'field': "Id",
  118. 'value': "12988262800448744331",
  119. 'type': "{D6597933-47CD-4FC8-B911-63F3E2B0993A}"
  120. })
  121. component.append(u64)
  122. editorComponentBase.append(component)
  123. pointLightComponentController = create_xml_element_from_string(
  124. "<Class name=\"AZ::Render::PointLightComponentController\" field=\"Controller\" version=\"1\" type=\"{23F82E30-2E1F-45FE-A9A7-B15632ED9EBD}\">"
  125. )
  126. pointLightComponentConfig = xml.etree.ElementTree.Element("Class", {
  127. 'name': "PointLightComponentConfig",
  128. 'field': "Configuration",
  129. 'version': "2",
  130. 'type': "{B6FC35BA-D22F-4C20-BFFC-3FE7A48858FA}"
  131. })
  132. componentConfig = xml.etree.ElementTree.Element("Class", {
  133. 'name': "ComponentConfig",
  134. 'field': "BaseClass1",
  135. 'version': "1",
  136. 'type': "{0A7929DF-2932-40EA-B2B3-79BC1C3490D0}"
  137. })
  138. colorConfig = xml.etree.ElementTree.Element("Class", {
  139. 'name': "Color",
  140. 'field': "Color",
  141. 'value': color,
  142. 'type': "{7894072A-9050-4F0F-901B-34B1A0D29417}"
  143. })
  144. colorIntesntiyModeConfig = xml.etree.ElementTree.Element("Class", {
  145. 'name': "char",
  146. 'field': "ColorIntensityMode",
  147. 'value': "0",
  148. 'type': "{3AB0037F-AF8D-48CE-BCA0-A170D18B2C03}"
  149. })
  150. inensityConfig = xml.etree.ElementTree.Element("Class", {
  151. 'name': "float",
  152. 'field': "Intensity",
  153. 'value': intensity,
  154. 'type': "{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"
  155. })
  156. attenuationRadiusModeConfig = xml.etree.ElementTree.Element("Class", {
  157. 'name': "unsigned char",
  158. 'field': "AttenuationRadiusMode",
  159. 'value': "1",
  160. 'type': "{72B9409A-7D1A-4831-9CFE-FCB3FADD3426}"
  161. })
  162. attenuationRadiusConfig = xml.etree.ElementTree.Element("Class", {
  163. 'name': "float",
  164. 'field': "AttenuationRadius",
  165. 'value': attenuationRadius,
  166. 'type': "{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"
  167. })
  168. bulbRadiusConfig = xml.etree.ElementTree.Element("Class", {
  169. 'name': "float",
  170. 'field': "BulbRadius",
  171. 'value': "0.05",
  172. 'type': "{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}"
  173. })
  174. pointLightComponentConfig.append(componentConfig)
  175. pointLightComponentConfig.append(colorConfig)
  176. pointLightComponentConfig.append(colorIntesntiyModeConfig)
  177. pointLightComponentConfig.append(inensityConfig)
  178. pointLightComponentConfig.append(attenuationRadiusModeConfig)
  179. pointLightComponentConfig.append(attenuationRadiusConfig)
  180. pointLightComponentConfig.append(bulbRadiusConfig)
  181. pointLightComponentController.append(pointLightComponentConfig)
  182. editorComponentAdapter.append(editorComponentBase)
  183. editorComponentAdapter.append(pointLightComponentController)
  184. editorRenderComponentAdapter.append(editorComponentAdapter)
  185. return editorRenderComponentAdapter
  186. def convert(self, xmlElement, _):
  187. # Now clear the legacy component
  188. xmlElement.clear()
  189. # And replace the content with an Atom point light component
  190. xmlElement.set("name", "AZ::Render::EditorPointLightComponent")
  191. xmlElement.set("field", "element")
  192. xmlElement.set("version", "1")
  193. xmlElement.set("type", "{C4D354BE-5247-41FD-9A8D-550C6772EE5B}")
  194. xmlElement.append(self.__create_adapter_xml(
  195. self.color,
  196. self.convert_legacy_light_intensity_to_atom_intensity(self.diffuse_multiplier),
  197. self.point_max_distance
  198. ))
  199. def reset(self):
  200. self.color = ""
  201. self.diffuse_multiplier = ""
  202. self.point_max_distance = ""