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

Adding ability to get vertex count and triangle count from model load #500

Merged
merged 2 commits into from
Oct 7, 2019
Merged
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
1 change: 1 addition & 0 deletions UnityGLTF/Assets/UnityGLTF/Scripts/GLTFComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public async Task Load()
}
}

print("model loaded with vertices: " + sceneImporter.Statistics.VertexCount.ToString() + ", triangles: " + sceneImporter.Statistics.TriangleCount.ToString());
LastLoadedScene = sceneImporter.LastLoadedScene;

Animations = sceneImporter.LastLoadedScene.GetComponents<Animation>();
Expand Down
20 changes: 20 additions & 0 deletions UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ public float Progress
}
}

public struct ImportStatistics
{
public long TriangleCount;
public long VertexCount;
}

/// <summary>
/// Converts gltf animation data to unity
/// </summary>
Expand Down Expand Up @@ -166,6 +172,11 @@ public bool IsMultithreaded
/// </summary>
public bool CullFarLOD = false;

/// <summary>
/// Statistics from the scene
/// </summary>
public ImportStatistics Statistics;

protected struct GLBStream
{
public Stream Stream;
Expand Down Expand Up @@ -280,6 +291,8 @@ public async Task LoadSceneAsync(int sceneIndex = -1, bool showSceneObj = true,

this.progressStatus = new ImportProgress();
this.progress = progress;

Statistics = new ImportStatistics();
progress?.Report(progressStatus);

if (_gltfRoot == null)
Expand Down Expand Up @@ -1620,8 +1633,14 @@ protected virtual async Task ConstructMesh(GLTFMesh mesh, int meshIndex, Cancell

var vertCount = primitive.Attributes[SemanticProperties.POSITION].Value.Count;
vertOffset += (int)vertCount;

if (unityData.Topology[i] == MeshTopology.Triangles && primitive.Indices != null && primitive.Indices.Value != null)
{
Statistics.TriangleCount += primitive.Indices.Value.Count / 3;
blgrossMS marked this conversation as resolved.
Show resolved Hide resolved
}
}

Statistics.VertexCount += vertOffset;
await ConstructUnityMesh(unityData, meshIndex, mesh.Name);
}

Expand Down Expand Up @@ -2333,6 +2352,7 @@ private async Task SetupLoad(Func<Task> callback)
_isRunning = true;
}

Statistics = new ImportStatistics();
if (_options.ThrowOnLowMemory)
{
_memoryChecker = new MemoryChecker();
Expand Down