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
@@ -0,0 +1,42 @@
/*
* 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.
*
*/
#include "WhiteBox_precompiled.h"
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
#include <AzToolsFramework/SourceControl/SourceControlAPI.h>
namespace WhiteBox
{
void RequestEditSourceControl(const char* absoluteFilePath)
{
bool active = false;
AzToolsFramework::SourceControlConnectionRequestBus::BroadcastResult(
active, &AzToolsFramework::SourceControlConnectionRequestBus::Events::IsActive);
if (active)
{
AzToolsFramework::SourceControlCommandBus::Broadcast(
&AzToolsFramework::SourceControlCommandBus::Events::RequestEdit, absoluteFilePath, true,
[]([[maybe_unused]] bool success, [[maybe_unused]] AzToolsFramework::SourceControlFileInfo info)
{
});
}
}
IEditor* GetIEditor()
{
IEditor* editor = nullptr;
AzToolsFramework::EditorRequests::Bus::BroadcastResult(editor, &AzToolsFramework::EditorRequests::GetEditor);
return editor;
}
} // namespace WhiteBox
@@ -0,0 +1,24 @@
/*
* 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.
*
*/
#pragma once
struct IEditor;
namespace WhiteBox
{
//! Small wrapper around an EBus call to request the file at the given path be added to source control.
void RequestEditSourceControl(const char* absoluteFilePath);
//! Small wrapper around an EBus call to retrieve the IEditor interface.
IEditor* GetIEditor();
} // namespace WhiteBox
@@ -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.
*
*/
#include "WhiteBox_precompiled.h"
#include "WhiteBoxMathUtil.h"
#include <AzCore/Math/Matrix3x3.h>
#include <AzCore/Math/Transform.h>
#include <AzCore/Math/Vector3.h>
namespace WhiteBox
{
//! Reference: Real-Time Collision Detection - 5.3.7 Intersecting Ray or Segment Against Cylinder
//! @note the parameters and style here are copied verbatim from the book
//! to make comparison and bug finding trivial.
bool IntersectSegmentCylinder(
const AZ::Vector3& sa, const AZ::Vector3& sb, const AZ::Vector3& p, const AZ::Vector3& q, float r, float& t)
{
// clang-format off
const AZ::Vector3 d = q - p;
const AZ::Vector3 m = sa - p;
const AZ::Vector3 n = sb - sa;
const float md = m.Dot(d);
const float nd = n.Dot(d);
const float dd = d.Dot(d);
if (md < 0.0f && md + nd < 0.0f) return false;
if (md > dd && md + nd > dd) return false;
const float nn = n.Dot(n);
const float mn = m.Dot(n);
const float a = dd * nn - nd * nd;
const float k = m.Dot(m) - r * r;
const float c = dd * k - md * md;
if (AZ::GetAbs(a) < AZ::Constants::FloatEpsilon) {
if (c > 0.0f) return false;
if (md < 0.0f) t = -mn / nn;
else if (md > dd) t = -mn / nn;
else t = 0.0f;
return true;
}
const float b = dd * mn - nd * md;
const float discr = b * b - a * c;
if (discr < 0.0f) return false;
t = (-b - sqrt(discr)) / a;
if (t < 0.0f || t > 1.0f) return false;
if (md + t * nd < 0.0f) {
if (nd <= 0.0f) return false;
t = -md / nd;
return k + 2 * t * (mn + t * nn) <= 0.0f;
}
else if (md + t * nd > dd) {
if (nd >= 0.0f) return false;
t = (dd - md) / nd;
return k + dd - 2 * md + t * (2 * (mn - nd) + t * nn) <= 0.0f;
}
return true;
// clang-format on
}
AZ::Vector3 ScalePosition(const float scale, const AZ::Vector3& localPosition, const AZ::Transform& localFromSpace)
{
const AZ::Transform spaceFromLocal = localFromSpace.GetInverse();
const AZ::Vector3 spacePosition = spaceFromLocal.TransformPoint(localPosition);
const AZ::Vector3 spaceScaledPosition =
AZ::Transform::CreateScale(AZ::Vector3(scale)).TransformPoint(spacePosition);
return localFromSpace.TransformPoint(spaceScaledPosition);
}
void CalculateOrthonormalBasis(const AZ::Vector3& n, AZ::Vector3& b1, AZ::Vector3& b2)
{
// choose a vector orthogonal to n as the direction of b2
if (fabsf(n.GetX()) > fabs(n.GetZ()))
{
b2 = AZ::Vector3(-n.GetY(), n.GetX(), 0.0f);
}
else
{
b2 = AZ::Vector3(0.0f, -n.GetZ(), n.GetY());
}
b2.Normalize();
b1 = b2.Cross(n);
}
AZ::Quaternion CalculateLocalOrientation(const AZ::Vector3& normal)
{
AZ::Vector3 b1, b2;
CalculateOrthonormalBasis(normal, b1, b2);
const AZ::Matrix3x3 mat = AZ::Matrix3x3::CreateFromColumns(normal, b1, b2);
return AZ::Quaternion::CreateFromMatrix3x3(mat);
}
} // namespace WhiteBox
@@ -0,0 +1,39 @@
/*
* 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.
*
*/
#pragma once
namespace WhiteBox
{
//! Intersect a segment with a cylinder
//! Reference: Real-Time Collision Detection - 5.3.7 Intersecting Ray or Segment Against Cylinder
//! @note: This exists because the version in AzCore has bugs. Should consider moving this to AzCore
//! @param sa The start of the line segment
//! @param sb The end of the line segment
//! @param p The base of the cylinder
//! @param q The top of the cylinder
//! @param r The radius of the cylinder
//! @param t The normalized distance along the line segment
//! @return if an intersection occured or not
bool IntersectSegmentCylinder(
const AZ::Vector3& sa, const AZ::Vector3& sb, const AZ::Vector3& p, const AZ::Vector3& q, float r, float& t);
//! Take a point in 'local' space, transform it to the new space, scale it uniformly, then return to 'local' space.
AZ::Vector3 ScalePosition(float scale, const AZ::Vector3& localPosition, const AZ::Transform& localFromSpace);
//! Hughes/Moeller calculate orthonormal basis.
void CalculateOrthonormalBasis(const AZ::Vector3& n, AZ::Vector3& b1, AZ::Vector3& b2);
//! Calculates local orientation from the orthonormal basis of the specified normal vector.
AZ::Quaternion CalculateLocalOrientation(const AZ::Vector3& normal);
} // namespace WhiteBox
@@ -0,0 +1,87 @@
/*
* 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.
*
*/
#include "WhiteBox_precompiled.h"
#include "WhiteBoxTextureUtil.h"
#include <AzCore/Casting/lossy_cast.h>
#include <AzCore/Math/Plane.h>
namespace WhiteBox
{
int FindLargestElement(const AZ::Vector3& vector)
{
AZ::Vector3 absVector = vector.GetAbs();
// if any components are equal, for convention, favor components in increasing order
if (absVector.GetElement(0) >= absVector.GetElement(1) && absVector.GetElement(0) >= absVector.GetElement(2))
{
return 0;
}
else if (
absVector.GetElement(1) >= absVector.GetElement(0) && absVector.GetElement(1) >= absVector.GetElement(2))
{
return 1;
}
else
{
return 2;
}
}
AZ::Vector2 CreatePlanarUVFromVertex(
const AZ::Vector3& normal, const AZ::Vector3& position, const AZ::Vector2& offset, const AZ::Vector2& scale)
{
// truncates a float to 3 decimal places
// note: there are the Round and Round3 methods in ManipulatorSnapping.h (which may very well be the
// source of the noise) but for this specific issue, we want to discard the information after 3 decimal
// places to ensure consistent behaviour (rounding could cause flipping between planes when the noise is
// around the rounding threshold)
auto truncateComponent = [](const float f)
{
const float factor3Places = 1000.0f;
AZ::s32 i = azlossy_cast<AZ::s32, float>(f * factor3Places);
return i / factor3Places;
};
// noise from grid snapping can manifest in the normal even if the positioning itself does not change so
// truncate the normal to 3 decimal places in order to ensure that the favoured component order for equal
// component values is consistent
const AZ::Vector3 truncatedNormal = AZ::Vector3(
truncateComponent(normal.GetX()), truncateComponent(normal.GetY()), truncateComponent(normal.GetZ()));
const int largestElem = FindLargestElement(truncatedNormal);
// swizzled vertex positions for each of the basis vector planes
const AZ::Vector2 uvX(position.GetZ(), position.GetY());
const AZ::Vector2 uvY(position.GetX(), position.GetZ());
const AZ::Vector2 uvZ(position.GetX(), position.GetY());
AZ::Vector2 uv;
if (largestElem == 0)
{
uv = uvX;
}
else if (largestElem == 1)
{
uv = uvY;
}
else
{
uv = uvZ;
}
return uv * scale + offset;
}
} // namespace WhiteBox
@@ -0,0 +1,28 @@
/*
* 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.
*
*/
#pragma once
#include <AzCore/Math/Vector2.h>
#include <AzCore/Math/Vector3.h>
namespace WhiteBox
{
//! Returns the index of the largest element in the vector
int FindLargestElement(const AZ::Vector3& vector);
//! Creates UV coordinates from vertex positioning on closest basis vector p
AZ::Vector2 CreatePlanarUVFromVertex(
const AZ::Vector3& normal, const AZ::Vector3& position, const AZ::Vector2& offset = AZ::Vector2(0.5f, 0.5f),
const AZ::Vector2& scale = AZ::Vector2(-1.0f, -1.0f));
} // namespace WhiteBox