Description : |
Below is the source of the DAZ Script that prepares the DzScriptedRenderer in DAZ Studio Advanced for rendering operations. |
Concepts Covered : |
|
Source : ./samples/advanced/scripted renderer/content/Scripted Renderer Presets/ |
00001 // DAZ Studio version 3.0 filetype DAZ Script 00002 /********************************************************************** 00003 File: LoadRenderScript.dsa 00004 00005 Copyright © 2002-2009 DAZ Productions. All Rights Reserved. 00006 00007 This file is part of the DAZ Script Documentation. 00008 00009 This file may be used only in accordance with the DAZ Script 00010 license provided with the DAZ Script Documentation. 00011 00012 The contents of this file may not be disclosed to third parties, 00013 copied or duplicated in any form, in whole or in part, without the 00014 prior written permission of DAZ Productions, except as explicitly 00015 allowed in the DAZ Script license. 00016 00017 See http://www.daz3d.com to contact DAZ Productions or for more 00018 information about DAZ Script. 00019 **********************************************************************/ 00020 var oOWNER; 00021 var oRENDER_MANAGER = App.getRenderMgr(); 00022 var oRENDERER = oRENDER_MANAGER.findRenderer("DzScriptedRenderer"); 00023 var sRENDER_SCRIPT = "support/ScriptedRendererExample/StandardRenderPass.dsa"; 00024 00025 if( oRENDERER ) 00026 { 00027 oOWNER = oRENDERER.getPropertyHolder(); 00028 } 00029 00030 /*********************************************************************/ 00031 function addFloatProperty( sPropertyGroup, sPropertyName, sPropertyLabel, fMin, fMax, fDefault, fValue, bClamped, bPercent, bMappable, bMustMap, oShadMap ) 00032 { 00033 var oProperty = oOWNER.findProperty( sPropertyName ); 00034 if( !oProperty || ( oProperty && oProperty.className() != "DzFloatProperty" ) ) 00035 { 00036 oProperty = new DzFloatProperty; 00037 oProperty.name = sPropertyName; 00038 } 00039 oProperty.setLabel( sPropertyLabel ); 00040 oProperty.setPath( sPropertyGroup ); 00041 oProperty.setMinMax( fMin, fMax ); 00042 oProperty.setIsClamped( bClamped ); 00043 oProperty.setDefaultValue( fDefault ); 00044 oProperty.setDisplayAsPercent( bPercent ); 00045 oProperty.setIsMappable( bMappable ); 00046 fValue != undefined ? oProperty.setValue( fValue ) : oProperty.setValue( fDefault ); 00047 if( bMappable ) 00048 { 00049 oProperty.setMustHaveMap( bMustMap ); 00050 if( oShadMap != undefined ) 00051 { 00052 oProperty.setMap( oShadMap ); 00053 } 00054 } 00055 oOWNER.addProperty( oProperty ); 00056 00057 return oProperty; 00058 } 00059 00060 /*********************************************************************/ 00061 function addIntProperty( sPropertyGroup, sPropertyName, sPropertyLabel, nMin, nMax, nDefault, nValue, bClamped, bMappable, bMustMap, oShadMap ) 00062 { 00063 var oProperty = oOWNER.findProperty( sPropertyName ); 00064 if( !oProperty || ( oProperty && oProperty.className() != "DzIntProperty" ) ) 00065 { 00066 oProperty = new DzIntProperty; 00067 oProperty.name = sPropertyName; 00068 } 00069 oProperty.setLabel( sPropertyLabel ); 00070 oProperty.setPath( sPropertyGroup ); 00071 oProperty.setMinMax( nMin, nMax ); 00072 oProperty.setIsClamped( bClamped ); 00073 oProperty.setDefaultValue( nDefault ); 00074 oProperty.setIsMappable( bMappable ); 00075 nValue != undefined ? oProperty.setValue( nValue ) : oProperty.setValue( nDefault ); 00076 if( bMappable ) 00077 { 00078 oProperty.setMustHaveMap( bMustMap ); 00079 if( oShadMap != undefined ) 00080 { 00081 oProperty.setMap( oShadMap ); 00082 } 00083 } 00084 oOWNER.addProperty( oProperty ); 00085 00086 return oProperty; 00087 } 00088 00089 /*********************************************************************/ 00090 function addBoolProperty( sPropertyGroup, sPropertyName, sPropertyLabel, bDefault, bValue ) 00091 { 00092 var oProperty = oOWNER.findProperty( sPropertyName ); 00093 if( !oProperty || ( oProperty && oProperty.className() != "DzBoolProperty" ) ) 00094 { 00095 oProperty = new DzBoolProperty; 00096 oProperty.name = sPropertyName; 00097 } 00098 oProperty.setLabel( sPropertyLabel ); 00099 oProperty.setPath( sPropertyGroup ); 00100 oProperty.setDefaultValue( bDefault ? 1 : 0 ); 00101 bValue != undefined ? oProperty.setBoolValue( bValue ) : oProperty.setBoolValue( bDefault ); 00102 oOWNER.addProperty( oProperty ); 00103 00104 return oProperty; 00105 } 00106 00107 /*********************************************************************/ 00108 function addColorProperty( sPropertyGroup, sPropertyName, sPropertyLabel, clrDefault, clrValue, bMappable, bMustMap, oShadMap ) 00109 { 00110 var oProperty = oOWNER.findProperty( sPropertyName ); 00111 if( !oProperty || ( oProperty && oProperty.className() != "DzColorProperty" ) ) 00112 { 00113 oProperty = new DzColorProperty; 00114 oProperty.name = sPropertyName; 00115 } 00116 oProperty.setLabel( sPropertyLabel ); 00117 oProperty.setPath( sPropertyGroup ); 00118 oProperty.setIsMappable( bMappable ); 00119 if( clrDefault != undefined ) 00120 { 00121 oProperty.setDefaultValue( clrDefault.rgb ); 00122 } 00123 00124 if( clrValue != undefined ) 00125 { 00126 oProperty.setColorValue( clrValue ); 00127 } 00128 00129 if( bMappable ) 00130 { 00131 oProperty.setMustHaveMap( bMustMap ); 00132 if( oShadMap != undefined ) 00133 { 00134 oProperty.setMap( oShadMap ); 00135 } 00136 } 00137 oOWNER.addProperty( oProperty ); 00138 00139 00140 return oProperty; 00141 } 00142 00143 /*********************************************************************/ 00144 function addEnumProperty( sPropertyGroup, sPropertyName, sPropertyLabel, aItems, nValue ) 00145 { 00146 var oProperty = oOWNER.findProperty( sPropertyName ); 00147 if( !oProperty || ( oProperty && oProperty.className() != "DzEnumProperty" ) ) 00148 { 00149 oProperty = new DzEnumProperty; 00150 oProperty.name = sPropertyName; 00151 } 00152 oProperty.setLabel( sPropertyLabel ); 00153 oProperty.setPath( sPropertyGroup ); 00154 if( aItems.length > 0 ) 00155 { 00156 for( var i = 0; i < aItems.length; i++ ) 00157 { 00158 oProperty.addItem( aItems[ i ], i ); 00159 } 00160 } 00161 00162 if( nValue != undefined ) 00163 { 00164 oProperty.setDefaultValue( nValue ); 00165 oProperty.setValue( nValue ); 00166 } 00167 oOWNER.addProperty( oProperty ); 00168 00169 return oProperty; 00170 } 00171 00172 /*********************************************************************/ 00173 function addImageProperty( sPropertyGroup, sPropertyName, sPropertyLabel, sShadVar, oValue ) 00174 { 00175 var oProperty = oOWNER.findProperty( sPropertyName ); 00176 if( !oProperty || ( oProperty && oProperty.className() != "DzImageProperty" ) ) 00177 { 00178 oProperty = new DzImageProperty; 00179 oProperty.name = sPropertyName; 00180 } 00181 oProperty.setLabel( sPropertyLabel ); 00182 oProperty.setPath( sPropertyGroup ); 00183 if( oValue != undefined ) 00184 { 00185 oProperty.setValue( oValue ); 00186 } 00187 oOWNER.addProperty( oProperty ); 00188 00189 return oProperty; 00190 } 00191 00192 /*********************************************************************/ 00193 function addStringProperty( sPropertyGroup, sPropertyName, sPropertyLabel, sShadVar, sValue ) 00194 { 00195 var oProperty = oOWNER.findProperty( sPropertyName ); 00196 if( !oProperty || ( oProperty && oProperty.className() != "DzStringProperty" ) ) 00197 { 00198 oProperty = new DzStringProperty; 00199 oProperty.name = sPropertyName; 00200 } 00201 oProperty.setLabel( sPropertyLabel ); 00202 oProperty.setPath( sPropertyGroup ); 00203 if( sValue != undefined ) 00204 { 00205 oProperty.setValue( sValue ); 00206 } 00207 oOWNER.addProperty( oProperty ); 00208 00209 return oProperty; 00210 } 00211 00212 /*********************************************************************/ 00213 function addFileProperty( sPropertyGroup, sPropertyName, sPropertyLabel, sValue, sFilter, nType ) 00214 { 00215 var oProperty = oOWNER.findProperty( sPropertyName ); 00216 if( !oProperty || ( oProperty && oProperty.className() != "DzFileProperty" ) ) 00217 { 00218 oProperty = new DzFileProperty; 00219 oProperty.name = sPropertyName; 00220 } 00221 oProperty.setLabel( sPropertyLabel ); 00222 oProperty.setPath( sPropertyGroup ); 00223 if( sValue != undefined ) 00224 { 00225 oProperty.setValue( sValue ); 00226 } 00227 00228 if( sFilter != undefined ) 00229 { 00230 oProperty.setFilter( sFilter ); 00231 } 00232 00233 if( nType != undefined ) 00234 { 00235 oProperty.setType( nType ); 00236 } 00237 oOWNER.addProperty( oProperty ); 00238 00239 return oProperty; 00240 } 00241 00242 /*********************************************************************/ 00243 function buildRenderProperties(){ 00244 var sPropertyGroup; 00245 var oProperty; 00246 00247 sPropertyGroup = "Renderer Options"; 00248 00249 oProperty = addEnumProperty( sPropertyGroup, "Bucket Order", "Bucket Order", [ "Horizontal", "Vertical", "ZigZag", "Spiral", "Circle" ], 0 ); 00250 oProperty = addIntProperty( sPropertyGroup, "Bucket Size", "Bucket Size", 8, 128, 16, undefined, true, false, false, undefined ); 00251 oProperty.setSensitivity( 8 ); 00252 oProperty = addIntProperty( sPropertyGroup, "Max Ray Depth", "Max Ray Depth", 0, 16, 4, undefined, true, false, false, undefined ); 00253 oProperty = addIntProperty( sPropertyGroup, "Pixel Samples X", "Pixel Samples (X)", 1, 8, 4, undefined, true, false, false, undefined ); 00254 oProperty = addIntProperty( sPropertyGroup, "Pixel Samples Y", "Pixel Samples (Y)", 1, 8, 4, undefined, true, false, false, undefined ); 00255 oProperty = addIntProperty( sPropertyGroup, "Shadow Samples", "Shadow Samples", 1, 32, 16, undefined, true, false, false, undefined ); 00256 oProperty.setSensitivity( 2 ); 00257 oProperty = addFloatProperty( sPropertyGroup, "Gain", "Gain", 0, 10, 1, undefined, true, false, false, false, undefined ); 00258 oProperty = addFloatProperty( sPropertyGroup, "Gamma", "Gamma", 0.01, 10, 1, undefined, true, false, false, false, undefined ); 00259 oProperty = addFloatProperty( sPropertyGroup, "Shading Rate", "Shading Rate", 0.01, 256, 1, undefined, true, false, false, false, undefined ); 00260 oProperty = addEnumProperty( sPropertyGroup, "Pixel Filter", "Pixel Filter", [ "Box", "Triangle", "Catmull-Rom", "Gaussian", "Sinc" ], 4 ); 00261 oProperty = addIntProperty( sPropertyGroup, "Pixel Filter Width X", "Pixel Filter Width (X)", 1, 32, 6, undefined, true, false, false, undefined ); 00262 oProperty = addIntProperty( sPropertyGroup, "Pixel Filter Width Y", "Pixel Filter Width (Y)", 1, 32, 6, undefined, true, false, false, undefined ); 00263 00264 sPropertyGroup = "Renderer Options/RIB Export"; 00265 00266 oProperty = addBoolProperty( sPropertyGroup, "Render to RIB", "Render to RIB", false, undefined ); 00267 oProperty = addFileProperty( sPropertyGroup, "RIB Path", "RIB Path", undefined, "RenderMan Interface Bytestream (*.rib)", undefined ); 00268 } 00269 00270 /*********************************************************************/ 00271 if( oRENDERER && oOWNER ) 00272 { 00273 // Check to make sure the render script exists 00274 var oFile = new DzFileInfo( App.getAbsoluteScriptPath( sRENDER_SCRIPT ) ); 00275 if( oFile.exists() ) 00276 { 00277 // Let the user know we're busy 00278 setBusyCursor(); 00279 00280 // Remove any old properties 00281 var nProperties = oOWNER.getNumProperties(); 00282 // Iterate in reverse order to ensure a valid index as properties are removed. 00283 for( var i = nProperties - 1; i >= 0; i -= 1 ) 00284 { 00285 oOWNER.removeProperty( oOWNER.getProperty(i) ); 00286 } 00287 00288 // Build our render properties 00289 buildRenderProperties(); 00290 // Set the render script 00291 oRENDERER.setRenderScript( sRENDER_SCRIPT ); 00292 // Set active renderer 00293 oRENDER_MANAGER.setActiveRenderer( oRENDERER ); 00294 00295 // Let the user know we're done 00296 clearBusyCursor(); 00297 } 00298 else 00299 { 00300 MessageBox.critical( String( "The Render Script could not be found.\n\"%1\"" ).arg(sRENDER_SCRIPT), "File Not Found", "&OK", ""); 00301 } 00302 } 00303 else 00304 { 00305 MessageBox.critical( "This action requires the Scripted Renderer included with DAZ Studio 3.x Advanced.\n" + 00306 "Please verify that you have a valid serial number.", "Version Error", "&OK", ""); 00307 } |