Files
o3de/Gems/WhiteBox/Editor/Scripts/default_shapes.py
T
Steve Pham b4a2edec6a Final update copyright headers to reference license files at the repo root (#1693)
* Final update copyright headers to reference license files at the repo root

Signed-off-by: spham <spham@amazon.com>

* Fix copyright validator unit tests to support the stale O3DE header scenario

Signed-off-by: spham <spham@amazon.com>
2021-06-30 19:51:55 -07:00

64 lines
2.2 KiB
Python
Executable File

"""
Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
SPDX-License-Identifier: Apache-2.0 OR MIT
"""
import Cylinder
import Icosahedron
import Sphere
import Staircase
import Tetrahedron
import WhiteBoxInit as init
import sys
import azlmbr.legacy.general as general
import azlmbr.bus as bus
import azlmbr.editor as editor
import azlmbr.entity
import azlmbr.object
import azlmbr.math
import azlmbr.whitebox.api as api
def on_change_default_shape_type(whiteBoxMeshComponent, defaultShapeType):
# return if defaultShapeType does not need python execution or is invalid
if not 0 <= defaultShapeType <= 4:
return
# define switch for shape functions
switch={
1: Tetrahedron.create_tetrahedron,
2: Icosahedron.create_icosahedron,
3: Cylinder.create_cylinder,
4: Sphere.create_sphere
}
# get the white box mesh handle
whiteBoxMesh = azlmbr.whitebox.request.bus.EditorWhiteBoxComponentRequestBus(bus.Event, 'GetWhiteBoxMeshHandle', whiteBoxMeshComponent)
# clear whiteBoxMesh
whiteBoxMesh.Clear()
# if defaultShapeType is 0, initialize as cube
if (defaultShapeType == 0):
whiteBoxMesh.InitializeAsUnitCube()
# else find the correct shape creation function and call it
else:
shape_creation_func = switch.get(defaultShapeType)
shape_creation_func(whiteBoxMesh)
# update white box mesh
whiteBoxMesh.CalculateNormals()
whiteBoxMesh.CalculatePlanarUVs()
azlmbr.whitebox.request.bus.EditorWhiteBoxComponentModeRequestBus(bus.Event, 'MarkWhiteBoxIntersectionDataDirty', whiteBoxMeshComponent)
azlmbr.whitebox.notification.bus.EditorWhiteBoxComponentNotificationBus(bus.Event, 'OnWhiteBoxMeshModified', whiteBoxMeshComponent)
azlmbr.whitebox.request.bus.EditorWhiteBoxComponentRequestBus(bus.Event, 'SerializeWhiteBox', whiteBoxMeshComponent)
if __name__ == "__main__":
entityId = int(sys.argv[1])
componentId = int(sys.argv[2])
entityComponentIdPair = api.util_MakeEntityComponentIdPair(entityId, componentId)
shapeType = int(sys.argv[3])
on_change_default_shape_type(entityComponentIdPair, shapeType)