コード例 #1
0
        public void GetPositionParams(ref Vector3 pos, float lodSize, out MaterialSampleParams ps, bool skipCache = false)
        {
            Vector3 localPos = pos - this.m_planetShape.Center();

            ps.DistanceToCenter = localPos.Length();
            ps.LodSize          = lodSize;
            if (ps.DistanceToCenter < 0.01f)
            {
                ps.SurfaceDepth  = 0f;
                ps.Gravity       = Vector3.Down;
                ps.Latitude      = 0f;
                ps.Longitude     = 0f;
                ps.Texcoord      = Vector2.One / 2f;
                ps.Face          = 0;
                ps.Normal        = Vector3.Backward;
                ps.SampledHeight = 0f;
            }
            else
            {
                ps.Gravity = localPos / ps.DistanceToCenter;
                MyCubemapHelpers.CalculateSampleTexcoord(ref localPos, out ps.Face, out ps.Texcoord);
                ps.SampledHeight = !skipCache?this.m_planetShape.GetValueForPositionWithCache(ps.Face, ref ps.Texcoord, out ps.Normal) : this.m_planetShape.GetValueForPositionCacheless(ps.Face, ref ps.Texcoord, out ps.Normal);

                ps.SurfaceDepth = this.m_planetShape.SignedDistanceWithSample(lodSize, ps.DistanceToCenter, ps.SampledHeight) * ps.Normal.Z;
                ps.Latitude     = ps.Gravity.Y;
                Vector2 vector2 = new Vector2(-ps.Gravity.X, -ps.Gravity.Z);
                vector2.Normalize();
                ps.Longitude = vector2.Y;
                if (-ps.Gravity.X > 0f)
                {
                    ps.Longitude = 2f - ps.Longitude;
                }
            }
        }
コード例 #2
0
        public PlanetMaterial GetLayeredMaterialForPosition(ref MaterialSampleParams ps, out byte biomeValue)
        {
            if (ps.DistanceToCenter < 0.01)
            {
                biomeValue = 0xff;
                return(this.m_defaultMaterial);
            }
            byte           key             = 0;
            PlanetMaterial defaultMaterial = null;
            byte           num2            = 0;

            if (this.m_biomeMap != null)
            {
                num2 = this.m_biomeMap.Faces[ps.Face].GetValue(ps.Texcoord.X, ps.Texcoord.Y);
            }
            if (this.m_biomePixelSize < ps.LodSize)
            {
                if (this.m_materialMap != null)
                {
                    key = this.m_materialMap.Faces[ps.Face].GetValue(ps.Texcoord.X, ps.Texcoord.Y);
                }
            }
            else if (this.m_materialMap != null)
            {
                key = this.ComputeMapBlend(ps.Texcoord, ps.Face, ref m_materialBC, this.m_materialMap.Faces[ps.Face]);
            }
            this.m_materials.TryGetValue(key, out defaultMaterial);
            if ((defaultMaterial == null) && (this.m_biomes != null))
            {
                List <PlanetMaterialRule> list = m_rangeBiomes[key];
                if ((list != null) && (list.Count != 0))
                {
                    float height = (ps.SampledHeight - this.m_planetShape.MinHillHeight) * this.m_invHeightRange;
                    foreach (PlanetMaterialRule rule in list)
                    {
                        if (rule.Check(height, ps.Latitude, ps.Longitude, ps.Normal.Z))
                        {
                            defaultMaterial = rule;
                            break;
                        }
                    }
                }
            }
            if (defaultMaterial == null)
            {
                defaultMaterial = this.m_defaultMaterial;
            }
            biomeValue = num2;
            return(defaultMaterial);
        }
