blog games developers documentation portfolio gallery

More in this category:

SetUpLODLevels()

void GameObject.SetUpLODLevels()
void GameObject.SetUpLODLevels(float maxWeight)
void GameObject.SetUpLODLevels(float[] lodScreenSizes, float[] maxWeights, bool recalcNormals)



Extensions to GameObject.
Convenient interfaces for SetUpLODLevelsWithLODSwitcher.

maxWeight is the level of compression. The higher the value the more compression. It uses 1 as default. When you use this parameter, it will internally use a float array for maxWeights of {0.65f * maxWeight, 1f * maxWeight, 1.5f * maxWeight}

maxWeights is an array of compression values for each LOD level to be generated. The number of elements should be identical to lodScreenSizes. SetUpLODLevels() uses the array {0.65f, 1f, 1.5f} as default
The result of the second LOD mesh using maxWeights {0.5f, 1.1f} is not the same as using maxWeights {1.1f} or maxWeights {0.3f, 0.56, 1.1f}. This is because the original mesh is first compressed with maxWeights[0]. For performance reasons the result of this compression is then compressed with maxWeights[1], etc.

lodScreenSizes is an array of floats that will be copied into the LODSwitcher component. It tells the LODSwitcher when to switch between LOD levels. The number of elements should be the same as maxWeights. SetUpLODLevels uses the array {0.6f, 0.3f, 0.15f} as default.

recalcNormals is a bool that is best set to true unless your original mesh has specific normals that should be left alone.

Examples:

public class Tester : MonoBehaviour {

void OnMouseUpAsButton() {
gameObject.SetUpLODLevels(); // use compression of 1
Debug.Log("This object is now game ready and has 4 LOD levels");
Debug.Log("The relative screen sizes it which the LOD levels switch are 0.6, 0.3 and 0.15");
}
}

public class Tester : MonoBehaviour {

void OnMouseUpAsButton() {
// switch LOD 0 to LOD 1 at relative screen size of 0.6
// switch LOD 1 to LOD 2 at relative screen size of 0.3
// compress the original mesh with 0.5 for LOD1 and 0.9 for LOD 2.
gameObject.SetUpLODLevels(new float[2] {0.6f, 0.3f}, new float[2] {0.5f, 0.9f}, true);

Debug.Log("This object is now game ready and has 3 LOD levels");
Debug.Log("The relative screen sizes at which the LOD levels switch are 0.6 and 0.3");
}
}






follow us