コード例 #1
0
        public MyTileTexture <byte> GetTerrainBlendTexture(MyPlanetMaterialBlendSettings settings)
        {
            MyTileTexture <byte> tex;

            string path     = settings.Texture;
            int    cellSize = settings.CellSize;

            if (!m_ditherTilesets.TryGetValue(path, out tex))
            {
                string fullPath = Path.Combine(MyFileSystem.ContentPath, path) + ".png";
                if (!File.Exists(fullPath))
                {
                    fullPath = Path.Combine(MyFileSystem.ContentPath, path) + ".dds";
                }

                SharpDXImage image = null;
                try
                {
                    image = SharpDXImage.Load(fullPath);
                }
                catch (Exception e)
                {
                    MyLog.Default.WriteLine(e.Message);
                }

                if (image == null)
                {
                    return(MyTileTexture <byte> .Default);
                }

                PixelBuffer buffer = image.GetPixelBuffer(0, 0, 0);

                Debug.Assert(buffer.Format == Format.R8_UNorm);

                if (buffer.Format != Format.R8_UNorm)
                {
                    return(MyTileTexture <byte> .Default);
                }

                tex = new MyTileTexture <byte>(buffer, cellSize);
                image.Dispose();
            }

            return(tex);
        }
コード例 #2
0
        public MyTileTexture<byte> GetTerrainBlendTexture(MyPlanetMaterialBlendSettings settings)
        {
            MyTileTexture<byte> tex;

            string path = settings.Texture;
            int cellSize = settings.CellSize;

            if (!m_ditherTilesets.TryGetValue(path, out tex))
            {
                string fullPath = Path.Combine(MyFileSystem.ContentPath, path) + ".png";
                if (!File.Exists(fullPath))
                    fullPath = Path.Combine(MyFileSystem.ContentPath, path) + ".dds";

                SharpDXImage image = null;
                try
                {
                    image = SharpDXImage.Load(fullPath);
                }
                catch (Exception e)
                {
                    MyLog.Default.WriteLine(e.Message);
                }

                if (image == null) return MyTileTexture<byte>.Default;

                PixelBuffer buffer = image.GetPixelBuffer(0, 0, 0);

                Debug.Assert(buffer.Format == Format.R8_UNorm);

                if (buffer.Format != Format.R8_UNorm) return MyTileTexture<byte>.Default;

                tex = new MyTileTexture<byte>(buffer, cellSize);
                image.Dispose();
            }

            return tex;
        }
コード例 #3
0
        public MyPlanetMaterialProvider(MyPlanetGeneratorDefinition generatorDef, MyPlanetShapeProvider planetShape)
        {
            m_materials = new Dictionary<byte, PlanetMaterial>(generatorDef.SurfaceMaterialTable.Length);

            for (int i = 0; i < generatorDef.SurfaceMaterialTable.Length; ++i)
            {
                byte materialValue = (byte)generatorDef.SurfaceMaterialTable[i].Value;

                m_materials[materialValue] = new PlanetMaterial(generatorDef.SurfaceMaterialTable[i]);
            }

            m_defaultMaterial = new PlanetMaterial(generatorDef.DefaultSurfaceMaterial);

            if (generatorDef.DefaultSubSurfaceMaterial != null)
            {
                m_subsurfaceMaterial = new PlanetMaterial(generatorDef.DefaultSubSurfaceMaterial);
            }
            else
            {
                m_subsurfaceMaterial = m_defaultMaterial;
            }

            m_planetShape = planetShape;

            MyCubemap[] maps;
            MyHeightMapLoadingSystem.Static.GetPlanetMaps(generatorDef.FolderName, generatorDef.Context, generatorDef.PlanetMaps, out maps);


            m_materialMap = maps[0];
            m_biomeMap = maps[1];
            m_oreMap = maps[2];
            m_occlusionMap = maps[3];

            if (m_biomeMap != null)
                m_mapResolutionMinusOne = m_biomeMap.Resolution - 1;

            m_generator = generatorDef;

            m_invHeightRange = 1 / (m_planetShape.MaxHillHeight - m_planetShape.MinHillHeight);

            m_biomePixelSize = (float)((planetShape.MaxHillHeight + planetShape.Radius) * Math.PI) / ((float)(m_mapResolutionMinusOne + 1) * 2);

            m_hashCode = generatorDef.FolderName.GetHashCode();

            // Material groups

            if (m_generator.MaterialGroups != null && m_generator.MaterialGroups.Length > 0)
            {
                m_biomes = new Dictionary<byte, PlanetBiome>();

                foreach (var group in m_generator.MaterialGroups)
                {
                    m_biomes.Add(group.Value, new PlanetBiome(group));
                }

            }

            m_blendingTileset = MyHeightMapLoadingSystem.Static.GetTerrainBlendTexture(m_generator.MaterialBlending);

            m_ores = new Dictionary<byte, PlanetOre>();

            foreach (var mapping in m_generator.OreMappings)
            {
                var mat = GetMaterial(mapping.Type);
                if (mat != null)
                {
                    if (m_ores.ContainsKey(mapping.Value))
                    {
                        string message = String.Format("Value {0} is already mapped to another ore.", mapping.Value);
                        Debug.Fail(message);
                        MyLog.Default.WriteLine(message);
                    }
                    else
                    {
                        m_ores[mapping.Value] = new PlanetOre()
                        {
                            Depth = mapping.Depth,
                            Start = mapping.Start,
                            Value = mapping.Value,
                            Material = mat
                        };
                    }
                }
            }

            Closed = false;
        }
コード例 #4
0
        public void Close()
        {
            if (m_providerForRules == this)
                m_providerForRules = null;

            // Clear to speed up collection

            m_blendingTileset = null;
            m_subsurfaceMaterial = null;
            m_generator = null;
            m_biomeMap = null;
            m_biomes = null;
            m_materials = null;
            m_planetShape = null;
            m_ores = null;

            m_materialMap = null;
            m_oreMap = null;
            m_biomeMap = null;
            m_occlusionMap = null;

            Closed = true;
        }