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$
  • $\begingroup$ Use linking. Select them and hit CTRL+L, then choose material. $\endgroup$ – FFeller Feb 25 '19 at 20:22
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.

| improve this answer | |
$\endgroup$
  • $\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$ – Juan Manuel Lynch Feb 26 '19 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 '19 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$ – Juan Manuel Lynch Feb 26 '19 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 '19 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$ – Juan Manuel Lynch Feb 26 '19 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.