diff --git a/.gitignore b/.gitignore index 41000c67a..829e6f1e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -bin +// ignore pattern for files so some can be unignored later +**/bin/**/*.* obj *.mdb @@ -17,3 +18,6 @@ releasing .mypy* *.json *.pyc + +// unignore Debug build DLLs +!bin/[Dd]ebug/[Ff]erram*.dll diff --git a/FerramAerospaceResearch/FARPartGeometry/GeometryPartModule.cs b/FerramAerospaceResearch/FARPartGeometry/GeometryPartModule.cs index 328d5e461..2246e6fee 100644 --- a/FerramAerospaceResearch/FARPartGeometry/GeometryPartModule.cs +++ b/FerramAerospaceResearch/FARPartGeometry/GeometryPartModule.cs @@ -43,6 +43,8 @@ You should have received a copy of the GNU General Public License */ using System; +using System.Text; +using System.Diagnostics; using System.Collections.Generic; using System.Reflection; using System.Threading; @@ -129,6 +131,96 @@ public bool Valid bool forceUseMeshes; [SerializeField] bool ignoreForMainAxis; + [SerializeField] + List ignoredTransforms, + unignoredTransforms; + [SerializeField] + bool ignoreIfNoRenderer; + +#if DEBUG + class DebugInfoBuilder + { + public List meshes, colliders, noRenderer; + + public DebugInfoBuilder() + { + meshes = new List(); + colliders = new List(); + noRenderer = new List(); + } + + public void Clear() + { + meshes.Clear(); + colliders.Clear(); + noRenderer.Clear(); + } + + public void Print(Part p) + { + StringBuilder sb = new StringBuilder(); + sb.Append($"{p.name} - mesh build info:"); + if (meshes.Count > 0) + { + sb.Append("\n Meshes: "); + sb.Append(string.Join(", ", meshes.ToArray())); + } + if (colliders.Count > 0) + { + sb.Append("\n Colliders: "); + sb.Append(string.Join(", ", colliders.ToArray())); + } + if (noRenderer.Count > 0) + { + sb.Append("\n No renderer found: "); + sb.Append(string.Join(", ", noRenderer.ToArray())); + } + FARLogger.Debug(sb.ToStringAndRelease()); + } + } + DebugInfoBuilder m_debugInfo = new DebugInfoBuilder(); +#endif + + [Conditional("DEBUG")] + private void DebugAddMesh(Transform t) + { +#if DEBUG + m_debugInfo.meshes.Add(t.name); +#endif + } + + [Conditional("DEBUG")] + private void DebugAddCollider(Transform t) + { +#if DEBUG + m_debugInfo.colliders.Add(t.name); +#endif + } + + [Conditional("DEBUG")] + private void DebugAddNoRenderer(Transform t) + { +#if DEBUG + m_debugInfo.noRenderer.Add(t.name); +#endif + } + + [Conditional("DEBUG")] + private void DebugClear() + { +#if DEBUG + m_debugInfo.Clear(); +#endif + } + + [Conditional("DEBUG")] + private void DebugPrint() + { +#if DEBUG + m_debugInfo.Print(part); +#endif + } + public bool IgnoreForMainAxis { @@ -220,6 +312,7 @@ internal void RebuildAllMeshData() partTransform = part.partTransform; List meshTransforms = part.PartModelTransformList(); + meshTransforms.RemoveAll(IgnoredPredicate); List geometryMeshes = CreateMeshListFromTransforms(ref meshTransforms); meshDataList = new List(); @@ -254,6 +347,11 @@ internal void RebuildAllMeshData() //overallMeshBounds = part.GetPartOverallMeshBoundsInBasis(worldToVesselMatrix); } + private bool IgnoredPredicate(Transform t) + { + return ignoredTransforms.Contains(t.name); + } + private Bounds SetBoundsFromMeshes() { Vector3 upper = Vector3.one * float.NegativeInfinity, lower = Vector3.one * float.PositiveInfinity; @@ -650,7 +748,7 @@ private MeshData GetColliderMeshData(Transform t) return null; } - private MeshData GetVisibleMeshData(Transform t, bool onlyMeshes) + private MeshData GetVisibleMeshData(Transform t, bool skipIfNoRenderer, bool onlyMeshes) { Mesh m = null; MeshFilter mf = t.GetComponent(); @@ -660,6 +758,24 @@ private MeshData GetVisibleMeshData(Transform t, bool onlyMeshes) if (mf != null) { + if (skipIfNoRenderer && !unignoredTransforms.Contains(t.name)) + { + MeshRenderer mr = t.GetComponent(); + if (mr == null) + { + DebugAddNoRenderer(t); + return null; + } + } +#if DEBUG + else + { + MeshRenderer mr = t.GetComponent(); + if (mr == null) + DebugAddNoRenderer(t); + } +#endif + m = mf.sharedMesh; //MeshRenderer mr = t.GetComponent(); @@ -693,6 +809,7 @@ private MeshData GetVisibleMeshData(Transform t, bool onlyMeshes) private List CreateMeshListFromTransforms(ref List meshTransforms) { + DebugClear(); List meshList = new List(); List validTransformList = new List(); @@ -721,6 +838,7 @@ private List CreateMeshListFromTransforms(ref List meshTran if (md == null) continue; + DebugAddCollider(t); meshList.Add(md); validTransformList.Add(t); cantUseColliders = false; @@ -746,10 +864,11 @@ private List CreateMeshListFromTransforms(ref List meshTran if (t.gameObject.activeInHierarchy == false) continue; - MeshData md = GetVisibleMeshData(t, false); + MeshData md = GetVisibleMeshData(t, ignoreIfNoRenderer, false); if (md == null) continue; + DebugAddMesh(t); meshList.Add(md); validTransformList.Add(t); } @@ -761,10 +880,11 @@ private List CreateMeshListFromTransforms(ref List meshTran { if (jettisonTransforms.Contains(t)) continue; - MeshData md = GetVisibleMeshData(t, false); + MeshData md = GetVisibleMeshData(t, ignoreIfNoRenderer, false); if (md == null) continue; + DebugAddMesh(t); meshList.Add(md); validTransformList.Add(t); } @@ -777,15 +897,17 @@ private List CreateMeshListFromTransforms(ref List meshTran { foreach (Transform t in meshTransforms) { - MeshData md = GetVisibleMeshData(t, false); + MeshData md = GetVisibleMeshData(t, ignoreIfNoRenderer, false); if (md == null) continue; + DebugAddMesh(t); meshList.Add(md); validTransformList.Add(t); } } } + DebugPrint(); meshTransforms = validTransformList; return meshList; } @@ -877,21 +999,39 @@ public void Rescale(Vector3 relativeRescaleFactor) public override void OnLoad(ConfigNode node) { base.OnLoad(node); - if(node.HasValue("forceUseColliders")) + LoadBool(node, "forceUseColliders", out forceUseColliders); + LoadBool(node, "forceUseMeshes", out forceUseMeshes); + LoadBool(node, "ignoreForMainAxis", out ignoreForMainAxis); + LoadBool(node, "ignoreIfNoRenderer", out ignoreIfNoRenderer); + ignoredTransforms = LoadList(node, "ignoreTransform"); + unignoredTransforms = LoadList(node, "unignoreTransform"); + } + + private void LoadBool(ConfigNode node, string name, out bool value) + { + if (node.HasValue(name)) { - bool.TryParse(node.GetValue("forceUseColliders"), out forceUseColliders); + bool.TryParse(node.GetValue(name), out value); _ready = false; } - if (node.HasValue("forceUseMeshes")) + else { - bool.TryParse(node.GetValue("forceUseMeshes"), out forceUseMeshes); - _ready = false; + value = false; } - if(node.HasValue("ignoreForMainAxis")) + } + + private List LoadList(ConfigNode node, string name) + { + var list = new List(); + if (node.HasValue(name)) { - bool.TryParse(node.GetValue("ignoreForMainAxis"), out ignoreForMainAxis); + foreach (string _name in node.GetValues(name)) + { + list.Add(_name); + } _ready = false; } + return list; } } } diff --git a/FerramAerospaceResearch/FerramAerospaceResearch.csproj b/FerramAerospaceResearch/FerramAerospaceResearch.csproj index 6b43ddb17..cd8a5ad33 100644 --- a/FerramAerospaceResearch/FerramAerospaceResearch.csproj +++ b/FerramAerospaceResearch/FerramAerospaceResearch.csproj @@ -19,7 +19,7 @@ true full false - bin\Debug\ + $(SolutionDir)bin\$(Configuration)\ DEBUG;TRACE prompt 4 @@ -29,7 +29,7 @@ pdbonly true - bin\Release\ + $(SolutionDir)bin\$(Configuration)\ TRACE;INFO prompt 4 diff --git a/GameData/FerramAerospaceResearch/FARVoxelGeometryOverrides.cfg b/GameData/FerramAerospaceResearch/FARVoxelGeometryOverrides.cfg index 772baf0e3..1b0bb4ed1 100644 --- a/GameData/FerramAerospaceResearch/FARVoxelGeometryOverrides.cfg +++ b/GameData/FerramAerospaceResearch/FARVoxelGeometryOverrides.cfg @@ -85,3 +85,40 @@ %ignoreForMainAxis = True } } + +// Ignore transforms without attached MeshRenderer +@PART[HeatShield0]:AFTER[FerramAerospaceResearch] +{ + @MODULE[GeometryPartModule] + { + %ignoreIfNoRenderer = true + } +} +@PART[HeatShield1]:AFTER[FerramAerospaceResearch] +{ + @MODULE[GeometryPartModule] + { + %ignoreIfNoRenderer = true + } +} +@PART[HeatShield2]:AFTER[FerramAerospaceResearch] +{ + @MODULE[GeometryPartModule] + { + %ignoreIfNoRenderer = true + } +} +@PART[HeatShield3]:AFTER[FerramAerospaceResearch] +{ + @MODULE[GeometryPartModule] + { + %ignoreIfNoRenderer = true + } +} +@PART[HeatShield1p5]:AFTER[FerramAerospaceResearch] +{ + @MODULE[GeometryPartModule] + { + %ignoreIfNoRenderer = true + } +} diff --git a/GameData/FerramAerospaceResearch/Plugins/FerramAerospaceResearch.dll b/GameData/FerramAerospaceResearch/Plugins/FerramAerospaceResearch.dll index a5f4b3c1f..a93f7f899 100644 Binary files a/GameData/FerramAerospaceResearch/Plugins/FerramAerospaceResearch.dll and b/GameData/FerramAerospaceResearch/Plugins/FerramAerospaceResearch.dll differ diff --git a/README.md b/README.md index 91f15ed51..7217d987c 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,12 @@ CHANGELOG ======================================================= -------------------master branch------------------- +Fixed voxelization of simple heat shields ([#37](https://github.com/dkavolis/Ferram-Aerospace-Research/pull/37)) +Added additional nodes to `GeometryPartModule` ([#37](https://github.com/dkavolis/Ferram-Aerospace-Research/pull/37), see PR for more details): +* `ignoreTransform` (string) +* `ignoreIfNoRenderer` (bool) +* `unignoreTransform` (string) + NRE fixes ([#36](https://github.com/dkavolis/Ferram-Aerospace-Research/pull/36)): * Trying to display debug voxels with no parts in the editor * Occasional NRE when voxelizing vehicle (due to race conditions?) diff --git a/bin/Debug/FerramAerospaceResearch.dll b/bin/Debug/FerramAerospaceResearch.dll new file mode 100644 index 000000000..b317eda66 Binary files /dev/null and b/bin/Debug/FerramAerospaceResearch.dll differ diff --git a/bin/Debug/ferramGraph.dll b/bin/Debug/ferramGraph.dll new file mode 100644 index 000000000..9f6611948 Binary files /dev/null and b/bin/Debug/ferramGraph.dll differ