Skip to content

Instantly share code, notes, and snippets.

@ronyx69
Last active June 8, 2019 14:50
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/ffff7459be346bc807b72b99713bbf9f to your computer and use it in GitHub Desktop.
Save ronyx69/ffff7459be346bc807b72b99713bbf9f to your computer and use it in GitHub Desktop.
Script for creating decals of any size using a premade mesh you can download here: https://drive.google.com/open?id=1hr6l0HO76g3K7tV3At_Brx29-EHxDVAQ (Based on original script by boformer. Added modless shader parameter saving method by boformer.)
// Decal Script (based on original script by boformer)
// (added modless shader parameter saving method by boformer)
//
// Removes the need for making a mesh, just import the provided decal mesh
// and this script will automatically change the size you set.
//
// Warning: Do not save vehicles after running this script without a game restart!
var size = new Vector2(8.0f, 8.0f); // Size of decal in meters - width and length
// (texture width and height will be stretched to match this)
var tile = new Vector3(1.0f, 1.0f); // Tiling amount
var slopeTolerance = -1.0f; // Box mesh height, leave at a negative value to calculate automatically
if (slopeTolerance < 0) slopeTolerance = Mathf.Clamp((size.x + size.y) / 4f, 2f, 32f);
var scale = new Vector4(size.x, slopeTolerance, size.y, 0); var tiling = new Vector4(tile.x, 0, tile.y, 0);
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as PropInfo;
var mesh = asset.m_mesh; var vertices = mesh.vertices; var vertexArray = new Vector3[vertices.Length]; vertices.CopyTo(vertexArray, 0);
for (int i = 0; i < vertices.Length; i++) {
if (vertexArray[i].x > 0) vertexArray[i].x = scale.x / 2f; else vertexArray[i].x = -scale.x / 2f;
if (vertexArray[i].y > 0) vertexArray[i].y = scale.y / 2f; else vertexArray[i].y = -scale.y / 2f;
if (vertexArray[i].z > 0) vertexArray[i].z = scale.z / 2f; else vertexArray[i].z = -scale.z / 2f; }
mesh.vertices = vertexArray; mesh.RecalculateBounds(); asset.CalculateGeneratedInfo();
asset.m_material.shader = Shader.Find("Custom/Props/Decal/Blend");
asset.m_material.SetVector("_DecalSize", scale); asset.m_material.SetVector("_DecalTiling", tiling);
asset.m_lodMesh = null; asset.m_lodMaterial = null; asset.m_lodRenderDistance = 1000;
typeof(PropInfo).GetField("m_UIEditorCategory", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(asset, "PropsResidentialGroundTiles");
asset.m_createRuining = false; asset.m_useColorVariations = false;
var vectorProps= Type.GetType("ColossalFramework.Packaging.ShaderUtil, ColossalManaged").GetField("vectorProps").GetValue(null) as string[];
vectorProps[4]="_DecalSize"; vectorProps[5]="_DecalTiling";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment