Digital Art Zone

 
     
render script question
Posted: 31 May 2012 08:23 PM   [ Ignore ]
New Member
Total Posts:  18
Joined  2012-02-05

I have no experience with Daz scripts.  I’m hoping something already exists that will meet my need.  I’m doing a 2D game and hope to automate at least part of the render process.  There are several animations per character, which will need to be rendered one at a time in 8 directions.  This will be done by rendering all frames of a given animation, rotating the viewport 45 degrees, render all frames again, rotate 45 degrees again, etc.  Ideally, the file name used would change with every rotation - i.e. each direction has a different file name.  Is there a script that can do this?  If so, where and how do you use it?

Profile
 
 
Posted: 09 June 2012 11:59 AM   [ Ignore ]   [ # 1 ]
Active Member
Avatar
RankRank
Total Posts:  803
Joined  2007-01-08

Hi!
  I had this script here that did the camera rotation. I have now updated it to include animation of the currently loaded scene. It isn’t tested much but it should work. Renders are going to be saved in: Users\<username>\AppData\Roaming\DAZ 3D\Studio4\temp and named Angle#Frame##.png
You can change a few things by editing the top few lines, which are commented. To use it, copy the code in Wordpad (if you are on Windows), and save the file, then change its extension from txt to dsa. Place it anywhere inside your My Library folder (but outside Runtime subfolder), for example in My Library/Scripts. Access it from your Content Library tab and it will render your animation. If your animation is less than 30 frames it may render the last frames several times. Remember to cut the rendered frames elsewhere, since they would be overwritten by a second animation rendered.

// DAZ Studio version 2.3  filetype DAZ Script 

 
var oDistanz=360//initial camera position in the z direction 
 
var oHeight=105//camera height 
 
var oSteps=8//number of renders 
 
var Save=1// 1= yes; other values=no 
 
var oOrbitCentre=1// 1=orbit bounding box's center, else orbits oCentre 
 
oCentre = new DzVec3(0,0,0); //0,100,0 useful if camera aims at the wrong height.
 
var oEccentricity=1// 1=circle; else ellipse. Affects X, not Y nor Z 

 // Get current camera 
 
var oViewport MainWindow.getViewportMgr().getActiveViewport(); 
 var 
oCamera oViewport.get3DViewport().getCamera(); 

 var 
oNewPos=new DzVec3
 function 
CameraPos(oCam,oiSteps,oCentre){        
        
var oSin=Math.sin(Math.PI*2*oiSteps/oSteps); 
        var 
oCos=Math.cos(Math.PI*2*oiSteps/oSteps); 
        var 
oNewPos=new DzVec3 (oEccentricity*oSin*oDistanz+oCentre.x,oHeight,oCos*oDistanz+oCentre.z); 
        
oCam.setWSPos(oNewPos); 
 


 
//Aimat script from the help 
  
const g_sTOOL_NAME "Aim Camera"
   
  
/*********************************************************************/ 
  // Box3 : Method for building a box 
  
function buildBoxoCamera )
      
// A box to grow; encompassing target nodes 
      
var boxTarget = new DzBox3
      
// Check if a node is selected 
      
var oPrimaryNode Scene.getPrimarySelection(); 
      
// A flag for whether or not any node warranted inclusion 
      
var bValid false
       
      
// If nodes are selected, get the number of selected nodes, otherwise get the number of all nodes in the scene 
      
var nNodes oPrimaryNode Scene.getNumSelectedNodes() : Scene.getNumNodes(); 
      
// Iterate over the nodes 
      
for( var 0nNodesn++ ) 
          
// If nodes are selected, get the 'current' selected node, otherwise get the 'current' node 
          
var oNode oPrimaryNode Scene.getSelectedNode) : Scene.getNode); 
          
// If the node is defined and it is not the 'current' camera 
          
if( oNode != undefined && oNode != oCamera 
              
// Grow the box to include the node bounding box 
              
boxTarget.include( oNode.getWSBoundingBox() ); 
              
// BINGO!... we got one! 
              
bValid true
          

      } 
      
