Last active
January 23, 2019 06:53
-
-
Save unitycoder/da7fc9d4c4264ea633db to your computer and use it in GitHub Desktop.
Revisions
-
unitycoder revised this gist
Apr 12, 2015 . 1 changed file with 11 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,42 +2,41 @@ using System.Collections; public class Melter : MonoBehaviour { public Transform heatPoint; public bool restoreColor=false; void Start () { var mesh = GetComponent<MeshFilter>().mesh; var cols = new Color[mesh.vertexCount]; for (int i = 0; i < mesh.vertexCount; i++) { cols[i] = Color.white; } mesh.colors = cols; UpdateColor(); } void Update () { UpdateColor(); } void UpdateColor() { float viewDistance = 1f; float fadeSpeed = 1f; var mesh = GetComponent<MeshFilter>().mesh; var verts = mesh.vertices; var cols = mesh.colors; for (int i = 0; i < mesh.vertexCount; i++) { //float distance = Vector3.Distance(heatPoint.position.normalized, verts[i].normalized); float dist = Mathf.Exp(Vector3.Distance(heatPoint.position, verts[i])); // broken float distance = Remap (dist,0f,3f,0f,1f); if (restoreColor) { cols[i].a = Mathf.Clamp01(cols[i].a-(viewDistance-distance)*Time.deltaTime*fadeSpeed); @@ -47,9 +46,9 @@ void UpdateColor() } mesh.colors = cols; } float Remap(float val, float low1, float high1, float low2, float high2) { return low2 + (val-low1)*(high2-low2)/(high1-low1); } } -
unitycoder created this gist
Mar 24, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ using UnityEngine; using System.Collections; public class Melter : MonoBehaviour { public Transform heatPoint; public bool restoreColor=false; void Start () { var mesh = GetComponent<MeshFilter>().mesh; var verts = mesh.vertices; var cols = mesh.colors; for (int i = 0; i < mesh.vertexCount; i++) { cols[i] = Color.white; } mesh.colors = cols; UpdateColor(); } void Update () { UpdateColor(); } void UpdateColor() { float viewDistance = 1f; float fadeSpeed = 1f; var mesh = GetComponent<MeshFilter>().mesh; var verts = mesh.vertices; var cols = mesh.colors; for (int i = 0; i < mesh.vertexCount; i++) { //float distance = Vector3.Distance(heatPoint.position.normalized, verts[i].normalized); float dist = Mathf.Exp(Vector3.Distance(heatPoint.position, verts[i])); // broken float distance = Remap (dist,0f,3f,0f,1f); if (restoreColor) { cols[i].a = Mathf.Clamp01(cols[i].a-(viewDistance-distance)*Time.deltaTime*fadeSpeed); }else{ cols[i].a = Mathf.Min(cols[i].a,Mathf.Clamp01(cols[i].a-(viewDistance-distance)*Time.deltaTime*fadeSpeed)); } } mesh.colors = cols; } float Remap(float val, float low1, float high1, float low2, float high2) { return low2 + (val-low1)*(high2-low2)/(high1-low1); } }