比较提交
合并到: unity-tech-cn:main
unity-tech-cn:/main
unity-tech-cn:/readback_mode
unity-tech-cn:/fix-editor-pause
unity-tech-cn:/docs
unity-tech-cn:/format
unity-tech-cn:/dr-test1
unity-tech-cn:/fix-compile
unity-tech-cn:/fix-links
unity-tech-cn:/fix_startup_exception
unity-tech-cn:/fix-docs
unity-tech-cn:/fix_label_id_report
unity-tech-cn:/update-setup-steps
unity-tech-cn:/labeler_mock
unity-tech-cn:/publish-fix
unity-tech-cn:/result_visualization
unity-tech-cn:/labeler_mock_mb
unity-tech-cn:/labeler_mock_on_camera
unity-tech-cn:/0.1.0-staging
unity-tech-cn:/dr-test2
unity-tech-cn:/release_cleanup
unity-tech-cn:/RC_0.2.0-preview.1
unity-tech-cn:/aisv614_0.2.0
unity-tech-cn:/aisv614_fix
unity-tech-cn:/aisv647_visualizations
unity-tech-cn:/RC-0.2.0-preview.1
unity-tech-cn:/fix_seg_colors
unity-tech-cn:/test
unity-tech-cn:/0.3.0-staging
unity-tech-cn:/aisv565_bbox3d
unity-tech-cn:/aisv749_viz_mem_leak_bug
unity-tech-cn:/aisv754_seg_alpha_bug
unity-tech-cn:/test_request_tracking_completion
unity-tech-cn:/test_new_versions
unity-tech-cn:/usim-randomization
unity-tech-cn:/with_cloud_tests
unity-tech-cn:/0.2.0-staging
unity-tech-cn:/parameter-bahaviours
unity-tech-cn:/upgrade_deps
unity-tech-cn:/0.4.0-staging
unity-tech-cn:/0.5.0-staging-2020.1
unity-tech-cn:/0.5.0-staging
unity-tech-cn:/resint_updates
unity-tech-cn:/tutorial-spelling-fix
unity-tech-cn:/priyesh-urp-dist-render
unity-tech-cn:/multiple-perception-cameras
unity-tech-cn:/pre_release_tests_nov2020
unity-tech-cn:/0.6.0-staging
unity-tech-cn:/fix_performance_tests
unity-tech-cn:/manual_capture
unity-tech-cn:/fod_generator_randomization_changes
unity-tech-cn:/multipleCameras
unity-tech-cn:/Labelbug1101
unity-tech-cn:/replace_index_md
unity-tech-cn:/depth_occlusion
unity-tech-cn:/0.8.0-preview.1_staging
unity-tech-cn:/validation-tool
unity-tech-cn:/addressables-test
unity-tech-cn:/int_tests_on_hdrp
unity-tech-cn:/keypoint_self_occlusion
unity-tech-cn:/seg_opacity
unity-tech-cn:/foreground_object_bounds_normalization
unity-tech-cn:/generic-asset-sources
unity-tech-cn:/local-position-labeler
unity-tech-cn:/pyrception-integration
unity-tech-cn:/fix_sampler_rounding_issue
unity-tech-cn:/h-i
unity-tech-cn:/0.7.0-staging
unity-tech-cn:/Released-0.6.0-preview.1
unity-tech-cn:/moved-from-attribute
unity-tech-cn:/frontpage_shuffle
unity-tech-cn:/coco_export
unity-tech-cn:/public-spec
unity-tech-cn:/fix-3Dexception-typo
unity-tech-cn:/feat-light-randomizer
unity-tech-cn:/schema-0.1.0
unity-tech-cn:/data-cap-update
unity-tech-cn:/0.8.0.preview.4_staging
unity-tech-cn:/faq-page
unity-tech-cn:/orthographic-camera-metadata
unity-tech-cn:/update-docs-0.8.0.preview.4
unity-tech-cn:/priyesh-cloudrendering-test
unity-tech-cn:/Release_0.8.0-preview.4
unity-tech-cn:/tutorial_patch
unity-tech-cn:/add_imageLink_field
unity-tech-cn:/fix_label_config_editor_indexing
unity-tech-cn:/coco_perception_output_hybrid
unity-tech-cn:/fxaa-clarification
unity-tech-cn:/no_editor_coverage
unity-tech-cn:/keypoint_self_occlusion_2020_3
unity-tech-cn:/for_vulkan_mem_test
unity-tech-cn:/solo_support
unity-tech-cn:/fix_multi_cam
unity-tech-cn:/randomizer-serialization-update
unity-tech-cn:/semantic_shader_tests
unity-tech-cn:/revert-sample-scene
unity-tech-cn:/package-analytics
unity-tech-cn:/github-action
unity-tech-cn:/fix-one-extra-frame-before-scenario-starts
unity-tech-cn:/scene_gen
unity-tech-cn:/0.9.0.preview.1_staging
unity-tech-cn:/tag-RC-0.9.0.preview.2
unity-tech-cn:/remove-usim-from-docs
unity-tech-cn:/docs/fix-readme-image-names
unity-tech-cn:/fix-links/jonh
unity-tech-cn:/addressables-test/scheduledcapture
unity-tech-cn:/orthographic-camera-metadata/additions
unity-tech-cn:/github-action/test
拉取从: unity-tech-cn:foreground_object_bounds_normalization
unity-tech-cn:/main
unity-tech-cn:/readback_mode
unity-tech-cn:/fix-editor-pause
unity-tech-cn:/docs
unity-tech-cn:/format
unity-tech-cn:/dr-test1
unity-tech-cn:/fix-compile
unity-tech-cn:/fix-links
unity-tech-cn:/fix_startup_exception
unity-tech-cn:/fix-docs
unity-tech-cn:/fix_label_id_report
unity-tech-cn:/update-setup-steps
unity-tech-cn:/labeler_mock
unity-tech-cn:/publish-fix
unity-tech-cn:/result_visualization
unity-tech-cn:/labeler_mock_mb
unity-tech-cn:/labeler_mock_on_camera
unity-tech-cn:/0.1.0-staging
unity-tech-cn:/dr-test2
unity-tech-cn:/release_cleanup
unity-tech-cn:/RC_0.2.0-preview.1
unity-tech-cn:/aisv614_0.2.0
unity-tech-cn:/aisv614_fix
unity-tech-cn:/aisv647_visualizations
unity-tech-cn:/RC-0.2.0-preview.1
unity-tech-cn:/fix_seg_colors
unity-tech-cn:/test
unity-tech-cn:/0.3.0-staging
unity-tech-cn:/aisv565_bbox3d
unity-tech-cn:/aisv749_viz_mem_leak_bug
unity-tech-cn:/aisv754_seg_alpha_bug
unity-tech-cn:/test_request_tracking_completion
unity-tech-cn:/test_new_versions
unity-tech-cn:/usim-randomization
unity-tech-cn:/with_cloud_tests
unity-tech-cn:/0.2.0-staging
unity-tech-cn:/parameter-bahaviours
unity-tech-cn:/upgrade_deps
unity-tech-cn:/0.4.0-staging
unity-tech-cn:/0.5.0-staging-2020.1
unity-tech-cn:/0.5.0-staging
unity-tech-cn:/resint_updates
unity-tech-cn:/tutorial-spelling-fix
unity-tech-cn:/priyesh-urp-dist-render
unity-tech-cn:/multiple-perception-cameras
unity-tech-cn:/pre_release_tests_nov2020
unity-tech-cn:/0.6.0-staging
unity-tech-cn:/fix_performance_tests
unity-tech-cn:/manual_capture
unity-tech-cn:/fod_generator_randomization_changes
unity-tech-cn:/multipleCameras
unity-tech-cn:/Labelbug1101
unity-tech-cn:/replace_index_md
unity-tech-cn:/depth_occlusion
unity-tech-cn:/0.8.0-preview.1_staging
unity-tech-cn:/validation-tool
unity-tech-cn:/addressables-test
unity-tech-cn:/int_tests_on_hdrp
unity-tech-cn:/keypoint_self_occlusion
unity-tech-cn:/seg_opacity
unity-tech-cn:/foreground_object_bounds_normalization
unity-tech-cn:/generic-asset-sources
unity-tech-cn:/local-position-labeler
unity-tech-cn:/pyrception-integration
unity-tech-cn:/fix_sampler_rounding_issue
unity-tech-cn:/h-i
unity-tech-cn:/0.7.0-staging
unity-tech-cn:/Released-0.6.0-preview.1
unity-tech-cn:/moved-from-attribute
unity-tech-cn:/frontpage_shuffle
unity-tech-cn:/coco_export
unity-tech-cn:/public-spec
unity-tech-cn:/fix-3Dexception-typo
unity-tech-cn:/feat-light-randomizer
unity-tech-cn:/schema-0.1.0
unity-tech-cn:/data-cap-update
unity-tech-cn:/0.8.0.preview.4_staging
unity-tech-cn:/faq-page
unity-tech-cn:/orthographic-camera-metadata
unity-tech-cn:/update-docs-0.8.0.preview.4
unity-tech-cn:/priyesh-cloudrendering-test
unity-tech-cn:/Release_0.8.0-preview.4
unity-tech-cn:/tutorial_patch
unity-tech-cn:/add_imageLink_field
unity-tech-cn:/fix_label_config_editor_indexing
unity-tech-cn:/coco_perception_output_hybrid
unity-tech-cn:/fxaa-clarification
unity-tech-cn:/no_editor_coverage
unity-tech-cn:/keypoint_self_occlusion_2020_3
unity-tech-cn:/for_vulkan_mem_test
unity-tech-cn:/solo_support
unity-tech-cn:/fix_multi_cam
unity-tech-cn:/randomizer-serialization-update
unity-tech-cn:/semantic_shader_tests
unity-tech-cn:/revert-sample-scene
unity-tech-cn:/package-analytics
unity-tech-cn:/github-action
unity-tech-cn:/fix-one-extra-frame-before-scenario-starts
unity-tech-cn:/scene_gen
unity-tech-cn:/0.9.0.preview.1_staging
unity-tech-cn:/tag-RC-0.9.0.preview.2
unity-tech-cn:/remove-usim-from-docs
unity-tech-cn:/docs/fix-readme-image-names
unity-tech-cn:/fix-links/jonh
unity-tech-cn:/addressables-test/scheduledcapture
unity-tech-cn:/orthographic-camera-metadata/additions
unity-tech-cn:/github-action/test
1 次代码提交
作者 | SHA1 | 备注 | 提交日期 |
---|---|---|---|
Mohsen Kamalzadeh | 799c8e10 | added object bounds normalization option to sample foreground object placement randomizer | 4 年前 |
共有 3 个文件被更改,包括 403 次插入 和 1 次删除
-
76com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/ForegroundObjectPlacementRandomizer.cs
-
317com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Utilities/MinMaxAABB.cs
-
11com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Utilities/MinMaxAABB.cs.meta
|
|||
using System; |
|||
using System.Runtime.CompilerServices; |
|||
using Unity.Mathematics; |
|||
|
|||
namespace SynthDet.Randomizers |
|||
{ |
|||
/// <summary>
|
|||
/// Axis aligned bounding box (AABB) stored in min and max form.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Axis aligned bounding boxes (AABB) are boxes where each side is parallel with one of the Cartesian coordinate axes
|
|||
/// X, Y, and Z. AABBs are useful for approximating the region an object (or collection of objects) occupies and quickly
|
|||
/// testing whether or not that object (or collection of objects) is relevant. Because they are axis aligned, they
|
|||
/// are very cheap to construct and perform overlap tests with them.
|
|||
/// </remarks>
|
|||
[System.Serializable] |
|||
internal struct SynthDetMinMaxAABB : IEquatable<SynthDetMinMaxAABB> |
|||
{ |
|||
/// <summary>
|
|||
/// The minimum point contained by the AABB.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// If any component of <see cref="Min"/> is greater than <see cref="Max"/> then this AABB is invalid.
|
|||
/// </remarks>
|
|||
/// <seealso cref="IsValid"/>
|
|||
public float3 Min; |
|||
|
|||
/// <summary>
|
|||
/// The maximum point contained by the AABB.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// If any component of <see cref="Max"/> is less than <see cref="Min"/> then this AABB is invalid.
|
|||
/// </remarks>
|
|||
/// <seealso cref="IsValid"/>
|
|||
public float3 Max; |
|||
|
|||
/// <summary>
|
|||
/// Constructs the AABB with the given minimum and maximum.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// If you have a center and extents, you can call <see cref="CreateFromCenterAndExtents"/> or <see cref="CreateFromCenterAndHalfExtents"/>
|
|||
/// to create the AABB.
|
|||
/// </remarks>
|
|||
/// <param name="min">Minimum point inside AABB.</param>
|
|||
/// <param name="max">Maximum point inside AABB.</param>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public SynthDetMinMaxAABB(float3 min, float3 max) |
|||
{ |
|||
Min = min; |
|||
Max = max; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Creates the AABB from a center and extents.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// This function takes full extents. It is the distance between <see cref="Min"/> and <see cref="Max"/>.
|
|||
/// If you have half extents, you can call <see cref="CreateFromCenterAndHalfExtents"/>.
|
|||
/// </remarks>
|
|||
/// <param name="center">Center of AABB.</param>
|
|||
/// <param name="extents">Full extents of AABB.</param>
|
|||
/// <returns>AABB created from inputs.</returns>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public static SynthDetMinMaxAABB CreateFromCenterAndExtents(float3 center, float3 extents) |
|||
{ |
|||
return CreateFromCenterAndHalfExtents(center, extents * 0.5f); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Creates the AABB from a center and half extents.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// This function takes half extents. It is half the distance between <see cref="Min"/> and <see cref="Max"/>.
|
|||
/// If you have full extents, you can call <see cref="CreateFromCenterAndExtents"/>.
|
|||
/// </remarks>
|
|||
/// <param name="center">Center of AABB.</param>
|
|||
/// <param name="halfExtents">Half extents of AABB.</param>
|
|||
/// <returns>AABB created from inputs.</returns>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public static SynthDetMinMaxAABB CreateFromCenterAndHalfExtents(float3 center, float3 halfExtents) |
|||
{ |
|||
return new SynthDetMinMaxAABB(center - halfExtents, center + halfExtents); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Computes the extents of the AABB.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Extents is the componentwise distance between min and max.
|
|||
/// </remarks>
|
|||
public float3 Extents => Max - Min; |
|||
|
|||
/// <summary>
|
|||
/// Computes the half extents of the AABB.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// HalfExtents is half of the componentwise distance between min and max. Subtracting HalfExtents from Center
|
|||
/// gives Min and adding HalfExtents to Center gives Max.
|
|||
/// </remarks>
|
|||
public float3 HalfExtents => (Max - Min) * 0.5f; |
|||
|
|||
/// <summary>
|
|||
/// Computes the center of the AABB.
|
|||
/// </summary>
|
|||
public float3 Center => (Max + Min) * 0.5f; |
|||
|
|||
/// <summary>
|
|||
/// Check if the AABB is valid.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// An AABB is considered valid if <see cref="Min"/> is componentwise less than or equal to <see cref="Max"/>.
|
|||
/// </remarks>
|
|||
/// <returns>True if <see cref="Min"/> is componentwise less than or equal to <see cref="Max"/>.</returns>
|
|||
public bool IsValid => math.all(Min <= Max); |
|||
|
|||
/// <summary>
|
|||
/// Computes the surface area for this axis aligned bounding box.
|
|||
/// </summary>
|
|||
public float SurfaceArea |
|||
{ |
|||
get |
|||
{ |
|||
float3 diff = Max - Min; |
|||
return 2 * math.dot(diff, diff.yzx); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests if the input point is contained by the AABB.
|
|||
/// </summary>
|
|||
/// <param name="point">Point to test.</param>
|
|||
/// <returns>True if AABB contains the input point.</returns>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public bool Contains(float3 point) => math.all(point >= Min & point <= Max); |
|||
|
|||
/// <summary>
|
|||
/// Tests if the input AABB is contained entirely by this AABB.
|
|||
/// </summary>
|
|||
/// <param name="aabb">AABB to test.</param>
|
|||
/// <returns>True if input AABB is contained entirely by this AABB.</returns>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public bool Contains(SynthDetMinMaxAABB aabb) => math.all((Min <= aabb.Min) & (Max >= aabb.Max)); |
|||
|
|||
/// <summary>
|
|||
/// Tests if the input AABB overlaps this AABB.
|
|||
/// </summary>
|
|||
/// <param name="aabb">AABB to test.</param>
|
|||
/// <returns>True if input AABB overlaps with this AABB.</returns>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public bool Overlaps(SynthDetMinMaxAABB aabb) |
|||
{ |
|||
return math.all(Max >= aabb.Min & Min <= aabb.Max); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Expands the AABB by the given signed distance.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Positive distance expands the AABB while negative distance shrinks the AABB.
|
|||
/// </remarks>
|
|||
/// <param name="signedDistance">Signed distance to expand the AABB with.</param>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public void Expand(float signedDistance) |
|||
{ |
|||
Min -= signedDistance; |
|||
Max += signedDistance; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Encapsulates the given AABB.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Modifies this AABB so that it contains the given AABB. If the given AABB is already contained by this AABB,
|
|||
/// then this AABB doesn't change.
|
|||
/// </remarks>
|
|||
/// <seealso cref="Contains(Unity.Mathematics.Geometry.SynthDetMinMaxAABB)"/>
|
|||
/// <param name="aabb">AABB to encapsulate.</param>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public void Encapsulate(SynthDetMinMaxAABB aabb) |
|||
{ |
|||
Min = math.min(Min, aabb.Min); |
|||
Max = math.max(Max, aabb.Max); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Encapsulate the given point.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Modifies this AABB so that it contains the given point. If the given point is already contained by this AABB,
|
|||
/// then this AABB doesn't change.
|
|||
/// </remarks>
|
|||
/// <seealso cref="Contains(Unity.Mathematics.float3)"/>
|
|||
/// <param name="point">Point to encapsulate.</param>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public void Encapsulate(float3 point) |
|||
{ |
|||
Min = math.min(Min, point); |
|||
Max = math.max(Max, point); |
|||
} |
|||
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public bool Equals(SynthDetMinMaxAABB other) |
|||
{ |
|||
return Min.Equals(other.Min) && Max.Equals(other.Max); |
|||
} |
|||
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public override string ToString() |
|||
{ |
|||
return string.Format("SynthDetMinMaxAABB({0}, {1})", Min, Max); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Transforms the AABB with the given transform.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// The resulting AABB encapsulates the transformed AABB which may not be axis aligned after the transformation.
|
|||
/// </remarks>
|
|||
/// <param name="transform">Transform to apply to AABB.</param>
|
|||
/// <param name="aabb">AABB to be transformed.</param>
|
|||
/// <returns>Transformed AABB.</returns>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public static SynthDetMinMaxAABB Transform(RigidTransform transform, SynthDetMinMaxAABB aabb) |
|||
{ |
|||
float3 halfExtentsInA = aabb.HalfExtents; |
|||
|
|||
// Rotate each axis individually and find their new positions in the rotated space.
|
|||
float3 x = math.rotate(transform.rot, new float3(halfExtentsInA.x, 0, 0)); |
|||
float3 y = math.rotate(transform.rot, new float3(0, halfExtentsInA.y, 0)); |
|||
float3 z = math.rotate(transform.rot, new float3(0, 0, halfExtentsInA.z)); |
|||
|
|||
// Find the new max corner by summing the rotated axes. Absolute value of each axis
|
|||
// since we are trying to find the max corner.
|
|||
float3 halfExtentsInB = math.abs(x) + math.abs(y) + math.abs(z); |
|||
float3 centerInB = math.transform(transform, aabb.Center); |
|||
|
|||
return new SynthDetMinMaxAABB(centerInB - halfExtentsInB, centerInB + halfExtentsInB); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Transforms the AABB with the given transform.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// The resulting AABB encapsulates the transformed AABB which may not be axis aligned after the transformation.
|
|||
/// </remarks>
|
|||
/// <param name="transform">Transform to apply to AABB.</param>
|
|||
/// <param name="aabb">AABB to be transformed.</param>
|
|||
/// <returns>Transformed AABB.</returns>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public static SynthDetMinMaxAABB Transform(float4x4 transform, SynthDetMinMaxAABB aabb) |
|||
{ |
|||
var transformed = Transform(new float3x3(transform), aabb); |
|||
transformed.Min += transform.c3.xyz; |
|||
transformed.Max += transform.c3.xyz; |
|||
return transformed; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Transforms the AABB with the given transform.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// The resulting AABB encapsulates the transformed AABB which may not be axis aligned after the transformation.
|
|||
/// </remarks>
|
|||
/// <param name="transform">Transform to apply to AABB.</param>
|
|||
/// <param name="aabb">AABB to be transformed.</param>
|
|||
/// <returns>Transformed AABB.</returns>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public static SynthDetMinMaxAABB Transform(float3x3 transform, SynthDetMinMaxAABB aabb) |
|||
{ |
|||
// From Christer Ericson's Real-Time Collision Detection on page 86 and 87.
|
|||
// We want the transformed minimum and maximums of the AABB. Multiplying a 3x3 matrix on the left of a
|
|||
// column vector looks like so:
|
|||
//
|
|||
// [ c0.x c1.x c2.x ] [ x ] [ c0.x * x + c1.x * y + c2.x * z ]
|
|||
// [ c0.y c1.y c2.y ] [ y ] = [ c0.y * x + c1.y * y + c2.y * z ]
|
|||
// [ c0.z c1.z c2.z ] [ z ] [ c0.z * x + c1.z * y + c2.z * z ]
|
|||
//
|
|||
// The column vectors we will use are the input AABB's min and max. Simply multiplying those two vectors
|
|||
// with the transformation matrix won't guarantee we get the new min and max since those are only two
|
|||
// points out of eight in the AABB and one of the other six may set the new min or max.
|
|||
//
|
|||
// To ensure we get the correct min and max, we must transform all eight points. But it's not necessary
|
|||
// to actually perform eight matrix multiplies to get our final result. Instead, we can build the min and
|
|||
// max incrementally by computing each term in the above matrix multiply separately then summing the min
|
|||
// (or max). For instance, to find the new minimum contributed by the original min and max x component, we
|
|||
// compute this:
|
|||
//
|
|||
// newMin.x = min(c0.x * Min.x, c0.x * Max.x);
|
|||
// newMin.y = min(c0.y * Min.x, c0.y * Max.x);
|
|||
// newMin.z = min(c0.z * Min.x, c0.z * Max.x);
|
|||
//
|
|||
// Then we add minimum contributed by the original min and max y components:
|
|||
//
|
|||
// newMin.x += min(c1.x * Min.y, c1.x * Max.y);
|
|||
// newMin.y += min(c1.y * Min.y, c1.y * Max.y);
|
|||
// newMin.z += min(c1.z * Min.y, c1.z * Max.y);
|
|||
//
|
|||
// And so on. Translation can be handled by simply initializing the new min and max with the translation
|
|||
// amount since it does not affect the min and max bounds in local space.
|
|||
var t1 = transform.c0.xyz * aabb.Min.xxx; |
|||
var t2 = transform.c0.xyz * aabb.Max.xxx; |
|||
var minMask = t1 < t2; |
|||
var transformed = new SynthDetMinMaxAABB(math.select(t2, t1, minMask), math.select(t2, t1, !minMask)); |
|||
t1 = transform.c1.xyz * aabb.Min.yyy; |
|||
t2 = transform.c1.xyz * aabb.Max.yyy; |
|||
minMask = t1 < t2; |
|||
transformed.Min += math.select(t2, t1, minMask); |
|||
transformed.Max += math.select(t2, t1, !minMask); |
|||
t1 = transform.c2.xyz * aabb.Min.zzz; |
|||
t2 = transform.c2.xyz * aabb.Max.zzz; |
|||
minMask = t1 < t2; |
|||
transformed.Min += math.select(t2, t1, minMask); |
|||
transformed.Max += math.select(t2, t1, !minMask); |
|||
return transformed; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 876ee9db09f834e87aebbb3628aa9934 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue