Exemple #1
0
        private static void PrepareHeightMap(MyHeightmapFace map, PixelBuffer imageData)
        {
            IntPtr dataPointer = imageData.DataPointer;
            int    rowStride   = imageData.RowStride;

            for (int i = 0; i < map.Resolution; i++)
            {
                Utilities.Read <ushort>(dataPointer, map.Data, map.GetRowStart(i), imageData.Width);
                dataPointer += rowStride;
            }
        }
Exemple #2
0
        public void CopyRange(Vector2I start, Vector2I end, MyHeightmapFace other, Vector2I oStart, Vector2I oEnd)
        {
            Vector2I myStep = MyCubemapHelpers.GetStep(ref start, ref end);
            Vector2I oStep  = MyCubemapHelpers.GetStep(ref oStart, ref oEnd);
            ushort   val;

            for (; start != end; start += myStep, oStart += oStep)
            {
                other.GetValue(oStart.X, oStart.Y, out val);
                SetValue(start.X, start.Y, val);
            }

            other.GetValue(oStart.X, oStart.Y, out val);
            SetValue(start.X, start.Y, val);
        }
Exemple #3
0
        public void CopyRange(Vector2I start, Vector2I end, MyHeightmapFace other, Vector2I oStart, Vector2I oEnd)
        {
            ushort   num;
            Vector2I step     = MyCubemapHelpers.GetStep(ref start, ref end);
            Vector2I vectori2 = MyCubemapHelpers.GetStep(ref oStart, ref oEnd);

            while (start != end)
            {
                other.GetValue(oStart.X, oStart.Y, out num);
                this.SetValue(start.X, start.Y, num);
                start  += step;
                oStart += vectori2;
            }
            other.GetValue(oStart.X, oStart.Y, out num);
            this.SetValue(start.X, start.Y, num);
        }
Exemple #4
0
        private static void PrepareHeightMap8Bit(MyHeightmapFace map, PixelBuffer imageData)
        {
            int y = 0;

            while (y < map.Resolution)
            {
                int x = 0;
                while (true)
                {
                    if (x >= map.Resolution)
                    {
                        y++;
                        break;
                    }
                    map.SetValue(x, y, (ushort)(imageData.GetPixel <byte>(x, y) * 0x100));
                    x++;
                }
            }
        }
Exemple #5
0
        public MyHeightCubemap GetHeightMap(string folderName, MyModContext context)
        {
            string modId = context.ModId;
            string name  = $"{modId ?? "BaseGame"}:{folderName}";
            bool   flag  = false;

            MyHeightmapFace[] faces = new MyHeightmapFace[6];
            int resolution          = 0;

            for (int i = 0; i < 6; i++)
            {
                faces[i] = this.GetHeightMap(folderName, MyCubemapHelpers.GetNameForFace(i), context);
                if (faces[i] == null)
                {
                    flag = true;
                }
                else if ((faces[i].Resolution == resolution) || (resolution == 0))
                {
                    resolution = faces[i].Resolution;
                }
                else
                {
                    flag = true;
                    MyLog.Default.Error("Cubemap faces must be all the same size!", Array.Empty <object>());
                }
                if (flag)
                {
                    break;
                }
            }
            if (flag)
            {
                MyLog.Default.WriteLine($"Error loading heightmap {folderName}, using fallback instead. See rest of log for details.");
                for (int j = 0; j < 6; j++)
                {
                    faces[j]   = MyHeightmapFace.Default;
                    resolution = faces[j].Resolution;
                }
            }
            return(new MyHeightCubemap(name, faces, resolution));
        }
Exemple #6
0
        private MyHeightmapFace GetHeightMap(string folderName, string faceName, MyModContext context)
        {
            string          path = this.GetPath(folderName, faceName, context);
            MyHeightmapFace map  = null;

            try
            {
                using (Image image = this.LoadTexture(path))
                {
                    if (image == null)
                    {
                        object[] args = new object[] { path };
                        MyLog.Default.Error("Could not load texture {0}, no suitable format found. ", args);
                    }
                    else
                    {
                        PixelBuffer imageData = image.GetPixelBuffer(0, 0, 0);
                        map = new MyHeightmapFace(imageData.Height);
                        if (imageData.Format == Format.R16_UNorm)
                        {
                            PrepareHeightMap(map, imageData);
                        }
                        else if (imageData.Format == Format.R8_UNorm)
                        {
                            PrepareHeightMap8Bit(map, imageData);
                        }
                        else
                        {
                            MyLog.Default.Error($"Heighmap texture {path}: Invalid format {imageData.Format} (expecting R16_UNorm or R8_UNorm).", Array.Empty <object>());
                        }
                        image.Dispose();
                    }
                }
            }
            catch (Exception exception)
            {
                MyLog.Default.WriteLine(exception.Message);
            }
            return(map);
        }
Exemple #7
0
 static MyHeightmapFace()
 {
     Default = new MyHeightmapFace(HeightmapNode.HEIGHTMAP_LEAF_SIZE);
     Default.Zero();
 }