Skip to content

Commit

Permalink
Fix assembly meshes regression
Browse files Browse the repository at this point in the history
FindModelComponents only finds meshes in the part, not in the assembly.
Go thru all the children to collect the meshes. Old implementation had a
bug anyways: same meshes could get collected multiple times.
  • Loading branch information
ihsoft committed May 24, 2016
1 parent b18e376 commit 2bbf14c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions Plugins/Source/KISAddonPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ private static void CollectMeshesFromAssembly(Part assembly,
// Always use world transformation from the root.
var rootWorldTransform = worldTransform ?? assembly.transform.localToWorldMatrix.inverse;

// This gives part's mesh(es) and all surface attached children part meshes.
// Get all meshes from the part's model.
MeshFilter[] meshFilters = assembly.FindModelComponents<MeshFilter>();
if (meshFilters.Length > 0) {
Logger.logInfo("Found {0} children meshes in: {1}", meshFilters.Length, assembly);
Expand All @@ -703,7 +703,8 @@ private static void CollectMeshesFromAssembly(Part assembly,
}
}

// Skinned meshes are only availabe via the renderers.
// Skinned meshes are baked on every frame before rendering. Bake them to get current mesh
// state.
var skinnedMeshRenderers = assembly.FindModelComponents<SkinnedMeshRenderer>();
if (skinnedMeshRenderers.Length > 0) {
Logger.logInfo("Found {0} skinned meshes in: {1}", skinnedMeshRenderers.Length, assembly);
Expand All @@ -715,12 +716,10 @@ private static void CollectMeshesFromAssembly(Part assembly,
meshCombines.Add(combine);
}
}
// Go thru the stacked children parts. They don't have local transformation.

// Collect meshes from the children parts.
foreach (Part child in assembly.children) {
if (child.transform.position.Equals(child.transform.localPosition)) {
CollectMeshesFromAssembly(child, meshCombines, worldTransform: rootWorldTransform);
}
CollectMeshesFromAssembly(child, meshCombines, worldTransform: rootWorldTransform);
}
}
}
Expand Down

0 comments on commit 2bbf14c

Please sign in to comment.