Example #1
0
        public void LoftGenerateProperNormals()
        {
            var  tube     = BuildTube(10.0f, 1.0f);
            Mesh loftMesh = tube.GenerateMesh(10, 16);

            for (int tri = 0; tri < loftMesh.triangles.Length; tri += 3)
            {
                var v1 = loftMesh.vertices[loftMesh.triangles[tri]];
                var v2 = loftMesh.vertices[loftMesh.triangles[tri + 1]];
                var v3 = loftMesh.vertices[loftMesh.triangles[tri + 2]];
                v1.y = 0.0f;
                v2.y = 0.0f;
                v3.y = 0.0f;

                var n1 = loftMesh.normals[loftMesh.triangles[tri]];
                var n2 = loftMesh.normals[loftMesh.triangles[tri + 1]];
                var n3 = loftMesh.normals[loftMesh.triangles[tri + 2]];

                UAssert.Near(v1.normalized, n1, 0.15f);
                UAssert.Near(v2.normalized, n2, 0.15f);
                UAssert.Near(v3.normalized, n3, 0.15f);
            }

            Mesh.DestroyImmediate(loftMesh);
        }
Example #2
0
        public void LoftAlignsShapeToPathDirection()
        {
            var  torus        = BuildTorus(1.0f, 0.25f);
            var  shapeSamples = 16u;
            var  pathSamples  = 16u;
            Mesh loftMesh     = torus.GenerateMesh(pathSamples, shapeSamples);

            for (int p = 0; p < pathSamples; ++p)
            {
                var pathT   = (float)p / (float)pathSamples;
                var pathDir = torus.Path.ForwardSample(pathT);
                var pathPos = torus.Path.PositionSample(pathT);
                for (int s = 0; s < shapeSamples - 1; ++s)
                {
                    var vertIdx          = (pathSamples * p) + s;
                    var vert             = loftMesh.vertices[vertIdx];
                    var nextVertIdx      = vertIdx + 1;
                    var nextVert         = loftMesh.vertices[nextVertIdx];
                    var vertsCrossCenter = Vector3.Cross(vert - pathPos, nextVert - pathPos);

                    UAssert.Near(pathDir, vertsCrossCenter.normalized, 0.05f);
                }
            }
            Mesh.DestroyImmediate(loftMesh);
        }
Example #3
0
        public void BeziersSampleThroughControlPoints()
        {
            var cpTStep  = 1.0f / (float)(_simpleArc.ControlPoints.Count() - 1);
            var currentT = 0.0f;

            // Sample at each control point
            foreach (var cp in _simpleArc.ControlPoints)
            {
                UAssert.Near(_simpleArc.PositionSample(currentT), cp.Point, 0.0001f);
                currentT += cpTStep;
            }
        }
Example #4
0
        public void ForwardSampleVerificationOnAStraightLine()
        {
            var points = new Vector3[] {
                new Vector3(-300.0f, 100.0f, 37.5f),
                new Vector3(1.2134f, -35.0f, 175.0f)
            };

            var bezier        = Bezier.ConstructSmoothSpline(points);
            var pntsDirection = (points[1] - points[0]).normalized;

            for (float t = 0.0f; t < 1.0f; t += 0.05f)
            {
                UAssert.Near(Vector3.Dot(bezier.ForwardSample(t), pntsDirection), 1.0f, 0.001f);
            }
        }
Example #5
0
        public void ConstructSmoothStraightLineSpline()
        {
            var points = new Vector3[] {
                new Vector3(-300.0f, 0.0f, 237.0f),
                new Vector3(1.0f, 25.0f, -187.0f)
            };

            var bezier = Bezier.ConstructSmoothSpline(points);

            // Check that all points are linear on the x axis
            for (float t = 0.0f; t < 1.0f; t += 0.05f)
            {
                UAssert.NearLineSegment(points[0], points[1], bezier.PositionSample(t), 0.001f);
            }
        }
Example #6
0
        public void ForwardDoesntFlipOnClosedSplines()
        {
            var points = new Vector3[] {
                new Vector3(10.0f, 0.0f, 0.0f),
                new Vector3(0.0f, 10.0f, 0.0f),
                new Vector3(-10.0f, 0.0f, 0.0f),
                new Vector3(0.0f, -10.0f, 0.0f),
            };

            var bezier = Bezier.ConstructSmoothSpline(points, true);

            var dir1 = bezier.ForwardSample(0.0f);
            var dir2 = bezier.ForwardSample(1.0f);

            UAssert.Near(dir1, dir2, 0.0001f);
        }
