Пример #1
0
        public MyVoxelMaterialDefinition GetMaterialForPosition(ref Vector3 pos, float lodSize, out byte biomeValue, bool preciseOrePositions)
        {
            MaterialSampleParams @params;

            biomeValue = 0;
            this.GetPositionParams(ref pos, lodSize, out @params, false);
            MyVoxelMaterialDefinition material = null;
            float num = !preciseOrePositions ? ((@params.SurfaceDepth / Math.Max((float)(lodSize * 0.5f), (float)1f)) + 0.5f) : (@params.SurfaceDepth + 0.5f);

            if (this.m_oreMap != null)
            {
                List <PlanetOre> list;
                byte             key = this.m_oreMap.Faces[@params.Face].GetValue(@params.Texcoord.X, @params.Texcoord.Y);
                if (this.m_ores.TryGetValue(key, out list))
                {
                    using (List <PlanetOre> .Enumerator enumerator = list.GetEnumerator())
                    {
                        while (true)
                        {
                            if (!enumerator.MoveNext())
                            {
                                break;
                            }
                            PlanetOre current = enumerator.Current;
                            if ((current.Start <= -num) && ((current.Start + current.Depth) >= -num))
                            {
                                return(current.Material);
                            }
                        }
                    }
                }
            }
            PlanetMaterial layeredMaterialForPosition = this.GetLayeredMaterialForPosition(ref @params, out biomeValue);
            float          num2 = @params.SurfaceDepth / lodSize;

            if (!layeredMaterialForPosition.HasLayers)
            {
                if (num2 >= -layeredMaterialForPosition.Depth)
                {
                    material = layeredMaterialForPosition.Material;
                }
            }
            else
            {
                VoxelMaterial[] layers = layeredMaterialForPosition.Layers;
                for (int i = 0; i < layers.Length; i++)
                {
                    if (num2 >= -layers[i].Depth)
                    {
                        material = layeredMaterialForPosition.Layers[i].Material;
                        break;
                    }
                }
            }
            if (material == null)
            {
                material = this.m_subsurfaceMaterial.FirstOrDefault;
            }
            return(material);
        }
Пример #2
0
 public Vector3 GetColorShift(Vector3 position, byte material, float maxDepth = 1f)
 {
     if (maxDepth >= 1f)
     {
         int                       num;
         Vector2                   vector2;
         List <PlanetOre>          list;
         MyVoxelMaterialDefinition voxelMaterialDefinition = MyDefinitionManager.Static.GetVoxelMaterialDefinition(material);
         if ((voxelMaterialDefinition == null) || (voxelMaterialDefinition.ColorKey == null))
         {
             return(Vector3.Zero);
         }
         MyCubemapHelpers.CalculateSampleTexcoord(ref position - this.m_planetShape.Center(), out num, out vector2);
         if (this.m_oreMap == null)
         {
             return(Vector3.Zero);
         }
         byte key = this.m_oreMap.Faces[num].GetValue(vector2.X, vector2.Y);
         if (!this.m_ores.TryGetValue(key, out list))
         {
             return(Vector3.Zero);
         }
         float num3 = (float)MathHelper.Saturate(this.m_perlin.GetValue((double)(vector2.X * 1000f), (double)(vector2.Y * 1000f), 0.0));
         using (List <PlanetOre> .Enumerator enumerator = list.GetEnumerator())
         {
             while (true)
             {
                 if (!enumerator.MoveNext())
                 {
                     break;
                 }
                 PlanetOre current        = enumerator.Current;
                 float     colorInfluence = current.ColorInfluence;
                 colorInfluence = 256f;
                 if ((colorInfluence >= 1f) && ((colorInfluence >= current.Start) && ((current.Start <= maxDepth) && (current.TargetColor != null))))
                 {
                     Vector3 targetShift = current.TargetColor.Value;
                     Color   violet      = Color.Violet;
                     if (targetShift == Vector3.Backward)
                     {
                         targetShift = new Vector3(0f, 1f, -0.08f);
                     }
                     else
                     {
                         targetShift = this.m_targetShift;
                     }
                     return((Vector3)((num3 * targetShift) * (1f - (current.Start / colorInfluence))));
                 }
             }
         }
     }
     return(Vector3.Zero);
 }
