User Tools

Site Tools

Render To Backdrop


Below is an example demonstrating how to render an image that is immediately set as the backdrop image for the scene, via script.

API Areas of Interest


// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
	// Get the backdrop for the scene
	var oBackDrop = Scene.getBackdrop();
	// Clear the backdrop
	// Get the render manager
	var oRenderMgr = App.getRenderMgr();
	// Render the scene; using the current settings
	// Retrieve the path to the rendered image
	var sLastRender = oRenderMgr.getLastSavedRenderPath();
	// If the path is empty
	if( sLastRender.isEmpty() ){
		// We are done...
	// Set the busy cursor to let the user know we are working
	// Create a file info object for easy pathing operations
	var oFile = new DzFileInfo( sLastRender );
	// Get the absolute path for the directory the image is in
	var sDirPath = oFile.path();
	// Construct the short name for the source file
	var sSrcFilename = String( "%1.%2" ).arg( oFile.baseName() ).arg( oFile.extension() );
	// Construct the short name for the target file
	var sTgtFilename = String( "%1.%2" ).arg( "background" ).arg( oFile.extension() );
	// Create a dir object for file access operations
	var oDir = new DzDir( sDirPath );
	// Copy the source file to the target file;
	// We step back a directory on the target file because we expect the render to be
	// in ./temp/render and that directory is cleared wholesale at each render,
	// but temp is not cleared until a new scene action, application quit or launch.
	oDir.copy( sSrcFilename, String( "../%1" ).arg( sTgtFilename ) );
	// Update the target directory path
	sDirPath = oDir.path();
	// Get the image manager
	var oImgMgr = App.getImageMgr();
	// Get a texture object for the target file
	var oTexture = oImgMgr.getImage( String( "%1/%2" ).arg( sDirPath ).arg( sTgtFilename ) );
	// Create a file info object for easy pathing operations
	oFile = new DzFileInfo( sTgtFilename );
	// If the last render is a png
	if( oFile.extension() == "png" ){
		// Since png is converted to jpg before being sent to tdlmake,
		// replace the target path with the jpg extension.
		sTgtFilename = String( "%1.jpg" ).arg( oFile.baseName() );
		// Remove the jpg to force the tdl to be recreated when the png is refreshed
		oDir.remove( sTgtFilename );
	// Refresh the image from disk
	// Set the backdrop's image to the target image
	oBackDrop.setTexture( oTexture );
	// We are done working, let the user know
// Finalize the function and invoke