Esempio n. 1
0
        private void FixElementScale(BlockModelElement element,
                                     BlockShaderVertex[] verts,
                                     float minX, float maxX, float minY, float maxY, float minZ, float maxZ,
                                     ref float facesMinX,
                                     ref float facesMaxX,
                                     ref float facesMinY,
                                     ref float facesMaxY,
                                     ref float facesMinZ,
                                     ref float facesMaxZ)
        {
            if (element.Rotation.Axis != Axis.Undefined && element.Rotation.Rescale)
            {
                var diffX = maxX - minX;
                var diffY = maxY - minY;
                var diffZ = maxZ - minZ;

                for (var i = 0; i < verts.Length; i++)
                {
                    var v = verts[i];

                    v.Position.X = (v.Position.X - minX) / diffX;
                    v.Position.Y = (v.Position.Y - minY) / diffY;
                    v.Position.Z = (v.Position.Z - minZ) / diffZ;

                    verts[i] = v;

                    if (v.Position.X < facesMinX)
                    {
                        facesMinX = v.Position.X;
                    }
                    else if (v.Position.X > facesMaxX)
                    {
                        facesMaxX = v.Position.X;
                    }

                    if (v.Position.Y < facesMinY)
                    {
                        facesMinY = v.Position.Y;
                    }
                    else if (v.Position.Y > facesMaxY)
                    {
                        facesMaxY = v.Position.Y;
                    }

                    if (v.Position.Z < facesMinZ)
                    {
                        facesMinZ = v.Position.Z;
                    }
                    else if (v.Position.Z > facesMaxZ)
                    {
                        facesMaxZ = v.Position.Z;
                    }
                }
            }
        }
Esempio n. 2
0
        private Vector3 FixRotation(Vector3 v, BlockModelElement element, int xRot, int yRot)
        {
            if (element.Rotation.Axis != Axis.Undefined)
            {
                var r     = element.Rotation;
                var angle = (float)(r.Angle * (Math.PI / 180f));

                var origin = r.Origin;

                var c = MathF.Cos(angle);
                var s = MathF.Sin(angle);

                switch (r.Axis)
                {
                case Axis.Y:
                {
                    var x = v.X - origin.X;
                    var z = v.Z - origin.Z;

                    v.X = origin.X + (x * c - z * s);
                    v.Z = origin.Z + (z * c + x * s);
                }
                break;

                case Axis.X:
                {
                    var x = v.Z - origin.Z;
                    var z = v.Y - origin.Y;

                    v.Z = origin.Z + (x * c - z * s);
                    v.Y = origin.Y + (z * c + x * s);
                }
                break;

                case Axis.Z:
                {
                    var x = v.X - origin.X;
                    var z = v.Y - origin.Y;

                    v.X = origin.X + (x * c - z * s);
                    v.Y = origin.Y + (z * c + x * s);
                }
                break;
                }
            }

            if (xRot > 0)
            {
                var rotX = (float)(xRot * (Math.PI / 180f));
                var c    = MathF.Cos(rotX);
                var s    = MathF.Sin(rotX);
                var z    = v.Z - 8f;
                var y    = v.Y - 8f;

                v.Z = 8f + (z * c - y * s);
                v.Y = 8f + (y * c + z * s);
            }

            if (yRot > 0)
            {
                var rotX = (float)(yRot * (Math.PI / 180f));
                var c    = MathF.Cos(rotX);
                var s    = MathF.Sin(rotX);
                var z    = v.X - 8f;
                var y    = v.Z - 8f;

                v.X = 8f + (z * c - y * s);
                v.Z = 8f + (y * c + z * s);
            }

            return(v);
        }