mirror of
https://github.com/PorktoberRevolution/ReStocked
synced 2024-09-01 17:34:42 +00:00
Always use fallback launch clamp implementation in flight
Instanced rendering doesnt work with lighting correctly in Unity, so we cant use it in the flight scene.
This commit is contained in:
parent
b4d446a9b8
commit
6153434179
Binary file not shown.
@ -32,6 +32,8 @@ namespace Restock
|
||||
private List<Color32> _girderColors;
|
||||
private List<int> _girderTris;
|
||||
|
||||
private bool _girderFlightUpdated = false;
|
||||
|
||||
private bool _girderHasTangents = false;
|
||||
private bool _girderHasColors = false;
|
||||
private int _girderVertCount;
|
||||
@ -51,10 +53,11 @@ namespace Restock
|
||||
this.LogWarning("You are using a computer which does not support instancing, " +
|
||||
"falling back to a slower launch clamp implementation");
|
||||
instancingEnabled = false;
|
||||
girderMesh = towerGirder.GetComponent<MeshFilter>().mesh;
|
||||
girderSegmentMesh = Instantiate<Mesh>(girderMesh);
|
||||
}
|
||||
|
||||
girderMesh = towerGirder.GetComponent<MeshFilter>().mesh;
|
||||
girderSegmentMesh = Instantiate<Mesh>(girderMesh);
|
||||
|
||||
base.OnLoad(node);
|
||||
}
|
||||
|
||||
@ -64,7 +67,7 @@ namespace Restock
|
||||
|
||||
girderMesh = towerGirder.GetComponent<MeshFilter>().mesh;
|
||||
|
||||
if (instancingEnabled)
|
||||
if (instancingEnabled && HighLogic.LoadedSceneIsEditor)
|
||||
{
|
||||
var girderRenderer = towerGirder.GetComponent<MeshRenderer>();
|
||||
girderRenderer.enabled = false; // we'll render manually from now on
|
||||
@ -76,7 +79,6 @@ namespace Restock
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Log("Instancing is disabled, setting up fallback");
|
||||
_girderVertCount = girderSegmentMesh.vertexCount;
|
||||
_girderTriCount = girderSegmentMesh.triangles.Length;
|
||||
|
||||
@ -115,13 +117,22 @@ namespace Restock
|
||||
girderSegments = Math.Min(girderSegments, maxSegments);
|
||||
girderSegments = Math.Max(girderSegments, 0);
|
||||
|
||||
if (instancingEnabled)
|
||||
{
|
||||
UpdateGirder(girderSegments);
|
||||
if (HighLogic.LoadedSceneIsEditor){
|
||||
if (instancingEnabled)
|
||||
{
|
||||
UpdateGirder(girderSegments);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateGirderFallback(girderSegments);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_girderFlightUpdated) return;
|
||||
|
||||
UpdateGirderFallback(girderSegments);
|
||||
_girderFlightUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,12 +147,12 @@ namespace Restock
|
||||
matrix = offset * matrix;
|
||||
}
|
||||
|
||||
Graphics.DrawMeshInstanced(girderMesh, 0, _girderMaterial, _girderMatrices, girderSegments, part.mpb);
|
||||
Graphics.DrawMeshInstanced(girderMesh, 0, _girderMaterial, _girderMatrices, girderSegments, part.mpb,
|
||||
UnityEngine.Rendering.ShadowCastingMode.On, true, towerGirder.gameObject.layer);
|
||||
}
|
||||
|
||||
private void UpdateGirderFallback(int newGirderSegments)
|
||||
{
|
||||
|
||||
if (newGirderSegments == _girderSegments) return;
|
||||
|
||||
if (newGirderSegments > _girderSegments)
|
||||
@ -177,7 +188,8 @@ namespace Restock
|
||||
if (_girderHasTangents) _girderTangents.RemoveRange(startIndex, count);
|
||||
if (_girderHasColors) _girderColors.RemoveRange(startIndex, count);
|
||||
|
||||
_girderTris.RemoveRange(newGirderSegments * _girderTriCount, (_girderSegments - newGirderSegments) * _girderTriCount);
|
||||
_girderTris.RemoveRange(newGirderSegments * _girderTriCount,
|
||||
(_girderSegments - newGirderSegments) * _girderTriCount);
|
||||
}
|
||||
|
||||
girderMesh.Clear();
|
||||
|
Loading…
Reference in New Issue
Block a user