private void Update() { BrushModeInput(); if (Input.GetKeyUp(brushModeKey) || Input.GetMouseButtonUp(2)) { singularMode = !singularMode; } FindNearestVertexAndEdit(); if (editing && !Input.GetMouseButton(0) && !Input.GetMouseButton(1)) { editing = false; if (meshChanged) { PolyPlanet.RecalculateMeshInfo(); } if (autoSaveData) { SaveCurrentMeshDataToScriptableObject(); } meshChanged = false; } BrushModeUI(); LevelBrushUI(); }
/// <summary> /// Applies perlin noise to mesh and saves it. /// </summary> public void ApplyNoiseToMesh() { vertices = PerlinMeshVerts(MeshF.mesh.vertices, seed, scale, octaves, persistance, lacunarity, maxHeight); MeshF.mesh.vertices = vertices; PolyPlanet.RecalculateMeshInfo(); if (autoSaveData) { SaveCurrentMeshDataToScriptableObject(); } }
/// <summary> /// Sets distance of every vertex to maxHeight. /// </summary> public void SetHeightToMaxHeight() { for (int i = 0; i < vertices.Length; i++) { vertices[i] = vertices[i].normalized * maxHeight; } MeshF.mesh.vertices = vertices; PolyPlanet.RecalculateMeshInfo(); if (autoSaveData) { SaveCurrentMeshDataToScriptableObject(); } }
private void SampleTexture(Texture2D _tex) { if (_tex == null) { return; } Color[] height = _tex.GetPixels(); List <Vector3> normalizedVertices = new List <Vector3>(vertices); for (int i = 0; i < normalizedVertices.Count; i++) { normalizedVertices[i] = normalizedVertices[i].normalized; } List <Vector2> uvs = new List <Vector2>(); foreach (var item in normalizedVertices) { uvs.Add( new Vector2( (Mathf.Atan2(item.z, item.x) / (2 * Mathf.PI) + 0.5f) * (_tex.width - 1), ((Mathf.Asin(item.y) / Mathf.PI) + 0.5f) * (_tex.height - 1) )); } for (int i = 0; i < vertices.Length; i++) { vertices[i] = vertices[i].normalized * Mathf.Lerp(1, maxHeight, height[Mathf.FloorToInt(uvs[i].y) * _tex.width + Mathf.FloorToInt(uvs[i].x)].r ); } MeshF.sharedMesh.vertices = vertices; PolyPlanet.RecalculateMeshInfo(); if (autoSaveData) { SaveCurrentMeshDataToScriptableObject(); } }