Skip to content

Instantly share code, notes, and snippets.

@ronyx69
Created November 24, 2018 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronyx69/0d4c484118aa32407cfc75c2e1b5a4d7 to your computer and use it in GitHub Desktop.
Save ronyx69/0d4c484118aa32407cfc75c2e1b5a4d7 to your computer and use it in GitHub Desktop.
Use static rotors shader sub meshes on vehicles for glass.
// Rotors Shader for Vehicle Glass
// Limited to 32 vertices per sub mesh.
// All vertex normals should be straight on the chosen axis.
var subMesh = 1; // vehicle sub mesh id starting from 1, as seen in the asset editor ui
var axis = "y"; // axis explanations:
// x - facing to the side, spins like a wheel
// y - facing up or down, spins like a heli propeller
// z - facing forward or backward, spins like a plane propeller, requires Rotors FlipXZ mod
var sm = (ToolsModifierControl.toolController.m_editPrefabInfo as VehicleInfo).m_subMeshes[subMesh].m_subInfo;
sm.m_material.shader = Shader.Find("Custom/Vehicles/Vehicle/Rotors");
var v = sm.m_mesh.vertices; byte b = 255; if (axis == "y") b = 0;
if (axis == "z") sm.m_UIPriority = 120122; Color[] colors = new Color[v.Length];
for (int i = 0; i < v.Length; i++) colors[i] = new Color32(128, (byte)(i*8), b, 255);
sm.m_mesh.colors = colors; Vector4[] tyres = new Vector4[v.Length];
for (int i = 0; i < v.Length; i++) tyres[i] = new Vector4(v[i].x, v[i].y, v[i].z, 0);
sm.m_generatedInfo.m_tyres = tyres; sm.m_mesh.RecalculateTangents(); sm.m_material.name = "rotsm-"+axis+"-"+subMesh;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment