Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
+90
View File
@@ -0,0 +1,90 @@
"""
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
its licensors.
For complete copyright and license terms please see the LICENSE at the root of this
distribution (the "License"). All use of this software is governed by the License,
or, if provided, by the license below or the license accompanying this file. Do not
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
"""
import WhiteBoxMath as whiteBoxMath
import WhiteBoxInit as init
import argparse
import azlmbr.legacy.general as general
import azlmbr.bus as bus
import azlmbr.whitebox.api as api
# usage: pyRunFile path/to/file/cylinder.py <sides> <size>
# number of sides is used to determine the number of vertices in each circle
def create_cylinder(whiteBoxMesh, sides=16, size=0.5):
# create all the vertices as two circles (top/bottom) with one additional vertex for the center of each circle
# create center vertices for each circle
top_vertex_pos = whiteBoxMath.spherical_to_cartesian(0.0, 0.0, size)
bottom_vertex_pos = whiteBoxMath.spherical_to_cartesian(180.0, 0.0, size)
top_vertex = whiteBoxMesh.AddVertex(top_vertex_pos)
bottom_vertex = whiteBoxMesh.AddVertex(bottom_vertex_pos)
# set up angles/distance for each of the cylinder circles
top_circle_vertices = []
bottom_circle_vertices = []
angle_increment = 360.0 / sides
# distance from the center of the cylinder to the vertices of the top/bottom circles
# simplifies to size times the square root of 2
vertex_dist = size * 1.414
# add vertices for each of the cylinder circles
for side in range (0, sides):
# internal angle from center of cylinder to any point on top/bottom circles
top_circle_pos = whiteBoxMath.spherical_to_cartesian(45.0, side * angle_increment, vertex_dist)
bottom_circle_pos = whiteBoxMath.spherical_to_cartesian(135.0, side * angle_increment, vertex_dist)
# add to list for vertices for the top/bottom circles
top_circle_vertex = whiteBoxMesh.AddVertex(top_circle_pos)
bottom_circle_vertex = whiteBoxMesh.AddVertex(bottom_circle_pos)
top_circle_vertices.append(top_circle_vertex)
bottom_circle_vertices.append(bottom_circle_vertex)
# create faces
top_circle_fvh = []
bottom_circle_fvh = []
for side in range (0, sides):
index1 = side
index2 = (side + 1) % sides
# add to list for face vertex handles for top/bottom circles
top_circle_fvh.append(api.util_MakeFaceVertHandles(top_vertex, top_circle_vertices[index1], top_circle_vertices[index2]))
bottom_circle_fvh.append(api.util_MakeFaceVertHandles(bottom_vertex, bottom_circle_vertices[index2], bottom_circle_vertices[index1]))
# add quad polygons to create the side of the cylinder
whiteBoxMesh.AddQuadPolygon(top_circle_vertices[index1], bottom_circle_vertices[index1], bottom_circle_vertices[index2], top_circle_vertices[index2])
# add top/bottom faces
whiteBoxMesh.AddPolygon(top_circle_fvh)
whiteBoxMesh.AddPolygon(bottom_circle_fvh)
if __name__ == "__main__":
# cmdline arguments
parser = argparse.ArgumentParser(description='Creates a cylinder shaped white box mesh.')
parser.add_argument('sides', nargs='?', default=16, type=int, help='number of vertices in each circle')
parser.add_argument('size', nargs='?', default=0.5, type=float, help='size of the cylinder')
args = parser.parse_args()
# initialize whiteBoxMesh
whiteBoxEntity = init.create_white_box_entity("WhiteBox-Cylinder")
whiteBoxMeshComponent = init.create_white_box_component(whiteBoxEntity)
whiteBoxMesh = init.create_white_box_handle(whiteBoxMeshComponent)
# clear whiteBoxMesh to make a cylinder from scratch
whiteBoxMesh.Clear()
create_cylinder(whiteBoxMesh, args.sides, args.size)
# update whiteBoxMesh
init.update_white_box(whiteBoxMesh, whiteBoxMeshComponent)
+113
View File
@@ -0,0 +1,113 @@
"""
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
its licensors.
For complete copyright and license terms please see the LICENSE at the root of this
distribution (the "License"). All use of this software is governed by the License,
or, if provided, by the license below or the license accompanying this file. Do not
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
"""
import WhiteBoxMath as whiteBoxMath
import WhiteBoxInit as init
import azlmbr.legacy.general as general
import azlmbr.bus as bus
import azlmbr.whitebox.api as api
# usage: pyRunFile path/to/file/icosahedron.py <radius>
# create the faces which will be used in the icosahedron
def create_icosahedron_faces(whiteBoxMesh, radius):
# get coordinates for all the vertices using the internal angles of a icosahedron
# upper side
pos1 = whiteBoxMath.spherical_to_cartesian(0.0, 0.0, radius)
pos2 = whiteBoxMath.spherical_to_cartesian(63.43, 18.0, radius)
pos3 = whiteBoxMath.spherical_to_cartesian(63.43, 90.0, radius)
pos4 = whiteBoxMath.spherical_to_cartesian(63.43, 162.0, radius)
pos5 = whiteBoxMath.spherical_to_cartesian(63.43, 234.0, radius)
pos6 = whiteBoxMath.spherical_to_cartesian(63.43, 306.0, radius)
# lower side
pos7 = whiteBoxMath.spherical_to_cartesian(180.0, 0.0, radius)
pos8 = whiteBoxMath.spherical_to_cartesian(116.57, 52.0, radius)
pos9 = whiteBoxMath.spherical_to_cartesian(116.57, 126.0, radius)
pos10 = whiteBoxMath.spherical_to_cartesian(116.57, 198.0, radius)
pos11 = whiteBoxMath.spherical_to_cartesian(116.57, 270.0, radius)
pos12 = whiteBoxMath.spherical_to_cartesian(116.57, 342.0, radius)
# create vertices from all the coordinates
# upper side
v1 = whiteBoxMesh.AddVertex(pos1)
v2 = whiteBoxMesh.AddVertex(pos2)
v3 = whiteBoxMesh.AddVertex(pos3)
v4 = whiteBoxMesh.AddVertex(pos4)
v5 = whiteBoxMesh.AddVertex(pos5)
v6 = whiteBoxMesh.AddVertex(pos6)
# lower side
v7 = whiteBoxMesh.AddVertex(pos7)
v8 = whiteBoxMesh.AddVertex(pos8)
v9 = whiteBoxMesh.AddVertex(pos9)
v10 = whiteBoxMesh.AddVertex(pos10)
v11 = whiteBoxMesh.AddVertex(pos11)
v12 = whiteBoxMesh.AddVertex(pos12)
# add faces to list
faces = []
# upper side
fvh1 = faces.append(api.util_MakeFaceVertHandles(v1, v2, v3))
fvh2 = faces.append(api.util_MakeFaceVertHandles(v1, v3, v4))
fvh3 = faces.append(api.util_MakeFaceVertHandles(v1, v4, v5))
fvh4 = faces.append(api.util_MakeFaceVertHandles(v1, v5, v6))
fvh5 = faces.append(api.util_MakeFaceVertHandles(v1, v6, v2))
# lower side
fvh6 = faces.append(api.util_MakeFaceVertHandles(v7, v12, v11))
fvh7 = faces.append(api.util_MakeFaceVertHandles(v7, v11, v10))
fvh8 = faces.append(api.util_MakeFaceVertHandles(v7, v10, v9))
fvh9 = faces.append(api.util_MakeFaceVertHandles(v7, v9, v8))
fvh10 = faces.append(api.util_MakeFaceVertHandles(v7, v8, v12))
# middle side
fvh11 = faces.append(api.util_MakeFaceVertHandles(v12, v8, v2))
fvh12 = faces.append(api.util_MakeFaceVertHandles(v8, v9, v3))
fvh13 = faces.append(api.util_MakeFaceVertHandles(v9, v10, v4))
fvh14 = faces.append(api.util_MakeFaceVertHandles(v10, v11, v5))
fvh15 = faces.append(api.util_MakeFaceVertHandles(v11, v12, v6))
fvh16 = faces.append(api.util_MakeFaceVertHandles(v2, v8, v3))
fvh17 = faces.append(api.util_MakeFaceVertHandles(v3, v9, v4))
fvh18 = faces.append(api.util_MakeFaceVertHandles(v4, v10, v5))
fvh19 = faces.append(api.util_MakeFaceVertHandles(v5, v11, v6))
fvh20 = faces.append(api.util_MakeFaceVertHandles(v6, v12, v2))
return faces
def create_icosahedron(whiteBoxMesh, radius=0.6):
# create list of faces to add to polygon
icosahedron_faces = create_icosahedron_faces(whiteBoxMesh, radius)
# add polygons to white box mesh
for face in icosahedron_faces:
whiteBoxMesh.AddPolygon([face])
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Creates an icosahedron.')
parser.add_argument('radius', nargs='?', default=0.6, type=int, help='radius of the icosahedron')
args = parser.parse_args()
whiteBoxEntity = init.create_white_box_entity("WhiteBox-Icosahedron")
whiteBoxMeshComponent = init.create_white_box_component(whiteBoxEntity)
whiteBoxMesh = init.create_white_box_handle(whiteBoxMeshComponent)
# clear whiteBoxMesh to make a icosahedron from scratch
whiteBoxMesh.Clear()
create_icosahedron(whiteBoxMesh, args.radius)
# update whiteBoxMesh
init.update_white_box(whiteBoxMesh, whiteBoxMeshComponent)
+98
View File
@@ -0,0 +1,98 @@
"""
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
its licensors.
For complete copyright and license terms please see the LICENSE at the root of this
distribution (the "License"). All use of this software is governed by the License,
or, if provided, by the license below or the license accompanying this file. Do not
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
"""
import Icosahedron
import WhiteBoxMath as whiteBoxMath
import WhiteBoxInit as init
import argparse
import azlmbr.legacy.general as general
import azlmbr.bus as bus
import azlmbr.whitebox.api as api
# usage: pyRunFile path/to/file/sphere.py <subdivisions>
# get the midpoint of v1 and v2 from created_midpoints if already made, otherwise create new one
def get_midpoint_vertex(whiteBoxMesh, v1, v2, radius, created_midpoints):
# get the index of the vertices to look them up
index1 = v1.Index()
index2 = v2.Index()
# search created_midpoints to see if this midpoint has already been made
# we store edges as tuples but keep in mind the edge (v1, v2) == (v2, v1) so we search both
if (index1, index2) in created_midpoints:
return created_midpoints.get((index1, index2))
if (index2, index1) in created_midpoints:
return created_midpoints.get((index2, index1))
# create the new midpoint vertex and store in created_midpoints
pos1 = whiteBoxMesh.VertexPosition(v1)
pos2 = whiteBoxMesh.VertexPosition(v2)
midpoint = whiteBoxMesh.AddVertex(whiteBoxMath.normalize_midpoint(pos1, pos2, radius))
created_midpoints.update({(index1, index2): midpoint})
return midpoint
# divide each triangular face into four smaller faces
def subdivide_faces(whiteBoxMesh, faces, radius):
new_faces = []
created_midpoints = dict()
for faceVertHandles in faces:
# get each vertex
v0 = faceVertHandles.VertexHandles[0]
v1 = faceVertHandles.VertexHandles[1]
v2 = faceVertHandles.VertexHandles[2]
# get the vertex representing the midpoint of each of the edges
v3 = get_midpoint_vertex(whiteBoxMesh, v0, v1, radius, created_midpoints)
v4 = get_midpoint_vertex(whiteBoxMesh, v1, v2, radius, created_midpoints)
v5 = get_midpoint_vertex(whiteBoxMesh, v0, v2, radius, created_midpoints)
# create four subdivided faces for each original face
new_faces.append(api.util_MakeFaceVertHandles(v0, v3, v5))
new_faces.append(api.util_MakeFaceVertHandles(v3, v1, v4))
new_faces.append(api.util_MakeFaceVertHandles(v4, v2, v5))
new_faces.append(api.util_MakeFaceVertHandles(v3, v4, v5))
return new_faces
# create sphere by subdividing an icosahedron
def create_sphere(whiteBoxMesh, subdivisions=2, radius=0.55):
# create icosahedron faces and subdivide them to create a sphere
icosahedron_faces = Icosahedron.create_icosahedron_faces(whiteBoxMesh, radius)
for division in range (0, subdivisions):
icosahedron_faces = subdivide_faces(whiteBoxMesh, icosahedron_faces, radius)
for face in icosahedron_faces:
whiteBoxMesh.AddPolygon([face])
if __name__ == "__main__":
# cmdline arguments
parser = argparse.ArgumentParser(description='Creates a sphere shaped white box mesh.')
parser.add_argument('subdivisions', nargs='?', default=3, choices=range(0, 5), type=int, help='number of subdivisions to form sphere from icosahedron')
parser.add_argument('radius', nargs='?', default=0.55, type=float, help='radius of the sphere')
args = parser.parse_args()
# initialize whiteBoxMesh
whiteBoxEntity = init.create_white_box_entity("WhiteBox-Sphere")
whiteBoxMeshComponent = init.create_white_box_component(whiteBoxEntity)
whiteBoxMesh = init.create_white_box_handle(whiteBoxMeshComponent)
# clear whiteBoxMesh to make a sphere from scratch
whiteBoxMesh.Clear()
create_sphere(whiteBoxMesh, args.subdivisions, args.radius)
# update whiteBoxMesh
init.update_white_box(whiteBoxMesh, whiteBoxMeshComponent)
+103
View File
@@ -0,0 +1,103 @@
"""
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
its licensors.
For complete copyright and license terms please see the LICENSE at the root of this
distribution (the "License"). All use of this software is governed by the License,
or, if provided, by the license below or the license accompanying this file. Do not
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
"""
import WhiteBoxMath as whiteBoxMath
import WhiteBoxInit as init
import argparse
import azlmbr.legacy.general as general
import azlmbr.bus as bus
import azlmbr.whitebox.api as api
# usage: pyRunFile path/to/file/staircase.py <steps> <depth> <height> <width>
# formula to determine the new amount of faces added with each polygon translation
def faces_added(step):
return (step + 2) * 4
# returns the face handles used to make the top back block, used for extruding upward
def top_back_face_handle(num_faces):
return api.FaceHandle(num_faces - 4)
# determines the edge that needs to be hidden at the back of the staircase
# next edge seems to related to prev edge by the recursive sequence e(n+1) = e(n)+20+6*n
def edge_to_hide(prev_edge, step):
if step == 0:
return 20
return prev_edge + 20 + 6 * step
def create_staircase_from_white_box_mesh(whiteBoxMesh, num_steps, depth, height, width):
# number of faces the mesh starts with
curr_faces = 12
# backmost face of the white box mesh, this will be extruded to add new steps for the staircase
back_face = api.FaceHandle(10)
# backmost face of the white box mesh, this will be extruded to add width to the staircase
side_face = api.FaceHandle(5)
# change the default whiteBoxMesh which will act as the first step to the staircase
if height != 1.0 and height > 0.0:
offset = height - 1.0
top_polygon = whiteBoxMesh.FacePolygonHandle(azlmbr.object.construct('FaceHandle', 0))
whiteBoxMesh.TranslatePolygon(top_polygon, offset)
if depth != 1.0 and depth > 0.0:
offset = depth - 1.0
back_polygon = whiteBoxMesh.FacePolygonHandle(back_face)
whiteBoxMesh.TranslatePolygon(back_polygon, offset)
if width != 1.0 and width > 0.0:
offset = width - 1.0
side_polygon = whiteBoxMesh.FacePolygonHandle(side_face)
whiteBoxMesh.TranslatePolygon(side_polygon, offset)
prev_edge = 0
# create rest of the staircase steps
for step in range(0, num_steps):
# extrude the back to create room for a new step
back_polygon = whiteBoxMesh.TranslatePolygonAppend(whiteBoxMesh.FacePolygonHandle(back_face), depth)
curr_faces += faces_added(step)
back_faces = back_polygon.FaceHandles
back_face = back_faces[-1]
# extrude upward to create the new step
top_back_polygon = whiteBoxMesh.FacePolygonHandle(top_back_face_handle(curr_faces))
whiteBoxMesh.TranslatePolygonAppend(top_back_polygon, height)
curr_faces += 8
# hide any edge created in the backside from extruding upward
prev_edge = edge_to_hide(prev_edge, step)
whiteBoxMesh.HideEdge(api.EdgeHandle(prev_edge))
def create_staircase(whiteBoxMesh, num_steps=2, depth=1.0, height=1.0, width=1.0):
# if calling create_staircase directly, we need to start with a unit cube
whiteBoxMesh.InitializeAsUnitCube()
create_staircase_from_white_box_mesh(whiteBoxMesh, num_steps, depth, height, width)
if __name__ == "__main__":
# cmdline arguments
parser = argparse.ArgumentParser(description='Creates a staircase shaped white box mesh.')
parser.add_argument('num_steps', nargs='?', default=4, type=int, help='number of steps in the staircase')
parser.add_argument('depth', nargs='?', default=1.0, type=float, help='depth of each step in the staircase')
parser.add_argument('height', nargs='?', default=1.0, type=float, help='height of each step in the staircase')
parser.add_argument('width', nargs='?', default=1.0, type=float, help='width of each step in the staircase')
args = parser.parse_args()
# initialize whiteBoxMesh
whiteBoxEntity = init.create_white_box_entity("WhiteBox-Staircase")
whiteBoxMeshComponent = init.create_white_box_component(whiteBoxEntity)
whiteBoxMesh = init.create_white_box_handle(whiteBoxMeshComponent)
create_staircase_from_white_box_mesh(whiteBoxMesh, args.num_steps, args.depth, args.height, args.width)
# update whiteBoxMesh
init.update_white_box(whiteBoxMesh, whiteBoxMeshComponent)
@@ -0,0 +1,70 @@
"""
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
its licensors.
For complete copyright and license terms please see the LICENSE at the root of this
distribution (the "License"). All use of this software is governed by the License,
or, if provided, by the license below or the license accompanying this file. Do not
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
"""
import WhiteBoxMath as whiteBoxMath
import WhiteBoxInit as init
import argparse
import azlmbr.legacy.general as general
import azlmbr.bus as bus
import azlmbr.whitebox.api as api
# usage: pyRunFile path/to/file/tetrahedron.py <radius>
# mathematically, a tetrahedron built with spherical coordinates will not be centered vertically at origin
# we need to calculate how far off it is to vertically center it
def calculate_offset_for_tetrahedron(radius):
h1 = whiteBoxMath.spherical_to_cartesian(0.0, 0.0, radius).z
h2 = whiteBoxMath.spherical_to_cartesian(109.5, 90.0, radius).z
offset = (h1 + h2) * -0.5
return whiteBoxMath.spherical_to_cartesian(0.0, 0.0, offset)
def create_tetrahedron(whiteBoxMesh, radius=0.75):
# get coordinates for all the vertices using the internal angles of a tetrahedron
offset = calculate_offset_for_tetrahedron(radius)
pos1 = whiteBoxMath.spherical_to_cartesian(0.0, 0.0, radius).Add(offset)
pos2 = whiteBoxMath.spherical_to_cartesian(109.5, 90.0, radius).Add(offset)
pos3 = whiteBoxMath.spherical_to_cartesian(109.5, 210.0, radius).Add(offset)
pos4 = whiteBoxMath.spherical_to_cartesian(109.5, 330.0, radius).Add(offset)
# create vertices from all the coordinates
v1 = whiteBoxMesh.AddVertex(pos1)
v2 = whiteBoxMesh.AddVertex(pos2)
v3 = whiteBoxMesh.AddVertex(pos3)
v4 = whiteBoxMesh.AddVertex(pos4)
# add polygons for each set of vertices
fvh1 = whiteBoxMesh.AddTriPolygon(v1, v2, v3)
fvh2 = whiteBoxMesh.AddTriPolygon(v1, v3, v4)
fvh3 = whiteBoxMesh.AddTriPolygon(v1, v4, v2)
fvh4 = whiteBoxMesh.AddTriPolygon(v2, v4, v3)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Creates a tetrahedron.')
parser.add_argument('radius', nargs='?', default=0.75, type=float, help='radius of the tetrahedron')
args = parser.parse_args()
# initialize whiteBoxMesh
whiteBoxEntity = init.create_white_box_entity("WhiteBox-Tetrahedron")
whiteBoxMeshComponent = init.create_white_box_component(whiteBoxEntity)
whiteBoxMesh = init.create_white_box_handle(whiteBoxMeshComponent)
# clear whiteBoxMesh to make a tetrahedron from scratch
whiteBoxMesh.Clear()
create_tetrahedron(whiteBoxMesh, args.radius)
# update whiteBoxMesh
init.update_white_box(whiteBoxMesh, whiteBoxMeshComponent)
+67
View File
@@ -0,0 +1,67 @@
"""
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
its licensors.
For complete copyright and license terms please see the LICENSE at the root of this
distribution (the "License"). All use of this software is governed by the License,
or, if provided, by the license below or the license accompanying this file. Do not
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
"""
# 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
# get Component Type for WhiteBoxMesh
whiteBoxMeshComponentTypeId = get_white_box_component_type()
# use old White Box entity to hold White Box component if it exists, otherwise use a new one
newEntityId = None
oldEntityId = general.find_editor_entity('WhiteBox')
if oldEntityId.IsValid():
whiteBoxMeshComponentExists = editor.EditorComponentAPIBus(bus.Broadcast, 'HasComponentOfType', oldEntityId, whiteBoxMeshComponentTypeId)
if (whiteBoxMeshComponentExists):
oldwhiteBoxMeshComponent = editor.EditorComponentAPIBus(bus.Broadcast, 'GetComponentOfType', oldEntityId, whiteBoxMeshComponentTypeId)
editor.EditorComponentAPIBus(bus.Broadcast, 'RemoveComponents', [oldwhiteBoxMeshComponent.GetValue()])
newEntityId = oldEntityId
else:
newEntityId = editor.ToolsApplicationRequestBus(bus.Broadcast, 'CreateNewEntity', EntityId())
editor.EditorEntityAPIBus(bus.Event, 'SetName', newEntityId, "WhiteBox")
# add whiteBoxMeshComponent to entity and enable
whiteBoxMeshComponentOutcome = editor.EditorComponentAPIBus(bus.Broadcast, 'AddComponentsOfType', newEntityId, [whiteBoxMeshComponentTypeId])
if (whiteBoxMeshComponentOutcome.IsSuccess()):
print("White Box Component added to entity.")
whiteBoxMeshComponents = whiteBoxMeshComponentOutcome.GetValue()
whiteBoxMeshComponent = whiteBoxMeshComponents[0]
editor.EditorComponentAPIBus(bus.Broadcast, 'EnableComponents', whiteBoxMeshComponents)
isComponentEnabled = editor.EditorComponentAPIBus(bus.Broadcast, 'IsComponentEnabled', whiteBoxMeshComponent)
if (isComponentEnabled):
print("Enabled Mesh component.")
whiteBoxMesh = azlmbr.whitebox.request.bus.EditorWhiteBoxComponentRequestBus(bus.Event, 'GetWhiteBoxMeshHandle', whiteBoxMeshComponent)
# translate append (extrude) a polygon
if (len(sys.argv) >= 2 and float(sys.argv[2]) != 0.0):
# create face handle from user input (argv[1])
faceHandle = azlmbr.object.construct('FaceHandle', int(sys.argv[1]))
# find the polygon handle that corresponds to the given face
facePolygonHandle = whiteBoxMesh.FacePolygonHandle(faceHandle)
# translate append (extrude) the polygon by a distance specified by the user (argv[2])
whiteBoxMesh.TranslatePolygonAppend(facePolygonHandle, float(sys.argv[2]))
# recalculate uvs as mesh will have changed
whiteBoxMesh.CalculatePlanarUVs()
# notify the white box component the mesh has changed to force it to rebuild the render mesh
azlmbr.whitebox.notification.bus.EditorWhiteBoxComponentNotificationBus(bus.Event, 'OnWhiteBoxMeshModified', whiteBoxMeshComponent)
@@ -0,0 +1,65 @@
"""
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
its licensors.
For complete copyright and license terms please see the LICENSE at the root of this
distribution (the "License"). All use of this software is governed by the License,
or, if provided, by the license below or the license accompanying this file. Do not
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
"""
# 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)
@@ -0,0 +1,35 @@
"""
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
its licensors.
For complete copyright and license terms please see the LICENSE at the root of this
distribution (the "License"). All use of this software is governed by the License,
or, if provided, by the license below or the license accompanying this file. Do not
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
"""
# setup path
import azlmbr.object
import azlmbr.math as math
# returns a Vector3 of cartesian coordinates from spherical coordinates
# phi and theta are in degrees
def spherical_to_cartesian(phi, theta, dist=1.0):
phi = math.Math_DegToRad(phi)
theta = math.Math_DegToRad(theta)
x = float(dist) * float(math.Math_Sin(phi)) * float(math.Math_Cos(theta))
y = float(dist) * float(math.Math_Sin(phi)) * float(math.Math_Sin(theta))
z = float(dist) * float(math.Math_Cos(phi))
return math.Vector3(x, y, z)
# converts two Cartesian points into their midpoint, normalized into a vector of size r
def normalize_midpoint(pos1, pos2, r=1.0):
pos = pos1.Add(pos2).MultiplyFloat(0.5)
pos.Normalize()
return pos.MultiplyFloat(r)
@@ -0,0 +1,68 @@
"""
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
its licensors.
For complete copyright and license terms please see the LICENSE at the root of this
distribution (the "License"). All use of this software is governed by the License,
or, if provided, by the license below or the license accompanying this file. Do not
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
"""
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)