public void BuildPanel(string name)
    {
        var   panel   = TestAllPanels.GetByID(name);
        float height  = panel.height;
        float width   = panel.width;
        var   panelGO = new GameObject(name, typeof(MeshRenderer), typeof(MeshFilter), typeof(BoxCollider), typeof(WallPanelInfo));

        panelGO.name = name;
        panelGO.tag  = "WallPanel";
        panelGO.transform.position = tm.TargetPosition;
        panelGO.transform.rotation = tm.TargetRotation;
        var panelMeshFilter   = panelGO.GetComponent <MeshFilter>();
        var panelMeshRenderer = panelGO.GetComponent <MeshRenderer>();
        var panelBoxCollider  = panelGO.GetComponent <BoxCollider>();

        panelBoxCollider.center = new Vector3(panel.width / -2.0f, panel.height / 2.0f, 0.025f);
        panelBoxCollider.size   = new Vector3(panel.width, panel.height, 0.05f);
        var info = panelGO.GetComponent <WallPanelInfo>();

        info.id     = name;
        info.width  = width;
        info.height = height;
        var up               = new Vector3(0, 1, 0);
        var right            = new Vector3(-1, 0, 0);
        var wallPanel        = new WallPanel(Vector3.zero, up, width, height, name);
        var wallPanelBuilder = new WallPanelBuilder(wallPanel);

        panelMeshFilter.mesh       = wallPanelBuilder.Build();
        panelMeshRenderer.material = panelMat;
        tm.SetNewPanelAsTarget(panelGO);
    }
