Last active
February 28, 2020 16:03
-
-
Save takumifukasawa/238c7c374ca9087c8f586e542b791f13 to your computer and use it in GitHub Desktop.
threejs v87: traverse meshes and map function
This file contains hidden or 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
import _ from 'lodash'; | |
function exec(obj, cb) { | |
switch (obj.type) { | |
case 'Mesh': | |
case 'SkinnedMesh': | |
case 'LineSegments': | |
cb(obj); | |
break; | |
default: | |
break; | |
} | |
} | |
export default function traverseMeshes(object, callback) { | |
// doesn't has children | |
if (!object.children || object.children.length < 1) { | |
exec(object, callback); | |
return; | |
} | |
_.forEach(object.children, (obj) => { | |
exec(obj, callback); | |
if (obj.children.length > 0) { | |
traverseMeshes(obj, callback); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment