Skip to content

Instantly share code, notes, and snippets.

@ronyx69
Last active May 20, 2018 10:22
Show Gist options
  • Save ronyx69/a66a990c0aaf3ff1e898b826cbf8be38 to your computer and use it in GitHub Desktop.
Save ronyx69/a66a990c0aaf3ff1e898b826cbf8be38 to your computer and use it in GitHub Desktop.
Calculates custom center-outwards tree wind sway with an adjustable multiplier.
// Tree Wind Sway Recalculator (Central)
// Recalculates vertex colors based on the proximity to center.
// Allows limiting sway with an adjustable multiplier.
var sway = 0.2f; // Sway multiplier 0.0 (none) to 1.0 (max)
var bias = 1.6f; // "Contrast" between center and outer parts,
// increasing this will make the middle more static,
// and the outside move more.
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as TreeInfo;
Vector3[] vertices = asset.m_mesh.vertices; Color[] colors = new Color[vertices.Length];
for (int i = 0; i < vertices.Length; i++)
colors[i] = new Color(0f, 0f, 0f, Mathf.Clamp((Mathf.Pow(Mathf.Sqrt(vertices[i].x * vertices[i].x + vertices[i].z * vertices[i].z), bias) / Mathf.Pow(bias, bias) * (sway/Mathf.Pow(bias, bias))), 0.0f, 1.0f));
asset.m_mesh.colors = colors;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment