Skip to content

Instantly share code, notes, and snippets.

@ronyx69
Last active July 4, 2018 07:33
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/18486e905c4ddf50ce14cafbd9c55ba0 to your computer and use it in GitHub Desktop.
Save ronyx69/18486e905c4ddf50ce14cafbd9c55ba0 to your computer and use it in GitHub Desktop.
Change parameters for the WindTurbine shader in asset editor or preview ingame.
// Wind Turbine Scripts
// Control wind turbine pivot, rotation mode, blade speed.
// Use the wind turbine template when importing!
// Vertex Colors
// Parts of the mesh must be vertex painted accordingly:
//
// The red channel controls turbine body rotation.
// The green channel controls blade rotation.
// The blue channel does not affect the animation. It may affect snow, not tested by me.
//
// For static parts vertex colors are 255, 255, 255. (white)
// For body rotation the red channel needs to be 0. (green or cyan)
// For blade rotation the green channel needs to be 0. (red or magenta)
// For blades attached to the body the red and green channels need to be 0. (blue or black)
// Wind Turbine Script
// Asset Editor (blade rotation may not be visible in asset editor)
var pivot = new Vector3(0.0f, 62.1f, 0.0f); // Pivot point of the rotation
var mode = 1; // Main body rotation: 0 = None, 1 = Wind, 2 = Constant (can't control speed)
var speed = 3.0f; // Speed of the blades.
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as BuildingInfo;
asset.m_material.SetVector("_WindAnimation", new Vector4(pivot.x, pivot.y, pivot.z, 0f));
asset.m_lodMaterial.SetVector("_WindAnimation", new Vector4(pivot.x, pivot.y, pivot.z, 0f));
var wb = new Vector4(0f, 0f, 0f, speed);
if(mode==1) wb.x=1.0f; else if(mode==2) wb.y=1.0f;
asset.m_material.SetVector("_WindAnimationB", wb);
asset.m_lodMaterial.SetVector("_WindAnimationB", wb);
// Wind Turbine Script
// InGame Preview
// NAME FORMATTING:
// VANILLA: name
// LOCAL: filename.Asset Name_Data
// WORKSHOP: steamid.Asset Name_Data
var assetname = "wind1.wind1_Data";
var pivot = new Vector3(0.0f, 62.1f, 0.0f); // Pivot point of the rotation
var mode = 1; // Main body rotation: 0 = None, 1 = Wind, 2 = Constant (can't control speed)
var speed = 3.0f; // Speed of the blades.
var asset = PrefabCollection<BuildingInfo>.FindLoaded(assetname);
asset.m_material.SetVector("_WindAnimation", new Vector4(pivot.x, pivot.y, pivot.z, 0f));
asset.m_lodMaterial.SetVector("_WindAnimation", new Vector4(pivot.x, pivot.y, pivot.z, 0f));
asset.m_lodMaterialCombined.SetVector("_WindAnimation", new Vector4(pivot.x, pivot.y, pivot.z, 0f));
var wb = new Vector4(0f, 0f, 0f, speed);
if(mode==1) wb.x=1.0f; else if(mode==2) wb.y=1.0f;
asset.m_material.SetVector("_WindAnimationB", wb);
asset.m_lodMaterial.SetVector("_WindAnimationB", wb);
asset.m_lodMaterialCombined.SetVector("_WindAnimationB", wb);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment