Create layered material with python
Posted: Thu Mar 30, 2023 10:01 am
Hey,
I'm trying to create a layered material via python. So far adding the Layered Material, Material Layer and general nodes works fine. But I encounter an issue when I try to connect everything together...
In the material generated from the code both the ImageTexture and Material Layer nodes aren't connected to their planned parent node.
Connecting the layered material with sub materials instead of material layers seems to work but I would like to use material layers so that I can further group multiple material layers a level below.
Any idea on why this isn't working or how I could circumvent this? Thanks already for your help
I'm trying to create a layered material via python. So far adding the Layered Material, Material Layer and general nodes works fine. But I encounter an issue when I try to connect everything together...
Code: Select all
from typing import Optional
import c4d
doc: c4d.documents.BaseDocument
op: Optional[c4d.BaseObject]
OCTANE_MAT_LAYERED_ID = 1052933
OCTANE_IMAGE_ID = 1029508
OCTANE_LAYER_ID = 1052932
OCTANE_SUB_MATERIAL_ID = 1040369
def main() -> None:
mat = c4d.BaseMaterial(OCTANE_MAT_LAYERED_ID)
doc.InsertMaterial(mat)
mat[c4d.LAYEREDMAT_NUM_OF_MATERIALS] = 2
mask_tex = c4d.BaseShader(OCTANE_IMAGE_ID)
mat.InsertShader(mask_tex)
mask_tex[c4d.IMAGETEXTURE_FILE] = "" #some path
mask_tex[c4d.IMAGETEXTURE_MODE] = 0
mask_tex[c4d.IMAGETEXTURE_GAMMA] = 2.2
mask_tex[c4d.IMAGETEX_BORDER_MODE] = 0
layer = c4d.BaseShader(OCTANE_LAYER_ID)
mat.InsertShader(layer)
layer[c4d.MATLAYER_LAYER_TYPE] = 1
layer[c4d.MATLAYER_DIFFUSE_LNK] = mask_tex
layer[c4d.MATLAYER_LAYER_OPACITY] = 0.2
mat[c4d.LAYEREDMAT_MAT2_LINK] = layer
c4d.EventAdd()
if __name__ == '__main__':
main()
Connecting the layered material with sub materials instead of material layers seems to work but I would like to use material layers so that I can further group multiple material layers a level below.
Any idea on why this isn't working or how I could circumvent this? Thanks already for your help
