Example #1
0
        public Cube(EntityModelCube cube, Vector2 textureSize, bool mirrored, float inflation)
        {
            _mirror = mirrored;

            var uv   = cube.Uv ?? new EntityModelUV();
            var size = cube.InflatedSize(inflation);

            this._textureSize = textureSize;

            //front verts with position and texture stuff
            _topLeftFront = new Vector3(0f, size.Y, 0f);
            _topLeftBack  = new Vector3(0f, size.Y, size.Z);

            _topRightFront = new Vector3(size.X, size.Y, 0f);
            _topRightBack  = new Vector3(size.X, size.Y, size.Z);

            // Calculate the position of the vertices on the bottom face.
            _btmLeftFront  = new Vector3(0f, 0f, 0f);
            _btmLeftBack   = new Vector3(0f, 0f, size.Z);
            _btmRightFront = new Vector3(size.X, 0f, 0f);
            _btmRightBack  = new Vector3(size.X, 0f, size.Z);

            Front =
                GetFrontVertex(
                    uv.South.WithSize(size.X, size.Y),
                    uv.South.Size.HasValue ? Vector2.Zero : new Vector2(cube.Size.Z, cube.Size.Z));

            Back =
                GetBackVertex(
                    uv.North.WithSize(size.X, size.Y),
                    uv.North.Size.HasValue ? Vector2.Zero : new Vector2(
                        cube.Size.Z + cube.Size.Z + cube.Size.X, cube.Size.Z));

            Left =
                GetLeftVertex(
                    uv.West.WithSize(size.Z, size.Y),
                    uv.West.Size.HasValue ? Vector2.Zero : new Vector2(0, cube.Size.Z));

            Right =
                GetRightVertex(
                    uv.East.WithSize(size.Z, size.Y),
                    uv.East.Size.HasValue ? Vector2.Zero : new Vector2(cube.Size.Z + cube.Size.X, cube.Size.Z));

            Top =
                GetTopVertex(
                    uv.Up.WithSize(size.X, size.Z), uv.Up.Size.HasValue ? Vector2.Zero : new Vector2(cube.Size.Z, 0));

            Bottom =
                GetBottomVertex(
                    uv.Down.WithSize(size.X, size.Z),
                    uv.Down.Size.HasValue ? Vector2.Zero : new Vector2(cube.Size.Z + cube.Size.X, 0));
        }
Example #2
0
            public Cube(EntityModel model, EntityModelCube cube, Vector2 textureSize, bool mirrored, float inflation)
            {
                _model  = model;
                _mirror = mirrored;
                //Mirrored = mirrored;
                var uv     = cube.Uv ?? new EntityModelUV();
                var size   = cube.InflatedSize(inflation);
                var origin = cube.InflatedOrigin(inflation);                 //, size;

                _pivot = (cube.Pivot ?? (origin + (size / 2f)));

                this._textureSize = textureSize;
                //		var xScale = (textureSize.X / model.Description.TextureWidth);
                //		var yScale = (textureSize.Y / model.Description.TextureHeight);

                //front verts with position and texture stuff
                _topLeftFront = new Vector3(origin.X, origin.Y + size.Y, origin.Z);
                _topLeftBack  = new Vector3(origin.X, origin.Y + size.Y, origin.Z + size.Z);               // * size;

                _topRightFront = new Vector3(origin.X + size.X, origin.Y + size.Y, origin.Z);              // * size;
                _topRightBack  = new Vector3(origin.X + size.X, origin.Y + size.Y, origin.Z + size.Z);     // * size;

                // Calculate the position of the vertices on the bottom face.
                _btmLeftFront  = new Vector3(origin.X, origin.Y, origin.Z);                   // * size;
                _btmLeftBack   = new Vector3(origin.X, origin.Y, origin.Z + size.Z);          //* size;
                _btmRightFront = new Vector3(origin.X + size.X, origin.Y, origin.Z);          // * size;
                _btmRightBack  = new Vector3(origin.X + size.X, origin.Y, origin.Z + size.Z); // * size;

                Front = Modify(cube, GetFrontVertex(
                                   uv.South.WithSize(size.X, size.Y),
                                   uv.South.Size.HasValue ?  Vector2.Zero : new Vector2(cube.Size.Z, cube.Size.Z)));

                Back = Modify(cube, GetBackVertex(
                                  uv.North.WithSize(size.X, size.Y),
                                  uv.North.Size.HasValue ?  Vector2.Zero : new Vector2(cube.Size.Z + cube.Size.Z + cube.Size.X, cube.Size.Z)));

                Left = Modify(cube, GetLeftVertex(
                                  uv.West.WithSize(size.Z, size.Y),
                                  uv.West.Size.HasValue ?  Vector2.Zero : new Vector2(0, cube.Size.Z)));

                Right = Modify(cube, GetRightVertex(
                                   uv.East.WithSize(size.Z, size.Y),
                                   uv.East.Size.HasValue ?  Vector2.Zero : new Vector2(cube.Size.Z + cube.Size.X, cube.Size.Z)));

                Top = Modify(cube, GetTopVertex(
                                 uv.Up.WithSize(size.X, size.Z),
                                 uv.Up.Size.HasValue ?  Vector2.Zero : new Vector2(cube.Size.Z, 0)));

                Bottom = Modify(cube, GetBottomVertex(
                                    uv.Down.WithSize(size.X, size.Z),
                                    uv.Down.Size.HasValue ? Vector2.Zero : new Vector2(cube.Size.Z + cube.Size.X, 0)));
            }