0
$\begingroup$

From this question: link I learned how to transfer UV maps from one object into a new instance. How can this be done with materials and material indices?

AN in 2.8 seems to have a new system but I'm still stuck in 2.79.

EDIT

@Omar Ahmad offered a solution which works great for the materials but material indices aren't transfered correctly here is how the graph looks like.enter image description here

$\endgroup$
1
  • $\begingroup$ Use linking. Select them and hit CTRL+L, then choose material. $\endgroup$
    – FFeller
    Feb 25, 2019 at 20:22

1 Answer 1

1
$\begingroup$

The Mesh Object Input node have a Material Indices output, you can use that as the input material indices of the Mesh Object Output node as follows:

Node Tree

Alternatively, you can use the following expression to get the material indices:

[p.material_index for p in object.data.polygons]

Where object is your object. To apply modifiers first, you can use the following expression:

object.an.getMesh(bpy.context.depsgraph, True).an.getPolygonMaterialIndices()

As for copying materials themselves, the 2.8 version have a system to set materials to object. But if you are on an older version, you will have to use a python script. Something like this should work:

target.data.materials.clear()
for material in source.data.materials:
    target.data.materials.append(material)

Where source and target are you source and target objects.

$\endgroup$
9
  • $\begingroup$ I accepted the answer too fast… sorry, but the material indices aren't been copied. I managed to transfer all the materials correctly though. Check the edit to see how the graph looks. $\endgroup$ Feb 26, 2019 at 9:39
  • $\begingroup$ @JuanManuelLynch I see. This would be a bug in Animation Nodes. I just fixed it, but the fix won't be available for older versions. I edited the answer to include another way to get the indices. $\endgroup$
    – Omar Emara
    Feb 26, 2019 at 11:37
  • $\begingroup$ now works as expected. There is still an issue... my root object, from where the instances are created, has a modifier (bevel), this modifier seems to get applied when the object instancer gets fed with my root mesh mixing all the polygon indices. Is there a workaround for this? $\endgroup$ Feb 26, 2019 at 12:48
  • $\begingroup$ @JuanManuelLynch I would have to see the node tree responsible for the instancing. But some nodes/options return meshes that have modifiers applied, could you make sure that no such option is enabled? If not, maybe you can ask another question with a minimal example illustrating the issue. $\endgroup$
    – Omar Emara
    Feb 26, 2019 at 13:47
  • $\begingroup$ you can check the tree in the EDIT of my question. Yes, I have the Apply modifier option enabled in my meshObjectInput node, and it actually works, the output mesh has the modifier correctly applied but the with incorrect polygon indices. I'll try to create a new question later with a more simple example. $\endgroup$ Feb 26, 2019 at 13:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .