Skip to content

Instantly share code, notes, and snippets.

@Leechael
Created April 27, 2022 15:19
Show Gist options
  • Save Leechael/6cf24bf221d8564e6c75a9a40e85241b to your computer and use it in GitHub Desktop.
Save Leechael/6cf24bf221d8564e6c75a9a40e85241b to your computer and use it in GitHub Desktop.
Count Visible Objects for Three.js
function countVisibleObjects(scene: THREE.Scene | THREE.Group | THREE.Object3D): number {
return scene.children.reduce(
(acc, obj) => {
if (obj.visible) {
return (obj.children.length) ? acc + countVisibleObjects(obj) + 1 : acc + 1
}
return acc
},
0
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment