예제 #1
0
        public static void CreateDefaultTriangles(MyObjectBuilder_BlockNavigationDefinition ob)
        {
            Vector3I size   = ob.Size;
            Vector3I center = ob.Center;

            int triCount = 4 * ((size.X * size.Y) + (size.X * size.Z) + (size.Y * size.Z));

            ob.Triangles = new MyObjectBuilder_BlockNavigationDefinition.Triangle[triCount];
            int i = 0;

            // Coords of the block's real center (i.e. origin) relative to blockDef.Center
            Vector3 origin = (size * 0.5f) - center - Vector3.Half;

            for (int d = 0; d < 6; ++d)
            {
                Base6Directions.Direction faceDirection = Base6Directions.EnumDirections[d];
                Base6Directions.Direction rightDir, upDir;
                Vector3 faceOrigin = origin;
                switch (faceDirection)
                {
                case Base6Directions.Direction.Right:
                    rightDir    = Base6Directions.Direction.Forward;
                    upDir       = Base6Directions.Direction.Up;
                    faceOrigin += new Vector3(0.5f, -0.5f, 0.5f) * size;
                    break;

                case Base6Directions.Direction.Left:
                    rightDir    = Base6Directions.Direction.Backward;
                    upDir       = Base6Directions.Direction.Up;
                    faceOrigin += new Vector3(-0.5f, -0.5f, -0.5f) * size;
                    break;

                case Base6Directions.Direction.Up:
                    rightDir    = Base6Directions.Direction.Right;
                    upDir       = Base6Directions.Direction.Forward;
                    faceOrigin += new Vector3(-0.5f, 0.5f, 0.5f) * size;
                    break;

                case Base6Directions.Direction.Down:
                    rightDir    = Base6Directions.Direction.Right;
                    upDir       = Base6Directions.Direction.Backward;
                    faceOrigin += new Vector3(-0.5f, -0.5f, -0.5f) * size;
                    break;

                case Base6Directions.Direction.Backward:
                    rightDir    = Base6Directions.Direction.Right;
                    upDir       = Base6Directions.Direction.Up;
                    faceOrigin += new Vector3(-0.5f, -0.5f, 0.5f) * size;
                    break;

                case Base6Directions.Direction.Forward:
                default:
                    rightDir    = Base6Directions.Direction.Left;
                    upDir       = Base6Directions.Direction.Up;
                    faceOrigin += new Vector3(0.5f, -0.5f, -0.5f) * size;
                    break;
                }

                Vector3 rightVec = Base6Directions.GetVector(rightDir);
                Vector3 upVec = Base6Directions.GetVector(upDir);

                int uMax = size.AxisValue(Base6Directions.GetAxis(upDir));
                int rMax = size.AxisValue(Base6Directions.GetAxis(rightDir));
                for (int u = 0; u < uMax; ++u)
                {
                    for (int r = 0; r < rMax; ++r)
                    {
                        var triangle = new MyObjectBuilder_BlockNavigationDefinition.Triangle();
                        triangle.Points = new SerializableVector3[3];

                        triangle.Points[0] = faceOrigin;
                        triangle.Points[1] = faceOrigin + rightVec;
                        triangle.Points[2] = faceOrigin + upVec;
                        ob.Triangles[i++]  = triangle;

                        triangle        = new MyObjectBuilder_BlockNavigationDefinition.Triangle();
                        triangle.Points = new SerializableVector3[3];

                        triangle.Points[0] = faceOrigin + rightVec;
                        triangle.Points[1] = faceOrigin + rightVec + upVec;
                        triangle.Points[2] = faceOrigin + upVec;
                        ob.Triangles[i++]  = triangle;

                        faceOrigin += rightVec;
                    }

                    faceOrigin -= rightVec * rMax;
                    faceOrigin += upVec;
                }
            }
        }
예제 #2
0
        public static void CreateDefaultTriangles(MyObjectBuilder_BlockNavigationDefinition ob)
        {
            Vector3I size   = (Vector3I)ob.Size;
            Vector3I center = (Vector3I)ob.Center;
            int      num    = 4 * (((size.X * size.Y) + (size.X * size.Z)) + (size.Y * size.Z));

            ob.Triangles = new MyObjectBuilder_BlockNavigationDefinition.Triangle[num];
            int     index  = 0;
            Vector3 vector = ((Vector3)((size * 0.5f) - center)) - Vector3.Half;
            int     num3   = 0;

            while (num3 < 6)
            {
                Base6Directions.Direction right;
                Base6Directions.Direction up;
                Base6Directions.Direction direction = Base6Directions.EnumDirections[num3];
                Vector3 vector2 = vector;
                switch (direction)
                {
                case Base6Directions.Direction.Backward:
                    right    = Base6Directions.Direction.Right;
                    up       = Base6Directions.Direction.Up;
                    vector2 += new Vector3(-0.5f, -0.5f, 0.5f) * size;
                    break;

                case Base6Directions.Direction.Left:
                    right    = Base6Directions.Direction.Backward;
                    up       = Base6Directions.Direction.Up;
                    vector2 += new Vector3(-0.5f, -0.5f, -0.5f) * size;
                    break;

                case Base6Directions.Direction.Right:
                    right    = Base6Directions.Direction.Forward;
                    up       = Base6Directions.Direction.Up;
                    vector2 += new Vector3(0.5f, -0.5f, 0.5f) * size;
                    break;

                case Base6Directions.Direction.Up:
                    right    = Base6Directions.Direction.Right;
                    up       = Base6Directions.Direction.Forward;
                    vector2 += new Vector3(-0.5f, 0.5f, 0.5f) * size;
                    break;

                case Base6Directions.Direction.Down:
                    right    = Base6Directions.Direction.Right;
                    up       = Base6Directions.Direction.Backward;
                    vector2 += new Vector3(-0.5f, -0.5f, -0.5f) * size;
                    break;

                default:
                    right    = Base6Directions.Direction.Left;
                    up       = Base6Directions.Direction.Up;
                    vector2 += new Vector3(0.5f, -0.5f, -0.5f) * size;
                    break;
                }
                Vector3 vector3 = Base6Directions.GetVector(right);
                Vector3 vector4 = Base6Directions.GetVector(up);
                int     num4    = size.AxisValue(Base6Directions.GetAxis(up));
                int     num5    = size.AxisValue(Base6Directions.GetAxis(right));
                int     num6    = 0;
                while (true)
                {
                    if (num6 >= num4)
                    {
                        num3++;
                        break;
                    }
                    int num7 = 0;
                    while (true)
                    {
                        if (num7 >= num5)
                        {
                            vector2 = (vector2 - (vector3 * num5)) + vector4;
                            num6++;
                            break;
                        }
                        MyObjectBuilder_BlockNavigationDefinition.Triangle triangle = new MyObjectBuilder_BlockNavigationDefinition.Triangle {
                            Points = new SerializableVector3[] {
                                vector2,
                                vector2 + vector3,
                                vector2 + vector4
                            }
                        };
                        index++;
                        ob.Triangles[index] = triangle;
                        triangle            = new MyObjectBuilder_BlockNavigationDefinition.Triangle {
                            Points = new SerializableVector3[3]
                        };
                        triangle.Points[0] = vector2 + vector3;
                        triangle.Points[1] = (vector2 + vector3) + vector4;
                        triangle.Points[2] = vector2 + vector4;
                        index++;
                        ob.Triangles[index] = triangle;
                        vector2            += vector3;
                        num7++;
                    }
                }
            }
        }