Integrating github/staging through commit ab87ed9
This commit is contained in:
@@ -75,7 +75,7 @@ namespace AZ
|
||||
m_status = Data::AssetData::AssetStatus::Ready;
|
||||
}
|
||||
|
||||
bool ModelAsset::LocalRayIntersectionAgainstModel(const AZ::Vector3& rayStart, const AZ::Vector3& dir, float& distance) const
|
||||
bool ModelAsset::LocalRayIntersectionAgainstModel(const AZ::Vector3& rayStart, const AZ::Vector3& dir, float& distance, AZ::Vector3& normal) const
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::AzRender);
|
||||
|
||||
@@ -97,11 +97,11 @@ namespace AZ
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_kdTree->RayIntersection(rayStart, dir, distance);
|
||||
return m_kdTree->RayIntersection(rayStart, dir, distance, normal);
|
||||
}
|
||||
}
|
||||
|
||||
return BruteForceRayIntersect(rayStart, dir, distance);
|
||||
return BruteForceRayIntersect(rayStart, dir, distance, normal);
|
||||
}
|
||||
|
||||
void ModelAsset::BuildKdTree() const
|
||||
@@ -136,7 +136,7 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
bool ModelAsset::BruteForceRayIntersect(const AZ::Vector3& rayStart, const AZ::Vector3& dir, float& distance) const
|
||||
bool ModelAsset::BruteForceRayIntersect(const AZ::Vector3& rayStart, const AZ::Vector3& dir, float& distance, AZ::Vector3& normal) const
|
||||
{
|
||||
// brute force - check every triangle
|
||||
if (GetLodAssets().empty() == false)
|
||||
@@ -147,12 +147,18 @@ namespace AZ
|
||||
float shortestDistance = std::numeric_limits<float>::max();
|
||||
bool anyHit = false;
|
||||
|
||||
AZ::Vector3 intersectionNormal;
|
||||
|
||||
for (const ModelLodAsset::Mesh& mesh : loadAssetPtr->GetMeshes())
|
||||
{
|
||||
if (LocalRayIntersectionAgainstMesh(mesh, rayStart, dir, distance))
|
||||
if (LocalRayIntersectionAgainstMesh(mesh, rayStart, dir, distance, intersectionNormal))
|
||||
{
|
||||
anyHit = true;
|
||||
shortestDistance = AZ::GetMin(distance, shortestDistance);
|
||||
if (distance < shortestDistance)
|
||||
{
|
||||
normal = intersectionNormal;
|
||||
shortestDistance = distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +174,7 @@ namespace AZ
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ModelAsset::LocalRayIntersectionAgainstMesh(const ModelLodAsset::Mesh& mesh, const AZ::Vector3& rayStart, const AZ::Vector3& dir, float& distance) const
|
||||
bool ModelAsset::LocalRayIntersectionAgainstMesh(const ModelLodAsset::Mesh& mesh, const AZ::Vector3& rayStart, const AZ::Vector3& dir, float& distance, AZ::Vector3& normal) const
|
||||
{
|
||||
const BufferAssetView& indexBufferView = mesh.GetIndexBufferAssetView();
|
||||
const AZStd::array_view<ModelLodAsset::Mesh::StreamBufferInfo>& streamBufferList = mesh.GetStreamBufferInfoList();
|
||||
@@ -216,7 +222,7 @@ namespace AZ
|
||||
|
||||
const AZ::Vector3 rayEnd = rayStart + dir * distance;
|
||||
AZ::Vector3 a, b, c;
|
||||
AZ::Vector3 normal;
|
||||
AZ::Vector3 intersectionNormal;
|
||||
float normalizedDistance = 1.f;
|
||||
|
||||
const AZ::u32* indexPtr = reinterpret_cast<const AZ::u32*>(indexRawBuffer.data());
|
||||
@@ -241,9 +247,13 @@ namespace AZ
|
||||
p = reinterpret_cast<const float*>(&positionRawBuffer[index2 * positionElementSize]);
|
||||
c.Set(const_cast<float*>(p));
|
||||
|
||||
if (AZ::Intersect::IntersectSegmentTriangleCCW(rayStart, rayEnd, a, b, c, normal, normalizedDistance))
|
||||
if (AZ::Intersect::IntersectSegmentTriangleCCW(rayStart, rayEnd, a, b, c, intersectionNormal, normalizedDistance))
|
||||
{
|
||||
closestNormalizedDistance = AZ::GetMin(closestNormalizedDistance, normalizedDistance);
|
||||
if (normalizedDistance < closestNormalizedDistance)
|
||||
{
|
||||
normal = intersectionNormal;
|
||||
closestNormalizedDistance = normalizedDistance;
|
||||
}
|
||||
anyHit = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,12 +221,12 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
bool ModelKdTree::RayIntersection(const AZ::Vector3& raySrc, const AZ::Vector3& rayDir, float& distance) const
|
||||
bool ModelKdTree::RayIntersection(const AZ::Vector3& raySrc, const AZ::Vector3& rayDir, float& distance, AZ::Vector3& normal) const
|
||||
{
|
||||
return RayIntersectionRecursively(m_pRootNode.get(), raySrc, rayDir, distance);
|
||||
return RayIntersectionRecursively(m_pRootNode.get(), raySrc, rayDir, distance, normal);
|
||||
}
|
||||
|
||||
bool ModelKdTree::RayIntersectionRecursively(ModelKdTreeNode* pNode, const AZ::Vector3& raySrc, const AZ::Vector3& rayDir, float& distance) const
|
||||
bool ModelKdTree::RayIntersectionRecursively(ModelKdTreeNode* pNode, const AZ::Vector3& raySrc, const AZ::Vector3& rayDir, float& distance, AZ::Vector3& normal) const
|
||||
{
|
||||
if (!pNode)
|
||||
{
|
||||
@@ -252,7 +252,7 @@ namespace AZ
|
||||
return false;
|
||||
}
|
||||
|
||||
AZ::Vector3 ignoreNormal;
|
||||
AZ::Vector3 intersectionNormal;
|
||||
float hitDistanceNormalized;
|
||||
const float maxDist(FLT_MAX);
|
||||
float nearestDist = maxDist;
|
||||
@@ -278,9 +278,15 @@ namespace AZ
|
||||
const AZ::Vector3 rayEnd = raySrc + rayDir * distance;
|
||||
|
||||
if (AZ::Intersect::IntersectSegmentTriangleCCW(raySrc, rayEnd, trianglePoints[0], trianglePoints[1], trianglePoints[2],
|
||||
ignoreNormal, hitDistanceNormalized) != Intersect::ISECT_RAY_AABB_NONE)
|
||||
intersectionNormal, hitDistanceNormalized) != Intersect::ISECT_RAY_AABB_NONE)
|
||||
{
|
||||
float hitDistance = hitDistanceNormalized * distance;
|
||||
|
||||
if (nearestDist > hitDistance)
|
||||
{
|
||||
normal = intersectionNormal;
|
||||
}
|
||||
|
||||
nearestDist = AZStd::GetMin(nearestDist, hitDistance);
|
||||
}
|
||||
}
|
||||
@@ -295,8 +301,8 @@ namespace AZ
|
||||
}
|
||||
|
||||
// running both sides to find the closest intersection
|
||||
const bool bFoundChild0 = RayIntersectionRecursively(pNode->GetChild(0), raySrc, rayDir, distance);
|
||||
const bool bFoundChild1 = RayIntersectionRecursively(pNode->GetChild(1), raySrc, rayDir, distance);
|
||||
const bool bFoundChild0 = RayIntersectionRecursively(pNode->GetChild(0), raySrc, rayDir, distance, normal);
|
||||
const bool bFoundChild1 = RayIntersectionRecursively(pNode->GetChild(1), raySrc, rayDir, distance, normal);
|
||||
|
||||
return bFoundChild0 || bFoundChild1;
|
||||
}
|
||||
|
||||
@@ -138,19 +138,6 @@ namespace AZ
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AZStd::array_view<uint8_t> ModelLodAsset::Mesh::GetSemanticBuffer(const AZ::Name& semantic) const
|
||||
{
|
||||
if (const BufferAssetView* bufferAssetView = GetSemanticBufferAssetView(semantic))
|
||||
{
|
||||
if (const BufferAsset* bufferAsset = bufferAssetView->GetBufferAsset().Get())
|
||||
{
|
||||
return bufferAsset->GetBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void ModelLodAsset::SetReady()
|
||||
{
|
||||
m_status = Data::AssetData::AssetStatus::Ready;
|
||||
|
||||
Reference in New Issue
Block a user