How to affect an image to a material property

Hello,

I try to create a simple script for automatically affecting the proper material to Kitbash3d props.

It's very easy because the name of the material is more or less the name of the different images that must be used for the diffuse, normal, etc.

But, how to affect the image "c:\normal.jpg" to the normal property of the material ?

 

Comments

  • Richard HaseltineRichard Haseltine Posts: 96,858
    edited February 2023
    Post edited by Richard Haseltine on
  • JPiatJPiat Posts: 68

    Of course, "read the manual" is a possible answer, another solution is to answer the question.

    So

    By exemple, for setting the main diffuse texture (Iray) :

    var imgManager = App.getImageMgr();

    var oNode = Scene.getPrimarySelection();

    var oObject = oNode.getObject();

    var oShape = oObject.getCurrentShape();

    var nMaterials = oShape.getNumMaterials();

    for( var i = 0; i < nMaterials; i += 1 ){

    var oMaterial = oShape.getMaterial( i );

    var oProp=oMaterial.findProperty( "Diffuse Color" );

    var sFullPahtImg = String("C:\\Image\\%1_basecolor.jpg").arg(oMaterial.getName());

    var img = imgManager.getImage(sFullPahtImg);

    oProp.setMap( img ); 

    }

     

     

     

     

     

Sign In or Register to comment.