Skip to content

Instantly share code, notes, and snippets.

@takumifukasawa
Last active February 28, 2020 16:03
Show Gist options
  • Save takumifukasawa/238c7c374ca9087c8f586e542b791f13 to your computer and use it in GitHub Desktop.
Save takumifukasawa/238c7c374ca9087c8f586e542b791f13 to your computer and use it in GitHub Desktop.
threejs v87: traverse meshes and map function
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