Skip to content

Instantly share code, notes, and snippets.

@boformer
Created April 25, 2019 09:19
Show Gist options
  • Save boformer/1c7cf5ab5dddc7929eeb5b2882b3c600 to your computer and use it in GitHub Desktop.
Save boformer/1c7cf5ab5dddc7929eeb5b2882b3c600 to your computer and use it in GitHub Desktop.
Rotating props without PropRotatingParams mod (based on a script by Ronyx69) - Multiple rotating parts
// Warning: Do not save vehicles after running this script without a game restart!
// Prop Rotating Script for multiple rotating parts.
// Control rotation axis, pivot and speed.
// Run in asset editor and see effects in real time.
// The LODs are not rotating, they are like regular props.
// Vertex color blue channel for rotating parts must be 0.
// Non-rotating parts remain vertex color white.
// Google how to do vertex color painting in your 3d software of choice!
// You can have 4 different rotating parts, (0 to 3)
// each needs a different value for vertex color green channel.
// If you are making a clock, set clock value to 1.
// speed for the 12 hour arm is 2,
// for the minute arm it's 24,
// for the second arm it's 1440.
// Part 0 (vertex color green channel = 0)
var axis0 = new Vector3(0.0f, 1.0f, 0.0f); // Set to 1 to choose rotation axis.
var pivot0 = new Vector3(0.0f, 0.0f, 0.0f); // Pivot point - center of rotation.
var speed0 = 1.0f; // Rotations per minute / per day for clocks (negative to reverse direction)
var clock0 = 0.0f; // Set to 1 to tie rotation to game clock.
// Part 1 (vertex color green channel = 64)
var axis1 = new Vector3(0.0f, 1.0f, 0.0f); // Set to 1 to choose rotation axis.
var pivot1 = new Vector3(0.0f, 0.0f, 0.0f); // Pivot point - center of rotation.
var speed1 = 1.0f; // Rotations per minute / per day for clocks (negative to reverse direction)
var clock1 = 0.0f; // Set to 1 to tie rotation to game clock.
// Part 2 (vertex color green channel = 128)
var axis2 = new Vector3(0.0f, 1.0f, 0.0f); // Set to 1 to choose rotation axis.
var pivot2 = new Vector3(0.0f, 0.0f, 0.0f); // Pivot point - center of rotation.
var speed2 = 1.0f; // Rotations per minute / per day for clocks (negative to reverse direction)
var clock2 = 0.0f; // Set to 1 to tie rotation to game clock.
// Part 3 (vertex color green channel = 192)
var axis3 = new Vector3(0.0f, 1.0f, 0.0f); // Set to 1 to choose rotation axis.
var pivot3 = new Vector3(0.0f, 0.0f, 0.0f); // Pivot point - center of rotation.
var speed3 = 1.0f; // Rotations per minute / per day for clocks (negative to reverse direction)
var clock3 = 0.0f; // Set to 1 to tie rotation to game clock.
// --- end of editable values ---
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as PropInfo;
if (asset.m_material == null)
{
Debug.LogError("Asset has no texture, unable to apply params!");
return;
}
asset.m_rollParams = new Vector4[4];
asset.m_rollLocation = new Vector4[4];
asset.m_rollParams[0] = new Vector4(axis0.x, axis0.y, axis0.z, speed0);
asset.m_rollLocation[0] = new Vector4(pivot0.x, pivot0.y, pivot0.z, 1.0f - clock0);
asset.m_rollParams[1] = new Vector4(axis1.x, axis1.y, axis1.z, speed1);
asset.m_rollLocation[1] = new Vector4(pivot1.x, pivot1.y, pivot1.z, 1.0f - clock1);
asset.m_rollParams[2] = new Vector4(axis2.x, axis2.y, axis2.z, speed2);
asset.m_rollLocation[2] = new Vector4(pivot2.x, pivot2.y, pivot2.z, 1.0f - clock2);
asset.m_rollParams[3] = new Vector4(axis3.x, axis3.y, axis3.z, speed3);
asset.m_rollLocation[3] = new Vector4(pivot3.x, pivot3.y, pivot3.z, 1.0f - clock3);
asset.m_material.shader = Shader.Find("Custom/Props/Prop/Rotating");
for (int i = 0; i < 4; i++)
{
asset.m_material.SetVector("_RollParams" + i, asset.m_rollParams[i]);
asset.m_material.SetVector("_RollLocation" + i, asset.m_rollLocation[i]);
}
if (asset.m_lodMaterial != null)
{
asset.m_lodMaterial.shader = Shader.Find("Custom/Props/Prop/Default");
}
asset.m_lodHasDifferentShader = true;
// Tells the asset editor to save _RollParams and _RollLocation shader properties
var vectorProps = Type.GetType("ColossalFramework.Packaging.ShaderUtil, ColossalManaged").GetField("vectorProps").GetValue(null) as string[];
vectorProps[4] = "_RollLocation0";
vectorProps[5] = "_RollParams0";
vectorProps[6] = "_RollLocation1";
vectorProps[7] = "_RollParams1";
vectorProps[8] = "_RollLocation2";
vectorProps[9] = "_RollParams2";
vectorProps[10] = "_RollLocation3";
vectorProps[11] = "_RollParams3";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment