public WorleyNoise.CellData RandomCellData(WorleyNoise cellWorley) { int x = UnityEngine.Random.Range(-500, 500); int z = UnityEngine.Random.Range(-500, 500); return(cellWorley.GetCellData(new int2(x, z))); }
WorleyNoise.CellProfile GetRandomCell() { WorleyNoise worley = GetWorleyNoise(); Random random = Random(); return(worley.GetCellProfile(random.NextInt2(-100, 100))); }
protected override void OnCreate() { entityManager = World.Active.EntityManager; playerSystem = World.Active.GetOrCreateSystem <PlayerEntitySystem>(); UpdateCurrentCellIndex(); previousCellIndex = new int2(100); sectorArchetype = entityManager.CreateArchetype( ComponentType.ReadWrite <LocalToWorld>(), ComponentType.ReadWrite <Translation>(), ComponentType.ReadWrite <RenderMeshProxy>() ); float3 matrixRoot = new float3(currentCellIndex.x, 0, currentCellIndex.y); sectorMatrix = new Matrix <Entity>(5, Allocator.Persistent, matrixRoot); cellMatrix = new Matrix <CellMatrixItem>(5, Allocator.Persistent, matrixRoot); EntityQueryDesc sectorSortQueryDesc = new EntityQueryDesc { All = new ComponentType[] { typeof(AdjacentCell), typeof(SectorCell), typeof(WorleyNoise.PointData) }, None = new ComponentType[] { typeof(Tags.TerrainEntity) } }; sectorSortQuery = GetEntityQuery(sectorSortQueryDesc); worley = TerrainSettings.CellWorley(); topologyUtil = new TopologyUtil().Construct(); }
public WorleyNoise.PointData RandomPointData(WorleyNoise cellWorley) { int x = UnityEngine.Random.Range(-5000, 5000); int z = UnityEngine.Random.Range(-5000, 5000); return(cellWorley.GetPointData(x, z)); }
void ResetTexture() { if (_texture.width != _resolution) { _texture.Resize(_resolution, _resolution); } NoiseGeneratorBase noise; if (_noiseType == NoiseType.Perlin) { noise = new PerlinNoise(_frequency, 1, 0); } else { noise = new WorleyNoise(_frequency, 1, 0); } var scale = 1.0f / _resolution; var z = Time.time * 0.1f; for (var iy = 0; iy < _resolution; iy++) { var y = scale * iy; for (var ix = 0; ix < _resolution; ix++) { var x = scale * ix; float c; if (_fractal == 1) { if (_dimensions == 2) { c = noise.GetAt(x, y); } else { c = noise.GetAt(x, y, z); } } else if (_dimensions == 2) { c = noise.GetFractal(x, y, _fractal); } else { c = noise.GetFractal(x, y, z, _fractal); } _texture.SetPixel(ix, iy, new Color(c, c, c)); } } _texture.Apply(); }
public ShapeGenerator(ShapeSettings settings) { this.minmax = new MinMax(); this.sealLevelMinMax = new MinMax(); this.settings = settings; pointsInSea = 0; perlin = new PerlinNoise(settings.noise.seed, settings.noise.freq); worley = new WorleyNoise(settings.noise.seed, settings.noise.freq, settings.noise.jitterWorley); simplex = new SimplexNoise(settings.noise.seed, settings.noise.freq); }
void Start() { mesh = new Mesh(); GetComponent <MeshFilter>().mesh = mesh; ws = new WorleyNoise(); ws.GenerateMap(_NB_POINTS, xSize, zSize, _DEPTH); random = new UnityEngine.Random(); CreateShape(); UpdateMesh(); }
protected override void OnCreate() { entityManager = World.Active.EntityManager; playerSystem = World.Active.GetOrCreateSystem <PlayerEntitySystem>(); cellSystem = World.Active.GetOrCreateSystem <CellSystem>(); monoBehaviour = GameObject.FindObjectOfType <DebugMonoBehaviour>(); debugWorley = TerrainSettings.CellWorley(); topologyUtil = new TopologyUtil().Construct(); worleyCurrentMarker = CreateCube(float3.zero, new float4(0, 1, 0, 1)); worleyAdjacentMarker = CreateCube(float3.zero, new float4(0, 0, 1, 1)); }
void DrawChildCells(float2 frequency) { WorleyNoise childWorley = worley; childWorley.frequency = frequency; float3 meanPointWorld = parentCell.data.position + vectorUtil.MeanPoint(parentCell.vertices); WorleyNoise.CellData startChild = childWorley.GetCellData(meanPointWorld); var checkNext = new NativeQueue <WorleyNoise.CellData>(Allocator.Temp); var alreadyChecked = new NativeList <int2>(Allocator.Temp); checkNext.Enqueue(startChild); alreadyChecked.Add(startChild.index); var children = new NativeList <WorleyNoise.CellProfile>(Allocator.Temp); while (checkNext.Count > 0) { WorleyNoise.CellData childData = checkNext.Dequeue(); WorleyNoise.CellData dataFromParent = worley.GetCellData(childData.position); bool childIsInParent = dataFromParent.index.Equals(parentCell.data.index); if (!childIsInParent) { continue; } WorleyNoise.CellProfile childProfile = childWorley.GetCellProfile(childData); float3 positionInParent = childProfile.data.position - parentCell.data.position; positionInParent.y += baseHeight; leaves.Draw(childProfile, positionInParent); children.Add(childProfile); for (int i = 0; i < childProfile.vertices.Length; i++) { WorleyNoise.CellData adjacent = childProfile.adjacentCells[i].c0; if (!alreadyChecked.Contains(adjacent.index)) { checkNext.Enqueue(adjacent); alreadyChecked.Add(adjacent.index); } } } checkNext.Dispose(); alreadyChecked.Dispose(); }
WorleyDatas GetWorleyDatas() { WorleyNoise worley = GetWorleyGenerator(); float3 randomPosition = Random().NextFloat3(); WorleyNoise.CellData cellFromIndex; WorleyNoise.CellData cellFromPosition; cellFromPosition = worley.GetCellData(randomPosition); cellFromIndex = worley.GetCellData(cellFromPosition.index); return(new WorleyDatas(cellFromIndex, cellFromPosition)); }
void Start() { textPrefab = UnityEditor.AssetDatabase.LoadAssetAtPath <GameObject>("Assets/New Text.prefab"); random = new Unity.Mathematics.Random((uint)UnityEngine.Random.Range(0, 10000)); //random = new Unity.Mathematics.Random(2456235); worley = new WorleyNoise() { frequency = 0.075f, //seed = random.NextInt(), seed = -878905037, perterbAmp = 0, cellularJitter = 0.3f, distanceFunction = WorleyNoise.DistanceFunction.Euclidean, cellularReturnType = WorleyNoise.CellularReturnType.Distance2 }; Debug.Log("Seed: " + worley.seed); TreeGenerator generator = new TreeGenerator { worley = this.worley, meshPrefab = UnityEditor.AssetDatabase.LoadAssetAtPath <GameObject>("Assets/TreeMesh.prefab"), material = UnityEditor.AssetDatabase.LoadAssetAtPath <Material>("Assets/Materials/DefaultMat.mat"), simplex = new SimplexNoise(worley.seed, 0.1f) }; bool one = false; int range = 1; if (!one) { for (int x = -range; x <= range; x++) { for (int z = -range; z <= range; z++) { int2 index = new int2(x, z); generator.Generate(index); } } } else { generator.Generate(new int2(0)); } //DebugWorley(30); }
public override void OnInspectorGUI() { DrawDefaultInspector(); WorleyNoise creator = (WorleyNoise)target; if (GUILayout.Button("生成噪声贴图")) { creator.CreateWolyTexture(); } if (GUILayout.Button("保存噪声贴图")) { creator.SaveTexture(); } }
WorleyNoise.CellData GetWorleyDataHelper(out WorleyNoise.CellData adjacentPlaceholder, out float dist2EdgePlaceholder, bool getAdjacent, bool getDistance) { WorleyNoise worley = GetWorleyGenerator(); float3 randomPosition = Random().NextFloat3(); return(worley.GetWorleyData( randomPosition.x, randomPosition.y, 0.01f, out adjacentPlaceholder, out dist2EdgePlaceholder, getAdjacent, getDistance )); }