Esempio n. 1
0
        public static bool Generate(BuildRMesh mesh, BuildRCollider collider, Vector2[] points, int[] facadeIndices, float roofBaseHeight, IVolume volume)
        {
            if (points.Length == 0)
            {
                return(false);
            }

            if (BuildrUtils.SelfIntersectingPoly(points))
            {
                return(false);
            }

            Roof  design     = volume.roof;
            float floorWidth = design.floorDepth;
            float roofDepth  = design.depth;
            float roofHeight = design.height;

            Surface mainSurface  = design.mainSurface;
            Surface floorSurface = design.floorSurface;
            int     mainSubmesh  = mesh.submeshLibrary.SubmeshAdd(mainSurface);
            int     floorSubmesh = mesh.submeshLibrary.SubmeshAdd(floorSurface);

            //mansard floor
            if (floorWidth > 0)
            {
                OffsetSkeleton offsetFloorPoly = new OffsetSkeleton(points, null, floorWidth);
                offsetFloorPoly.direction = 1;
                offsetFloorPoly.Execute();
                Shape floorShape = offsetFloorPoly.shape;

                if (floorShape != null)
                {
                    ToMesh(ref mesh, ref floorShape, roofBaseHeight, 0, facadeIndices, volume, floorSubmesh, design.floorSurface);

                    points = new Vector2[floorShape.terminatedNodeCount];
                    for (int i = 0; i < floorShape.terminatedNodeCount; i++)
                    {
                        points[i] = floorShape.TerminatedNode(i).position;
                    }
                }
                else
                {
                    return(false);
                    //todo
                }
            }

            if (points.Length == 0)
            {
                return(false);
            }

            //mansard pitch
            OffsetSkeleton offsetRoofPoly = new OffsetSkeleton(points, null, roofDepth);

            offsetRoofPoly.direction = 1;
            offsetRoofPoly.Execute();
            Shape roofShape = offsetRoofPoly.shape;

            if (roofShape == null)
            {
                return(false);
            }

            if (facadeIndices.Length < roofShape.baseEdges.Count)
            {
                return(false);
            }

            ToMesh(ref mesh, ref roofShape, roofBaseHeight, roofHeight, facadeIndices, volume, mainSubmesh, mainSurface, design.hasDormers);

            points = new Vector2[roofShape.terminatedNodeCount];
            for (int i = 0; i < roofShape.terminatedNodeCount; i++)
            {
                points[i] = roofShape.TerminatedNode(i).position;
            }

            //mansard top
            ToMesh(ref mesh, points, roofBaseHeight + roofHeight, facadeIndices, volume, floorSubmesh, floorSurface);

            return(true);
        }