Help - how to apply a shader definition via script?

CrescentCrescent Posts: 328

I modified a script to loop through every material in a scene, removes all bump and displacement maps as well as setting the strength value to 0. I want to also have it apply the default DAZ matte shader to each material.  The matte shader is [DS installation path]\scripts\support\DAZ\shaderDefinitions\surface\dzmatteDef.dsa  There was a post a long while back where someone claimed to have done it but the script they posted doesn't work.  (It's missing part of their for loop, which I was able to fix, but the rest still didn't work - maybe a version issue?)

Could someone help with this?  

 

 

// DAZ Studio version 3.0  filetype DAZ Script
//
// Adopted from a script by mCasual/Jacques
// public domain
//
// what this script does:
//
// Go through the materials in the scene.
// Sets the Displacement and Bump Map strength for all materials to 0 and removes the associated maps.

//================================================================================
processAllNodes( setProps );

//================================================================================
function processAllNodes( func )
{
    var nodeList = Scene.getNodeList();
    var numNodes = nodeList.length;
    for( var i = 0; i < numNodes; i++ )
    {
        var node = nodeList[i];
        var object = node.getObject();
        if( object )
        {
            var shape = object.getCurrentShape();
            if( shape )
            {
                var materialList = shape.getAllMaterials();
                var numMaterials = materialList.length;
                for( j = 0; j < numMaterials; j++ )
                {
                    var material = materialList[j];
                    func( material )
                }
            }
        }
    }
}
//================================================================================
function setProps( material )
{
    zeroProp( material, "Bump Strength" );
    zeroProp( material, "Displacement Strength" );
}

//================================================================================
function zeroProp( material, propName )
{
    var prop = material.findProperty( propName );
    prop.setValue( 0 )
    prop.setMap("")
}
 

Post edited by Crescent on

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,842

    Try saving a legacy materials preset - that should still, as I recall, have the code for applying a shader. You could also look at older .dsa materials presets (or shader presets) if I'm wrong and that function has been subsumed into the DzPresetHelper object.

Sign In or Register to comment.