Ejemplo n.º 1
0
        private static void DrawFloorplans(IBuilding _building, IVolume mouseOverPlan)
        {
            int        numberOfFloorplans = _building.numberOfPlans;
            Vector3    position           = _building.transform.position;
            Quaternion rotation           = _building.transform.rotation;

            Camera sceneCamera = Camera.current;

            Vector3[] centerPoints = new Vector3[numberOfFloorplans];
            for (int f = 0; f < numberOfFloorplans; f++)
            {
                centerPoints[f] = BuildrUtils.CalculateFloorplanCenter(_building[f]);
            }
            //            Ray ray = sceneCamera.ScreenPointToRay(new Vector3(Event.current.mousePosition.x, Screen.height - Event.current.mousePosition.y - 30, 0));
            //            Floorplan mouseOverPlan = BuildrUtils.OnFloorplanSelectionClick(_building, ray);

            //Draw Floorplan outlines
            for (int f = 0; f < numberOfFloorplans; f++)
            {
                IVolume volume         = _building[f];
                int     numberOfPoints = volume.numberOfPoints;
                Vector2 leftPoint      = Vector2.right;
                Vector3 labelPoint     = volume.BuildingPoint(0) + position;

                int numberOfTopPoints = 0;
                for (int p = 0; p < numberOfPoints; p++)
                {
                    if (volume.IsWallStraight(p))
                    {
                        numberOfTopPoints++;
                    }
                    else
                    {
                        numberOfTopPoints += 9;
                    }
                }
                Vector3[] planVs     = new Vector3[numberOfTopPoints];
                int       planVIndex = 0;
                Vector3   planUp     = Vector3.up * volume.planHeight;

                for (int p = 0; p < numberOfPoints; p++)
                {
                    Vector3 p0   = volume.WorldPoint(p) + planUp;//rotation * floorplan.BuildingPoint(p) + position);
                    Vector2 p0ss = sceneCamera.WorldToScreenPoint(p0);
                    if (p0ss.x < leftPoint.x)
                    {
                        leftPoint  = p0ss;
                        labelPoint = p0;
                    }
                    //Render handles
                    if (volume.IsWallStraight(p))
                    {
                        planVs[planVIndex] = p0;
                        planVIndex++;
                    }
                    else
                    {
                        Vector3   p1        = volume.WorldPoint((p + 1) % numberOfPoints) + planUp; //rotation * floorplan.BuildingPoint((p + 1) % numberOfPoints) + position);
                        Vector3   cw0       = volume.WorldControlPointA(p) + planUp;                //rotation * floorplan.BuildingControlPoint(p) + position);
                        Vector3   cw1       = volume.WorldControlPointB(p) + planUp;                //rotation * floorplan.BuildingControlPoint(p) + position);
                        Vector3[] curveWall = new Vector3[10];
                        for (int t = 0; t < 10; t++)
                        {
                            Vector3 cp = FacadeSpline.Calculate(p0, cw0, cw1, p1, t / 9f);
                            curveWall[t] = cp;
                            if (t < 9)
                            {
                                planVs[planVIndex] = cp;
                                planVIndex++;
                            }
                        }
                    }
                }

                if ((Volume)volume == BuildingEditor.volume)
                {
                    Handles.color = SELECTED_BLUEPRINT_COLOUR;
                }
                else if (mouseOverPlan == volume)
                {
                    Handles.color = HIGHLIGHTED_BLUEPRINT_COLOUR;
                }
                else
                {
                    Handles.color = UNSELECTED_BLUEPRINT_COLOUR;
                }

                //                Handles.DrawAAConvexPolygon(planVs);//draw plan outline
                DrawConcavePolygonHandle.Shape(planVs, Handles.color);
//                Vector2 textDimensions = GUI.skin.label.CalcSize(new GUIContent(volume.name));
                Handles.Label(labelPoint, volume.name);

                int     linkCount  = volume.linkPlanCount;
                Vector3 thisCenter = centerPoints[f];
                Handles.color = Color.green;
                for (int l = 0; l < linkCount; l++)
                {
                    if (f == l)
                    {
                        continue;
                    }
//                    Volume link = volume.linkedPlans[l];
                    Vector3 linkCenter = centerPoints[l];
                    Handles.DrawDottedLine(thisCenter, linkCenter, 5);
                }

                int     numberOfFloors  = volume.floors;
                float   planHeight      = volume.floorHeight;
                float   totalPlanHeight = volume.planHeight;
                Vector3 planHeightV     = totalPlanHeight * Vector3.up;

                Handles.color = new Color(0, 0.2f, 1, 0.5f);

                for (int p = 0; p < numberOfPoints; p++)
                {
                    Vector3 p0 = rotation * volume.BuildingPoint(p) + position;
                    Vector3 p1 = rotation * volume.BuildingPoint((p + 1) % numberOfPoints) + position;

                    //Render handles
                    if (volume.IsWallStraight(p))
                    {
                        int wallSections = Mathf.FloorToInt(Vector3.Distance(p0, p1) / volume.minimumWallUnitLength);
                        if (wallSections < 1)
                        {
                            wallSections = 1;
                        }
                        for (int ws = 0; ws < wallSections + 1; ws++)
                        {
                            float   lerp    = ws / ((float)wallSections);
                            Vector3 basePos = Vector3.Lerp(p0, p1, lerp);
                            Handles.DrawLine(basePos, basePos + planHeightV);
                        }

                        for (int fl = 0; fl < numberOfFloors + 1; fl++)
                        {
                            Handles.color = fl == 0 || fl == numberOfFloors ? MAIN_LINE_COLOUR : SUB_LINE_COLOUR;
                            float   lineHeight  = fl * planHeight;
                            Vector3 lineHeightV = lineHeight * Vector3.up;
                            Handles.DrawLine(p0 + lineHeightV, p1 + lineHeightV);
                        }
                    }
                    else
                    {
                        Vector3   cw0       = volume.WorldControlPointA(p);
                        Vector3   cw1       = volume.WorldControlPointB(p);
                        Vector3[] curveWall = new Vector3[10];
                        float     arcLength = 0;
                        for (int t = 0; t < 10; t++)
                        {
                            Vector3 cp = FacadeSpline.Calculate(p0, cw0, cw1, p1, t / 9f);
                            curveWall[t] = cp;
                            if (t > 0)
                            {
                                arcLength += Vector3.Distance(curveWall[t - 1], curveWall[t]);
                            }
                        }

                        for (int fl = 0; fl < numberOfFloors + 1; fl++)
                        {
                            Handles.color = fl == 0 || fl == numberOfFloors ? MAIN_LINE_COLOUR : SUB_LINE_COLOUR;
                            float   lineHeight  = fl * planHeight;
                            Vector3 lineHeightV = lineHeight * Vector3.up;

                            for (int t = 0; t < 9; t++)
                            {
                                Vector3 cwp0 = curveWall[t];
                                Vector3 cwp1 = curveWall[t + 1];
                                Handles.DrawLine(cwp0 + lineHeightV, cwp1 + lineHeightV);
                            }
                            //                            Handles.DrawLine(p0 + lineHeightV, p1 + lineHeightV);
                        }
                    }

                    Handles.color = MAIN_LINE_COLOUR;
                    Handles.DrawLine(p0, p0 + Vector3.up * totalPlanHeight);

                    if ((Volume)volume == BuildingEditor.volume)
                    {
                        Vector3 facadeCenter = Vector3.Lerp(p0, p1, 0.5f) + planUp;
//                        float gtbSize = HandleUtility.GetHandleSize(facadeCenter) * 0.1f;
//                        Handles.Label(facadeCenter, "Is gabled");
//                        Handles.Button(facadeCenter, Quaternion.identity, gtbSize, gtbSize, Handles.DotCap);

                        Handles.BeginGUI();
                        Vector2 portalScreenPos = Camera.current.WorldToScreenPoint(facadeCenter);
                        portalScreenPos.y = Camera.current.pixelHeight - portalScreenPos.y;
                        Rect screenRect = new Rect(portalScreenPos, new Vector2(350, 500));
                        GUILayout.BeginArea(screenRect);

                        EditorGUILayout.LabelField(string.Format("Facade: {0}", p + 1));
                        //                        RoofFacadeInspectorGUI(volume, p);

                        GUILayout.EndArea();
                        Handles.EndGUI();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void BuildFloorplan()
        {
            LAYERS.Clear();
            SceneMeshLayer layerOpengings = new SceneMeshLayer();
            SceneMeshLayer layer0         = new SceneMeshLayer();
            SceneMeshLayer layer1         = new SceneMeshLayer();
            SceneMeshLayer layer2         = new SceneMeshLayer();

            LAYERS.Add(layerOpengings);
            LAYERS.Add(layer0);
            LAYERS.Add(layer1);
            LAYERS.Add(layer2);

            Building building = BuildingEditor.building;

            bPosition = building.transform.position;
            bRotation = building.transform.rotation;
            BuildRSettings settings        = building.settings;
            int            numberOfVolumes = building.numberOfPlans;
            Quaternion     rotation        = building.transform.rotation;

            Vector3[] centerPoints = new Vector3[numberOfVolumes];
            for (int f = 0; f < numberOfVolumes; f++)
            {
                centerPoints[f] = BuildrUtils.CalculateFloorplanCenter(building[f]);
            }
            for (int v = 0; v < numberOfVolumes; v++)
            {
                Volume  volume           = (Volume)building[v];
                bool    isSelectedVolume = BuildingEditor.volume == volume;
                int     numberOfPoints   = volume.numberOfPoints;
                Vector3 vUp = Vector3.up * volume.floorHeight;
                Dictionary <int, List <Vector2Int> > anchorPoints = volume.facadeWallAnchors;

                IFloorplan[] floorplans     = volume.InteriorFloorplans();
                int          floorplanCount = floorplans.Length;
                for (int f = 0; f < floorplanCount; f++)//floors
                {
                    IFloorplan floorplan           = floorplans[f];
                    bool       isSelectedFloorplan = BuildingEditor.floorplan == (Floorplan)floorplan;
                    float      intPlanBaseHeight   = volume.CalculateFloorHeight(f);
                    Vector3    baseUpV             = Vector3.up * intPlanBaseHeight;

                    //draw external outline of selected floor
                    if (numberOfPoints > 0 && isSelectedVolume)
                    {
                        SceneMeshLayer    useLayer = isSelectedFloorplan ? layer1 : layer0;
                        List <Vector2Int> planVs   = new List <Vector2Int>();
                        Color             fillCol  = settings.subLineColour;
                        Color             lineCol  = settings.mainLineColour;
                        for (int p = 0; p < numberOfPoints; p++)
                        {
                            if (volume.IsWallStraight(p))
                            {
                                if (!planVs.Contains(volume[p].position))
                                {
                                    planVs.Add(volume[p].position);
                                }
                                Vector3 p0 = volume[p].position.vector3XZ + baseUpV;
                                Vector3 p1 = volume[(p + 1) % numberOfPoints].position.vector3XZ + baseUpV;
                                Vector3 p2 = p0 + vUp;
                                Vector3 p3 = p1 + vUp;

                                useLayer.shapes.Add(new SceneMeshShape(fillCol, p0, p1, p3, p2));
                                useLayer.lines.Add(new SceneMeshLine(p2, p3, lineCol));
                                useLayer.lines.Add(new SceneMeshLine(p0, p2, lineCol));
                                useLayer.lines.Add(new SceneMeshLine(p1, p3, lineCol));
                                if (isSelectedFloorplan)
                                {
                                    useLayer.lines.Add(new SceneMeshLine(p0, p1, Color.red));

                                    List <Vector2Int> anchors = anchorPoints[p];
                                    int wallSections          = anchors.Count;
                                    for (int w = 0; w < wallSections - 1; w++)
                                    {
                                        Vector3 a          = anchors[w].vector3XZ + baseUpV;
                                        float   anchorSize = 0.05f;
                                        if (w == 0)
                                        {
                                            anchorSize *= 2;
                                        }
                                        useLayer.dots.Add(new SceneMeshDot(a, anchorSize, settings.anchorColour));
                                    }
                                }
                            }
                            else
                            {
                                List <Vector2Int> anchors = anchorPoints[p];
                                int wallSections          = anchors.Count;
                                for (int w = 0; w < wallSections - 2; w++)
                                {
                                    if (!planVs.Contains(anchors[w]))
                                    {
                                        planVs.Add(anchors[w]);
                                    }
                                    Vector3 p0 = anchors[w].vector3XZ + baseUpV;
                                    Vector3 p1 = anchors[w + 1].vector3XZ + baseUpV;
                                    Vector3 p2 = p0 + vUp;
                                    Vector3 p3 = p1 + vUp;

                                    useLayer.lines.Add(new SceneMeshLine(p2, p3, lineCol));
                                    if (w == 0)
                                    {
                                        useLayer.lines.Add(new SceneMeshLine(p0, p2, lineCol));
                                    }
                                    if (w == wallSections - 2)
                                    {
                                        useLayer.lines.Add(new SceneMeshLine(p1, p3, lineCol));
                                    }

                                    useLayer.shapes.Add(new SceneMeshShape(fillCol, p0, p1, p3, p2));

                                    if (isSelectedFloorplan)
                                    {
                                        useLayer.lines.Add(new SceneMeshLine(p0, p1, Color.red));

                                        float anchorSize = 0.05f;
                                        if (w == 0)
                                        {
                                            anchorSize *= 2;
                                        }
                                        if (w < wallSections - 1)
                                        {
                                            useLayer.dots.Add(new SceneMeshDot(p0, anchorSize, settings.anchorColour));
                                        }
                                    }
                                }
                            }
                        }

                        if (isSelectedFloorplan)
                        {
                            int       planVCount = planVs.Count;
                            Vector3[] planV3     = new Vector3[planVCount];
                            for (int pv = 0; pv < planVCount; pv++)
                            {
                                planV3[pv] = planVs[pv].vector3XZ + baseUpV;
                            }
                            ShapeWithLines(useLayer, planV3, Color.red, new Color(1, 1, 1, 0.9f));
                        }
                    }

                    if (isSelectedFloorplan)
                    {
                        Room[]            rooms       = floorplan.AllRooms();
                        int               roomCount   = rooms.Length;
                        List <Vector2Int> shapePoints = new List <Vector2Int>();
                        for (int r = 0; r < roomCount; r++)
                        {
                            Room room           = rooms[r];
                            bool isRoomSelected = room == BuildingEditor.room && BuildingEditor.roomPortal == null && BuildingEditor.opening == null;
                            shapePoints.Clear();

                            FloorplanUtil.RoomWall[] roomWalls = FloorplanUtil.CalculatePoints(room, volume);
                            int roomWallCount = roomWalls.Length;

                            Color wallCol     = isRoomSelected ? settings.roomWallSelectedColour : settings.roomWallColour;
                            Color floorCol    = isRoomSelected ? settings.roomWallSelectedColour : settings.roomFloorColour;
                            Color mainLineCol = isRoomSelected ? settings.selectedPointColour : settings.mainLineColour;
                            Color subLineCol  = isRoomSelected ? settings.selectedPointColour : settings.subLineColour;

                            for (int rwp = 0; rwp < roomWallCount; rwp++)
                            {
                                FloorplanUtil.RoomWall roomWall = roomWalls[rwp];
                                int offsetCount = roomWall.offsetPoints.Length;

                                Vector2Int pi0 = roomWall.baseA;
                                Vector2Int pi1 = roomWall.baseB;

                                if (pi0 == pi1)
                                {
                                    continue;            //not a wall
                                }
                                for (int op = 0; op < offsetCount - 1; op++)
                                {
                                    Vector2Int wsint0 = new Vector2Int(roomWall.offsetPoints[op]);
                                    if (!shapePoints.Contains(wsint0))
                                    {
                                        shapePoints.Add(wsint0);
                                    }
                                    Vector3 ws0 = new Vector3(roomWall.offsetPoints[op].x, 0, roomWall.offsetPoints[op].y) + baseUpV;

                                    if (isSelectedFloorplan)//draw anchor points
                                    {
                                        float anchorSize = 0.05f;
                                        if (op == 0)
                                        {
                                            anchorSize *= 2;
                                        }
                                        layer1.dots.Add(new SceneMeshDot(ws0, anchorSize * 0.05f, settings.linkedAnchorColour));
                                    }

                                    int     nextIndex = (op + 1) % offsetCount;
                                    Vector3 ws1       = new Vector3(roomWall.offsetPoints[nextIndex].x, 0, roomWall.offsetPoints[nextIndex].y) + baseUpV;
                                    Vector3 ws2       = ws0 + vUp;
                                    Vector3 ws3       = ws1 + vUp;

                                    layer1.lines.Add(new SceneMeshLine(ws0, ws1, mainLineCol));
                                    layer1.lines.Add(new SceneMeshLine(ws0, ws2, subLineCol));
                                    layer1.lines.Add(new SceneMeshLine(ws1, ws3, subLineCol));

                                    layer1.shapes.Add(new SceneMeshShape(wallCol, ws0, ws1, ws3, ws2));
                                }
                            }

                            int       shapePointsCount = shapePoints.Count;
                            Vector3[] planV3           = new Vector3[shapePointsCount];
                            for (int pv = 0; pv < shapePointsCount; pv++)
                            {
                                planV3[pv] = shapePoints[pv].vector3XZ + baseUpV;
                            }
                            ShapeWithLines(layer1, planV3, mainLineCol, floorCol, settings.highlightPerpendicularity, settings.highlightPerpendicularityColour, settings.highlightAngleColour);

                            RoomPortal[] portals     = room.GetAllPortals();
                            int          portalCount = portals.Length;
                            for (int pt = 0; pt < portalCount; pt++)
                            {
                                RoomPortal portal           = portals[pt];
                                bool       isSelected       = BuildingEditor.roomPortal == portal;
                                Color      portalLineColour = isSelectedFloorplan ? settings.mainLineColour : settings.subLineColour;
                                Color      portalFillColour = isSelected ? settings.selectedPointColour : settings.mainLineColour;
                                if (!isSelectedFloorplan)
                                {
                                    portalFillColour = Color.clear;
                                }
                                DrawPortal(layer2, rotation, intPlanBaseHeight, volume.floorHeight, room, portal, portalLineColour, portalFillColour);
                            }
                        }

                        for (int r = 0; r < roomCount; r++)
                        {
                            Room    room       = rooms[r];
                            Vector3 roomCenter = room.center.vector3XZ + baseUpV + Vector3.up * volume.floorHeight;
                            layer1.labels.Add(new SceneMeshLabel(roomCenter, string.Format("Room {0}", (r + 1))));
                        }
                    }

                    //Draw vertical openings
                    if (BuildingEditor.floorplan != null)
                    {
                        VerticalOpening[] openings = building.GetAllOpenings();
                        int openingCount           = openings.Length;
                        for (int o = 0; o < openingCount; o++)
                        {
                            VerticalOpening opening           = openings[o];
                            bool            isSelectedOpening = BuildingEditor.opening == opening;

                            Vector3 openingPosition = opening.position.vector3XZ;
                            openingPosition.y = volume.floorHeight * opening.baseFloor;
                            Vector3    openingSize     = opening.size.vector3XZ;
                            float      openingWidth    = openingSize.x;
                            float      openingHeight   = openingSize.z;
                            Quaternion openingRotation = Quaternion.Euler(0, opening.rotation, 0);
                            Vector3    p0        = openingPosition + openingRotation * new Vector3(-openingWidth, 0, -openingHeight) * 0.5f;
                            Vector3    p1        = openingPosition + openingRotation * new Vector3(openingWidth, 0, -openingHeight) * 0.5f;
                            Vector3    p2        = openingPosition + openingRotation * new Vector3(openingWidth, 0, openingHeight) * 0.5f;
                            Vector3    p3        = openingPosition + openingRotation * new Vector3(-openingWidth, 0, openingHeight) * 0.5f;
                            Vector3    openingUp = Vector3.up * volume.floorHeight * (opening.floors + 1);

                            //"Phil" Mitchels
                            Color fillCol = settings.subLineColour;
                            fillCol.a = 0.05f;
                            layerOpengings.shapes.Add(new SceneMeshShape(fillCol, p0, p1, p2, p3));
                            layerOpengings.shapes.Add(new SceneMeshShape(fillCol, p0, p1, p1 + openingUp, p0 + openingUp));
                            layerOpengings.shapes.Add(new SceneMeshShape(fillCol, p1, p2, p2 + openingUp, p1 + openingUp));
                            layerOpengings.shapes.Add(new SceneMeshShape(fillCol, p2, p3, p3 + openingUp, p2 + openingUp));
                            layerOpengings.shapes.Add(new SceneMeshShape(fillCol, p3, p0, p0 + openingUp, p3 + openingUp));

                            //lines
                            Color lineCol = settings.invertLineColour;
                            layer0.lines.Add(new SceneMeshLine(p0, p1, lineCol));
                            layer0.lines.Add(new SceneMeshLine(p1, p2, lineCol));
                            layer0.lines.Add(new SceneMeshLine(p2, p3, lineCol));
                            layer0.lines.Add(new SceneMeshLine(p3, p0, lineCol));

                            layer0.lines.Add(new SceneMeshLine(p0 + openingUp, p1 + openingUp, lineCol));
                            layer0.lines.Add(new SceneMeshLine(p1 + openingUp, p2 + openingUp, lineCol));
                            layer0.lines.Add(new SceneMeshLine(p2 + openingUp, p3 + openingUp, lineCol));
                            layer0.lines.Add(new SceneMeshLine(p3 + openingUp, p0 + openingUp, lineCol));

                            layer0.lines.Add(new SceneMeshLine(p0, p0 + openingUp, lineCol));
                            layer0.lines.Add(new SceneMeshLine(p1, p1 + openingUp, lineCol));
                            layer0.lines.Add(new SceneMeshLine(p2, p2 + openingUp, lineCol));
                            layer0.lines.Add(new SceneMeshLine(p3, p3 + openingUp, lineCol));


                            layer0.labels.Add(new SceneMeshLabel(openingPosition + openingUp, string.Format("Opening {0}", o + 1)));

                            if (volume == BuildingEditor.volume && BuildingEditor.floorplan != null)
                            {
                                Vector3 floorUpA = Vector3.up * volume.CalculateFloorHeight(volume.Floor(BuildingEditor.floorplan));
                                Vector3 floorUpB = floorUpA + Vector3.up * volume.floorHeight;

                                Color          col      = isSelectedOpening ? Color.green : Color.red;
                                SceneMeshLayer useLayer = isSelectedOpening ? layer2 : layer2;

                                useLayer.lines.Add(new SceneMeshLine(p0 + floorUpA, p1 + floorUpA, col));
                                useLayer.lines.Add(new SceneMeshLine(p1 + floorUpA, p2 + floorUpA, col));
                                useLayer.lines.Add(new SceneMeshLine(p2 + floorUpA, p3 + floorUpA, col));
                                useLayer.lines.Add(new SceneMeshLine(p3 + floorUpA, p0 + floorUpA, col));

                                useLayer.lines.Add(new SceneMeshLine(p0 + floorUpB, p1 + floorUpB, col));
                                useLayer.lines.Add(new SceneMeshLine(p1 + floorUpB, p2 + floorUpB, col));
                                useLayer.lines.Add(new SceneMeshLine(p2 + floorUpB, p3 + floorUpB, col));
                                useLayer.lines.Add(new SceneMeshLine(p3 + floorUpB, p0 + floorUpB, col));

                                useLayer.lines.Add(new SceneMeshLine(p0 + floorUpA, p0 + floorUpB, col));
                                useLayer.lines.Add(new SceneMeshLine(p1 + floorUpA, p1 + floorUpB, col));
                                useLayer.lines.Add(new SceneMeshLine(p2 + floorUpA, p2 + floorUpB, col));
                                useLayer.lines.Add(new SceneMeshLine(p3 + floorUpA, p3 + floorUpB, col));
                            }
                        }
                    }
                }
            }
        }