Quantcast
Channel: Daz Script Developer Discussion - Daz 3D Forums
Viewing all articles
Browse latest Browse all 1036

World Recenter script - feedback sought

$
0
0

I've finally dipped my toe into the world of Daz scripting and written my first one. Here's what it does...

There are rendering errors that can occur in Iray if a character is too far away from the world origin. Eyes can turn black. Strange marks show on scalps. Maybe other stuff too. So what I've written is a script to move the selected object to (0,0,0) and everything else in the scene stays in the same place relative to it. The only thing that doesn't move is the Perspective View position (is it possible to move that via scripting?).

I've tested it, and it seems to work, but I'd appreciate a once-over from more experienced eyes. Is there anything that I've missed?

// DAZ Studio version 4.10.0.123 filetype DAZ Script
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables

(function(){

   /*********************************************************************/
   // String : A function for retrieving a translation if one exists

   function text( sText )
   {
      // If the version of the application supports qsTr()
      if( typeof( qsTr ) != "undefined" ){
         // Return the translated (if any) text
         return qsTr( sText );
      }
      // Return the original text
      return sText;
   };

   // Define common message variables
   var sButton = text( "&OK" );

   // Get the selected nodes
   var aNodes = Scene.getSelectedNodeList();
   // Get the number of nodes
   var nNodes = aNodes.length;

   if( nNodes != 1 ){
      // We're done...
      MessageBox.warning( "Please select a single item in the scene before invoking this script", "Selection Error", sButton, "" );
      return;
   }

   var oNode = aNodes[0];

    //Offset is the selected object's position, less any origin positioning
    //This should give the same figures that show in the X/Y/Z Translate properties
    // (for unparented items)

    var vOffset = oNode.getWSPos().subtract(oNode.getOrigin());

    var aAllNodes = Scene.getNodeList();
    var nAllNodes = aAllNodes.length;

    // Iterate over the nodes
    for( var i = 0; i < nAllNodes; i += 1 ){

       // Get the 'current' node
       oNode = aAllNodes[ i ];

       // If the node is a root node, move it by the offset amount
       // if it isn't, there's no need as it'll move with its parent

       if (oNode.isRootNode()) {
          var vNewPos = oNode.getWSPos().subtract(vOffset);
          oNode.setWSPos(vNewPos);
       }
   }

   // Finalize the function and invoke
})();

 


Viewing all articles
Browse latest Browse all 1036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>