Click or drag to resize

MeshesRescaleTextureToLength Method

Rescales texture so what one sample covers exactly one unit of the primitive length.

Namespace:  KSPDev.ModelUtils
Assembly:  KSPDev_Utils.2.5 (in KSPDev_Utils.2.5.dll) Version: 2.5 for KSP v1
Syntax
C#
public static void RescaleTextureToLength(
	GameObject obj,
	float lengthUnit = 1f,
	Renderer renderer = null
)
Request Example View Source

Parameters

obj
Type: UnityEngineGameObject
Game object to adjust material on. Z axis scale gives the length.
lengthUnit (Optional)
Type: SystemSingle
Length to be completely covered by one sample of the texture.
renderer (Optional)
Type: UnityEngineRenderer
Specific renderer to adjust texture in. If null then first renderer on the object will be updated. Note, that getting renderer from the object is an expensive operation. When performance is the key it makes sense caching the renderer, and passing it in every rescale call.
Remarks

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.

See Also