Skip to content

Instantly share code, notes, and snippets.

@boformer
Last active April 8, 2019 13:54
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 boformer/a788e8ab428bf7ced2361ace33fd36ef to your computer and use it in GitHub Desktop.
Save boformer/a788e8ab428bf7ced2361ace33fd36ef to your computer and use it in GitHub Desktop.
Change building lod distance script
// Change the LOD distance of building assets. Run this script while the building is loaded in asset editor, then save the building
// It basically "fakes" a mesh in the basement, adds something to the building bounds in negative direction.
// The game thinks that the asset is bigger and gives it a higher LOD distance
// maximum support value is 1000f, minimum is 250f
var lodRenderDistance = 1000f;
// --- end of editable values ---
var prefab = ToolsModifierControl.toolController.m_editPrefabInfo as BuildingInfo;
prefab.CalculateGeneratedInfo();
var targetF = (Mathf.Clamp(lodRenderDistance, 250f, 1000f) - 200f) / (1.41421354f * 10);
targetF *= targetF;
var size = prefab.m_generatedInfo.m_max - prefab.m_generatedInfo.m_min;
var targetHeight = (targetF - size.x * size.z) / (size.x + size.z);
var height = size.y;
Debug.Log("targetHeight: " + targetHeight + ", height: " + height);
if (targetHeight > height)
{
Debug.Log("Previous minY: " + prefab.m_generatedInfo.m_min.y);
prefab.m_generatedInfo.m_min.y -= (targetHeight - height);
Debug.Log("New minY: " + prefab.m_generatedInfo.m_min.y);
var newSize = prefab.m_generatedInfo.m_max - prefab.m_generatedInfo.m_min;
float num = RenderManager.LevelOfDetailFactor * 10f;
float f = newSize.x * newSize.z + newSize.x * newSize.y + newSize.z * newSize.y;
var newMinLodDistance = Mathf.Min(1000f, Mathf.Sqrt(f) * num + 200f);
Debug.Log("newMinLodDistance: " + newMinLodDistance + ", newSize: " + newSize);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment