Example #1
0
 public RotationData(RotationData self)
 {
     RotationAxis             = self.RotationAxis;
     RotationAngle            = self.RotationAngle;
     RotationPoint            = self.RotationPoint;
     UsePositionAsCenterPoint = self.UsePositionAsCenterPoint;
 }
Example #2
0
        public virtual void GenerateSides(int startingID)
        {
            Vector3 center = new Vector3(0, 0, 0);

            for (int i = 0; i < Sides.Length; i++)
            {
                Vector3 sideCenter = new Vector3(0, 0, 0);
                for (int j = 0; j < Sides[i].Plane.Length; j++)
                {
                    sideCenter += Sides[i].Plane[j];
                }

                sideCenter /= Sides[i].Plane.Length;

                center += sideCenter;
            }
            center /= Sides.Length;

            while (Data.Rotation.Count > 0)
            {
                RotationData rotData = Data.Rotation[0];
                Data.Rotation.RemoveAt(0);
                if (rotData.UsePositionAsCenterPoint)
                {
                    center = Position;
                }
                if (rotData.RotationPoint != null)
                {
                    center = (Vector3)rotData.RotationPoint;
                }

                Rotate(rotData.RotationAxis, rotData.RotationAngle, center);
            }

            CalculateUVs();
        }
Example #3
0
        public static List <Shape> Generate(StairData data, RotationData rotationData = null)
        {
            List <Shape> shapes         = new List <Shape>();
            Vector3      posChangeDepth = new Vector3();
            Vector3      posChangeWidth = new Vector3();
            float        rotationAngle  = 0;

            switch (data.Direction)
            {
            case Direction.North:
                rotationAngle  = 90;
                posChangeDepth = new Vector3(0, -1, -1);
                posChangeWidth = new Vector3(-1, 0, -1);
                break;

            case Direction.South:
                rotationAngle  = 270;
                posChangeDepth = new Vector3(0, 1, -1);
                posChangeWidth = new Vector3(1, 0, -1);
                break;

            case Direction.West:
                rotationAngle  = 180;
                posChangeDepth = new Vector3(1, 0, -1);
                posChangeWidth = new Vector3(0, 1, -1);
                break;

            case Direction.East:
                rotationAngle  = 0;
                posChangeDepth = new Vector3(-1, 0, -1);
                posChangeWidth = new Vector3(0, -1, -1);
                break;
            }

            //Each individual step
            for (int i = 0; i < data.StairCount; i++)
            {
                int run  = i * data.Run;
                int rise = i * data.Rise;

                switch (data.Direction)
                {
                case Direction.North:
                    shapes.Add(new Cube()
                    {
                        FuncDetailID = data.FuncDetailId,
                        Position     = data.Position + new Vector3(0, run, rise + data.Rise * 0.5f),
                        Data         = new CubeShapeData()
                        {
                            Size = new Vector3(data.StairWidth, data.Run, data.Rise)
                        }
                    });
                    break;

                case Direction.South:
                    shapes.Add(new Cube()
                    {
                        FuncDetailID = data.FuncDetailId,
                        Position     = data.Position + new Vector3(0, -run, rise + data.Rise * 0.5f),
                        Data         = new CubeShapeData()
                        {
                            Size = new Vector3(data.StairWidth, data.Run, data.Rise)
                        }
                    });
                    break;

                case Direction.West:
                    shapes.Add(new Cube()
                    {
                        FuncDetailID = data.FuncDetailId,
                        Position     = data.Position + new Vector3(-run, 0, rise + data.Rise * 0.5f),
                        Data         = new CubeShapeData()
                        {
                            Size = new Vector3(data.Run, data.StairWidth, data.Rise)
                        }
                    });
                    break;

                case Direction.East:
                    shapes.Add(new Cube()
                    {
                        FuncDetailID = data.FuncDetailId,
                        Position     = data.Position + new Vector3(run, 0, rise + data.Rise * 0.5f),
                        Data         = new CubeShapeData()
                        {
                            Size = new Vector3(data.Run, data.StairWidth, data.Rise)
                        }
                    });
                    break;
                }
            }

            Cube lastStair  = (Cube)shapes[shapes.Count - 1];
            Cube frontPiece = new Cube(lastStair);

            frontPiece.Position.Z = Lerp(shapes[0].Position.Z, lastStair.Position.Z, 0.5f) - data.Rise * 0.5f;
            ((CubeShapeData)frontPiece.Data).Size.Z = data.Rise * (data.StairCount - 1);

            shapes.Add(frontPiece);

            Vector3 perfectlyCenteredPosition = new Vector3(posChangeDepth.X * (data.Run * 1.5f), posChangeDepth.Y * (data.Run * 1.5f), (posChangeDepth.Z * (data.Rise * 0.5f)) + data.Rise * 0.5f);

            //Clip Brush
            shapes.Add(new Polygon()
            {
                FuncDetailID = data.FuncDetailId,
                Texture      = Textures.CLIP,
                Position     = data.Position + perfectlyCenteredPosition,
                Data         = new PolygonShapeData()
                {
                    Rotation = new List <RotationData>()
                    {
                        new RotationData()
                        {
                            RotationAxis             = new Vector3(1, 0, 0),
                            RotationAngle            = 90,
                            UsePositionAsCenterPoint = true,
                        },
                        new RotationData()
                        {
                            RotationAxis             = new Vector3(0, 0, 1),
                            RotationAngle            = rotationAngle,
                            UsePositionAsCenterPoint = true
                        }
                    },
                    Depth         = data.StairWidth,
                    Scalar        = 1,
                    PolygonPoints = new List <Vector2>()
                    {
                        new Vector2(0, 0),
                        new Vector2(data.Run * data.StairCount, 0),
                        new Vector2(data.Run * data.StairCount, data.Rise * data.StairCount)
                    }
                }
            });

            if (data.RailingThickness != 0)
            {
                //Railing Left
                shapes.Add(new Polygon()
                {
                    FuncDetailID = data.FuncDetailId,
                    Texture      = Textures.DEV_MEASUREGENERIC01B,
                    Position     = data.Position + perfectlyCenteredPosition + posChangeWidth * new Vector3(data.StairWidth * 0.5f + data.RailingThickness * 0.5f, data.StairWidth * 0.5f + data.RailingThickness * 0.5f, 0),
                    Data         = new PolygonShapeData()
                    {
                        Rotation = new List <RotationData>()
                        {
                            new RotationData()
                            {
                                RotationAxis             = new Vector3(1, 0, 0),
                                RotationAngle            = 90,
                                UsePositionAsCenterPoint = true,
                            },
                            new RotationData()
                            {
                                RotationAxis             = new Vector3(0, 0, 1),
                                RotationAngle            = rotationAngle,
                                UsePositionAsCenterPoint = true
                            }
                        },
                        Depth         = data.RailingThickness,
                        Scalar        = 1,
                        PolygonPoints = new List <Vector2>()
                        {
                            new Vector2(0, 0),
                            new Vector2(data.Run * data.StairCount + data.Run, 0),
                            new Vector2(data.Run * data.StairCount + data.Run, data.Rise * data.StairCount),
                            new Vector2(data.Run * data.StairCount, data.Rise * data.StairCount),
                        }
                    }
                });

                //Railing Right
                shapes.Add(new Polygon()
                {
                    FuncDetailID = data.FuncDetailId,
                    Texture      = Textures.DEV_MEASUREGENERIC01B,
                    Position     = data.Position + perfectlyCenteredPosition + posChangeWidth * new Vector3(-data.StairWidth * 0.5f - data.RailingThickness * 0.5f, -data.StairWidth * 0.5f - data.RailingThickness * 0.5f, 0),
                    Data         = new PolygonShapeData()
                    {
                        Rotation = new List <RotationData>()
                        {
                            new RotationData()
                            {
                                RotationAxis             = new Vector3(1, 0, 0),
                                RotationAngle            = 90,
                                UsePositionAsCenterPoint = true,
                            },
                            new RotationData()
                            {
                                RotationAxis             = new Vector3(0, 0, 1),
                                RotationAngle            = rotationAngle,
                                UsePositionAsCenterPoint = true
                            }
                        },
                        Depth         = data.RailingThickness,
                        Scalar        = 1,
                        PolygonPoints = new List <Vector2>()
                        {
                            new Vector2(0, 0),
                            new Vector2(data.Run * data.StairCount + data.Run, 0),
                            new Vector2(data.Run * data.StairCount + data.Run, data.Rise * data.StairCount),
                            new Vector2(data.Run * data.StairCount, data.Rise * data.StairCount),
                        }
                    }
                });
            }

            rotationData.RotationPoint = data.Position;

            if (rotationData != null)
            {
                for (int i = 0; i < shapes.Count; i++)
                {
                    shapes[i].Data.Rotation.Add(rotationData);
                }
            }

            for (int i = 0; i < shapes.Count; i++)
            {
                shapes[i].Visgroup = data.Visgroup;
            }


            return(shapes);
        }