Пример #3
0
 public MyPlanetMaterialProvider(MyPlanetGeneratorDefinition generatorDef, MyPlanetShapeProvider planetShape, MyCubemap[] maps)
 {
     this.m_materials = new Dictionary <byte, PlanetMaterial>(generatorDef.SurfaceMaterialTable.Length);
     for (int i = 0; i < generatorDef.SurfaceMaterialTable.Length; i++)
     {
         byte num2 = generatorDef.SurfaceMaterialTable[i].Value;
         this.m_materials[num2] = new PlanetMaterial(generatorDef.SurfaceMaterialTable[i], generatorDef.MinimumSurfaceLayerDepth);
     }
     this.m_defaultMaterial    = new PlanetMaterial(generatorDef.DefaultSurfaceMaterial, generatorDef.MinimumSurfaceLayerDepth);
     this.m_subsurfaceMaterial = (generatorDef.DefaultSubSurfaceMaterial == null) ? this.m_defaultMaterial : new PlanetMaterial(generatorDef.DefaultSubSurfaceMaterial, generatorDef.MinimumSurfaceLayerDepth);
     this.m_planetShape        = planetShape;
     this.Maps          = maps;
     this.m_materialMap = maps[0];
     this.m_biomeMap    = maps[1];
     this.m_oreMap      = maps[2];
     if (this.m_materialMap != null)
     {
         this.m_mapResolutionMinusOne = this.m_materialMap.Resolution - 1;
     }
     this.m_generator      = generatorDef;
     this.m_invHeightRange = 1f / (this.m_planetShape.MaxHillHeight - this.m_planetShape.MinHillHeight);
     this.m_biomePixelSize = ((float)((planetShape.MaxHillHeight + planetShape.Radius) * 3.1415926535897931)) / ((this.m_mapResolutionMinusOne + 1) * 2f);
     this.m_hashCode       = generatorDef.FolderName.GetHashCode();
     if ((this.m_generator.MaterialGroups != null) && (this.m_generator.MaterialGroups.Length != 0))
     {
         this.m_biomes = new Dictionary <byte, PlanetBiome>();
         foreach (MyPlanetMaterialGroup group in this.m_generator.MaterialGroups)
         {
             this.m_biomes[group.Value] = new PlanetBiome(group, this.m_generator.MinimumSurfaceLayerDepth);
         }
     }
     if (MyHeightMapLoadingSystem.Static != null)
     {
         this.m_blendingTileset = MyHeightMapLoadingSystem.Static.GetTerrainBlendTexture(this.m_generator.MaterialBlending);
     }
     this.m_ores = new Dictionary <byte, List <PlanetOre> >();
     foreach (MyPlanetOreMapping mapping in this.m_generator.OreMappings)
     {
         MyVoxelMaterialDefinition material = GetMaterial(mapping.Type);
         if (material != null)
         {
             PlanetOre item = new PlanetOre {
                 Depth          = mapping.Depth,
                 Start          = mapping.Start,
                 Value          = mapping.Value,
                 Material       = material,
                 ColorInfluence = mapping.ColorInfluence
             };
             if (mapping.ColorShift != null)
             {
                 item.TargetColor = new Vector3?(mapping.ColorShift.Value.ColorToHSV());
             }
             if (!this.m_ores.ContainsKey(mapping.Value))
             {
                 List <PlanetOre> list1 = new List <PlanetOre>();
                 list1.Add(item);
                 List <PlanetOre> list = list1;
                 this.m_ores.Add(mapping.Value, list);
             }
             this.m_ores[mapping.Value].Add(item);
         }
     }
     this.Closed = false;
 }