Exemple #2
0
        private static (WallBoardPanel left, WallBoardPanel right) CreateOffsetPanel(WallPanel panel, double studWidth, Polygon panelPerimeter, Material wallBoard)
        {
            var leftTrans = new Transform(panel.Transform);

            leftTrans.Move(leftTrans.ZAxis * studWidth / 2);
            var panelL = new WallBoardPanel(panelPerimeter, leftTrans, wallBoard);

            var rightTrans = new Transform(panel.Transform);

            rightTrans.Move(rightTrans.ZAxis * (-studWidth / 2 - Units.InchesToMeters(0.625)));
            var panelR = new WallBoardPanel(panelPerimeter, rightTrans, wallBoard);

            return(panelL, panelR);
        }
        private static WallPanel CreateSimpleWallPanel(Line wallLine, double thickness, double height, Material mat)
        {
            var wallProfile   = new Profile(Polygon.Rectangle(Vector3.Origin, new Vector3(wallLine.Length(), height)));
            var d             = wallLine.Direction();
            var z             = d.Cross(Vector3.ZAxis);
            var wallTransform = new Transform(wallLine.Start, d, z);
            var extrude       = new Extrude(wallProfile, thickness, Vector3.ZAxis, false);
            var geomRep       = new Representation(new[] { extrude });

            var identifier = $"{Math.Round(wallLine.Length(), 2)} x {Math.Round(height, 2)}";
            var wallpanel  = new WallPanel(identifier, wallProfile, true, thickness, wallTransform, mat, geomRep, false, Guid.NewGuid(), "");

            return(wallpanel);
        }
        private static List <WallPanel> ProcessWallsByProfile(PanelsFromWallsInputs input, List <WallByProfile> allWallsByProfile, out int totalCount, out int uniqueCount, out int nonStandardCount)
        {
            var panelsOut = new List <WallPanel>();
            Dictionary <string, Color> colorMap = new Dictionary <string, Color>();

            uniqueCount      = 0;
            nonStandardCount = 0;
            var rand            = new Random();
            int uniqueIDCounter = 0;

            foreach (var wall in allWallsByProfile)
            {
                var centerline = wall.Centerline;
                var profile    = wall.Profile;
                var clVec      = centerline.Direction();
                var wallNormal = clVec.Cross(Vector3.ZAxis);
                var toWall     = new Transform(centerline.Start, clVec, wallNormal);
                var fromWall   = new Transform(toWall);

                fromWall.Invert();


                var flatProfile = fromWall.OfProfile(profile);
                var polygons = new[] { flatProfile.Perimeter }.Union(flatProfile.Voids).Select(p => Make2d(p)).ToList();
                var grid = new Grid2d(polygons);
                grid.U.DivideByFixedLength(input.PanelLength, FixedDivisionMode.RemainderAtEnd);
                foreach (var cell in grid.GetCells())
                {
                    var cellGeometry = cell.GetTrimmedCellGeometry().OfType <Polygon>();
                    var isTrimmed    = cell.IsTrimmed();
                    if (!isTrimmed)
                    {
                        var polygon = Make2d(cellGeometry.FirstOrDefault());
                        if (polygon == null)
                        {
                            continue;
                        }
                        var cellProfile = new Profile(polygon);

                        var thicknessTransform = new Transform(0, 0, -wall.Thickness / 2.0);
                        cellProfile = thicknessTransform.OfProfile(cellProfile);
                        var   extrude    = new Extrude(cellProfile, wall.Thickness, Vector3.ZAxis, false);
                        var   identifier = $"{Math.Round(cell.U.Domain.Length, 2)} x {Math.Round(cell.V.Domain.Length, 2)}";
                        Color color      = default(Color);
                        if (colorMap.ContainsKey(identifier))
                        {
                            color = colorMap[identifier];
                        }
                        else
                        {
                            color = new Color(rand.NextDouble(), rand.NextDouble(), rand.NextDouble(), 1.0);
                            colorMap.Add(identifier, color);
                        }
                        var material = input.ColorCodeByLength ? new Material(color, 0, 0, false, null, true, Guid.NewGuid(), color.ToString()) : BuiltInMaterials.Concrete;
                        var geomRep  = new Representation(new[] { extrude });
                        var panel    = new WallPanel(identifier, cellProfile, true, wall.Thickness, toWall, material, geomRep, false, Guid.NewGuid(), "");
                        panelsOut.Add(panel);
                    }
                    else
                    {
                        foreach (var polygon in cellGeometry)
                        {
                            var cellProfile        = new Profile(polygon);
                            var thicknessTransform = new Transform(0, 0, -wall.Thickness / 2.0);
                            cellProfile = thicknessTransform.OfProfile(cellProfile);
                            var extrude    = new Extrude(cellProfile, wall.Thickness, Vector3.ZAxis, false);
                            var identifier = $"C-{uniqueIDCounter++:00}";
                            var color      = new Color(rand.NextDouble(), rand.NextDouble(), rand.NextDouble(), 1.0);
                            colorMap.Add(identifier, color);
                            var material = input.ColorCodeByLength ? new Material(color, 0, 0, false, null, true, Guid.NewGuid(), color.ToString()) : BuiltInMaterials.Concrete;
                            var geomRep  = new Representation(new[] { extrude });
                            var panel    = new WallPanel(identifier, cellProfile, true, wall.Thickness, toWall, material, geomRep, false, Guid.NewGuid(), "");
                            panelsOut.Add(panel);
                        }
                    }
                }
            }

            totalCount = panelsOut.Count;

            return(panelsOut);
        }
    IEnumerator BuildWallPanels(ModulationReport report)
    {
        Dictionary <string, GameObject> wallPanelGameObjects = new Dictionary <string, GameObject>();

        foreach (KeyValuePair <string, List <PositionRotation> > cornerback in report.WallPanels)
        {
            var   panel   = TestAllPanels.GetByID(cornerback.Key);
            float height  = panel.height;
            float width   = panel.width;
            var   panelGO = new GameObject(name, typeof(MeshRenderer), typeof(MeshFilter), typeof(BoxCollider), typeof(WallPanelInfo));
            panelGO.name = cornerback.Key;
            panelGO.tag  = "WallPanel";
            var panelMeshFilter   = panelGO.GetComponent <MeshFilter>();
            var panelMeshRenderer = panelGO.GetComponent <MeshRenderer>();
            var panelBoxCollider  = panelGO.GetComponent <BoxCollider>();
            panelBoxCollider.center = new Vector3(panel.width / -2.0f, panel.height / 2.0f, 0.025f);
            panelBoxCollider.size   = new Vector3(panel.width, panel.height, 0.01f);

            var radius          = 0.03f;
            var cornerCollider1 = panelGO.AddComponent <SphereCollider>();
            var cornerCollider2 = panelGO.AddComponent <SphereCollider>();
            var cornerCollider3 = panelGO.AddComponent <SphereCollider>();
            var cornerCollider4 = panelGO.AddComponent <SphereCollider>();

            cornerCollider1.radius = radius;
            cornerCollider2.radius = radius;
            cornerCollider3.radius = radius;
            cornerCollider4.radius = radius;

            cornerCollider2.center = panel.height * panelGO.transform.up;
            cornerCollider3.center = -panel.width * panelGO.transform.right;
            cornerCollider4.center = panel.height * panelGO.transform.up + -panel.width * panelGO.transform.right;

            var info = panelGO.GetComponent <WallPanelInfo>();
            info.id     = cornerback.Key;
            info.width  = width;
            info.height = height;
            var up               = new Vector3(0, 1, 0);
            var right            = new Vector3(-1, 0, 0);
            var wallPanel        = new WallPanel(Vector3.zero, up, width, height, cornerback.Key);
            var wallPanelBuilder = new WallPanelBuilder(wallPanel);
            panelMeshFilter.mesh       = wallPanelBuilder.Build();
            panelMeshRenderer.material = wallPanelsMaterial;
            wallPanelGameObjects.Add(cornerback.Key, panelGO);
            yield return(null);
        }

        foreach (KeyValuePair <string, List <PositionRotation> > cornerback in report.WallPanels)
        {
            string     id             = cornerback.Key;
            GameObject externalCorner = wallPanelGameObjects [id];
            int        k = 0;
            foreach (PositionRotation transform in cornerback.Value)
            {
                Vector3    position = transform.Position;
                Quaternion rotation = Quaternion.Euler(transform.RotationV3);
                Instantiate(externalCorner, position, rotation);

                if (++k == 5)
                {
                    k = 0;
                    yield return(null);
                }
            }
        }
    }