Keep texture centered when extending pipes

(this will be important later)
pull/630/head^2
Andrew Cassidy 5 years ago
parent 46c068f4a7
commit 1ba8caa1ac
No known key found for this signature in database
GPG Key ID: 963017B38FD477A1

@ -27,6 +27,12 @@ namespace Restock
// initial scale of the pipe object, may not be 1
private float baseStretch;
// scale vector for the material
private Vector2 texScale = Vector2.one;
// offset vector for the material
private Vector2 texOffset = Vector2.zero;
public override void OnStart(StartState state)
@ -76,15 +82,17 @@ namespace Restock
// updates the texture stretch to match the pipe object's local scale
private void UpdateStretch()
{
var stretch = line.localScale.z;
var scaleVect = Vector2.one;
scaleVect[pipeStretchIndex] = stretch / baseStretch;
var stretch = line.localScale.z / baseStretch;
texScale[pipeStretchIndex] = stretch;
texOffset[pipeStretchIndex] = (1 - stretch) / 2;
foreach (var material in pipeMaterials)
{
foreach (var id in pipeMaterialIDs)
{
material.SetTextureScale(id, scaleVect);
material.SetTextureScale(id, texScale);
material.SetTextureOffset(id, texOffset);
}
}
}

Loading…
Cancel
Save