Skip to content

Commit

Permalink
Merge pull request #37 from dkavolis/geom_transforms
Browse files Browse the repository at this point in the history
Additional nodes for GeometryPartModule
  • Loading branch information
dkavolis authored Apr 4, 2019
2 parents 48e992e + 0786d93 commit cdb2a11
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 14 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin
// ignore pattern for files so some can be unignored later
**/bin/**/*.*
obj

*.mdb
Expand All @@ -17,3 +18,6 @@ releasing
.mypy*
*.json
*.pyc

// unignore Debug build DLLs
!bin/[Dd]ebug/[Ff]erram*.dll
162 changes: 151 additions & 11 deletions FerramAerospaceResearch/FARPartGeometry/GeometryPartModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -129,6 +131,96 @@ public bool Valid
bool forceUseMeshes;
[SerializeField]
bool ignoreForMainAxis;
[SerializeField]
List<string> ignoredTransforms,
unignoredTransforms;
[SerializeField]
bool ignoreIfNoRenderer;

#if DEBUG
class DebugInfoBuilder
{
public List<string> meshes, colliders, noRenderer;

public DebugInfoBuilder()
{
meshes = new List<string>();
colliders = new List<string>();
noRenderer = new List<string>();
}

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
{
Expand Down Expand Up @@ -220,6 +312,7 @@ internal void RebuildAllMeshData()

partTransform = part.partTransform;
List<Transform> meshTransforms = part.PartModelTransformList();
meshTransforms.RemoveAll(IgnoredPredicate);
List<MeshData> geometryMeshes = CreateMeshListFromTransforms(ref meshTransforms);

meshDataList = new List<GeometryMesh>();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<MeshFilter>();
Expand All @@ -660,6 +758,24 @@ private MeshData GetVisibleMeshData(Transform t, bool onlyMeshes)

if (mf != null)
{
if (skipIfNoRenderer && !unignoredTransforms.Contains(t.name))
{
MeshRenderer mr = t.GetComponent<MeshRenderer>();
if (mr == null)
{
DebugAddNoRenderer(t);
return null;
}
}
#if DEBUG
else
{
MeshRenderer mr = t.GetComponent<MeshRenderer>();
if (mr == null)
DebugAddNoRenderer(t);
}
#endif

m = mf.sharedMesh;

//MeshRenderer mr = t.GetComponent<MeshRenderer>();
Expand Down Expand Up @@ -693,6 +809,7 @@ private MeshData GetVisibleMeshData(Transform t, bool onlyMeshes)

private List<MeshData> CreateMeshListFromTransforms(ref List<Transform> meshTransforms)
{
DebugClear();
List<MeshData> meshList = new List<MeshData>();
List<Transform> validTransformList = new List<Transform>();

Expand Down Expand Up @@ -721,6 +838,7 @@ private List<MeshData> CreateMeshListFromTransforms(ref List<Transform> meshTran
if (md == null)
continue;

DebugAddCollider(t);
meshList.Add(md);
validTransformList.Add(t);
cantUseColliders = false;
Expand All @@ -746,10 +864,11 @@ private List<MeshData> CreateMeshListFromTransforms(ref List<Transform> 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);
}
Expand All @@ -761,10 +880,11 @@ private List<MeshData> CreateMeshListFromTransforms(ref List<Transform> 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);
}
Expand All @@ -777,15 +897,17 @@ private List<MeshData> CreateMeshListFromTransforms(ref List<Transform> 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;
}
Expand Down Expand Up @@ -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<string> LoadList(ConfigNode node, string name)
{
var list = new List<string>();
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;
}
}
}
4 changes: 2 additions & 2 deletions FerramAerospaceResearch/FerramAerospaceResearch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>$(SolutionDir)bin\$(Configuration)\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand All @@ -29,7 +29,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<OutputPath>$(SolutionDir)bin\$(Configuration)\</OutputPath>
<DefineConstants>TRACE;INFO</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand Down
37 changes: 37 additions & 0 deletions GameData/FerramAerospaceResearch/FARVoxelGeometryOverrides.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Binary file not shown.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down
Binary file added bin/Debug/FerramAerospaceResearch.dll
Binary file not shown.
Binary file added bin/Debug/ferramGraph.dll
Binary file not shown.

0 comments on commit cdb2a11

Please sign in to comment.