Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by kinginthenorth · Apr 30, 2016 at 11:40 AM · polygon-count

How could I count my poly / tri ?

Hello everyone,

I am a 3d artist, currently working on a test to get a job.

This test has a polygon limitation. If I enable the 'stats' window in the camera tab, it gives me every rendered triangles which is not what I need. I need to know how many polygons / triangles I have from my meshes, so yes I could just multiply the amount of triangles by the number of items I duplicated etc (count it manually) but it would take useless time.

Every software has that I guess it's somewhere in here I just can't find it?

Thank you for your help

Adrien

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by flashframe · Apr 30, 2016 at 03:09 PM

Hi, I wrote a little Editor Window that does what you want. Put this script in a folder called Editor, and access the panel by going to Tools/MeshInfo. It will display the Triangle and Vertex count for the object that is selected in the hierarchy.

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 
 public class MeshInfo : EditorWindow {
 
     private int vertexCount;
     private int submeshCount;
     private int triangleCount;
 
     [MenuItem ("Tools/Mesh Info")]
     static void Init ()
     {
         // Get existing open window or if none, make a new one:
         MeshInfo window = (MeshInfo) EditorWindow.GetWindow (typeof (MeshInfo));
         window.titleContent.text = "Mesh Info";
     }
 
     void OnSelectionChange()
     {
         Repaint();
     }
 
 
 
     void OnGUI()
     {
         if(Selection.activeGameObject && Selection.activeGameObject.GetComponent<MeshFilter>())
         {
             vertexCount = Selection.activeGameObject.GetComponent<MeshFilter>().sharedMesh.vertexCount;
             triangleCount = Selection.activeGameObject.GetComponent<MeshFilter>().sharedMesh.triangles.Length/3;
             submeshCount = Selection.activeGameObject.GetComponent<MeshFilter>().sharedMesh.subMeshCount;
 
             EditorGUILayout.LabelField(Selection.activeGameObject.name);
             EditorGUILayout.LabelField("Vertices: ", vertexCount.ToString());
             EditorGUILayout.LabelField("Triangles: ", triangleCount.ToString());
             EditorGUILayout.LabelField("SubMeshes: ", submeshCount.ToString());
         }
     }
 
 }
 
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kinginthenorth · Apr 30, 2016 at 04:02 PM 0
Share

Hey.

well that's really nice ! Thank you for your time, I'll try that out :)

Adrien

avatar image kinginthenorth · Apr 30, 2016 at 04:03 PM 0
Share

It's working out pretty well. $$anonymous$$ay I ask you for one more thing? I'd need a few more line to get the total polycount. (or multiple object selected?)

Thank you very much

Adrien

avatar image flashframe kinginthenorth · Apr 30, 2016 at 04:14 PM 0
Share

If you want it to work for multiple selected objects you could try changing the OnGui() method to this:

 void OnGUI()
     {
         vertexCount = 0;
         triangleCount = 0;
         submeshCount = 0;
         
         foreach(GameObject g in Selection.gameObjects)
         {
             if(g.GetComponent<$$anonymous$$eshFilter>())
             {
                 vertexCount += g.GetComponent<$$anonymous$$eshFilter>().shared$$anonymous$$esh.vertexCount;
                 triangleCount += g.GetComponent<$$anonymous$$eshFilter>().shared$$anonymous$$esh.triangles.Length/3;
                 submeshCount += g.GetComponent<$$anonymous$$eshFilter>().shared$$anonymous$$esh.sub$$anonymous$$eshCount;
             }
         }
 
         EditorGUILayout.LabelField("Vertices: ", vertexCount.ToString());
         EditorGUILayout.LabelField("Triangles: ", triangleCount.ToString());
         EditorGUILayout.LabelField("Sub$$anonymous$$eshes: ", submeshCount.ToString());
     }

Don't forget to accept my answer if you feel it solves your original question :-)

avatar image
1

Answer by kinginthenorth · May 02, 2016 at 03:18 PM

Hey,

