mirror of
https://github.com/PorktoberRevolution/ReStocked
synced 2024-09-01 17:34:42 +00:00
parent
ea39b490a3
commit
75b05e96fe
Binary file not shown.
@ -5,30 +5,28 @@ namespace Restock
|
||||
{
|
||||
public class ModuleRestockLaunchClamp : LaunchClamp
|
||||
{
|
||||
[KSPField] public string trf_towerGirder_name = "";
|
||||
[KSPField] public string trf_towerYoke_name = "";
|
||||
|
||||
[KSPField] public Transform towerPivot;
|
||||
[KSPField] public Transform towerYoke;
|
||||
[KSPField] public Transform towerAnchor;
|
||||
[KSPField] public Transform towerGirder;
|
||||
[KSPField] public Transform towerStretch;
|
||||
[KSPField] public int maxSegments = 100;
|
||||
|
||||
private bool _flightUpdate = false;
|
||||
private Material _girderMaterial;
|
||||
private Matrix4x4[] _girderMatrices;
|
||||
private Mesh _girderMesh;
|
||||
|
||||
private int _girderSegments;
|
||||
private Matrix4x4[] _girderMatrices;
|
||||
[KSPField] public int maxSegments = 100;
|
||||
[KSPField] public Transform towerAnchor;
|
||||
[KSPField] public Transform towerGirder;
|
||||
|
||||
[KSPField] public Transform towerPivot;
|
||||
[KSPField] public Transform towerStretch;
|
||||
[KSPField] public Transform towerYoke;
|
||||
[KSPField] public string trf_towerGirder_name = "";
|
||||
[KSPField] public string trf_towerYoke_name = "";
|
||||
|
||||
public override void OnLoad(ConfigNode node)
|
||||
{
|
||||
towerPivot = base.part.FindModelTransform(trf_towerPivot_name);
|
||||
towerYoke = base.part.FindModelTransform(trf_towerYoke_name);
|
||||
towerAnchor = base.part.FindModelTransform(trf_anchor_name);
|
||||
towerGirder = base.part.FindModelTransform(trf_towerGirder_name);
|
||||
towerStretch = base.part.FindModelTransform(trf_towerStretch_name);
|
||||
towerPivot = part.FindModelTransform(trf_towerPivot_name);
|
||||
towerYoke = part.FindModelTransform(trf_towerYoke_name);
|
||||
towerAnchor = part.FindModelTransform(trf_anchor_name);
|
||||
towerGirder = part.FindModelTransform(trf_towerGirder_name);
|
||||
towerStretch = part.FindModelTransform(trf_towerStretch_name);
|
||||
|
||||
base.OnLoad(node);
|
||||
}
|
||||
@ -51,41 +49,33 @@ namespace Restock
|
||||
{
|
||||
this.LogError("Could not enable instancing! Aborting");
|
||||
_girderSegments = -1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void LateUpdate()
|
||||
{
|
||||
|
||||
if (_girderSegments < 0) return;
|
||||
|
||||
if (!HighLogic.LoadedSceneIsEditor)
|
||||
{
|
||||
if (_flightUpdate) return;
|
||||
else _flightUpdate = true;
|
||||
}
|
||||
var height = HighLogic.LoadedSceneIsEditor ? towerStretch.position.y : this.height;
|
||||
var initialHeight = this.initialHeight;
|
||||
|
||||
var height1 = HighLogic.LoadedSceneIsEditor ? towerStretch.position.y : base.height;
|
||||
var initialHeight1 = base.initialHeight;
|
||||
|
||||
towerAnchor.position = towerStretch.position - (towerStretch.up * height1);
|
||||
towerAnchor.position = towerStretch.position - towerStretch.up * height;
|
||||
|
||||
var vec1 = Vector3.down;
|
||||
var vec2 = towerAnchor.localPosition - towerYoke.localPosition;
|
||||
towerYoke.localRotation = Quaternion.FromToRotation(vec1, vec2);
|
||||
|
||||
_girderSegments = Mathf.CeilToInt(height1 / base.initialHeight);
|
||||
_girderSegments = Mathf.CeilToInt(height / this.initialHeight);
|
||||
_girderSegments = Math.Min(_girderSegments, maxSegments);
|
||||
_girderSegments = Math.Max(_girderSegments, 0);
|
||||
|
||||
var matrix = towerGirder.localToWorldMatrix;
|
||||
var offset = Matrix4x4.Translate(matrix.MultiplyVector(Vector3.down * base.initialHeight));
|
||||
var offset = Matrix4x4.Translate(towerGirder.TransformVector(Vector3.down * initialHeight));
|
||||
|
||||
for (int i = 0; i < _girderSegments; i++)
|
||||
for (var i = 0; i < _girderSegments; i++)
|
||||
{
|
||||
_girderMatrices[i] = matrix;
|
||||
matrix *= offset;
|
||||
matrix = offset * matrix;
|
||||
}
|
||||
|
||||
Graphics.DrawMeshInstanced(_girderMesh, 0, _girderMaterial, _girderMatrices, _girderSegments, part.mpb);
|
||||
|
Loading…
Reference in New Issue
Block a user