コード例 #3
0
        public void GetPositionParams(ref Vector3 pos, float lodSize, out MaterialSampleParams ps, bool skipCache = false)
        {
            Vector3 localPosition = pos - m_planetShape.Center();

            ps.DistanceToCenter = localPosition.Length();

            ps.LodSize = lodSize;

            if (ps.DistanceToCenter < 0.01f)
            {
                ps.SurfaceDepth  = 0;
                ps.Gravity       = Vector3.Down;
                ps.Latitude      = 0;
                ps.Longitude     = 0;
                ps.Texcoord      = Vector2.One / 2;
                ps.Face          = 0;
                ps.Normal        = Vector3.Backward;
                ps.SampledHeight = 0;
                return;
            }

            ps.Gravity = localPosition / ps.DistanceToCenter;

            MyCubemapHelpers.CalculateSampleTexcoord(ref localPosition, out ps.Face, out ps.Texcoord);

            // this guarantess texcoord in [0,1)
            if (skipCache)
            {
                ps.SampledHeight = m_planetShape.GetValueForPositionCacheless(ps.Face, ref ps.Texcoord, out ps.Normal);
            }
            else
            {
                ps.SampledHeight = m_planetShape.GetValueForPositionWithCache(ps.Face, ref ps.Texcoord, out ps.Normal);
            }

            ps.SurfaceDepth = m_planetShape.SignedDistanceWithSample(lodSize, ps.DistanceToCenter, ps.SampledHeight) * ps.Normal.Z;
            ps.Latitude     = ps.Gravity.Y;

            Vector2 lon = new Vector2(-ps.Gravity.X, -ps.Gravity.Z);

            lon.Normalize();

            ps.Longitude = lon.Y;
            if (-ps.Gravity.X > 0)
            {
                ps.Longitude = 2 - ps.Longitude;
            }
        }
コード例 #4
0
        public PlanetMaterial GetLayeredMaterialForPosition(ref MaterialSampleParams ps, out byte spawnsItems, ref byte occlusion)
        {
            if (ps.DistanceToCenter < 0.01)
            {
                spawnsItems = 255;
                occlusion   = 0;
                return(m_defaultMaterial);
            }

            Byte           roundedMaterial = 0;
            PlanetMaterial voxelMaterial   = null;
            byte           spawns          = 0;

            bool computeOcclusion = m_occlusionMap != null && ps.SurfaceDepth > -(ps.LodSize * 2) && occlusion != 0;

            if (m_biomeMap != null)
            {
                spawns = m_biomeMap.Faces[ps.Face].GetValue(ps.Texcoord.X, ps.Texcoord.Y);
            }

            if (m_biomePixelSize < ps.LodSize)
            {
                if (m_materialMap != null)
                {
                    roundedMaterial = m_materialMap.Faces[ps.Face].GetValue(ps.Texcoord.X, ps.Texcoord.Y);
                }

                if (computeOcclusion)
                {
                    occlusion = m_occlusionMap.Faces[ps.Face].GetValue(ps.Texcoord.X, ps.Texcoord.Y);
                }
                else
                {
                    occlusion = 0;
                }
            }
            else
            {
                if (m_biomeMap != null)
                {
                    roundedMaterial = ComputeMapBlend(ps.Texcoord, ps.Face, ref m_materialBC,
                                                      m_materialMap.Faces[ps.Face]);
                }

                if (computeOcclusion)
                {
                    occlusion = ComputeMapBlend(ps.Texcoord, ps.Face, ref m_occlusionBC,
                                                m_occlusionMap.Faces[ps.Face]);
                }
                else
                {
                    occlusion = 0;
                }
            }
            m_materials.TryGetValue(roundedMaterial, out voxelMaterial);

            if (MyFakes.ENABLE_DEFINITION_ENVIRONMENTS && voxelMaterial == null && m_biomes != null)
            {
                var rules = m_rangeBiomes[roundedMaterial];

                if (rules != null && rules.Count != 0)
                {
                    float height = (ps.SampledHeight - m_planetShape.MinHillHeight) * m_invHeightRange;

                    foreach (var rule in rules)
                    {
                        if (rule.Check(height, ps.Latitude, ps.Longitude, ps.Normal.Z))
                        {
                            voxelMaterial = rule;
                            break;
                        }
                    }
                }
            }

            if (voxelMaterial == null)
            {
                voxelMaterial = m_defaultMaterial;
            }

            spawnsItems = spawns;

            return(voxelMaterial);
        }