コード例 #1
1
    /// <summary>
    /// Reads from the provided file name all parameters and data for a
    /// heightmap.  If the data for the heightmap does not exist, then
    /// no data is written to the provided texture.
    /// </summary>
    /// <param name='fileName'>
    /// The file name.  This can be relative or fully-qualified.
    /// </param>
    /// <param name='no'>
    /// The <see cref="NormalOptions" /> that will store read-in parameters.
    /// </param>
    /// <param name='co'>
    /// The <see cref="CloudOptions" /> that will store read-in parameters for
    /// <see cref="CloudFractal" />.
    /// </param>
    /// <param name='wo'>
    /// The <see cref="WorleyOptions" />  that will store read-in parameters for
    /// <see cref="WorleyNoise" />.
    /// </param>
    /// <param name='tex'>
    /// The <code>Texture2D</code> containing the heightmap data.
    /// </param>
    public static void Read(string fileName, ref NormalOptions no,
	                        ref CloudOptions co, ref VoronoiOptions vo,
							ref Texture2D tex)
    {
        using(BinaryReader r = new BinaryReader(File.OpenRead(fileName)))
        {
            no.size = r.ReadInt32();
            no.seed = r.ReadInt32();
            no.cloudInf = r.ReadSingle();
            no.voronoiInf = r.ReadSingle();
            no.useThermalErosion = r.ReadBoolean();
            no.useHydroErosion = r.ReadBoolean();
            no.showSeams = r.ReadBoolean();

            co.upperLeftStart = r.ReadSingle();
            co.lowerLeftStart = r.ReadSingle();
            co.lowerRightStart = r.ReadSingle();
            co.upperRightStart = r.ReadSingle();

            vo.metric = (DistanceFunctions.DistanceMetric)r.ReadInt32();
            vo.combiner = (CombinerFunctions.CombineFunction)r.ReadInt32();
            vo.numberOfFeaturePoints = r.ReadInt32();
            vo.numberOfSubregions = r.ReadInt32();
            vo.multiplier = r.ReadSingle();

            tex.Resize(no.size, no.size);
            int bLeft = (int)(r.BaseStream.Length - r.BaseStream.Position);
            if(bLeft > 0)
                tex.LoadImage(r.ReadBytes(bLeft));
        }
    }
コード例 #2
0
ファイル: VoronoiDiagram.cs プロジェクト: seflopod/EarthMake
    public VoronoiDiagram(int size, int seed, VoronoiOptions options)
    {
        mSize = size;
        delDistanceFunc = DistanceFunctions.GetDistanceFunction(options.metric);
        delCombiningFunc = CombinerFunctions.GetFunction(options.combiner);
        mNumFeaturePoints = options.numberOfFeaturePoints;
        mNumSubregions = options.numberOfSubregions;
        mMultiplier = options.multiplier;

        aFeaturePoints = new int[0];
        mRNG = new LCGRandom(seed);
    }
コード例 #3
0
    /// <summary>
    /// Overload for <see cref="Write" /> that does not have texture data.
    /// </summary>
    /// <param name='fileName'>
    /// The file name.  This can be relative or fully-qualified.
    /// </param>
    /// <param name='no'>
    /// The <see cref="NormalOptions" /> to write.
    /// </param>
    /// <param name='co'>
    /// The <see cref="CloudOptions" /> to write.
    /// </param>
    /// <param name='wo'>
    /// The <see cref="WorleyOptions" /> to write.
    /// </param>
    /// <param name='tex'>
    /// The <code>Texture2D</code> containing the heightmap data.
    /// </param>
    public static void Write(string fileName, NormalOptions no, CloudOptions co,
	                         VoronoiOptions vo)
    {
        Write(fileName, no, co, vo, null);
    }
コード例 #4
0
    /// <summary>
    /// Write the specified the heightmap and all paramaters to the provided
    /// file name.
    /// </summary>
    /// <param name='fileName'>
    /// The file name.  This can be relative or fully-qualified.
    /// </param>
    /// <param name='no'>
    /// The <see cref="NormalOptions" /> to write.
    /// </param>
    /// <param name='co'>
    /// The <see cref="CloudOptions" /> to write.
    /// </param>
    /// <param name='wo'>
    /// The <see cref="WorleyOptions" /> to write.
    /// </param>
    /// <param name='tex'>
    /// The <code>Texture2D</code> containing the heightmap data.
    /// </param>
    /// <description>
    /// This uses a <code>BinaryWriter</code> to convert all data into binary
    /// data for writing.
    /// </description>
    public static void Write(string fileName, NormalOptions no, CloudOptions co,
								VoronoiOptions vo, Texture2D tex)
    {
        //if file already exists, will overwrite without warning
        using(BinaryWriter w = new BinaryWriter(File.Open(fileName+".emb",
                                                FileMode.Create)))
        {
            w.Write(no.size);
            w.Write(no.seed);
            w.Write(no.cloudInf);
            w.Write(no.voronoiInf);
            w.Write(no.useThermalErosion);
            w.Write(no.useHydroErosion);
            w.Write(no.showSeams);

            w.Write(co.upperLeftStart);
            w.Write(co.lowerLeftStart);
            w.Write(co.lowerRightStart);
            w.Write(co.upperRightStart);

            w.Write((int)vo.metric);
            w.Write((int)vo.combiner);
            w.Write(vo.numberOfFeaturePoints);
            w.Write(vo.numberOfSubregions);
            w.Write(vo.multiplier);

            if(tex != null)
                w.Write(tex.EncodeToPNG());
        }
    }
コード例 #5
0
 public TerrainGenerator(NormalOptions normalOpt, CloudOptions cloudOpt, VoronoiOptions voronoiOpt)
 {
     Init(normalOpt, cloudOpt, voronoiOpt);
 }
コード例 #6
0
    private void Init(NormalOptions normalOpt, CloudOptions cloudOpt, VoronoiOptions voronoiOpt)
    {
        _normalOpt = normalOpt;
        _cloudOpt = cloudOpt;
        _voronoiOpt = voronoiOpt;

        _cfGen = new CloudFractal(_normalOpt.size, _normalOpt.seed, _cloudOpt);
        _vnGen = new VoronoiDiagram(_normalOpt.size, _normalOpt.seed, _voronoiOpt);
        _heightMap = new float[_normalOpt.size * _normalOpt.size];
    }