DAZ Script "Render to Backdrop" sample

Todo:
Port from DAZ Script 1 to DAZ Script 2
Description :

This script is a simple example, showing how to render an image that is immediately set as the backdrop image for the scene.

 
Concepts Covered :
 
Source : ./samples/
00001 /**********************************************************************
00002     File: renderToBackdrop.ds
00003 
00004     Copyright © 2002-2006 DAZ Productions. All Rights Reserved.
00005 
00006     This file is part of the DAZ Script Documentation.
00007 
00008     This file may be used only in accordance with the DAZ Script 
00009     license provided with the DAZ Script Documentation.
00010 
00011     The contents of this file may not be disclosed to third parties, 
00012     copied or duplicated in any form, in whole or in part, without the 
00013     prior written permission of DAZ Productions, except as explicitly
00014     allowed in the DAZ Script license.
00015 
00016     See http://www.daz3d.com to contact DAZ Productions or for more 
00017     information about DAZ Script.
00018 **********************************************************************/
00019 /*********************************************************************/
00020 // Get the backdrop for the scene
00021 var oBackDrop = Scene.getBackdrop();
00022 // Clear the backdrop
00023 oBackDrop.clear();
00024 //Get the Render Manager
00025 var oRenderMgr = App.getRenderMgr();
00026 // Render the scene; using the current settings
00027 oRenderMgr.doRender();
00028 // Retrieve the path to the rendered image
00029 var sLastRender = oRenderMgr.getLastSavedRenderPath();
00030 // If the path is valid
00031 if ( !sLastRender.isEmpty() ){
00032     // Set the busy cursor to let the user know we're working
00033     setBusyCursor();
00034     // Create a file info object for easy pathing operations
00035     var oFile = new DzFileInfo( sLastRender );
00036     // Get the absolute path for the directory the image is in
00037     var sDirPath = oFile.path();
00038     // Construct the short name for the source file
00039     var sSrcFilename = String( "%1.%2" ).arg( oFile.baseName() ).arg( oFile.extension() );
00040     // Construct the short name for the target file
00041     var sTgtFilename = String( "%1.%2" ).arg( "background" ).arg( oFile.extension() );
00042     // Create a dir object for file access operations
00043     var oDir = new DzDir( sDirPath );
00044     // Copy the source file to the target file;
00045     // We step back a directory on the target file because we expect the render to be
00046     // in ./temp/render and that directory is cleared wholesale at each render,
00047     // but temp isn't cleared until a new scene action, application quit or launch.
00048     oDir.copy( sSrcFilename, String( "../%1" ).arg( sTgtFilename ) );
00049     // Update the target directory path
00050     oDir.cdUp();
00051     sDirPath = oDir.path();
00052     // Get the image manager
00053     var oImgMgr = App.getImageMgr();
00054     // Get an image object for the target file
00055     var oImg = oImgMgr.getImage( String( "%1/%2" ).arg( sDirPath ).arg( sTgtFilename ) );
00056     // If the last render is a png
00057     if( sTgtFilename.lower().right( 4 ) == ".png" ){
00058         // Since png is converted to jpg before being sent to tdlmake,
00059         // replace the target path with the jpg extension.
00060         sTgtFilename = String( "%1.jpg" ).arg( sTgtFilename.substring( 0, sTgtFilename.length - 4 ) );
00061         // Remove the jpg to force the tdl to be recreated when the png is refreshed
00062         oDir.remove( sTgtFilename );
00063     }
00064     // Refresh the image from disk
00065     oImg.refresh();
00066     // Set the backdrop's image to the target image
00067     oBackDrop.setImage( oImg );
00068     // We're done working, let the user know
00069     clearBusyCursor();
00070 }

Generated on Thu Sep 24 12:21:07 2009

Copyright © 2002 - 2009 DAZ 3D, Inc.