Last active
February 28, 2020 16:03
-
-
Save takumifukasawa/dde3ae6fd1d740222a2de9421dd0ed28 to your computer and use it in GitHub Desktop.
threejs v87: traverse materials and map function
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
import _ from 'lodash'; | |
export default function traverseMaterials(object, callback) { | |
// multi material | |
if (_.isArray(object.material)) { | |
_.forEach(object.material, (material) => { | |
callback(material); | |
}); | |
return; | |
} | |
// multi material of old threejs version | |
if (object.material.materials) { | |
_.forEach(object.material.materials, (material) => { | |
callback(material); | |
}); | |
return; | |
} | |
callback(object.material); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment