Ejemplo n.º 1
0
 static SampleFunctions()
 {
     functions = new UtilFuncs.Sampler[6];
     simplex   = new SE.OpenSimplexNoise(7);
     // Flat ground
     functions[0] = (float x, float y, float z) => {
         Debug.LogFormat("Sampling at {0} {1} {2}", x, y, z);
         return(0.5f - y);
     };
     // Sphere
     functions[1] = (float x, float y, float z) => {
         Vector3 p = new Vector3(x - 0.5f, y - 0.5f, z - 0.5f);
         return(Sphere(p.x, p.y, p.z, 0.25f));
     };
     // Simplex
     functions[2] = (float x, float y, float z) => {
         float r = 1132f;
         return((float)simplex.Evaluate(x * r, y * r, z * r));
     };
     // Rotated Cuboid
     functions[3] = (float x, float y, float z) => {
         Vector3 p = new Vector3((x - 1.5f) * 2f, (y - 1.5f) * 2f, (z - 1.5f) * 2f);
         return(RotatedCuboid(p, 0.6f));
     };
     // Simplex Terrain
     functions[4] = (float x, float y, float z) => {
         float result = y - 1.5f;
         float r      = 3f;
         float r2     = r * 8;
         result += 0.5f * (float)simplex.Evaluate(x * r, y * r, z * r);
         result += 0.15f * (float)simplex.Evaluate(x * r2, y * r2, z * r2);
         return(result);
     };
 }
Ejemplo n.º 2
0
        private static float sample(SE.OpenSimplexNoise noise, float x, float y, float z)
        {
            float r      = 0.2f;
            float f      = 0.03f;
            float ms     = 0.009f;
            float result = 2.0f - y;

            result += (float)noise.Evaluate(x * r, y * r, z * r) * 1.6f;
            result += (float)noise.Evaluate(x * f, y * f, z * f) * 20f;
            result += (float)noise.Evaluate(x * f, y * f, z * ms) * 50f;

            return(result);
        }
Ejemplo n.º 3
0
        public static ChunkJobResult CreateChunk(ChunkJob Job)
        {
            ChunkJobResult result = new ChunkJobResult();

            try {
                Stopwatch s = new Stopwatch();
                s.Start();
                SE.OpenSimplexNoise noise = new SE.OpenSimplexNoise(1);

                result.Error       = null;
                result.OriginalJob = Job;
                result.DebugPrint  = "";


                ExtractionInput input = new ExtractionInput();
                input.Isovalue   = 0;
                input.LODSides   = Job.LOD;
                input.Resolution = new Util.Vector3i(Job.Resolution, Job.Resolution, Job.Resolution);
                input.Size       = new Vector3(Job.CellSize, Job.CellSize, Job.CellSize);

                int numTimesSampled = 0;

                input.Sample = (float x, float y, float z) => {
                    numTimesSampled++;
                    float res = sample(noise, x + Job.Min.x, y + Job.Min.y, z + Job.Min.z);
                    return(res);
                };

                ExtractionResult ExResult = SurfaceExtractor.ExtractSurface(input);
                result.Result = ExResult;



                s.Stop();
                result.ProcessingTime = s.ElapsedMilliseconds;
            }
            catch (System.Exception exc) {
                result.Error = "Error in thread " + Job.ThreadID + ": " + exc.Message + ", Stacktrace: " + exc.StackTrace;
            }
            return(result);
        }