コード例 #1
0
        public override MyVoxelMaterialDefinition GetMaterialForPosition(ref Vector3 pos, float lodSize)
        {
            Vector3 localPosition  = pos - Shape.Center();
            float   lenghtToCenter = localPosition.Length();

            if (lenghtToCenter < 0.01)
            {
                return(null);
            }

            float distance = m_planetShape.SampleField(ref pos);

            if (distance <= MyCsgPrecomputedHelpres.FROZEN_OCEAN_LEVEL && MyFakes.ENABLE_PLANET_FROZEN_SEA)
            {
                return(MyDefinitionManager.Static.GetVoxelMaterialDefinition("Ice_01"));
            }

            float originalDistance = m_planetShape.SignedDistanceUnchecked(ref pos, lodSize, null, null);


            if (lenghtToCenter <= m_oreDeposits.MinDepth)
            {
                MyVoxelMaterialDefinition definiton = m_oreDeposits.GetMaterialForPosition(ref pos, lodSize);
                if (definiton != null)
                {
                    return(definiton);
                }
            }

            if (originalDistance < -2.0f)
            {
                return(MyDefinitionManager.Static.GetVoxelMaterialDefinition("Stone_01"));
            }

            Vector3I samplePos;
            Vector2  positon = Vector2.Zero;

            MyCsgPrecomputedHelpres.CalculateSamplePosition(ref localPosition, out samplePos, ref positon, m_resolution);

            byte materialData;

            m_reader[samplePos.X].Read(sizeof(int) + samplePos.Z * m_resolution + samplePos.Y, out materialData);

            byte material      = (byte)(materialData & 127);
            byte spawns        = (byte)(materialData & 128);
            var  voxelMaterial = MyDefinitionManager.Static.GetVoxelMaterialDefinition(material);

            if (voxelMaterial != null)
            {
                voxelMaterial.SpawnsFlora = spawns == 0 ? false : true;
            }
            return(voxelMaterial);
        }
コード例 #2
0
        public override MyVoxelMaterialDefinition GetMaterialForPosition(ref Vector3 pos, float lodSize)
        {
            Vector3 localPosition  = pos - Shape.Center();
            float   lenghtToCenter = localPosition.Length();


            if (lenghtToCenter <= m_oreDeposits.MinDepth)
            {
                MyVoxelMaterialDefinition definiton = m_oreDeposits.GetMaterialForPosition(ref pos, lodSize);
                if (definiton != null)
                {
                    return(definiton);
                }
            }

            float angleToPole = Vector3.Dot(localPosition / lenghtToCenter, Vector3.Up);

            int   nearestMaterial = -1;
            float minDistance     = float.MaxValue;
            float noiseValue      = (float)(0.5 * m_noise.GetValue(pos.X, pos.Y, pos.Z) + 0.5);


            for (int i = 0; i < m_materialLayers.Length; ++i)
            {
                float heightStartDistance = m_materialLayers[i].HeightStartDeviation * noiseValue;
                float angleStartDistance  = m_materialLayers[i].AngleStartDeviation * noiseValue;

                float heightEndDistance = m_materialLayers[i].HeightEndDeviation * noiseValue;
                float angleEndDistance  = m_materialLayers[i].AngleEndDeviation * noiseValue;

                if (lenghtToCenter >= (m_materialLayers[i].StartHeight - lodSize - heightStartDistance) && (m_materialLayers[i].EndHeight + heightEndDistance) >= lenghtToCenter &&
                    angleToPole > m_materialLayers[i].StartAngle - angleStartDistance && m_materialLayers[i].EndAngle + angleEndDistance > angleToPole)
                {
                    float distanceTolayer = Math.Abs(lenghtToCenter - m_materialLayers[i].StartHeight + heightStartDistance);
                    if (minDistance > distanceTolayer)
                    {
                        minDistance     = distanceTolayer;
                        nearestMaterial = i;
                    }
                }
            }

            return(nearestMaterial == -1 ? null : m_materialLayers[nearestMaterial].MaterialDefinition);
        }