Simple Script Example - Add LIE Layer to Existing Texture

bohemian3bohemian3 Posts: 1,034

Hi all - thanks for all the posts here, learning so much.

I found the document for LIE DzLayeredTexture - but there's not an example there, unfortunately of how to implement.  I can probably work from this documentation to create what I need, but I thought I'd ask if someone already has a simple script to do the following.  I know you can save a LIE preset but unless I'm doing it wrong, it seems bound to the current object and surface - you can't seem to save a 'generic' overlay.  I want to add a grunge layer on top of whatever surface I have selected through script.

1) Add an Image layer - Source Over
2) Add an Image Mask - Source Over
3) And Save

That's all.  Also, I can't use my iRay diffuse overlay because I'm already using that for something else.

If you by chance have that, I appreciate it.

Post edited by bohemian3 on

Comments

  • bohemian3bohemian3 Posts: 1,034
    edited November 2022

    @Richard Haseltine - Thank you so much - Here's the final script - It adds an additional grunge LIE layer on top of the current texture to any surfaces that are selected.  Still to do: More robust error checking and cleaning up orphans if another layer is added.  Again, thanks

    oNode = Scene.getPrimarySelection(); 
    var oObject = oNode.getObject();
    print (oObject.name);
    
    var oShape = oObject.getCurrentShape();	
    nMaterials = oShape.getNumSelectedMaterials();
    
    for (var i = 0;  i < nMaterials; i++)
    {
    	var oMaterial = oShape.getSelectedMaterial (i);
    	
    			var aProperty = oMaterial.findProperty("Diffuse Color");				
    
                  if (aProperty.name == 'Diffuse Color') {
    					oTexture = oMaterial.getColorMap();				
    					addOverlay(aProperty,oTexture.getFilename(), "Grunge.jpg", "GrungeMask.png");
    					print ("----------");
    					print (oMaterial.name, oTexture.getFilename(), aProperty, oTexture.name)						
                  }							
    }
    
    function addOverlay(diffuseProp, currentTexturePath, imageGrunge, imageMask ) {
    
    	print (currentTexturePath, diffuseProp, imageGrunge, imageMask);
    	var oImageMgr = App.getImageMgr();
     
    	var sBasePath = "C:/Users/YourHomeBase/OneDrive/Pictures/";
    	var sBaseLayerPath = String("%1/%2").arg( sBasePath ).arg( imageGrunge );
    	var sMaskLayerPath = String("%1/%2").arg( sBasePath ).arg( imageMask );
     
    	var oBaseLayerFile = new DzFileInfo( sBaseLayerPath );
    	var oMaskLayerFile = new DzFileInfo( sMaskLayerPath );
     
    	var sBaseLayerName = oBaseLayerFile.baseName();
    	var sMaskLayerName = String("%1 Mask").arg( oMaskLayerFile.baseName() );
     
    	var sTextureName = oImageMgr.getUniqueImageName( "Grunge" );
    	var oLayeredTexture = oImageMgr.createLayeredTexture( sTextureName );
    
        diffuseProp.setMap( oLayeredTexture  );					
     
    	oLayeredTexture.size = new Size( 4096, 4096);
     
    	if( App.version64 >= 0x0004000600020017 ){
    		 if( !oBaseLayerFile.exists() ){
    			// We are done..
    			return;
    		} 
    
    		var oOriginalImage = oLayeredTexture.createLayer( "Original Image" );
    		oOriginalImage.imageFile = currentTexturePath; 
     
    		var oLayer = oLayeredTexture.createLayer( sBaseLayerName );
    		oLayer.imageFile = sBaseLayerPath; 
     
    		if( !oMaskLayerFile.exists() ){
    			return;
    		}
     
    		var oMask = oLayer.createMask( sMaskLayerName );
    		oMask.imageFile = sMaskLayerPath;
    
    	} else {
    		var oLayeredImage = new DzLayeredImage();
     
    		if( oBaseLayerFile.exists() ){
    			var oImageLayer = new DzImageFileLayer();
    			oImageLayer.filename = sBaseLayerPath;
    			oImageLayer.label = sBaseLayerName;
    			oLayeredImage.addLayer( oImageLayer );
     
    			if( oMaskLayerFile.exists() ){
    				var oImageMask = new DzImageMask();
    				oImageMask.filename = sMaskLayerPath;
    				oImageMask.label = sMaskLayerName;
    				oImageLayer.setMask( oImageMask );
    			}
    		}
    
    		oLayeredImage.toLayeredTexture( oLayeredTexture );
    	}
    }
    Post edited by bohemian3 on
  • Please make sure you comply with the license terms when using the samples -

  • bohemian3bohemian3 Posts: 1,034
    edited November 2022

    @Richard Haseltine Okay - I just read the license -  If I were to distribute my version with a freebie I'm working, the way I read this is as long as I include a link to the original script and license with a note of changes made, I can do that?  Am I reading that correctly?  

    Richard Haseltine said:

    Please make sure you comply with the license terms when using the samples -

    Post edited by bohemian3 on
  • bohemian3 said:

    @Richard Haseltine Okay - I just read the license -  If I were to distribute my version with a freebie I'm working, the way I read this is as long as I include a link to the original script and license with a note of changes made, I can do that?  Am I reading that correctly?  

    Richard Haseltine said:

    Please make sure you comply with the license terms when using the samples -

    If you download the script, rather than copying and pasting, the header already has most of the required information - obviously not your changes.

Sign In or Register to comment.