Exemple #1
0
 public void UpdateDetailsGradientMap()
 {
     Color32[] pixels = new Color32[DetailsGradientMap.width];
     for (int x = 0; x < pixels.Length; x++)
     {
         pixels[x] = DetailsGradient.Evaluate(x / (float)DetailsGradientMap.width);
     }
     //if (pixels == DetailsGradientMap.GetPixels32()) return;
     DetailsGradientMap.SetPixels32(pixels);
     DetailsGradientMap.Apply(true);
     PlanetMaterial.SetTexture("_DetailsGradient", DetailsGradientMap);
 }
Exemple #2
0
 public void UpdateHeightGradientMap()
 {
     Color32[] pixels = new Color32[HeightGradientMap.width];
     for (int x = 0; x < pixels.Length; x++)
     {
         pixels[x] = HeightGradient.Evaluate(x / (float)HeightGradientMap.width);
     }
     if (pixels == HeightGradientMap.GetPixels32())
     {
         return;
     }
     HeightGradientMap.SetPixels32(pixels);
     HeightGradientMap.Apply(true);
     PlanetMaterial.SetTexture("_HeightGradient", HeightGradientMap);
 }
        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;
        }
        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;
        }