Esempio n. 1
0
        public static Mesh Triangulate(
            List <Vector2> sourceVertices,
            List <List <Vector2> > holes,
            UnfoldedCurve unfoldedCurve,
            string name = null)
        {
            List <int>     trianles;
            List <Vector3> vertices;

            MeshGenerator.Triangulate(
                sourceVertices,
                holes,
                false,
                out vertices,
                out trianles);

            for (int count = vertices.Count, i = 0; i < count; i++)
            {
                var vertex = vertices[i];
                var point  = unfoldedCurve.Unfold(new SystemVector2(vertex.x, vertex.y));
                vertices[i] = new Vector3(point.X, vertex.z, point.Y);
            }

            return(MeshGenerator.CreateMesh(vertices.ToArray(), trianles.ToArray(), false, name));
        }
        private static OpeningPoint3D GetHole3DPoint(UnfoldedCurve curve, OpeningPoint2D point2D)
        {
            var unwrapped = curve.Unfold(new Vector2(point2D.Position.x, 0f));
            var result    = new Vector3(unwrapped.X, point2D.Position.y, unwrapped.Y);

            return(new OpeningPoint3D(
                       result,
                       new Vector3(point2D.Normal.x, 0f, point2D.Normal.y)));
        }
        private static OpeningPoint2D ProjectOpeningPoint(
            Vector2 openingPoint,
            WallData wall,
            UnfoldedCurve unfoldedWall,
            UnfoldedCurve unfoldedWallSide,
            Func <WallPointNormals, Vector2> normalGetter)
        {
/*            Debug.Log (
 *              $"unwrappedWall {string.Join (",", Array.ConvertAll (unwrappedWall.UnwrappedPoints, x => x.ToString ()))}");
 *
 *          Debug.Log (
 *              $"unwrappedWallSide {string.Join (",", Array.ConvertAll (unwrappedWallSide.UnwrappedPoints, x => x.ToString ()))}");*/

            var wallPoints = wall.Points;

            for (int i = 1; i < wallPoints.Length; i++)
            {
                if (openingPoint.x > unfoldedWall.UnfoldedPoints[i].X)
                {
                    continue;
                }

                var normals       = wall.Normals.Value;
                var normal        = normalGetter(normals[i]);
                var prevNormal    = normalGetter(normals[i - 1]);
                var averageNormal = normal + prevNormal;
                var unwrapped     = unfoldedWall
                                    .Unfold(new Vector2(openingPoint.x, 0f))
                                    .ToUnityVector2();

//                var unwrappedDebug = new Vector3 (unwrapped.x, openingPoint.y, unwrapped.y);

                var unwrappedOnSide = unwrapped.TransposePoint(averageNormal, wall.Width / 2f);
                var wrappedOnSide   = unfoldedWallSide.Fold(unwrappedOnSide);
                var result          = new Vector2(wrappedOnSide.x, openingPoint.y);

//                var unwrappedOnSideDebug = new Vector3 (unwrappedOnSide.x, openingPoint.y, unwrappedOnSide.y);

//                Debug.DrawLine(unwrappedDebug, unwrappedOnSideDebug, color, float.MaxValue);
//                Debug.DrawLine(unwrappedDebug, unwrappedOnSideDebug + new Vector3(normal.x, 0f, normal.y), Color.yellow, float.MaxValue);

/*
 *              Debug.Log (
 *                  $"openingPoint {openingPoint} unwrapped {unwrapped} unwrappedOnSide {unwrappedOnSide} wrappedOnSide {wrappedOnSide} result {result}");
 */

                return(new OpeningPoint2D(result, -averageNormal));
            }

            throw new NotImplementedException();
        }