示例#1
0
 void Update()
 {
     if (Input.GetMouseButton(0))
     {
         Ray        ray = GetComponent <Camera>().ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit, cam.farClipPlane))
         {
             //Debug.Log(hit.point);
             var tc  = PTHelpers.GetHeightmapCoord(hit.point);
             var x   = (int)Mathf.Clamp(Mathf.Floor(tc.x * 512) - 16, 0f, 480f);
             var y   = (int)Mathf.Clamp(Mathf.Floor(tc.y * 512) - 16, 0f, 480f);
             var cur = tex.GetPixels(
                 x,
                 y,
                 32,
                 32);
             for (var i = 0; i < 1024; i++)
             {
                 cur[i].r = cur[i].g = cur[i].b = Mathf.Clamp(cur[i].r + (brush[i] * strength), 0f, 1f);
             }
             tex.SetPixels(
                 x,
                 y,
                 32,
                 32,
                 cur);
             byte[] bytes = tex.EncodeToPNG();
             File.WriteAllBytes(Application.dataPath + "/PlanetTex.png", bytes);
             ps.UpdateTerrain();
         }
     }
 }
示例#2
0
    private void UpdateVisibility()
    {
        var horizonAngle = Mathf.Acos(p.radius / Camera.main.transform.position.magnitude) * Mathf.Rad2Deg;

        if (!Application.isPlaying || PTHelpers.GetAngle(d) < horizonAngle + 15f)
        {
            isVisible = true;
            if (!mr.enabled)
            {
                mr.enabled = true;
                PTHelpers.segmentCount++;
            }
        }
        else
        {
            isVisible = false;
            if (mr.enabled)
            {
                mr.enabled = false;
                PTHelpers.segmentCount--;
            }
        }
    }
示例#3
0
 public static float GetHeight(Vector3 p, float radius, DisplacementLayer[] displace)
 {
     if (displace != null)
     {
         float maxHeight   = 0f;
         float addedHeight = 0f;
         for (var i = 0; i < displace.Length; i++)
         {
             var d        = displace[i];
             var strength = 1f;
             if (maxHeight > 0f)
             {
                 strength = d.heightStrength.Evaluate(addedHeight / maxHeight);
             }
             if (d.noise == NOISE.Perlin)
             {
                 addedHeight += d.height * Noise.Perlin(d.detail * p.x + d.seed, d.detail * p.y, d.detail * p.z) * strength;
             }
             else if (d.noise == NOISE.Worley)
             {
                 addedHeight += d.height * Noise.Worley(d.detail * p.x + d.seed, d.detail * p.y, d.detail * p.z) * strength;
             }
             else if (d.noise == NOISE.FractalMapped)
             {
                 addedHeight += d.height * Noise.FractalMapped(d.detail * p.x + d.seed, d.detail * p.y, d.detail * p.z) * strength;
             }
             else
             {
                 var np = PTHelpers.GetHeightmapCoord(p);
                 addedHeight += d.height * d.texture.GetPixelBilinear(np.x, np.y).grayscale;
             }
             maxHeight += d.height;
         }
         return(radius + addedHeight);
     }
     return(radius);
 }
示例#4
0
 private IEnumerator SubdivideDecider()
 {
     // Decide if the mesh should be subdivided
     if (!Application.isPlaying || p.minSubdivisions - d.subdivision > 0 || (Application.isPlaying && isVisible && p.maxSubdivisions - d.subdivision > 0 && PTHelpers.GetDistance(d) < PTHelpers.GetSize(d)))
     {
         if (segments.Count == 0)
         {
             if (Application.isPlaying)
             {
                 yield return(StartCoroutine(SubdivideSegment(d)));
             }
             else
             {
                 IEnumerator e = SubdivideSegment(d);
                 while (e.MoveNext())
                 {
                     ;
                 }
             }
         }
         else
         {
             for (var i = 0; i < segments.Count; i++)
             {
                 yield return(StartCoroutine(segments[i].Generate()));
             }
         }
     }
     else
     {
         if (segments.Count > 0)
         {
             while (segments.Count > 0)
             {
                 segments[0].Disable();
                 segments.RemoveAt(0);
             }
             if (mc != null)
             {
                 mc.enabled = true;
             }
             UpdateVisibility();
         }
     }
 }