2
0

scene_data.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. """
  6. import azlmbr.scene as sceneApi
  7. import json
  8. # Wraps the AZ.SceneAPI.Containers.SceneGraph.NodeIndex internal class
  9. class SceneGraphNodeIndex:
  10. def __init__(self, sceneGraphNodeIndex) -> None:
  11. self.nodeIndex = sceneGraphNodeIndex
  12. def as_number(self):
  13. return self.nodeIndex.AsNumber()
  14. def distance(self, other):
  15. return self.nodeIndex.Distance(other)
  16. def is_valid(self) -> bool:
  17. return self.nodeIndex.IsValid()
  18. def equal(self, other) -> bool:
  19. return self.nodeIndex.Equal(other)
  20. # Wraps AZ.SceneAPI.Containers.SceneGraph.Name internal class
  21. class SceneGraphName():
  22. def __init__(self, sceneGraphName) -> None:
  23. self.name = sceneGraphName
  24. def get_path(self) -> str:
  25. return self.name.GetPath()
  26. def get_name(self) -> str:
  27. return self.name.GetName()
  28. # Wraps AZ.SceneAPI.Containers.SceneGraph class
  29. class SceneGraph():
  30. def __init__(self, sceneGraphInstance) -> None:
  31. self.sceneGraph = sceneGraphInstance
  32. @classmethod
  33. def is_valid_name(cls, name):
  34. return sceneApi.SceneGraph_IsValidName(name)
  35. @classmethod
  36. def node_seperation_character(cls):
  37. return sceneApi.SceneGraph_GetNodeSeperationCharacter()
  38. def get_node_name(self, node):
  39. return self.sceneGraph.GetNodeName(node)
  40. def get_root(self):
  41. return self.sceneGraph.GetRoot()
  42. def has_node_content(self, node) -> bool:
  43. return self.sceneGraph.HasNodeContent(node)
  44. def has_node_sibling(self, node) -> bool:
  45. return self.sceneGraph.HasNodeSibling(node)
  46. def has_node_child(self, node) -> bool:
  47. return self.sceneGraph.HasNodeChild(node)
  48. def has_node_parent(self, node) -> bool:
  49. return self.sceneGraph.HasNodeParent(node)
  50. def is_node_end_point(self, node) -> bool:
  51. return self.sceneGraph.IsNodeEndPoint(node)
  52. def get_node_parent(self, node):
  53. return self.sceneGraph.GetNodeParent(node)
  54. def get_node_sibling(self, node):
  55. return self.sceneGraph.GetNodeSibling(node)
  56. def get_node_child(self, node):
  57. return self.sceneGraph.GetNodeChild(node)
  58. def get_node_count(self):
  59. return self.sceneGraph.GetNodeCount()
  60. def find_with_path(self, path):
  61. return self.sceneGraph.FindWithPath(path)
  62. def find_with_root_and_path(self, root, path):
  63. return self.sceneGraph.FindWithRootAndPath(root, path)
  64. def get_node_content(self, node):
  65. return self.sceneGraph.GetNodeContent(node)
  66. # Contains a dictionary to contain and export AZ.SceneAPI.Containers.SceneManifest
  67. class SceneManifest():
  68. def __init__(self):
  69. self.manifest = {'values': []}
  70. def add_mesh_group(self, name) -> dict:
  71. meshGroup = {}
  72. meshGroup['$type'] = '{07B356B7-3635-40B5-878A-FAC4EFD5AD86} MeshGroup'
  73. meshGroup['name'] = name
  74. meshGroup['nodeSelectionList'] = {'selectedNodes': [], 'unselectedNodes': []}
  75. meshGroup['rules'] = {'rules': [{'$type': 'MaterialRule'}]}
  76. self.manifest['values'].append(meshGroup)
  77. return meshGroup
  78. def add_prefab_group(self, name, id, json) -> dict:
  79. prefabGroup = {}
  80. prefabGroup['$type'] = '{99FE3C6F-5B55-4D8B-8013-2708010EC715} PrefabGroup'
  81. prefabGroup['name'] = name
  82. prefabGroup['id'] = id
  83. prefabGroup['prefabDomData'] = json
  84. self.manifest['values'].append(prefabGroup)
  85. return prefabGroup
  86. def mesh_group_select_node(self, meshGroup, nodeName):
  87. meshGroup['nodeSelectionList']['selectedNodes'].append(nodeName)
  88. def mesh_group_unselect_node(self, meshGroup, nodeName):
  89. meshGroup['nodeSelectionList']['unselectedNodes'].append(nodeName)
  90. def mesh_group_add_advanced_coordinate_system(self, meshGroup, originNodeName, translation, rotation, scale):
  91. originRule = {}
  92. originRule['$type'] = 'CoordinateSystemRule'
  93. originRule['useAdvancedData'] = True
  94. originRule['originNodeName'] = '' if originNodeName is None else originNodeName
  95. if translation is not None:
  96. originRule['translation'] = translation
  97. if rotation is not None:
  98. originRule['rotation'] = rotation
  99. if scale != 1.0:
  100. originRule['scale'] = scale
  101. meshGroup['rules']['rules'].append(originRule)
  102. def mesh_group_add_comment(self, meshGroup, comment):
  103. commentRule = {}
  104. commentRule['$type'] = 'CommentRule'
  105. commentRule['comment'] = comment
  106. meshGroup['rules']['rules'].append(commentRule)
  107. def export(self):
  108. return json.dumps(self.manifest)