Instantly share code, notes, and snippets.

Embed
What would you like to do?
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