public AutoSplatRules( long minHeightMM, long maxHeightMM, AutoSplatConfig autoSplatConfig )
        {
            MinHeightMM = minHeightMM;
            MaxHeightMM = maxHeightMM;

            ConvertConfigToRules( autoSplatConfig );
        }
        public AutoSplatRules(long minHeightMM, long maxHeightMM, AutoSplatConfig autoSplatConfig)
        {
            MinHeightMM = minHeightMM;
            MaxHeightMM = maxHeightMM;

            ConvertConfigToRules(autoSplatConfig);
        }
        private void ConvertConfigToRules(AutoSplatConfig autoSplatConfig)
        {
            // Initialize textures

            layerTextureNames[SAND_INDEX]  = autoSplatConfig.SandTextureName;
            layerTextureNames[GRASS_INDEX] = autoSplatConfig.GrassTextureName;
            layerTextureNames[ROCK_INDEX]  = autoSplatConfig.RockTextureName;
            layerTextureNames[SNOW_INDEX]  = autoSplatConfig.SnowTextureName;

            // Create height angle ranges bottom-up; in all cases we use rock for
            // the vertical -- the steeper the rockier. Actually, more accurately,
            // we don't use full vertical; in the auto splat normal rules, we only
            // go up to one radian.  So each of these is actually a triplet, where
            // we use the same texture for up to 57.2 degrees, then start adding rock.

            AutoSplatHeightAngleRange range;
            float angleStart = 0f;
            float angleMid   = 90f - 57.2957795f;
            float angleEnd   = 90f;

            // Min height - Sand
            range = new AutoSplatHeightAngleRange(Math.Min(MinHeightMM, 0));
            range.AddAngleTexturePair(angleStart, SAND_INDEX);
            range.AddAngleTexturePair(angleMid, SAND_INDEX);
            range.AddAngleTexturePair(angleEnd, ROCK_INDEX);
            InternalAddHeightAngleRange(range);

            // Grass - blend inflection point for grass
            range = new AutoSplatHeightAngleRange((long)autoSplatConfig.SandToGrassHeight);
            range.AddAngleTexturePair(angleStart, GRASS_INDEX);
            range.AddAngleTexturePair(angleMid, GRASS_INDEX);
            range.AddAngleTexturePair(angleEnd, ROCK_INDEX);
            InternalAddHeightAngleRange(range);

            // Rock - blend inflection point for rock
            range = new AutoSplatHeightAngleRange((long)autoSplatConfig.GrassToRockHeight);
            range.AddAngleTexturePair(angleStart, ROCK_INDEX);
            range.AddAngleTexturePair(angleEnd, ROCK_INDEX);
            InternalAddHeightAngleRange(range);

            // Snow - blend inflection point for snow
            range = new AutoSplatHeightAngleRange((long)autoSplatConfig.RockToSnowHeight);
            range.AddAngleTexturePair(angleStart, SNOW_INDEX);
            range.AddAngleTexturePair(angleMid, SNOW_INDEX);
            range.AddAngleTexturePair(angleEnd, ROCK_INDEX);
            InternalAddHeightAngleRange(range);

            // Max height - Snow!
            if (MaxHeightMM > autoSplatConfig.RockToSnowHeight)
            {
                // Max height - Snow!
                range = new AutoSplatHeightAngleRange(MaxHeightMM);
                range.AddAngleTexturePair(angleStart, SNOW_INDEX);
                range.AddAngleTexturePair(angleEnd, SNOW_INDEX);
                InternalAddHeightAngleRange(range);
            }
        }
        public AutoSplatMaterial(AutoSplatConfig config, int pageX, int pageZ)
        {
            this.config = config;

            this.pageX = pageX;
            this.pageZ = pageZ;

            //LogManager.Instance.Write("Create AutoSplatMaterial ({0}, {1})", pageX, pageZ);

            config.ConfigChange += ConfigChange;
        }
        public AutoSplatMaterial(AutoSplatConfig config, int pageX, int pageZ)
        {
            this.config = config;

            this.pageX = pageX;
            this.pageZ = pageZ;

            //LogManager.Instance.Write("Create AutoSplatMaterial ({0}, {1})", pageX, pageZ);

            config.ConfigChange += ConfigChange;
        }
        public void AddToScene()
        {
            inScene = true;
            AutoSplatConfig terrainConfig;

            terrainConfig = new AutoSplatConfig();

            terrainConfig.UseParams = useParams;
            terrainConfig.UseGeneratedShadeMask = useGeneratedShadeMask;

            terrainConfig.SandToGrassHeight = sandToGrassHeight;
            terrainConfig.GrassToRockHeight = grassToRockHeight;
            terrainConfig.RockToSnowHeight = rockToSnowHeight;

            terrainConfig.TextureTileSize = textureTileSize;

            terrainConfig.SandTextureName = sandTextureName;
            terrainConfig.GrassTextureName = grassTextureName;
            terrainConfig.RockTextureName = rockTextureName;
            terrainConfig.SnowTextureName = snowTextureName;
            terrainConfig.ShadeMaskTextureName = shadeMaskTextureName;

            TerrainManager.Instance.TerrainMaterialConfig = terrainConfig;
        }
        private void ConvertConfigToRules( AutoSplatConfig autoSplatConfig )
        {
            // Initialize textures

            layerTextureNames[ SAND_INDEX ]  = autoSplatConfig.SandTextureName;
            layerTextureNames[ GRASS_INDEX ] = autoSplatConfig.GrassTextureName;
            layerTextureNames[ ROCK_INDEX ]  = autoSplatConfig.RockTextureName;
            layerTextureNames[ SNOW_INDEX ]  = autoSplatConfig.SnowTextureName;

            // Create height angle ranges bottom-up; in all cases we use rock for
            // the vertical -- the steeper the rockier. Actually, more accurately,
            // we don't use full vertical; in the auto splat normal rules, we only
            // go up to one radian.  So each of these is actually a triplet, where
            // we use the same texture for up to 57.2 degrees, then start adding rock.

            AutoSplatHeightAngleRange range;
            float angleStart = 0f;
            float angleMid   = 90f - 57.2957795f;
            float angleEnd   = 90f;

            // Min height - Sand
            range = new AutoSplatHeightAngleRange( Math.Min( MinHeightMM, 0 ) );
            range.AddAngleTexturePair( angleStart, SAND_INDEX );
            range.AddAngleTexturePair( angleMid, SAND_INDEX );
            range.AddAngleTexturePair( angleEnd, ROCK_INDEX );
            InternalAddHeightAngleRange( range );

            // Grass - blend inflection point for grass
            range = new AutoSplatHeightAngleRange( (long) autoSplatConfig.SandToGrassHeight );
            range.AddAngleTexturePair( angleStart, GRASS_INDEX );
            range.AddAngleTexturePair( angleMid, GRASS_INDEX );
            range.AddAngleTexturePair( angleEnd, ROCK_INDEX );
            InternalAddHeightAngleRange( range );

            // Rock - blend inflection point for rock
            range = new AutoSplatHeightAngleRange( (long) autoSplatConfig.GrassToRockHeight );
            range.AddAngleTexturePair( angleStart, ROCK_INDEX );
            range.AddAngleTexturePair( angleEnd, ROCK_INDEX );
            InternalAddHeightAngleRange( range );

            // Snow - blend inflection point for snow
            range = new AutoSplatHeightAngleRange( (long) autoSplatConfig.RockToSnowHeight );
            range.AddAngleTexturePair( angleStart, SNOW_INDEX );
            range.AddAngleTexturePair( angleMid, SNOW_INDEX );
            range.AddAngleTexturePair( angleEnd, ROCK_INDEX );
            InternalAddHeightAngleRange( range );

            // Max height - Snow!
            if( MaxHeightMM > autoSplatConfig.RockToSnowHeight )
            {
                // Max height - Snow!
                range = new AutoSplatHeightAngleRange( MaxHeightMM );
                range.AddAngleTexturePair( angleStart, SNOW_INDEX );
                range.AddAngleTexturePair( angleEnd, SNOW_INDEX );
                InternalAddHeightAngleRange( range );
            }
        }