// If the scene is empty or there were no worthy nodes 
      
if( !nNodes || !bValid 
          
// Um... Houston? 
          
return undefined
      

      
// Ahh... done. 
      
return boxTarget
  

   
  
/*********************************************************************/ 
  // Set the busy cursor to let the user know we're working 
  
setBusyCursor(); 
  
// Get the active viewport 
  
var oViewport MainWindow.getViewportMgr().getActiveViewport(); 
  
// Get the current camera 
  
var oCamera oViewport.get3DViewport().getCamera(); 
  
// Get a box encompassing the nodes to aim at 
  
var boxTarget buildBoxoCamera ); 
   
  
// If the box is defined 
  
if( boxTarget )
      
// Start collecting actions for the undo stack; for non-'view' cameras 
      
if( !oCamera.isViewCamera() ) 
          beginUndo
(); 
          
oCamera.beginEdit(); 
      

      
// Aim the camera at the center of the box 
      
oCamera.aimAtboxTarget.getCenter() ); 
       
      
// Stop collecting events and accept; for non-'view' cameras 
      
if( !oCamera.isViewCamera() ) 
          oCamera
.finishEdit(); 
          
acceptUndog_sTOOL_NAME ); 
     

  } 
  
// We're done working, let the user know 
  
clearBusyCursor(); 
 
// end aimat script 

 
var currentFrame Scene.getFrame();
 var 
range Scene.getAnimRange();  
 var 
tick Scene.getTimeStep();  
 var 
startFrame =  range.start tick;
 var 
endFrame  =  range.end tick;
 var 
step 1;//wStep.value;
 
for( var fr startFramefr <= endFramefr += step )
 
{
 Scene
.setFrame(fr);  
 for (var 
i=0i<oStepsi++)
 CameraPos
(oCamera,i,oCentre
 
oCamera.aimAtboxTarget.getCenter() ); 
 var 
oRenderMgr App.getRenderMgr(); 
 
 
oRenderMgr.doRender(); 
 if(
Save==1)
     
var sLastRender oRenderMgr.getLastSavedRenderPath(); 
     var 
oFile = new DzFileInfosLastRender ); 
     var 
sDirPath oFile.path(); 
     var 
sSrcFilename String"%1.%2" ).argoFile.baseName() ).argoFile.extension() ); 
     var 
sTgtFilename String"%1.%2" ).arg"Angle"+i+"Frame"+fr ).argoFile.extension() ); 
     var 
oDir = new DzDirsDirPath ); 
     
oDir.copysSrcFilenameString"../%1" ).argsTgtFilename ) ); 
     
oDir.cdUp(); 
     
sDirPath oDir.path(); 
     var 
oImgMgr App.getImageMgr(); 
     
}    
 }
 
