Files
o3de/Gems/WhiteBox/Editor/Scripts/WhiteBoxInit.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

61 lines
2.3 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
"""
# setup path
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
from azlmbr.entity import EntityId
from azlmbr.entity import EntityType
# get Component Type for WhiteBoxMesh
def get_white_box_component_type():
typeIdsList = editor.EditorComponentAPIBus(bus.Broadcast, 'FindComponentTypeIdsByEntityType', ['White Box'], EntityType().Game)
whiteBoxMeshComponentTypeId = typeIdsList[0]
return whiteBoxMeshComponentTypeId
# use old White Box entity to hold White Box component if it exists, otherwise use a new one
def create_white_box_entity(name="WhiteBox"):
newEntityId = editor.ToolsApplicationRequestBus(bus.Broadcast, 'CreateNewEntity', EntityId())
editor.EditorEntityAPIBus(bus.Event, 'SetName', newEntityId, name)
return newEntityId
# add whiteBoxMeshComponent to entity and enable
def create_white_box_component(entityId):
whiteBoxMeshComponentTypeId = get_white_box_component_type()
whiteBoxMeshComponentOutcome = editor.EditorComponentAPIBus(bus.Broadcast, 'AddComponentsOfType', entityId, [whiteBoxMeshComponentTypeId])
whiteBoxMeshComponents = whiteBoxMeshComponentOutcome.GetValue()
whiteBoxMeshComponent = whiteBoxMeshComponents[0]
editor.EditorComponentAPIBus(bus.Broadcast, 'EnableComponents', whiteBoxMeshComponents)
return whiteBoxMeshComponent
# create whiteBoxMeshHandle from bus call
def create_white_box_handle(whiteBoxMeshComponent):
whiteBoxMesh = azlmbr.whitebox.request.bus.EditorWhiteBoxComponentRequestBus(bus.Event, 'GetWhiteBoxMeshHandle', whiteBoxMeshComponent)
return whiteBoxMesh
# update normals, uvs, and notify white box mesh
def update_white_box(whiteBoxMesh, whiteBoxMeshComponent):
whiteBoxMesh.CalculateNormals()
whiteBoxMesh.CalculatePlanarUVs()
azlmbr.whitebox.notification.bus.EditorWhiteBoxComponentNotificationBus(bus.Event, 'OnWhiteBoxMeshModified', whiteBoxMeshComponent)
azlmbr.whitebox.request.bus.EditorWhiteBoxComponentRequestBus(bus.Event, 'SerializeWhiteBox', whiteBoxMeshComponent)