MeshesRescaleTextureToLength Method |
Namespace: KSPDev.ModelUtils
public static void RescaleTextureToLength( GameObject obj, float lengthUnit = 1f, Renderer renderer = null )
Normally one texture sample covers the whole primitive regardless to its length. By calling this method you ensure that one sample keeps its ratio comparing to a linear unit. If primitive is too short to fit the texture then the texture is truncated. If primitive is too long to be covered by one sample then the texture will be tiled to fill the space.
This methods assumes UV data on the primitive was created for a length of 1m. With this assumption in mind the Z axis of the local scale is considered "the length". CreatePrimitive(PrimitiveType, Vector3, Material, Transform) method guarantees that newly created primitive always has length of one meter but if primitive was created by other means its default length can be different.