This should do the trick (replacing each texture with its copy):
(
fn recurseMap mat =
for i = 1 to (getNumSubTexmaps mat)
where (local map = getSubTexmap mat i) != undefined do
(
setSubTexmap mat i (copy map)
recurseMap map
)
fn recurseMat mat =
for i = 1 to (getNumSubMtls mat)
where (local subMat = getSubMtl mat i) != undefined do
if getNumSubMtls subMat > 0 then
(
recurseMap subMat
recurseMat subMat
)
else recurseMap subMat
updateSceneMaterialLib()
for mat in sceneMaterials do
(
recurseMat mat
recurseMap mat
)
)