Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by AR_Rizvi · Sep 04, 2013 at 01:02 PM · polygon-count

Selected Mesh Polygon Count

i am building a game on a low spec system nd i really need to know that is their is a way to count the polygons of a selected mesh Through script i am aware of the stats window nd verts and tries count but i want to count the polygons of my mesh can someone plz guide me on a right path if it is possible then how to do it any help would be appreciated Thanks AR

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

4 Replies

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

Answer by ArkaneX · Sep 04, 2013 at 01:32 PM

You can use

 gameObject.GetComponent<MeshFilter>().mesh.triangles.Length/3

For more reference, please look at Mesh.triangles

Comment
Add comment · Show 6 · 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 AR_Rizvi · Sep 05, 2013 at 09:24 AM 0
Share

Thanks so much for the reply

but when i use your suggetion its giving me this error

Assets/_Scripts/poly_count.cs(16,79): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement

may b i am missimg something

avatar image ArkaneX · Sep 05, 2013 at 09:33 AM 0
Share

$$anonymous$$y script returns number of triangles, but this number has to be assigned to some variable, e.g.

 var numTriangles = gameObject.GetComponent<$$anonymous$$eshFilter>().mesh.triangles.Length/3;
 Debug.Log(numTriangles);

assu$$anonymous$$g that gameObject is the object (with mesh) for which you want to check number of triangles.

avatar image AR_Rizvi · Sep 05, 2013 at 10:14 AM 0
Share

yup i got that and done the changes and its working but for the exact numbers of polygons which my mesh had in 3dsmax i have to divide the result by 2 nd its working awesomely thank you so much fr support

avatar image ArkaneX · Sep 05, 2013 at 10:52 AM 0
Share

That means you probably had your mesh created with quads not triangles. On import to Unity the mesh was triangulated, and the number of created triangles is twice the number of quads. So your calculation will be valid for quad meshes only.

avatar image AR_Rizvi · Sep 05, 2013 at 12:07 PM 0
Share

Thanks for looking at this .... :)

yup figured it out now and trying to do exact polygon count as it shows in 3dsmax so cud u suggest some calculations coz it is fairly differ with every other object i import so can u help with this exact poly count thing

Show more comments
avatar image
6

Answer by sysmaya · Jul 20, 2016 at 02:39 PM

Select Mesh in inspector. Ver Imagen.alt text


mesh-count.png (150.7 kB)
Comment
Add comment · 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
1

Answer by AR_Rizvi · Sep 06, 2013 at 04:49 AM

