render script question

ktg1ktg1 Posts: 0
edited December 1969 in Daz Studio Discussion

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?

Comments

  • ReDaveReDave Posts: 815
    edited June 2012

    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\\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 buildBox( oCamera ){ 
          // 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 n = 0; n < nNodes; n++ ) { 
              // If nodes are selected, get the 'current' selected node, otherwise get the 'current' node 
              var oNode = oPrimaryNode ? Scene.getSelectedNode( n ) : Scene.getNode( n ); 
              // 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 = buildBox( oCamera ); 
       
      // 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.aimAt( boxTarget.getCenter() ); 
           
          // Stop collecting events and accept; for non-'view' cameras 
          if( !oCamera.isViewCamera() ) { 
              oCamera.finishEdit(); 
              acceptUndo( g_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 = startFrame; fr <= endFrame; fr += step )
     {
     Scene.setFrame(fr);  
     for (var i=0; i
    Post edited by ReDave on
  • ktg1ktg1 Posts: 0
    edited December 1969

    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.

  • ReDaveReDave Posts: 815
    edited December 1969

    Hmm, camera height works for me (I tried with 5, and I saw the feet all right ;) ), 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.

  • ktg1ktg1 Posts: 0
    edited December 1969

    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.

  • ReDaveReDave Posts: 815
    edited December 1969

    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 :-S ). 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.

  • ktg1ktg1 Posts: 0
    edited December 1969

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

  • ReDaveReDave Posts: 815
    edited June 2012

    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 buildBox( oCamera ){ 
          // 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 n = 0; n < nNodes; n++ ) { 
              // If nodes are selected, get the 'current' selected node, otherwise get the 'current' node 
              var oNode = oPrimaryNode ? Scene.getSelectedNode( n ) : Scene.getNode( n ); 
              // 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 = buildBox( oCamera ); 
       
      // 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.aimAt( boxTarget.getCenter() ); 
           
          // Stop collecting events and accept; for non-'view' cameras 
          if( !oCamera.isViewCamera() ) { 
              oCamera.finishEdit(); 
              acceptUndo( g_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 = startFrame; fr <= endFrame; fr += step )
     {
     Scene.setFrame(fr);  
     for (var i=0; i

    I hope it works this time!
    Post edited by ReDave on
  • ktg1ktg1 Posts: 0
    edited December 1969

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

  • ReDaveReDave Posts: 815
    edited December 1969

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

Sign In or Register to comment.