WhiteBoxInit.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. # setup path
  7. import azlmbr.legacy.general as general
  8. import azlmbr.bus as bus
  9. import azlmbr.editor as editor
  10. import azlmbr.entity
  11. import azlmbr.object
  12. import azlmbr.math
  13. import azlmbr.whitebox.api as api
  14. from azlmbr.entity import EntityId
  15. from azlmbr.entity import EntityType
  16. # get Component Type for WhiteBoxMesh
  17. def get_white_box_component_type():
  18. typeIdsList = editor.EditorComponentAPIBus(bus.Broadcast, 'FindComponentTypeIdsByEntityType', ['White Box'], EntityType().Game)
  19. whiteBoxMeshComponentTypeId = typeIdsList[0]
  20. return whiteBoxMeshComponentTypeId
  21. # use old White Box entity to hold White Box component if it exists, otherwise use a new one
  22. def create_white_box_entity(name="WhiteBox"):
  23. newEntityId = editor.ToolsApplicationRequestBus(bus.Broadcast, 'CreateNewEntity', EntityId())
  24. editor.EditorEntityAPIBus(bus.Event, 'SetName', newEntityId, name)
  25. return newEntityId
  26. # add whiteBoxMeshComponent to entity and enable
  27. def create_white_box_component(entityId):
  28. whiteBoxMeshComponentTypeId = get_white_box_component_type()
  29. whiteBoxMeshComponentOutcome = editor.EditorComponentAPIBus(bus.Broadcast, 'AddComponentsOfType', entityId, [whiteBoxMeshComponentTypeId])
  30. whiteBoxMeshComponents = whiteBoxMeshComponentOutcome.GetValue()
  31. whiteBoxMeshComponent = whiteBoxMeshComponents[0]
  32. editor.EditorComponentAPIBus(bus.Broadcast, 'EnableComponents', whiteBoxMeshComponents)
  33. return whiteBoxMeshComponent
  34. # create whiteBoxMeshHandle from bus call
  35. def create_white_box_handle(whiteBoxMeshComponent):
  36. whiteBoxMesh = azlmbr.whitebox.request.bus.EditorWhiteBoxComponentRequestBus(bus.Event, 'GetWhiteBoxMeshHandle', whiteBoxMeshComponent)
  37. return whiteBoxMesh
  38. # update normals, uvs, and notify white box mesh
  39. def update_white_box(whiteBoxMesh, whiteBoxMeshComponent):
  40. whiteBoxMesh.CalculateNormals()
  41. whiteBoxMesh.CalculatePlanarUVs()
  42. azlmbr.whitebox.notification.bus.EditorWhiteBoxComponentNotificationBus(bus.Event, 'OnWhiteBoxMeshModified', whiteBoxMeshComponent)
  43. azlmbr.whitebox.request.bus.EditorWhiteBoxComponentRequestBus(bus.Event, 'SerializeWhiteBox', whiteBoxMeshComponent)