Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CPU performance #515

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -543,26 +543,23 @@ void GenerateSubAssets(Subassets subassets, AlembicTreeNode root, AlembicStreamD
void CollectSubAssets(Subassets subassets, AlembicTreeNode node)
{
int submeshCount = 0;
var meshFilter = node.gameObject.GetComponent<MeshFilter>();
if (meshFilter != null)
if (node.gameObject.TryGetComponent<MeshFilter>(out var meshFilter))
{
var m = meshFilter.sharedMesh;
submeshCount = m.subMeshCount;
m.name = node.gameObject.name;
subassets.Add(node.abcObject.abcObject.fullname, m);
}

var renderer = node.gameObject.GetComponent<MeshRenderer>();
if (renderer != null)
if (node.gameObject.TryGetComponent<MeshRenderer>(out var renderer))
{
var mats = new Material[submeshCount];
for (int i = 0; i < submeshCount; ++i)
mats[i] = subassets.defaultMaterial;
renderer.sharedMaterials = mats;
}

var apr = node.gameObject.GetComponent<AlembicPointsRenderer>();
if (apr != null)
if (node.gameObject.TryGetComponent<AlembicPointsRenderer>(out var apr))
{
var cubeGO = GameObject.CreatePrimitive(PrimitiveType.Cube);
apr.InstancedMesh = cubeGO.GetComponent<MeshFilter>().sharedMesh;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void DrawMaterialUI(AlembicImporter importer, bool multiEdit)
{
importer.RemoveRemap(o.ToSourceAssetIdentifier());
}
else if (AssetDatabase.GetAssetPath(assign).ToLower().EndsWith("abc"))
else if (AssetDatabase.GetAssetPath(assign).EndsWith("abc", StringComparison.OrdinalIgnoreCase))
{
Debug.LogError("Materials cannot be remapped to materials bundled with Alembic files.");
}
Expand Down Expand Up @@ -390,7 +390,7 @@ static Material LoadMaterial(string assetName, string[] searchPath)
string.Equals(Path.GetFileNameWithoutExtension(str), assetName,
StringComparison.CurrentCultureIgnoreCase));

if (path == null || path.ToLower().EndsWith("abc")) // we don't want to assign materials from other alembics since these gets recreated on every re-import.
if (path == null || path.EndsWith("abc", StringComparison.OrdinalIgnoreCase)) // we don't want to assign materials from other alembics since these gets recreated on every re-import.
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,7 @@ class MeshCapturer : ComponentCapturer, IDisposable
public override void Setup(Component c)
{
m_target = c as MeshRenderer;
MeshFilter meshFilter = m_target.GetComponent<MeshFilter>();
if (meshFilter == null)
if (!m_target.TryGetComponent<MeshFilter>(out var meshFilter))
{
m_target = null;
return;
Expand Down Expand Up @@ -712,8 +711,7 @@ public override void Setup(Component c)
m_mbuf.SetupSubmeshes(abcObject, mesh);

m_meshSrc = target.sharedMesh;
m_cloth = m_target.GetComponent<Cloth>();
if (m_cloth != null)
if (m_target.TryGetComponent<Cloth>(out m_cloth))
{
m_cbuf = new ClothBuffer();
m_cbuf.rootBone = m_target.rootBone != null ? m_target.rootBone : m_target.GetComponent<Transform>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ internal abstract class AlembicElement : IDisposable

public Camera GetOrAddCamera()
{
var c = abcTreeNode.gameObject.GetComponent<Camera>();
if (c == null)
if (!abcTreeNode.gameObject.TryGetComponent<Camera>(out var c))
{
c = abcTreeNode.gameObject.AddComponent<Camera>();
c.usePhysicalProperties = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ public override void AbcSyncDataEnd()
if (split.host == null)
continue;

var mf = split.host.GetComponent<MeshFilter>();
if (mf != null)
if (split.host.TryGetComponent<MeshFilter>(out var mf))
mf.sharedMesh = split.mesh;
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public override void AbcPrepareSample()
return;
}

var cloud = abcTreeNode.gameObject.GetComponent<AlembicPointsCloud>();
if (cloud != null)
if (abcTreeNode.gameObject.TryGetComponent<AlembicPointsCloud>(out var cloud))
{
m_abcSchema.sort = cloud.m_sort;
if (cloud.m_sort && cloud.m_sortFrom != null)
Expand All @@ -49,8 +48,7 @@ public override void AbcSyncDataBegin()
sample.GetSummary(ref m_sampleSummary);

// get points cloud component
var cloud = abcTreeNode.gameObject.GetComponent<AlembicPointsCloud>();
if (cloud == null)
if (!abcTreeNode.gameObject.TryGetComponent<AlembicPointsCloud>(out var cloud))
{
cloud = abcTreeNode.gameObject.AddComponent<AlembicPointsCloud>();
abcTreeNode.gameObject.AddComponent<AlembicPointsRenderer>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public override void AbcSyncDataEnd()
}
else
{
trans.position = m_abcData.translation;
trans.rotation = m_abcData.rotation;
trans.SetPositionAndRotation(m_abcData.translation, m_abcData.rotation);
trans.localScale = m_abcData.scale;
}
}
Expand Down