Created
April 27, 2022 15:19
-
-
Save Leechael/6cf24bf221d8564e6c75a9a40e85241b to your computer and use it in GitHub Desktop.
Count Visible Objects for Three.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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