Beispiel #1
0
        public static Heightmap Create <T>(Int2 size, HeightfieldTypes heightType, Vector2 heightRange, float heightScale, T[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            HeightmapUtils.CheckHeightParameters(size, heightType, heightRange, heightScale, true);

            var length = size.X * size.Y;

            switch (data)
            {
            case float[] floats when floats.Length == length: break;

            case short[] shorts when shorts.Length == length: break;

            case byte[] bytes when bytes.Length == length: break;

            default: throw new ArgumentException($"{ typeof(T[]) } is not supported in { heightType } height type. Or { nameof(data) }.{ nameof(data).Length } doesn't match { nameof(size) }.");
            }

            var heightmap = new Heightmap
            {
                HeightType  = heightType,
                Size        = size,
                HeightRange = heightRange,
                HeightScale = heightScale,
                Floats      = data as float[],
                Shorts      = data as short[],
                Bytes       = data as byte[],
            };

            return(heightmap);
        }
        public static bool IsValid([NotNull] this Heightmap heightmap)
        {
            if (heightmap is null)
            {
                throw new ArgumentNullException(nameof(heightmap));
            }

            var length = heightmap.Size.X * heightmap.Size.Y;

            bool hasValidHeights = false;

            switch (heightmap.HeightType)
            {
            case HeightfieldTypes.Float when heightmap.Floats != null && heightmap.Floats.Length == length:
                hasValidHeights = true;
                break;

            case HeightfieldTypes.Short when heightmap.Shorts != null && heightmap.Shorts.Length == length:
                hasValidHeights = true;
                break;

            case HeightfieldTypes.Byte when heightmap.Bytes != null && heightmap.Bytes.Length == length:
                hasValidHeights = true;
                break;
            }

            return(HeightmapUtils.CheckHeightParameters(heightmap.Size, heightmap.HeightType, heightmap.HeightRange, heightmap.HeightScale, false) &&
                   hasValidHeights);
        }
Beispiel #3
0
 public bool IsValid() => HeightmapUtils.CheckHeightParameters(HeightStickSize, HeightType, HeightRange, HeightScale, false) &&
 MathUtil.IsInRange(InitialShort, -short.MaxValue, short.MaxValue);
 public bool IsValid() => HeightmapUtils.CheckHeightParameters(HeightStickSize, HeightType, HeightRange, HeightScale, false) &&
 MathUtil.IsInRange(InitialHeight, HeightRange.X, HeightRange.Y);