default_shapes.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 Cylinder
  7. import Icosahedron
  8. import Sphere
  9. import Staircase
  10. import Tetrahedron
  11. import WhiteBoxInit as init
  12. import sys
  13. import azlmbr.legacy.general as general
  14. import azlmbr.bus as bus
  15. import azlmbr.editor as editor
  16. import azlmbr.entity
  17. import azlmbr.object
  18. import azlmbr.math
  19. import azlmbr.whitebox.api as api
  20. def on_change_default_shape_type(whiteBoxMeshComponent, defaultShapeType):
  21. # return if defaultShapeType does not need python execution or is invalid
  22. if not 0 <= defaultShapeType <= 4:
  23. return
  24. # define switch for shape functions
  25. switch={
  26. 1: Tetrahedron.create_tetrahedron,
  27. 2: Icosahedron.create_icosahedron,
  28. 3: Cylinder.create_cylinder,
  29. 4: Sphere.create_sphere
  30. }
  31. # get the white box mesh handle
  32. whiteBoxMesh = azlmbr.whitebox.request.bus.EditorWhiteBoxComponentRequestBus(bus.Event, 'GetWhiteBoxMeshHandle', whiteBoxMeshComponent)
  33. if not whiteBoxMesh.IsValid():
  34. print('Could not resolve White Box Mesh')
  35. return
  36. # clear whiteBoxMesh
  37. whiteBoxMesh.Clear()
  38. # if defaultShapeType is 0, initialize as cube
  39. if (defaultShapeType == 0):
  40. whiteBoxMesh.InitializeAsUnitCube()
  41. # else find the correct shape creation function and call it
  42. else:
  43. shape_creation_func = switch.get(defaultShapeType)
  44. shape_creation_func(whiteBoxMesh)
  45. # update white box mesh
  46. whiteBoxMesh.CalculateNormals()
  47. whiteBoxMesh.CalculatePlanarUVs()
  48. azlmbr.whitebox.request.bus.EditorWhiteBoxComponentModeRequestBus(bus.Event, 'MarkWhiteBoxIntersectionDataDirty', whiteBoxMeshComponent)
  49. azlmbr.whitebox.notification.bus.EditorWhiteBoxComponentNotificationBus(bus.Event, 'OnWhiteBoxMeshModified', whiteBoxMeshComponent)
  50. azlmbr.whitebox.request.bus.EditorWhiteBoxComponentRequestBus(bus.Event, 'SerializeWhiteBox', whiteBoxMeshComponent)
  51. if __name__ == "__main__":
  52. entityId = int(sys.argv[1])
  53. componentId = int(sys.argv[2])
  54. entityComponentIdPair = api.util_MakeEntityComponentIdPair(entityId, componentId)
  55. shapeType = int(sys.argv[3])
  56. on_change_default_shape_type(entityComponentIdPair, shapeType)