var i=0;
Profile
 
 
Posted: 11 June 2012 06:33 PM   [ Ignore ]   [ # 2 ]
New Member
Total Posts:  18
Joined  2012-02-05

Great script.  Thank you, ReDave!  Just a couple of things that would be nice to change. 
1.  I’d like to change the camera height to, perhaps, 135.  I tried changing the 2nd line to have var oHeight=135;  but it did the same thing.  I even tried restarting Daz Studio, but it still looks like the same angle (105). 
2.  Daz opens up its small render window with each frame rendered.  This could be around 100 per animation.  I have to close every one of those windows after its done.  Is there a way to prevent that or have it automatically close when done?
If you have any ideas on these things, let me know. 
Thanks again.

Profile
 
 
Posted: 12 June 2012 12:07 PM   [ Ignore ]   [ # 3 ]
Active Member
Avatar
RankRank
Total Posts:  803
Joined  2007-01-08

Hmm, camera height works for me (I tried with 5, and I saw the feet all right wink ), however camera height is only half of the pointing vector. I completely forgot until now how the aiming was done in that script: it automatically aims at the center of the bounding box of the selected nodes, so select your whole figure, plus hat if any, to raise the view.
Regarding the second problem I have made experiments, but it doesn’t seem to work with Save=1 (it always wants to overwrite the same file for some reason). So you can set Save=0 and look for the empty line between
var oRenderMgr = App.getRenderMgr();
and
oRenderMgr.doRender();

In that empty line add the following:
var oROptions = App.getRenderMgr().getRenderOptions();
oROptions.RenderImgTarget=2;
oROptions.renderImgFilename=String( “%1.%2” ).arg( “Angle”+i+“Frame”+fr ).arg( “png” );


This should save the pictures elsewhere, though, they ended up in my Content folder for me. But it may be based on the last Content folder you rendered to, I’m none too sure. I’d advise making short experiments first, I use three frames and 1 step, myself.

Profile
 
 
Posted: 12 June 2012 08:43 PM   [ Ignore ]   [ # 4 ]
New Member
Total Posts:  18
Joined  2012-02-05

You’re right, the camera height (oHeight) works.  It just wasn’t what I had expected.  I was thinking it would be like an angle, with 90 = straight on, 180 top down, or something like that.  I see now that its not like that.  Not sure what the unit is, but I will work with it and decide on a setting I like.
As for the script changes, I added it, and running it that way gave an error (and didn’t render anything).  I determined the line it didn’t like is the one that started with:
oROptions.renderImgFilename
I then tried hardcoding a filename to eliminate the error.  It ran like that, but still had the issue of many windows poping up that need to be closed.
This one isn’t a show-stopper for me, but if you have any other ideas, I’d like to hear.
Thanks again for helping me out.

Profile
 
 
Posted: 16 June 2012 12:39 PM   [ Ignore ]   [ # 5 ]
Active Member
Avatar
RankRank
Total Posts:  803
Joined  2007-01-08

Regarding the aiming, remember it points at the center of the bounding box of whatever is selected, so if you can’t find a bodypart that allows the camera to point at the proper angle, try creating a box (Create->New primitive) at frame 0 and set it at the correct height, keep only it selected and turn it invisible.
What version of DS are you running?  I don’t get that error on 4.5 RC1.  However it doesn’t like my hack (which actually worked for me the last time I tried, but doesn’t work right now confused ). I’d like to figure out how to make the renders save themselves without windows popping up, but I don’t think I can troubleshoot it until mid-week.

Profile
 
 
Posted: 16 June 2012 08:36 PM   [ Ignore ]   [ # 6 ]
New Member
Total Posts:  18
Joined  2012-02-05

I’m using Daz Studio Pro 4, the 64-bit version.  Running on Windows 7.

Profile
 
 
Posted: 22 June 2012 11:44 AM   [ Ignore ]   [ # 7 ]
Active Member
Avatar
RankRank
Total Posts:  803
Joined  2007-01-08

I would never have found it on my own, but after getting the correct keywords yet again from a script by Casual, I think I’ve managed. There’s now a variable to change the render to folder (add double slashes \\ instead of just one) in the declarations block near the top.

// DAZ Studio version 2.3  filetype DAZ Script 

 
var oDistanz=360//initial camera position in the z direction 
 
var oHeight=135//camera height 
 
var oSteps=3//number of renders 
 
var Save=1// 1= yes; other values=no 
 
var oOrbitCentre=1// 1=orbit bounding box's center, else orbits oCentre 
 
oCentre = new DzVec3(0,100,0); //0,100,0 
 
var oEccentricity=1// 1=circle; else ellipse. Affects X, not Y nor Z 
 
var s_OutputPath "d:\\test\\";
 
 
// Get current camera 
 
var oViewport MainWindow.getViewportMgr().getActiveViewport(); 
 var 
oCamera oViewport.get3DViewport().getCamera(); 

 var 
oNewPos=new DzVec3
 function 
CameraPos(oCam,oiSteps,oCentre){        
        
var oSin=Math.sin(Math.PI*2*oiSteps/oSteps); 
        var 
oCos=Math.cos(Math.PI*2*oiSteps/oSteps); 
        var 
oNewPos=new DzVec3 (oEccentricity*oSin*oDistanz+oCentre.x,oHeight,oCos*oDistanz+oCentre.z); 
        
oCam.setWSPos(oNewPos); 
 


 
//Aimat script from the help 
  
const g_sTOOL_NAME "Aim Camera"
   
  
/*********************************************************************/ 
  // Box3 : Method for building a box 
  
function buildBoxoCamera )
      
// A box to grow; encompassing target nodes 
      
var boxTarget = new DzBox3
      
// Check if a node is selected 
      
var oPrimaryNode Scene.getPrimarySelection(); 
      
// A flag for whether or not any node warranted inclusion 
      
var bValid false
       
      
// If nodes are selected, get the number of selected nodes, otherwise get the number of all nodes in the scene 
      
var nNodes oPrimaryNode Scene.getNumSelectedNodes() : Scene.getNumNodes(); 
      
// Iterate over the nodes 
      
for( var 0nNodesn++ ) 
          
// If nodes are selected, get the 'current' selected node, otherwise get the 'current' node 
          
var oNode oPrimaryNode Scene.getSelectedNode) : Scene.getNode); 
          
// If the node is defined and it is not the 'current' camera 
          
if( oNode != undefined && oNode != oCamera 
              
// Grow the box to include the node bounding box 
              
boxTarget.include( oNode.getWSBoundingBox() ); 
              
// BINGO!... we got one! 
              
bValid true
          

      } 
      
// If the scene is empty or there were no worthy nodes 
      
if( !nNodes || !bValid 
          
// Um... Houston? 
          
return undefined
      

      
// Ahh... done. 
      
return boxTarget
  

   
  
/*********************************************************************/ 
  // Set the busy cursor to let the user know we're working 
  
setBusyCursor(); 
  
// Get the active viewport 
  
var oViewport MainWindow.getViewportMgr().getActiveViewport(); 
  
// Get the current camera 
  
var oCamera oViewport.get3DViewport().getCamera(); 
  
// Get a box encompassing the nodes to aim at 
  
var boxTarget buildBoxoCamera ); 
   
  
// If the box is defined 
  
if( boxTarget )
      
// Start collecting actions for the undo stack; for non-'view' cameras 
      
if( !oCamera.isViewCamera() ) 
          beginUndo
(); 
          
oCamera.beginEdit(); 
      

      
// Aim the camera at the center of the box 
      
oCamera.aimAtboxTarget.getCenter() ); 
       
      
// Stop collecting events and accept; for non-'view' cameras 
      
if( !oCamera.isViewCamera() ) 
          oCamera
.finishEdit(); 
          
acceptUndog_sTOOL_NAME ); 
     

  } 
  
// We're done working, let the user know 
  
clearBusyCursor(); 
 
// end aimat script 

 
var currentFrame Scene.getFrame();
 var 
range Scene.getAnimRange();  
 var 
tick Scene.getTimeStep();  
 var 
startFrame =  range.start tick;
 var 
endFrame  =  range.end tick;
 var 
step 1;//wStep.value;
 
for( var fr startFramefr <= endFramefr += step )
 
{
 Scene
.setFrame(fr);  
 for (var 
i=0i<oStepsi++)
 CameraPos
(oCamera,i,oCentre
 
oCamera.aimAtboxTarget.getCenter() ); 
 var 
oRenderMgr App.getRenderMgr(); 
 var 
settings oRenderMgr.getRenderOptions();
 
settings.renderImgToId settings.DirectToFile;
 var 
outPic s_OutputPath+"Angle"+i+"Frame"+fr+".png" ;
 
settings.renderImgFilename outPic;
 
oRenderMgr.doRender(); 
  
}
 
var i=0;

I hope it works this time!

Profile
 
 
Posted: 29 June 2012 10:58 PM   [ Ignore ]   [ # 8 ]
New Member
Total Posts:  18
Joined  2012-02-05

Worked like a charm - no more little windows to close.  Fabulous script.  Thanks again, ReDave!

Profile
 
 
Posted: 30 June 2012 12:17 PM   [ Ignore ]   [ # 9 ]
Active Member
Avatar
RankRank
Total Posts:  803
Joined  2007-01-08

No problem, since most of the script is old! wink Glad to have gotten it to work at last!

Profile