i used this code for my script of counting selected mesh's polys and tries

     using UnityEngine;
 using UnityEditor;
 public class SelectionCount : EditorWindow {
  
     // scripted by AR_Rizvi
     // date 6-sep-2013
     
     [MenuItem("Window/SelectionCount")]    //FindMissingScripts    //MissingTexture
     
     
     
     public static void ShowWindow()
     {
         EditorWindow.GetWindow(typeof(SelectionCount));
         
     }
     
 //    static    int selection = 0, lastSelection = 0;
     
     void OnInspectorUpdate() {
         // Call Repaint on OnInspectorUpdate as it repaints the windows
         // less times as if it was OnGUI/Update
         Repaint();
     }
 
      int moreThenOneComp = 0, selection =0;
     float mynum;
     float mynum1;
     float mynum_tri;
     float unit_tri;
     GameObject Obj;
     
     
     public void OnGUI()
     {
         
         GUILayout.BeginHorizontal ("box");
         GUILayout.Label("Selected GameObject");
         if (GUILayout.Button("Find Texture (None)"))
         {
             FindInSelected();
         }
          GUILayout.EndHorizontal ();
         
         //*******************************
         
         if(Selection.objects.Length != selection)
         {
             selection = Selection.objects.Length;
         
             
             moreThenOneComp = 0;
             
             GameObject[] cobj = Selection.gameObjects;
             foreach (GameObject c in cobj)
             {
                 if(c.GetComponents<Component>().Length > 1)
                 {
                     moreThenOneComp++;
                 }
                 
             }
                 //----------------------
             
         
             
             
             //----------------------
             
             
         }
         
         GUILayout.BeginHorizontal ("box");
         GUILayout.Label(selection+": Selected Object");
         
         GUILayout.Label(moreThenOneComp+": Has more Component");
         GUILayout.EndHorizontal ();
         //****************************
     
         
         
         
         GUILayout.Space(5);
         GUILayout.BeginHorizontal ("box");
         
         GameObject[] count_object = Selection.gameObjects;
         
         if (count_object.Length > 0)
         {    //----------------------
     
             mynum = 0.0f;
             mynum1=0.0f;
             mynum_tri = 0.0f;
             unit_tri = 0.0f;
             
             
             foreach (GameObject c in count_object)
             {
                 if(c.GetComponent<MeshFilter>())
                 {
                     mynum =  c.GetComponent<MeshFilter>().mesh.triangles.Length/3;
                    mynum1+=    mynum/2;
     
                     mynum_tri+=  c.GetComponent<MeshFilter>().mesh.triangles.Length/3;    
                     
                     unit_tri+=  c.GetComponent<MeshFilter>().mesh.triangles.Length;    
                 }
                 
             }
             
 
         }
         else
         {
             mynum = 0.0f;
             mynum1=0.0f;
             mynum_tri = 0.0f;
         }
         
 //            GUILayout.Label( "Polygons " + mynum1);
              GUILayout.Label( "3ds Max Tris " + mynum_tri);
         GUILayout.Label( "Unity Tris " + unit_tri);
             GUILayout.EndHorizontal ();
         
     }
     
     
     
     
     private static void FindInSelected()
     {
         GameObject[] go = Selection.gameObjects;
         
 //        int go_count = 0, /*components_count = 0,*/ missing_count = 0;
         int go_count = 0,missing_count = 0;
         
         foreach (GameObject g in go)
         {
             go_count++;
 //            Component[] components = g.GetComponents<Component>();
 //            for (int i = 0; i < components.Length; i++)
 //            {
 //                components_count++;
 //                if (components[i] == null)
 //                {
 //                    missing_count++;
 //                    Debug.Log(g.name + " has an empty script attached in position: " + i, g);
 //                }
 //            }
 //            
             //---------------------------------------------------------------------------------------------
             
             MeshRenderer[] meshRendcomponent = g.GetComponentsInChildren<MeshRenderer>();
             
             
             foreach (MeshRenderer mr in meshRendcomponent) //    
             {
 //                Debug.Log("Found MeshRenderer " + mr.name);
                foreach (Material m in mr.sharedMaterials)
                 {
 //                    Debug.Log("Found material " + m.name);
 //                    Texture2D tex = m.GetTexture("_MainTex") as Texture2D;
                     
 //                    Texture2D tex = m.GetTexture() as Texture2D;
                     
                     if(m.mainTexture)
                     {
 //                        Debug.Log("Texture name---- " + m.mainTexture);     
                     }
                     else
                     {
 //                        Debug.Log("Missing texture--: "+mr.name); 
                         Debug.LogError("No texture found, GameObject:"+g.name + ", Mat Name is: " + m,g);
                          missing_count++;
                     }
                      
 //                    if (tex != null)
 //                    {
 //                        Debug.Log("Found texture " + tex.name);
 //                    }
 //                    else
 //                    {
 //                        Debug.Log("Missing diffuse texture");
 //                    }
                 }
                 
             }
 //            
             //---------------------------------------------------------------------------------------------
             
         }
  
 //        Debug.Log(string.Format("Searched {0} GameObjects, {1} components, found {2} missing", go_count, components_count, missing_count));
         Debug.Log(string.Format("Searched {0} GameObjects,  found {1} missing", go_count,missing_count));
     }
 }
Comment
Add comment · Show 1 · 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 AR_Rizvi · Sep 06, 2013 at 04:51 AM 0
Share

Just uncomment some code to work you way through thanks ArkaneX for support and thanks Frima$$anonymous$$ickD for answer thankyou guys cheers

avatar image
0

Answer by FrimaMickD · Sep 04, 2013 at 01:37 PM

The triangles on the mesh represent the indices of the vertex used to build every triangles on your mesh (the polygons). So basically, dividing your triangles count by 3 will give you the number of triangles (poly) drawn.

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 ArkaneX · Sep 04, 2013 at 01:42 PM 0
Share

Out of curiosity - how did you do it, that your answer which was created later than $$anonymous$$e, is positioned higher, without any upvotes? View is sorted by 'voted first'.

avatar image FrimaMickD · Sep 04, 2013 at 01:57 PM 1
Share

I don't know, when I was on the page your answer was not there, so maybe I got to the page first, did something else and than answered? Sry, was not my intention!

avatar image ArkaneX · Sep 04, 2013 at 02:01 PM 0
Share

No problem - as I stated I asked out of curiosity only, because it's the first time I see such issue :)

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

19 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Material doesn't have a color property '_Color' 4 Answers

Setting Scroll View Width GUILayout 1 Answer

poly and vertex counting at runtime 6 Answers


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