4

With three.js , is there a way to retrieve the polygon count of a scene? I did a search, but the only results that pop up at related to actual polygons and whether meshes have too many, etc.

user3591153
  • 409
  • 4
  • 14

2 Answers2

5

I believe renderer.info.render.faces may be what you're after.

msun
  • 761
  • 4
  • 8
  • doesn't seem to provide the polygon count. Even with objects in the scene, it just returns 0. – user3591153 Oct 27 '16 at 01:43
  • Do you have some code or example of what you have in the scene? See [here](https://threejs.org/docs/index.html#Reference/Renderers/WebGLRenderer.info). Note the stats only update after the renderer has rendered the scene -- perhaps you need that info before the scene has been rendered? – msun Oct 27 '16 at 02:37
  • ah.. I was rendering multiple things, so I had to place it after the render with the correct objects. It works now. – user3591153 Oct 29 '16 at 01:18
  • renderer.info no longer has a member 'faces' go [here](https://threejs.org/docs/#api/en/renderers/WebGLRenderer.info) to see latest members – Jordan Lee Burnes Jul 30 '22 at 17:51
3

[ Update ] On Three.js revision r100 you would get that data through:

renderer = new THREE.WebGLRenderer();
// Code that loads your geometry here
console.log( renderer.info.render.triangles );

This same object has several a lot of data that can give you a hint over your memory leaks, so you might just want to console log the whole renderer object and browse all of its properties!

Xedret
  • 1,823
  • 18
  • 25
  • `renderer.info.render.triangles` returns `0`in my case. of course, I have a 3D model attached to this renderer. actually, all of the fields are 0. Is there a way to refresh / re-calc the `info` object? – ranbuch Jan 27 '19 at 06:04
  • I would love to but that's a big project, I don't know how :( Basically I'm using `glTF Loader` and adding the model to my scene. – ranbuch Jan 28 '19 at 16:22
  • 1
    Only works after you rendered the scene at least once. @ranbuch – nex Sep 30 '19 at 10:36
  • @nex no, that's not is. I'm running revision 104 BTW. – ranbuch Oct 01 '19 at 18:44
  • Works now with revision 112 – ranbuch Jun 03 '20 at 10:44