Example #7
0
        public void ContinuousLoftsDontBreakNormalsAtLoop()
        {
            var  torus      = BuildTorus(10.0f, 1.0f);
            var  shapeSteps = 10u;
            var  pathSteps  = 16u;
            Mesh loftMesh   = torus.GenerateMesh(shapeSteps, pathSteps);

            for (var s = 0u; s < shapeSteps; ++s)
            {
                var norm1 = loftMesh.normals[s];
                var norm2 = loftMesh.normals[(shapeSteps * pathSteps) + s];

                UAssert.Near(norm1, norm2, 0.001f);
            }

            Mesh.DestroyImmediate(loftMesh);
        }
Example #8
0
        public void ForwardSampleVerificationOnACircle()
        {
            var points = new Vector3[] {
                new Vector3(1.0f, 0.0f, 0.0f),
                new Vector3(0.0f, 1.0f, 0.0f),
                new Vector3(-1.0f, 0.0f, 0.0f),
                new Vector3(0.0f, -1.0f, 0.0f),
            };

            var bezier = Bezier.ConstructSmoothSpline(points);

            for (float t = 0.0f; t < 1.0f; t += 0.05f)
            {
                var expectedAngle = Mathf.Cos(t);
                UAssert.Near(Vector3.Dot(bezier.ForwardSample(t), Vector3.up), expectedAngle, 0.1f);
            }
        }
Example #9
0
        public void LoftsGenerateUVs()
        {
            var  torus        = BuildTorus(10.0f, 1.0f);
            var  shapeSamples = 10u;
            var  pathSamples  = 5u;
            Mesh loftMesh     = torus.GenerateMesh(shapeSamples, pathSamples);

            var maxDist = Mathf.Sqrt(2.001f);

            for (int p = 0; p < pathSamples; ++p)
            {
                for (int s = 0; s < shapeSamples - 1; ++s)
                {
                    var uv = loftMesh.uv[(pathSamples * p) + s];
                    UAssert.Near(Vector2.zero, uv, maxDist);
                }
            }

            Mesh.DestroyImmediate(loftMesh);
        }
Example #10
0
        public void LoftMeshGenerationVerification()
        {
            var tube = BuildTube(10.0f, 1.0f);

            Mesh loftMesh = tube.GenerateMesh(10, 16);

            // Vert and Tri counts are expected values
            Assert.AreEqual(17 * 11, loftMesh.vertexCount);
            Assert.AreEqual(16 * 10 * 2, loftMesh.triangles.Length / 3);

            for (int tri = 0; tri < loftMesh.triangles.Length; tri += 3)
            {
                // All triangles' face normals point away from the shape
                var center = loftMesh.FaceCenter(tri);
                var normal = loftMesh.FaceNorm(tri);
                center.y = 0.0f;
                UAssert.Near(Vector3.Dot(-center.normalized, normal), 1.0f, 0.01f);
            }

            Mesh.DestroyImmediate(loftMesh);
        }
Example #11
0
        public void ConstructSmoothSplineVerification()
        {
            var points = new Vector3[] {
                new Vector3(0.0f, 0.0f, 0.0f),
                new Vector3(1.0f, 0.0f, 0.0f),
                new Vector3(0.0f, 1.0f, 0.0f),
                new Vector3(0.0f, 0.0f, 1.0f),
                new Vector3(1.0f, 1.0f, 0.0f),
                new Vector3(0.0f, 1.0f, 1.0f),
                new Vector3(1.0f, 0.0f, 1.0f),
                new Vector3(1.0f, 1.0f, 1.0f)
            };

            var bezier = Bezier.ConstructSmoothSpline(points);

            // Check that the end points are sane
            UAssert.Near(bezier.PositionSample(0.0f), points[0], 0.0001f);
            UAssert.Near(bezier.PositionSample(1.0f), points[points.Length - 1], 0.0001f);

            // Check that there are no crazy values
            Vector3 pointCenter = MathExt.Average(points);

            for (float t = 0.0f; t < 1.0f; t += 0.01f)
            {
                UAssert.Near(bezier.PositionSample(t), pointCenter, 1.0f);
            }

            // Check that all the spline tangents are locked
            var controlPoints = new List <Bezier.ControlPoint>(bezier.ControlPoints);

            for (int i = 1; i < controlPoints.Count - 1; ++i)
            {
                var controlPoint   = controlPoints[i];
                var relativeInTan  = controlPoint.InTangent - controlPoint.Point;
                var relativeOutTan = controlPoint.OutTangent - controlPoint.Point;

                UAssert.Near(relativeInTan, relativeOutTan * -1.0f, 0.0001f);
            }
        }
Example #12
0
 public void FaceCenterVerification()
 {
     UAssert.Near(new Vector3(2.0f / 3.0f, 0.0f, 1.0f / 3.0f), _mesh.FaceCenter(0), 0.001f);
 }
Example #13
0
 public void FaceNormVerification()
 {
     UAssert.Near(Vector3.up, _mesh.FaceNorm(0), 0.001f);
 }