< Summary

Class:GDX.MeshExtensions
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/MeshExtensions.cs
Covered lines:0
Uncovered lines:14
Coverable lines:14
Total lines:46
Line coverage:0% (0 of 14)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:1
Method coverage:0% (0 of 1)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CalculateVolume(...)0%6200%

File(s)

./Packages/com.dotbunny.gdx/GDX/MeshExtensions.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5#if !UNITY_DOTSRUNTIME
 6
 7using Unity.Mathematics;
 8using UnityEngine;
 9
 10namespace GDX
 11{
 12    /// <summary>
 13    ///     <see cref="UnityEngine.Mesh" /> Based Extension Methods
 14    /// </summary>
 15    /// <exception cref="UnsupportedRuntimeException">Not supported on DOTS Runtime.</exception>
 16    [VisualScriptingCompatible(2)]
 17    public static class MeshExtensions
 18    {
 19        /// <summary>
 20        ///     Determine the volume of a given mesh.
 21        /// </summary>
 22        /// <remarks>
 23        ///     Based off of https://n-e-r-v-o-u-s.com/blog/?p=4415.
 24        /// </remarks>
 25        /// <param name="targetMesh">The mesh to evaluate for its volume.</param>
 26        /// <returns>The meshes volume.</returns>
 27        public static float CalculateVolume(this Mesh targetMesh)
 028        {
 029            float volume = 0;
 030            Vector3[] vertices = targetMesh.vertices;
 031            int[] triangles = targetMesh.triangles;
 032            int triangleLength = targetMesh.triangles.Length;
 33
 034            for (int i = 0; i < triangleLength; i += 3)
 035            {
 036                float3 p1 = vertices[triangles[i + 0]];
 037                float3 p2 = vertices[triangles[i + 1]];
 038                float3 p3 = vertices[triangles[i + 2]];
 039                volume += math.dot(math.cross(p1, p2), p3);
 040            }
 41
 042            return math.abs(volume / 6.0f);
 043        }
 44    }
 45}
 46#endif // !UNITY_DOTSRUNTIME