Description : |
Below is the source for a DAZ Script that will generate a geometric plane. A dialog allows the user the ability to control the size and the number of divisions for the plane. The method DsActions::begin(), contains the portion of script illustrating use of the DAZ Studio Geometry Pipeline. |
Concepts Covered : |
|
Source : ./samples/ |
00001 /********************************************************************** 00002 File: geomPipe.ds 00003 00004 Copyright © 2002-2006 DAZ Productions. All Rights Reserved. 00005 00006 This file is part of the DAZ Script Documentation. 00007 00008 This file may be used only in accordance with the DAZ Script 00009 license provided with the DAZ Script Documentation. 00010 00011 The contents of this file may not be disclosed to third parties, 00012 copied or duplicated in any form, in whole or in part, without the 00013 prior written permission of DAZ Productions, except as explicitly 00014 allowed in the DAZ Script license. 00015 00016 See http://www.daz3d.com to contact DAZ Productions or for more 00017 information about DAZ Script. 00018 **********************************************************************/ 00019 /***************************** 00020 Script Globals 00021 *****************************/ 00022 const g_sTOOL_NAME = "Geometry Pipeline Sample"; 00023 const g_oFILE = new DzFile( getScriptFileName() ); 00024 const g_sSCRIPT_NAME = String( "%1.%2" ).arg( g_oFILE.baseName() ).arg( g_oFILE.extension() ); 00025 const g_bSHIFT_PRESSED = shiftPressed(); 00026 const g_bCONTROL_PRESSED = ctrlPressed(); 00027 00028 var g_oSettings = new DsSettings; 00029 var g_oGui = new DsInterface; 00030 var g_oActions = new DsActions; 00031 00032 /*********************************************************************/ 00033 // DsSettings - A class for setting/getting stored values 00034 /*********************************************************************/ 00035 class DsSettings{ 00036 /***************************** 00037 Class Members 00038 *****************************/ 00039 var m_oMgr = App.getAppSettingsMgr(); 00040 00041 /*********************************************************************/ 00042 // void : Method for recording settings 00043 function set( sPath, sName, oValue ){ 00044 // Add a temporary 'sub-directory' onto the settings manager path 00045 m_oMgr.pushPath( sPath ); 00046 // Store the setting; dependant on type 00047 switch( typeof oValue ){ 00048 // If value is a string 00049 case "string": 00050 // Set as String 00051 m_oMgr.setStringValue( sName, oValue ); 00052 break; 00053 // If value is bool 00054 case "boolean": 00055 // Set as a Bool 00056 m_oMgr.setBoolValue( sName, oValue ); 00057 break; 00058 // If value is an int, float or double 00059 case "number": 00060 // Set as Float 00061 m_oMgr.setFloatValue( sName, oValue ); 00062 break; 00063 // If none of the above 00064 default: 00065 // Don't do anything 00066 break; 00067 } 00068 // Return the settings manager path to it's previous state. 00069 m_oMgr.popPath(); 00070 } 00071 00072 /*********************************************************************/ 00073 // QObject : Method for retrieving settings 00074 function get( sPath, sName, oValue ){ 00075 // Create a variable to store the value 00076 var v; 00077 // Add a temporary 'sub-directory' onto the settings manager path 00078 m_oMgr.pushPath( sPath ); 00079 // Retrieve the setting; dependant on type 00080 switch( typeof oValue ){ 00081 // If value is a string 00082 case "string": 00083 v = m_oMgr.getStringValue( sName, oValue ); 00084 break; 00085 // If value is a bool 00086 case "boolean": 00087 v = m_oMgr.getBoolValue( sName, oValue ); 00088 break; 00089 // If value is an int, float or double 00090 case "number": 00091 v = m_oMgr.getFloatValue( sName, oValue ); 00092 break; 00093 // If none of the above 00094 default: 00095 // Don't do anything 00096 break; 00097 } 00098 // Return the settings manager path to it's previous state. 00099 m_oMgr.popPath(); 00100 // Return the value 00101 return v; 00102 } 00103 } 00104 00105 /*********************************************************************/ 00106 // DsInterface - A class for interfacing with the user 00107 /*********************************************************************/ 00108 class DsInterface{ 00109 /***************************** 00110 Class Members 00111 *****************************/ 00112 const m_nMARGIN = 5; 00113 const m_nSPACING = 5; 00114 const m_nMIN_BTN_WIDTH = 80; 00115 const m_nMAX_BTN_HEIGHT = 20; 00116 const m_nWIDGET_WIDTH = 190; 00117 00118 // List of Boolean options 00119 var m_aBoolNames = new Array; 00120 var m_aBoolObjs = new Array; 00121 // List of String options 00122 var m_aStrNames = new Array; 00123 var m_aStrObjs = new Array; 00124 // List of ComboBox options 00125 var m_aCmbNames = new Array; 00126 var m_aCmbObjs = new Array; 00127 // 00128 var m_wDlg, m_wTabStack; 00129 var m_wOptionPage, m_wPrefsPage; 00130 var m_wCombGB, m_wPrefsGB; 00131 var m_wSizeLbl, m_wDivsnLbl; 00132 var m_wSize, m_wSizeUnits, m_wDivisions; 00133 var m_wHelpBtn, m_wAcceptBtn, m_wCancelBtn; 00134 var m_wRcrdOnExec, m_wRcrdBtn, m_wRdBtn, m_wDfltBtn; 00135 00136 /*********************************************************************/ 00137 // void : Build the 'common' portion of the interface (used in hidden and unhidden modes) 00138 function doCommon(){ 00139 // --------------------- 00140 // --- Main dialog 00141 // --------------------- 00142 m_wDlg = new DzDialog; 00143 m_wTabStack = new DzTabWidget( m_wDlg ); 00144 // --------------------- 00145 // --- Options Page 00146 // --------------------- 00147 m_wOptionPage = new DzVGroupBox( m_wTabStack ); 00148 m_wCombGB = new DzVGroupBox( m_wOptionPage ); 00149 // --- Size 00150 m_wSizeLbl = new DzLabel( m_wCombGB ); 00151 m_wSize = new DzLineEdit( m_wCombGB ); 00152 m_aStrObjs.push( m_wSize ); 00153 m_aStrNames.push( 'size' ); 00154 m_wSizeUnits = new DzComboBox( m_wCombGB ); 00155 m_wSizeUnits.insertItem( "m" ); 00156 m_wSizeUnits.insertItem( "cm" ); 00157 m_wSizeUnits.insertItem( "yd" ); 00158 m_wSizeUnits.insertItem( "ft" ); 00159 m_wSizeUnits.insertItem( "in" ); 00160 m_aCmbObjs.push( m_wSizeUnits ); 00161 m_aCmbNames.push( 'units' ); 00162 // --- Divisions 00163 m_wDivsnLbl = new DzLabel( m_wCombGB ); 00164 m_wDivisions = new DzLineEdit( m_wCombGB ); 00165 m_aStrObjs.push( m_wDivisions ); 00166 m_aStrNames.push( 'divisions' ); 00167 // --------------------- 00168 // --- Preferences Page 00169 // --------------------- 00170 m_wPrefsPage = new DzVGroupBox( m_wTabStack ); 00171 m_wPrefsGB = new DzVGroupBox( m_wPrefsPage ); 00172 // --- Record on Execution 00173 m_wRcrdOnExec = new DzCheckBox( m_wPrefsGB ); 00174 m_aBoolObjs.push( m_wRcrdOnExec ); 00175 m_aBoolNames.push( 'rcrdOnExec' ); 00176 // Set the initial options 00177 setDefaults(); 00178 } 00179 00180 /*********************************************************************/ 00181 // void : Method for running with the dialog unhidden 00182 function doDialog(){ 00183 // Build the common portion of the dialog 00184 doCommon(); 00185 var oHelp = App.getHelpMgr(); 00186 var oMgr = MainWindow.getActionMgr(); 00187 var oAction = oMgr ? oMgr.findAction( "DzWhatsThisAction" ) : undefined; 00188 // --------------------- 00189 // --- Main dialog 00190 // --------------------- 00191 m_wDlg.caption = String( "%1 (%2)" ).arg( g_sTOOL_NAME ).arg( g_sSCRIPT_NAME ); 00192 m_wDlg.whatsThis = 00193 String( "<b>File : </b> %1<br>" ).arg( g_sSCRIPT_NAME ) + 00194 String( "<b>Type : </b> %2<br>" ).arg( getScriptType() ) + 00195 String( "<b>Size : </b> %3<br>" ).arg( g_oFILE.sizeStr() ) + 00196 String( "<b>Version : </b> %4<br>" ).arg( getScriptVersionString() ) + 00197 String( "<b>Created : </b> %5<br>" ).arg( g_oFILE.created().toString( "dddd, MMMM d yyyy h:mm ap" ) ) + 00198 String( "<b>Modified : </b> %6" ).arg( g_oFILE.lastModified().toString( "dddd, MMMM d yyyy h:mm ap" ) ); 00199 // --- Main dialog layout 00200 var wDlgLayout = new DzGridLayout( m_wDlg ); 00201 wDlgLayout.margin = m_nMARGIN; 00202 wDlgLayout.spacing = m_nSPACING; 00203 wDlgLayout.addMultiCellWidget( m_wTabStack, 0, 0, 0, 2 ); 00204 // --- Dialog Buttons 00205 var wDlgBtnsGB = new DzGroupBox( m_wDlg ); 00206 wDlgBtnsGB.flat = true; 00207 var wDlgBtnsLyt = new DzGridLayout( wDlgBtnsGB ); 00208 wDlgBtnsLyt.margin = m_nMARGIN; 00209 wDlgBtnsLyt.spacing = m_nSPACING; 00210 // --- Help button 00211 m_wHelpBtn = new DzPushButton( wDlgBtnsGB ); 00212 m_wHelpBtn.pixmap = new Pixmap( String( "%1/images/icons/whatsthissmallicon.png" ).arg( App.getResourcesPath() ) ); 00213 m_wHelpBtn.maxHeight = m_nMAX_BTN_HEIGHT; 00214 if( oAction ) 00215 connect( m_wHelpBtn, "clicked()", oAction, "activate()" ); 00216 m_wHelpBtn.toolTip = oHelp.getToolTip( "WhatsThis" ); 00217 m_wHelpBtn.whatsThis = oHelp.getHelpString( "WhatsThis" ); 00218 wDlgBtnsLyt.addWidget( m_wHelpBtn, 0, 0 ); 00219 // --- Space 00220 wDlgBtnsLyt.setColStretch( 1, 1 ); 00221 // --- Accept button 00222 m_wAcceptBtn = new DzPushButton( wDlgBtnsGB ); 00223 m_wAcceptBtn.text = "&Accept"; 00224 m_wAcceptBtn.minWidth = m_nMIN_BTN_WIDTH; 00225 m_wAcceptBtn.maxHeight = m_nMAX_BTN_HEIGHT; 00226 m_wDlg.setAcceptButton( m_wAcceptBtn ); 00227 m_wAcceptBtn.toolTip = oHelp.getToolTip( "AcceptDialog" ); 00228 m_wAcceptBtn.whatsThis = oHelp.getHelpString( "AcceptDialog" ); 00229 wDlgBtnsLyt.addWidget( m_wAcceptBtn, 0, 2 ); 00230 // --- Cancel button 00231 m_wCancelBtn = new DzPushButton( wDlgBtnsGB ); 00232 m_wCancelBtn.text = "&Cancel"; 00233 m_wCancelBtn.minWidth = m_nMIN_BTN_WIDTH; 00234 m_wCancelBtn.maxHeight = m_nMAX_BTN_HEIGHT; 00235 m_wDlg.setRejectButton( m_wCancelBtn ); 00236 m_wCancelBtn.toolTip = oHelp.getToolTip( "CancelDialog" ); 00237 m_wCancelBtn.whatsThis = oHelp.getHelpString( "CancelDialog" ); 00238 wDlgBtnsLyt.addWidget( m_wCancelBtn, 0, 3 ); 00239 00240 wDlgLayout.addMultiCellWidget( wDlgBtnsGB, 1, 1, 0, 2 ); 00241 // --------------------- 00242 // --- Options Page 00243 // --------------------- 00244 m_wOptionPage.whatsThis = oHelp.getHelpString( "PresetOptionTab" ); 00245 m_wOptionPage.flat = true; 00246 m_wOptionPage.insideMargin = m_nMARGIN; 00247 m_wOptionPage.insideSpacing = m_nSPACING; 00248 m_wCombGB.columns = 3; 00249 // --- Size 00250 m_wSizeLbl.text = "Size :"; 00251 m_wSizeLbl.alignment = m_wSizeLbl.AlignRight; 00252 m_wSizeLbl.whatsThis = oHelp.getHelpString( "PrimitiveSize" ); 00253 m_wSize.alignment = m_wSize.AlignRight; 00254 m_wSize.whatsThis = m_wSizeLbl.whatsThis; 00255 m_wSizeUnits.whatsThis = m_wSizeLbl.whatsThis; 00256 // --- Divisions 00257 m_wDivsnLbl.text = "Divisions :"; 00258 m_wDivsnLbl.alignment = m_wDivsnLbl.AlignRight; 00259 m_wDivsnLbl.whatsThis = oHelp.getHelpString( "PrimitiveDivisions" ); 00260 m_wDivisions.alignment = m_wDivisions.AlignRight; 00261 m_wDivisions.whatsThis = m_wDivsnLbl.whatsThis; 00262 // Add the 'Options Page' widget to the tab stack 00263 m_wTabStack.addTab( m_wOptionPage, "Options" ); 00264 // --------------------- 00265 // --- Preferences Page 00266 // --------------------- 00267 m_wPrefsPage.whatsThis = oHelp.getHelpString( "PresetPrefTab" ); 00268 m_wPrefsPage.flat = true; 00269 m_wPrefsPage.insideMargin = m_nMARGIN; 00270 m_wPrefsPage.insideSpacing = m_nSPACING; 00271 m_wPrefsGB.margin = m_nMARGIN; 00272 m_wPrefsGB.spacing = m_nSPACING; 00273 // --- Record on Execution CheckBox 00274 m_wRcrdOnExec.text = "Set Preferred Options on Accept"; 00275 m_wRcrdOnExec.whatsThis = oHelp.getHelpString( "PresetPrefOnAccept" ); 00276 // --- Set Preferred Options Button 00277 m_wRcrdBtn = new DzPushButton( m_wPrefsGB ); 00278 m_wRcrdBtn.text = "&Set Preferred Options"; 00279 m_wRcrdBtn.whatsThis = oHelp.getHelpString( "PresetSetPref" ); 00280 connect( m_wRcrdBtn, "pressed()", setOptions ); 00281 // --- Read Preferred Options Button 00282 m_wRdBtn = new DzPushButton( m_wPrefsGB ); 00283 m_wRdBtn.text = "&Read Preferred Options"; 00284 m_wRdBtn.whatsThis = oHelp.getHelpString( "PresetReadPref" ); 00285 connect( m_wRdBtn, "pressed()", getOptions ); 00286 // --- Restore Default Options Button 00287 m_wDfltBtn = new DzPushButton( m_wPrefsGB ); 00288 m_wDfltBtn.text = "Restore &Default Options"; 00289 m_wDfltBtn.whatsThis = oHelp.getHelpString( "PresetRestoreDef" ); 00290 connect( m_wDfltBtn, "pressed()", setDefaults ); 00291 // --- Notes 00292 var wNotesGB = new DzVGroupBox( m_wPrefsPage ); 00293 wNotesGB.title = "Notes :"; 00294 wNotesGB.margin = m_nMARGIN; 00295 wNotesGB.spacing = m_nSPACING; 00296 wNotesGB.minWidth = m_nWIDGET_WIDTH + 100; 00297 var wKeyLbl = new DzLabel( wNotesGB ); 00298 wKeyLbl.text = oHelp.getHelpString( "PresetNotes" ); 00299 // Add the 'Preferences Page' widget to the tab stack 00300 m_wTabStack.addTab( m_wPrefsPage, "Preferences" ); 00301 // --------------------- 00302 // --- Polish 00303 // --------------------- 00304 m_wDlg.maxWidth = m_wDlg.minWidth; 00305 m_wDlg.maxHeight = m_wDlg.minHeight; 00306 // Get the users prefered options 00307 getOptions(); 00308 // If the dialog is not canceled 00309 if( m_wDlg.exec() ){ 00310 // If the 'Record on Execute' checkbox is checked, record the current options 00311 if( m_wRcrdOnExec.checked ){ setOptions(); } 00312 // Do... whatever it is that we do 00313 g_oActions.begin(); 00314 } 00315 } 00316 00317 /*********************************************************************/ 00318 // void : Method for running with the dialog hidden 00319 function doNoDialog(){ 00320 // Build the common portion of the dialog 00321 doCommon(); 00322 // If the user was holding the shift modifier, update the options from the ones recorded 00323 if( g_bSHIFT_PRESSED ){ getOptions(); } 00324 // Do... whatever it is that we do 00325 g_oActions.begin(); 00326 } 00327 00328 /*********************************************************************/ 00329 // void : Method for setting initial option values 00330 function setDefaults(){ 00331 // --- ComboBox options 00332 // Iterate over all items for the surfaces combo box 00333 for( var i = 0; i < m_wSizeUnits.count; i++ ){ 00334 // If we find one equal to the default we want 00335 if( m_wSizeUnits.text( i ) == "cm" ){ 00336 // Set the current item 00337 m_wSizeUnits.currentItem = i; 00338 // We found it, we're done here 00339 break; 00340 } 00341 // As a backup, default to the first item 00342 m_wSizeUnits.currentItem = 0; 00343 } 00344 00345 // --- String options 00346 m_wSize.text = 10; 00347 m_wDivisions.text = 3; 00348 00349 // --- Boolean options 00350 m_wRcrdOnExec.checked = false; 00351 } 00352 00353 /*********************************************************************/ 00354 // void : Method for retrieving options 00355 function getOptions(){ 00356 // Iterate over all boolean option objects 00357 for( var i = 0; i < m_aBoolObjs.length; i++ ){ 00358 // Set the 'current' boolean option to the recorded value 00359 m_aBoolObjs[ i ].checked = g_oSettings.get( g_oActions.stripSpaces( g_sTOOL_NAME ), m_aBoolNames[ i ], m_aBoolObjs[ i ].checked ); 00360 } 00361 // Iterate over all string option objects 00362 for( var i = 0; i < m_aStrObjs.length; i++ ){ 00363 // Set the 'current' string option to the recorded value 00364 m_aStrObjs[ i ].text = g_oSettings.get( g_oActions.stripSpaces( g_sTOOL_NAME ), m_aStrNames[ i ], m_aStrObjs[ i ].text ); 00365 } 00366 // Iterate over all combobox option objects 00367 for( var i = 0; i < m_aCmbObjs.length; i++ ){ 00368 // Get the recorded currentText value 00369 var tStr = g_oSettings.get( g_oActions.stripSpaces( g_sTOOL_NAME ), m_aCmbNames[ i ], m_aCmbObjs[ i ].currentText ); 00370 // Iterate over all combo box option objects 00371 for( var j = 0; j < m_aCmbObjs[ i ].count; j++ ){ 00372 // If the recorded value is valid 00373 if( m_aCmbObjs[ i ].text( j ) == tStr ){ 00374 // Set the currentItem string option to the recorded value 00375 m_aCmbObjs[ i ].currentItem = j; 00376 break; 00377 } 00378 } 00379 } 00380 } 00381 00382 /*********************************************************************/ 00383 // void : Method for recording options 00384 function setOptions(){ 00385 // Iterate over all boolean option objects 00386 for( var i = 0; i < m_aBoolObjs.length; i++ ){ 00387 // Record the current boolean option 00388 g_oSettings.set( g_oActions.stripSpaces( g_sTOOL_NAME ), m_aBoolNames[ i ], m_aBoolObjs[ i ].checked ); 00389 } 00390 // Iterate over all string option objects 00391 for( var i = 0; i < m_aStrObjs.length; i++ ){ 00392 // Record the current string option 00393 g_oSettings.set( g_oActions.stripSpaces( g_sTOOL_NAME ), m_aStrNames[ i ], m_aStrObjs[ i ].text ); 00394 } 00395 // Iterate over all combobox option objects 00396 for( var i = 0; i < m_aCmbObjs.length; i++ ){ 00397 // Record the currentText string option 00398 g_oSettings.set( g_oActions.stripSpaces( g_sTOOL_NAME ), m_aCmbNames[ i ], m_aCmbObjs[ i ].currentText ); 00399 } 00400 } 00401 00402 /*********************************************************************/ 00403 // QString : Method for retrieving the size 00404 function getSize(){ return parseFloat( m_wSize.text ); } 00405 00406 /*********************************************************************/ 00407 // QString : Method for retrieving the units of size 00408 function getSizeUnits(){ return m_wSizeUnits.currentText; } 00409 00410 /*********************************************************************/ 00411 // QString : Method for retrieving the number of divisions 00412 function getDivisions(){ return parseInt( m_wDivisions.text ); } 00413 } 00414 00415 /*********************************************************************/ 00416 // DsActions - A class for performing various actions 00417 /*********************************************************************/ 00418 class DsActions{ 00419 /*********************************************************************/ 00420 // String : Method for striping spaces out of a string 00421 function stripSpaces( sString ){ 00422 var rePattern = RegExp( " " ); 00423 rePattern.global = true; 00424 return sString.replace( rePattern, "" ); 00425 } 00426 00427 /*********************************************************************/ 00428 // Number : A method to convert from meters/yards/feet/inches to centimeters 00429 function convertToCM( fVal, sFromUnit : String ){ 00430 switch( sFromUnit.lower() ){ 00431 case "m": 00432 return fVal * 100; 00433 case "yd": 00434 return fVal * 36.0 * 2.54; 00435 case "ft": 00436 return fVal * 12.0 * 2.54; 00437 case "in": 00438 return fVal * 2.54; 00439 } 00440 00441 return fVal; 00442 } 00443 00444 /*********************************************************************/ 00445 // String : A method for coming up with a unique name 00446 function getUniqueName( sName ){ 00447 // Initialize 00448 var sUnqName = sName; 00449 // If a node by the same nam e already exists 00450 if( Scene.findNode( sUnqName ) ){ 00451 // Create an array of the name parts 00452 var aName = sUnqName.split( " " ); 00453 // Initialize 00454 var sPreName = sUnqName; 00455 // If the last name part is a number 00456 if( !isNaN( aName[ aName.length - 1 ] ) ){ 00457 // Get rid of the number 00458 aName.pop(); 00459 // Reconstruct the name without the number 00460 sPreName = aName.join( " " ); 00461 } 00462 // Initialize a count 00463 var i = 2; 00464 // Until we cannot find a node with the label 00465 while( Scene.findNode( String( "%1 %2" ).arg( sPreName ).arg( i ) ) ) 00466 // Increment the count 00467 i++; 00468 // Construct the unique name 00469 sUnqName = String( "%1 %2" ).arg( sPreName ).arg( i ); 00470 } 00471 00472 // Return the unique name 00473 return sUnqName; 00474 } 00475 00476 /*********************************************************************/ 00477 // String : A method for coming up with a unique label 00478 function getUniqueLabel( sLabel ){ 00479 // Initialize 00480 var sUnqLabel = sLabel; 00481 // If a node by the same label already exists 00482 if( Scene.findNodeByLabel( sUnqLabel ) ){ 00483 // Create an array of the label parts 00484 var aLabel = sUnqLabel.split( " " ); 00485 // Initialize 00486 var sPreLabel = sUnqLabel; 00487 // Get the last label part 00488 var sLastPart = aLabel[ aLabel.length - 1 ]; 00489 // If the last label part is a number enclosed in parens 00490 if( sLastPart.startsWith( "(" ) && sLastPart.endsWith( ")" ) && 00491 !isNaN( sLastPart.substring( 1, sLastPart.length - 1 ) ) ){ 00492 // Get rid of the number 00493 aLabel.pop(); 00494 // Reconstruct the Label without the number 00495 sPreLabel = aLabel.join( " " ); 00496 } 00497 // Initialize a count 00498 var i = 2; 00499 // Until we cannot find a node with the label 00500 while( Scene.findNodeByLabel( String( "%1 (%2)" ).arg( sPreLabel ).arg( i ) ) ) 00501 // Increment the count 00502 i++; 00503 // Construct the unique Label 00504 sUnqLabel = String( "%1 (%2)" ).arg( sPreLabel ).arg( i ); 00505 } 00506 00507 // Return the unique Label 00508 return sUnqLabel; 00509 } 00510 00511 /*********************************************************************/ 00512 // void : Method to do whatever it is we do 00513 function begin(){ 00514 // Get the user input 00515 var fSize = g_oGui.getSize(); 00516 var sUnit = g_oGui.getSizeUnits(); 00517 var nDivisions = g_oGui.getDivisions(); 00518 00519 // Let the user know we're busy 00520 setBusyCursor(); 00521 00522 // Build the name of the node 00523 var sName = String( "Plane_%1x%2_%3%4" ).arg( nDivisions ).arg( nDivisions ).arg( fSize ).arg( sUnit ); 00524 00525 // Create new node 00526 var oNode = new DzNode; 00527 oNode.setName( getUniqueName( sName ) ); 00528 oNode.setLabel( getUniqueLabel( sName ) ); 00529 00530 // Create a new object 00531 var oObject = new DzObject; 00532 oObject.name = sName; 00533 00534 // Create a new polygonal shape 00535 var oPolyShape = new DzPolyShape; 00536 oPolyShape.name = "Default"; 00537 oPolyShape.setLabel( oPolyShape.name ); 00538 00539 // Create a new polygonal mesh 00540 var oPolyMesh = new DzPolyMesh; 00541 00542 // Get the [uv] map 00543 var oMap = oPolyMesh.getUVs(); 00544 00545 // Set the mesh for the shape 00546 oPolyShape.setPolyMesh( oPolyMesh ); 00547 00548 // Create a new default material 00549 var oMaterial = new DzDefaultMaterial; 00550 oMaterial.name = "Default"; 00551 oMaterial.setLabel( oMaterial.name ); 00552 00553 // Add the material to the shape 00554 oPolyShape.addMaterial( oMaterial ); 00555 00556 // Begin editing the mesh 00557 oPolyMesh.beginEdit(); 00558 00559 // Activate the material - all new geometry will be added to this 00560 oPolyMesh.activateMaterial( oPolyShape.findMaterialIndex( oMaterial ) ); 00561 00562 // Convert the input value to centimeters 00563 fSize = convertToCM( fSize, sUnit ); 00564 00565 // Declare some variables for generating the mesh 00566 var i, j, idx, numVerts = nDivisions + 1; 00567 var x, z, fHalfSize = fSize / 2; 00568 var vecUVs = new DzVec3( 0, 0, 0 ); 00569 00570 // Create the vertices 00571 for( i = 0; i < numVerts; i++ ){ 00572 z = i / nDivisions; 00573 vecUVs.y = z; 00574 for( j = 0; j < numVerts; j++ ){ 00575 x = j / nDivisions; 00576 vecUVs.x = x; 00577 oPolyMesh.addVertex( x * fSize - fHalfSize, 0, fHalfSize - z * fSize ); 00578 oMap.appendPnt2Vec( vecUVs ); 00579 } 00580 } 00581 00582 // Create the faces 00583 for( i = 0; i < nDivisions; i++ ){ 00584 for( j = 0; j < nDivisions; j++ ){ 00585 oPolyMesh.startFace(); 00586 idx = j + (i * numVerts); 00587 oPolyMesh.addFaceEdge( idx, idx ); 00588 00589 idx = j + (i * numVerts) + 1; 00590 oPolyMesh.addFaceEdge( idx, idx ); 00591 00592 idx = j + ((i + 1) * numVerts) + 1; 00593 oPolyMesh.addFaceEdge( idx, idx ); 00594 00595 idx = j + ((i + 1) * numVerts); 00596 oPolyMesh.addFaceEdge( idx, idx ); 00597 oPolyMesh.finishFace(); 00598 } 00599 } 00600 00601 // Finish editing the mesh 00602 oPolyMesh.finishEdit(); 00603 00604 // Add the shape to the object 00605 oObject.addShape( oPolyShape ); 00606 00607 // Add the object to the node 00608 oNode.setObject( oObject ); 00609 00610 // Add the node to the scene 00611 Scene.addNode( oNode ); 00612 00613 // Let the user know we're done 00614 clearBusyCursor(); 00615 } 00616 } 00617 00618 /*********************************************************************/ 00619 // Do... whatever it is that we do 00620 g_oGui.doDialog(); |