Thank you again for your time, I'm sorry to annoy with that, but that Void edit does not work, can't count for multiple objects.

Thanks

Adrien

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image flashframe · May 02, 2016 at 03:57 PM 2
Share

Hmm, it works for me. For clarity, this is the full script:

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 
 public class $$anonymous$$eshInfo : EditorWindow {
 
     private int vertexCount;
     private int submeshCount;
     private int triangleCount;
 
     [$$anonymous$$enuItem ("Tools/$$anonymous$$esh Info")]
     static void Init ()
     {
         // Get existing open window or if none, make a new one:
         $$anonymous$$eshInfo window = ($$anonymous$$eshInfo) EditorWindow.GetWindow (typeof ($$anonymous$$eshInfo));
         window.titleContent.text = "$$anonymous$$esh Info";
     }
 
     void OnSelectionChange()
     {
         Repaint();
     }
 
 
 
     void OnGUI()
     {
         vertexCount = 0;
         triangleCount = 0;
         submeshCount = 0;
 
         foreach(GameObject g in Selection.gameObjects)
         {
             if(g.GetComponent<$$anonymous$$eshFilter>())
             {
                 vertexCount += g.GetComponent<$$anonymous$$eshFilter>().shared$$anonymous$$esh.vertexCount;
                 triangleCount += g.GetComponent<$$anonymous$$eshFilter>().shared$$anonymous$$esh.triangles.Length/3;
                 submeshCount += g.GetComponent<$$anonymous$$eshFilter>().shared$$anonymous$$esh.sub$$anonymous$$eshCount;
             }
         }
 
         EditorGUILayout.LabelField("Vertices: ", vertexCount.ToString());
         EditorGUILayout.LabelField("Triangles: ", triangleCount.ToString());
         EditorGUILayout.LabelField("Sub$$anonymous$$eshes: ", submeshCount.ToString());
     }
 
 }

This gives me the total Vertices and Triangle count if I select 1 or more gameobjects in the hierarchy with meshfilter components. $$anonymous$$aybe I misunderstood your request?

avatar image AndreiMarian flashframe · Feb 20 at 03:26 PM 0
Share

OK, here's yet another iteration to extend the count to selected *GameObject*s and all their children, only *MeshFilter*s taken into account:

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 
 public class MeshInfo : EditorWindow
 {
     private int vertexCount;
     private int submeshCount;
     private int triangleCount;
 
     [MenuItem("Tools/Mesh Info")]
     static void Init()
     {
         // Get existing open window or if none, make a new one:
         MeshInfo window = (MeshInfo)EditorWindow.GetWindow(typeof(MeshInfo));
         window.titleContent.text = "Mesh Info";
     }
 
     void OnSelectionChange()
     {
         Repaint();
     }
 
     void OnGUI()
     {
         vertexCount = 0;
         triangleCount = 0;
         submeshCount = 0;
 
         foreach(GameObject g in Selection.gameObjects)
         {
             foreach(MeshFilter mf in g.GetComponentsInChildren<MeshFilter>())
             {
                 vertexCount += mf.sharedMesh.vertexCount;
                 triangleCount += mf.sharedMesh.triangles.Length / 3;
                 submeshCount += mf.sharedMesh.subMeshCount;
             }
         }
 
         EditorGUILayout.LabelField("Vertices: ", vertexCount.ToString());
         EditorGUILayout.LabelField("Triangles: ", triangleCount.ToString());
         EditorGUILayout.LabelField("SubMeshes: ", submeshCount.ToString());
     }
 }

avatar image kinginthenorth · May 02, 2016 at 03:59 PM 0
Share

Okay it's perfectly working thank you a lot for your help I'm just very lame at coding aha.

avatar image flashframe kinginthenorth · May 02, 2016 at 04:05 PM 0
Share

No worries, glad it's working :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

poly and vertex counting at runtime 6 Answers

Perfect Cubes vs. 1 Rectangular Prism (Performance Question) 1 Answer

How to increase the polygon count? 0 Answers

searching for a "model a game car" tutorial? 2 Answers

How many tris? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges