How to affect an image to a material property
JPiat
Posts: 70
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
These samples show many aspects of handling materials http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/start#materials
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 );
}