Advertisement
Guest User

Untitled

a guest
Jul 5th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.38 KB | None | 0 0
  1. // DAZ Studio version 4.12.0.86 filetype DAZ Script
  2.  
  3. (function(){
  4.  
  5. var s_oFileInfo = new DzFileInfo( getScriptFileName() );
  6. var s_sToolName = s_oFileInfo.baseName();
  7. s_oFileInfo.deleteLater();
  8.  
  9. var s_aSkeletons = Scene.getSkeletonList();
  10.  
  11. var s_oPrimaryNode = Scene.getPrimarySelection();
  12. var s_oPrimarySkeleton = undefined;
  13. if( s_oPrimaryNode ){
  14. if( s_oPrimaryNode.inherits( "DzSkeleton" ) ){
  15. s_oPrimarySkeleton = s_oPrimaryNode;
  16. } else if( s_oPrimaryNode.inherits( "DzBone" ) ){
  17. s_oPrimarySkeleton = s_oPrimaryNode.getSkeleton();
  18. }
  19. }
  20.  
  21. var s_sExporter = "DzFbxExporter";//"DzDAZCOLLADAExporter"
  22. var s_sExportExt = "fbx";//"dae"
  23.  
  24. // TODO: This should be a preference controlled by the user instead of
  25. // a hard-coded path on the primary drive of the user's machine; this
  26. // either needs to be configurable on both sides of the "bridge", or
  27. // this side needs to store a DzAppSettings with the path used and the
  28. // other side needs to retrieve the path; either way, both sides need
  29. // to agree before a change can be pushed to end users
  30. var s_sExportPath = "C:/TEMP3D";
  31. if( App.platform() == DzApp.MacOSX ){
  32. s_sExportPath = "/users/Shared/temp3d";
  33. }
  34.  
  35. var s_sExportBaseName = "DazToMaya";
  36. /*********************************************************************/
  37.  
  38. function getXRot( oSkeleton, sBoneLabel )
  39. {
  40. if( !oSkeleton || sBoneLabel.isEmpty() ){
  41. return undefined;
  42. }
  43.  
  44. var oBone = oSkeleton.findBoneByLabel( sBoneLabel );
  45. if( !oBone ){
  46. return undefined;
  47. }
  48.  
  49. var oControl = oBone.getXRotControl();
  50. var nValue = oControl.getValue();
  51. //print( ":: get x :: " + sBoneLabel + " :: " + nValue );
  52. return nValue;
  53. };
  54.  
  55. /*********************************************************************/
  56.  
  57. function setXRot( oSkeleton, sBoneLabel, nValue )
  58. {
  59. if( !oSkeleton
  60. || sBoneLabel.isEmpty()
  61. || nValue == undefined ){
  62. return;
  63. }
  64.  
  65. //print( ":: set x :: " + sBoneLabel + " :: " + nValue );
  66. var oBone = oSkeleton.findBoneByLabel( sBoneLabel );
  67. if( !oBone ){
  68. return;
  69. }
  70.  
  71. var oControl = oBone.getXRotControl();
  72. oControl.setValue( nValue );
  73. };
  74. // This function will give all the head morphs of selected character
  75. // and will create the rule to be used in the fbx export.
  76. /*********************************************************************/
  77.  
  78. function createMorphRules(){
  79. var oNode = Scene.getPrimarySelection();
  80. if( !oNode ){
  81. return;
  82. }
  83. if( oNode.inherits( "DzBone" ) ){
  84. oNode = oNode.getSkeleton();
  85. }
  86. if( oNode.inherits( "DzSkeleton" ) ){
  87. oNode = oNode.findBone( "head" );
  88. }
  89. if( !oNode ){
  90. return;
  91. }
  92. var oProperty;
  93. var oPropGroup;
  94. var oPropTree;
  95. var oPropOwner;
  96. var oTgtProperty;
  97. var oTgtPropGroup;
  98. var oTgtPropTree;
  99. var oTgtPropOwner;
  100. var aProperties = oNode.getPropertyList();
  101. var morphRule;
  102. var morphName;
  103. var morphList=[];
  104. var morphRule = "";
  105. for( var i = 0, n = aProperties.length; i < n; i += 1 ){
  106. oProperty = aProperties[ i ];
  107. if( !oProperty.getPath().startsWith( "/Pose Controls" ) ){
  108. continue;
  109. }
  110.  
  111. if( oProperty.isAlias() ){
  112. oTgtProperty = oProperty.getAliasTarget();
  113. oTgtPropGroup = oTgtProperty.getGroup();
  114. oTgtPropTree = oTgtPropGroup.getTree();
  115. oTgtPropOwner = oTgtPropTree.getOwner();
  116. morphName =oTgtProperty.name;
  117. morphList[i]=morphName;
  118. //oTgtPropOwner.name + "." +
  119. continue;
  120. }
  121. }
  122. //Remove any nulls or undefined in the array
  123. morphList = morphList.filter(Boolean);
  124.  
  125. for( var i = 0, n = morphList.length; i < n; i += 1 ){
  126.  
  127. morphRule = morphRule + morphList[i] + "\n1\n";
  128.  
  129. };
  130.  
  131. return morphRule = morphRule.substring(0,morphRule.length - 2);
  132. };
  133.  
  134. /*********************************************************************/
  135.  
  136. function heelsFix( oSkeleton )
  137. {
  138. if( oSkeleton ){
  139. return;
  140. }
  141.  
  142. //Left
  143. try { var xRotLeftMetatarsals = getXRot( oSkeleton, "Left Metatarsals" ); } catch( error ){}
  144. try { var xRotLeftHeel = getXRot( oSkeleton, "Left Heel" ); } catch( error ){}
  145. try { var xRotLeftFoot = getXRot( oSkeleton, "Left Foot" ); } catch( error ){}
  146. try { var xRotLeftToes = getXRot( oSkeleton, "Left Toes" ); } catch( error ){}
  147. try { var xRotLeftBigToe = getXRot( oSkeleton, "Left Big Toe" ); } catch( error ){}
  148. try { var xRotLeftBigToe2 = getXRot( oSkeleton, "Left Big Toe_2" ); } catch( error ){}
  149. try { var xRotLeftSmallToe1 = getXRot( oSkeleton, "Left Small Toe 1" ); } catch( error ){}
  150. try { var xRotLeftSmallToe12 = getXRot( oSkeleton, "Left Small Toe 1_2" ); } catch( error ){}
  151. try { var xRotLeftSmallToe2 = getXRot( oSkeleton, "Left Small Toe 2" ); } catch( error ){}
  152. try { var xRotLeftSmallToe22 = getXRot( oSkeleton, "Left Small Toe 2_2" ); } catch( error ){}
  153. try { var xRotLeftSmallToe3 = getXRot( oSkeleton, "Left Small Toe 3" ); } catch( error ){}
  154. try { var xRotLeftSmallToe32 = getXRot( oSkeleton, "Left Small Toe 3_2" ); } catch( error ){}
  155. try { var xRotLeftSmallToe4 = getXRot( oSkeleton, "Left Small Toe 4" ); } catch( error ){}
  156. try { var xRotLeftSmallToe42 = getXRot( oSkeleton, "Left Small Toe 4_2" ); } catch( error ){}
  157.  
  158. //Right
  159. try { var xRotRightMetatarsals = getXRot( oSkeleton, "Right Metatarsals" ); } catch( error ){}
  160. try { var xRotRightHeel = getXRot( oSkeleton, "Right Heel" ); } catch( error ){}
  161. try { var xRotRightFoot = getXRot( oSkeleton, "Right Foot" ); } catch( error ){}
  162. try { var xRotRightToes = getXRot( oSkeleton, "Right Toes" ); } catch( error ){}
  163. try { var xRotRightBigToe = getXRot( oSkeleton, "Right Big Toe" ); } catch( error ){}
  164. try { var xRotRightBigToe2 = getXRot( oSkeleton, "Right Big Toe_2" ); } catch( error ){}
  165. try { var xRotRightSmallToe1 = getXRot( oSkeleton, "Right Small Toe 1" ); } catch( error ){}
  166. try { var xRotRightSmallToe12 = getXRot( oSkeleton, "Right Small Toe 1_2" ); } catch( error ){}
  167. try { var xRotRightSmallToe2 = getXRot( oSkeleton, "Right Small Toe 2" ); } catch( error ){}
  168. try { var xRotRightSmallToe22 = getXRot( oSkeleton, "Right Small Toe 2_2" ); } catch( error ){}
  169. try { var xRotRightSmallToe3 = getXRot( oSkeleton, "Right Small Toe 3" ); } catch( error ){}
  170. try { var xRotRightSmallToe32 = getXRot( oSkeleton, "Right Small Toe 3_2" ); } catch( error ){}
  171. try { var xRotRightSmallToe4 = getXRot( oSkeleton, "Right Small Toe 4" ); } catch( error ){}
  172. try { var xRotRightSmallToe42 = getXRot( oSkeleton, "Right Small Toe 4_2" ); } catch( error ){}
  173.  
  174. Scene.selectAllNodes( false );
  175.  
  176. oSkeleton.select( true );
  177.  
  178. var oMgr = MainWindow.getActionMgr();
  179. var oAction = oMgr.findAction( "DzRestoreFigurePoseAction" );
  180. if( oAction ){
  181. oAction.trigger();
  182. }
  183.  
  184. var nZero = 0;
  185.  
  186. //Left
  187. //print( "-----------------------------------------" );
  188. try { setXRot( oSkeleton, "Left Metatarsals", xRotLeftMetatarsals ); } catch( error ){}
  189. try { setXRot( "Left Heel", nZero ); } catch( error ){}
  190. //try { setXRot( oSkeleton, "Left Foot", xRotLeftFoot ); } catch( error ){}
  191. try { setXRot( oSkeleton, "Left Toes", xRotLeftToes ); } catch( error ){}
  192. try { setXRot( oSkeleton, "Left Big Toe", xRotLeftBigToe ); } catch( error ){}
  193. try { setXRot( oSkeleton, "Left Big Toe_2", xRotLeftBigToe2 ); } catch( error ){}
  194. try { setXRot( oSkeleton, "Left Small Toe 1", xRotLeftSmallToe1 ); } catch( error ){}
  195. try { setXRot( oSkeleton, "Left Small Toe 1_2", xRotLeftSmallToe12 ); } catch( error ){}
  196. try { setXRot( oSkeleton, "Left Small Toe 2", xRotLeftSmallToe2 ); } catch( error ){}
  197. try { setXRot( oSkeleton, "Left Small Toe 2_2", xRotLeftSmallToe22 ); } catch( error ){}
  198. try { setXRot( oSkeleton, "Left Small Toe 3", xRotLeftSmallToe3 ); } catch( error ){}
  199. try { setXRot( oSkeleton, "Left Small Toe 3_2", xRotLeftSmallToe32 ); } catch( error ){}
  200. try { setXRot( oSkeleton, "Left Small Toe 4", xRotLeftSmallToe4 ); } catch( error ){}
  201. try { setXRot( oSkeleton, "Left Small Toe 4_2", xRotLeftSmallToe42 ); } catch( error ){}
  202.  
  203. //Right
  204. //print( "-----------------------------------------" );
  205. try { setXRot( oSkeleton, "Right Metatarsals", xRotRightMetatarsals ); } catch( error ){}
  206. try { setXRot( oSkeleton, "Right Heel", nZero ); } catch( error ){}
  207. //try { setXRot( oSkeleton, "Right Foot", xRotRightFoot ); } catch( error ){}
  208. try { setXRot( oSkeleton, "Right Toes", xRotRightToes ); } catch( error ){}
  209. try { setXRot( oSkeleton, "Right Big Toe", xRotRightBigToe ); } catch( error ){}
  210. try { setXRot( oSkeleton, "Right Big Toe_2", xRotRightBigToe2 ); } catch( error ){}
  211. try { setXRot( oSkeleton, "Right Small Toe 1", xRotRightSmallToe1 ); } catch( error ){}
  212. try { setXRot( oSkeleton, "Right Small Toe 1_2", xRotRightSmallToe12 ); } catch( error ){}
  213. try { setXRot( oSkeleton, "Right Small Toe 2", xRotRightSmallToe2 ); } catch( error ){}
  214. try { setXRot( oSkeleton, "Right Small Toe 2_2", xRotRightSmallToe22 ); } catch( error ){}
  215. try { setXRot( oSkeleton, "Right Small Toe 3", xRotRightSmallToe3 ); } catch( error ){}
  216. try { setXRot( oSkeleton, "Right Small Toe 3_2", xRotRightSmallToe32 ); } catch( error ){}
  217. try { setXRot( oSkeleton, "Right Small Toe 4", xRotRightSmallToe4 ); } catch( error ){}
  218. try { setXRot( oSkeleton, "Right Small Toe 4_2", xRotRightSmallToe42 ); } catch( error ){}
  219.  
  220. //print( "-----" );
  221. };
  222.  
  223. // --- START convert_figure_to_props ----
  224. /**********************************************************************
  225.  
  226. The following is derived from a work published as part of the
  227. Daz Script Documentation. This portion of the script, and/or any
  228. portion thereof, may only be used in accordance with the
  229. following license:
  230.  
  231. Creative Commons Attribution 3.0 Unported (CC BY 3.0)
  232. - http://creativecommons.org/licenses/by/3.0
  233.  
  234. **********************************************************************/
  235. // Source: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/nodes/convert_figure_to_props/start
  236.  
  237. // - Modified to remove display of messages presented to the user
  238.  
  239. function convert2Prop( oSelectedNode )
  240. {
  241. // If the selected node is a bone
  242. if( oSelectedNode.inherits( "DzBone" ) ){
  243. // Get the skeleton
  244. oSelectedNode = oSelectedNode.getSkeleton();
  245. }
  246.  
  247. // If we don't have a skeleton
  248. if( !oSelectedNode.inherits( "DzSkeleton" ) ){
  249. return;
  250. }
  251.  
  252. // Provide busy feedback to the user
  253. setBusyCursor();
  254.  
  255. // Declare working variables
  256. var oNode, oParent;
  257.  
  258. // Get the number of followers for the skeleton
  259. var nFollowers = oSelectedNode.getNumFollowSkeletons();
  260. // Presize an array to collect the converted nodes
  261. var aProps = new Array( nFollowers );
  262.  
  263. // Iterate over the followers; reverse order,
  264. // the list will change with each conversion
  265. for( var i = nFollowers - 1; i >= 0; i -= 1 ){
  266. // Get the 'current' follower
  267. oNode = oSelectedNode.getFollowSkeleton( i );
  268. // Get the parent of the follower
  269. oParent = oNode.getNodeParent();
  270. // If we have a parent
  271. if( oParent ){
  272. // Unparent the follower, in place
  273. oParent.removeNodeChild( oNode, true );
  274. }
  275.  
  276. // Convert the follower to a prop and collect it
  277. aProps[ i ] = oSelectedNode.convertFigureToProp( oNode, oNode.name );
  278. }
  279.  
  280. // Create an array helper; to improve speed of resizing the array
  281. var oArrayHelper = new DzArrayHelper();
  282.  
  283. // Get all of the child nodes of the figure
  284. var aNodes = oSelectedNode.getNodeChildren( true );
  285.  
  286. // Iterate over the skeleton nodes
  287. for( var i = 0; i < aNodes.length; i += 1 ){
  288. oNode = aNodes[ i ];
  289. // If the node is not a bone; its some sort of 'prop'
  290. if( !oNode.inherits( "DzBone" ) ){
  291. // Get the parent of the node
  292. oParent = oNode.getNodeParent();
  293. // If we have a parent
  294. if( oParent ){
  295. // Unparent the prop, in place
  296. oParent.removeNodeChild( oNode, true );
  297. // Add the prop to the list
  298. aProps = oArrayHelper.addToArray( aProps, oNode );
  299. }
  300. }
  301. }
  302.  
  303. // Convert the figure to a prop
  304. oSelectedNode = oSelectedNode.convertFigureToProp( oSelectedNode, oSelectedNode.name );
  305.  
  306. // Iterate over the props
  307. for( var i = 0; i < aProps.length; i += 1 ){
  308. // Get the 'current' prop
  309. oNode = aProps[ i ];
  310. // Parent the prop to the figure, in place
  311. oSelectedNode.addNodeChild( oNode, true );
  312. }
  313.  
  314. // Update the user
  315. clearBusyCursor();
  316. };
  317.  
  318. // --- END convert_figure_to_props ----
  319. /*********************************************************************/
  320.  
  321. function sceneContainsSkeleton()
  322. {
  323. return Scene.getNumSkeletons() > 0;
  324. };
  325.  
  326. /*********************************************************************/
  327. function sceneContainsHipNode()
  328. {
  329. var oNode;
  330. for( var i = 0, n = Scene.getNumNodes(); i < n; i += 1 ){
  331. // Get the current node
  332. oNode = Scene.getNode( i );
  333. if( oNode.getName().toLowerCase() == "hip" ){
  334. return true;
  335. }
  336. }
  337.  
  338. return false;
  339. };
  340.  
  341. // --- START replaceInstance ----
  342. // Adapted: https://www.daz3d.com/forums/discussion/comment/4940501/#Comment_4940501
  343. /*********************************************************************/
  344. function doAction( sClassName )
  345. {
  346. var oMgr = MainWindow.getActionMgr();
  347. var oAction = oMgr.findAction( sClassName );
  348. if( !oAction ){
  349. return;
  350. }
  351.  
  352. oAction.trigger();
  353. };
  354.  
  355. /*********************************************************************/
  356. function replaceInstance( oInstance, oNode )
  357. {
  358. var oParent = oInstance.getNodeParent();
  359. Scene.selectAllNodes( false );
  360.  
  361. oInstance.select( true );
  362. doAction( "DzCopyNodeAction" );
  363. oInstance.select( false );
  364.  
  365. var aNodes = Scene.getNodeList();
  366. var nNodes = aNodes.length;
  367.  
  368. oNode.select( true );
  369. //doAction( "DzDuplicateNodeHierarchyAction" );
  370. doAction( "DzDuplicateNodeAction" );
  371. oNode.select( false );
  372.  
  373. aNodes = Scene.getNodeList();
  374. var oReplacement = aNodes[nNodes];
  375.  
  376. if( oParent ){
  377. oParent.addNodeChild( oReplacement );
  378. }
  379.  
  380. oReplacement.select( true );
  381. doAction( "DzPasteNodeAction" );
  382. oReplacement.select( false );
  383.  
  384. var oControl = oReplacement.getScaleControl();
  385. if( oControl.getValue() == 0 ){
  386. oControl.setValue( 1 );
  387. }
  388.  
  389. oControl = oReplacement.getXScaleControl();
  390. if( oControl.getValue() == 0 ){
  391. oControl.setValue( 1 );
  392. }
  393.  
  394. oControl = oReplacement.getYScaleControl();
  395. if( oControl.getValue() == 0 ){
  396. oControl.setValue( 1 );
  397. }
  398.  
  399. oControl = oReplacement.getZScaleControl();
  400. if( oControl.getValue() == 0 ){
  401. oControl.setValue( 1 );
  402. }
  403.  
  404. Scene.removeNode( oInstance );
  405. };
  406.  
  407. // --- END replaceInstance ----
  408. /*********************************************************************/
  409. function replaceInstanceAll()
  410. {
  411. var oNode;
  412. var nNodes = Scene.getNumNodes();
  413. var aInstances = new Array( nNodes );
  414. for( var i = 0; i < nNodes; i += 1 ){
  415. oNode = Scene.getNode( i );
  416. if( oNode.inherits( "DzInstanceNode" ) ){
  417. //replace( oNode, oNode.getTarget() );
  418. //debug( oNode.getLabel() + ":" + oNode.getTarget().getLabel() );
  419. aInstances[i] = oNode;
  420. }
  421. }
  422.  
  423. aInstances = aInstances.filter( Boolean );
  424.  
  425. if( aInstances.length > 0 ){
  426. var nResult = MessageBox.question(
  427. qsTr( "Instances found. They need to be replaced before export. Replace them?" ),
  428. s_sToolName, qsTr( "&Yes" ), qsTr( "&No" )
  429. );
  430. if( nResult == 0 ){
  431. //debug( "yes" );
  432. for( var i = 0; i < aInstances.length; i += 1 ){
  433. oNode = aInstances[i];
  434. //debug( oNode.getLabel() + ":" + oNode.getTarget().getLabel() );
  435. try {
  436. replaceInstance( oNode, oNode.getTarget() );
  437. }
  438. catch( error ){}
  439. }
  440. }
  441. }
  442. };
  443.  
  444. replaceInstanceAll();
  445.  
  446.  
  447. if( sceneContainsSkeleton() ){
  448. if( !sceneContainsHipNode() ){
  449. var aConvert = Scene.getSkeletonList();
  450. var nConvert = aConvert.length;
  451. if( nConvert > 0 ){
  452. var nResult = MessageBox.question(
  453. qsTr( "Some objects needs to be converted to props. Convert?\nThis operation is NOT undoable! (save first if needed)" ),
  454. s_sToolName, qsTr( "&Yes" ), qsTr( "&No" ) );
  455. if( nResult == 0 ){
  456. for( var i = 0; i < nConvert; i += 1 ){
  457. //debug( aConvert[i].getName() );
  458. try {
  459. convert2Prop( aConvert[i] )
  460. } catch( error ){}
  461. }
  462. }
  463. }
  464. }
  465. }
  466.  
  467. // --- START export_fbx_silent ----
  468. /**********************************************************************
  469.  
  470. The following is derived from a work published as part of the
  471. Daz Script Documentation. This portion of the script, and/or any
  472. portion thereof, may only be used in accordance with the
  473. following license:
  474.  
  475. Creative Commons Attribution 3.0 Unported (CC BY 3.0)
  476. - http://creativecommons.org/licenses/by/3.0
  477.  
  478. **********************************************************************/
  479. // Source: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/file_io/export_fbx_silent/start
  480.  
  481. // - Modified to support switching exporters
  482. // - Other changes for this specific use case
  483.  
  484. /*********************************************************************/
  485. function exportScene( sClassName, sPath, sBaseName, sExt )
  486. {
  487. // Get the export manager
  488. var oExportMgr = App.getExportMgr();
  489. // Find the exporter
  490. var oExporter = oExportMgr.findExporterByClassName( sClassName );
  491. // If the exporter exists
  492. if( oExporter ){
  493. // Create a settings object
  494. var oSettings = new DzFileIOSettings();
  495.  
  496. // Define whether or not to show options
  497. var bShowOptions = false;
  498.  
  499. // Define whether or not to show options before prompting for a path;
  500. // requires 4.9.3.22 or later
  501. var bOptionsBeforeFile = (bShowOptions && App.version64 >= 0x0004000900030016);
  502.  
  503. // Get the options for the exporter
  504. if( !oExporter.getOptions( oSettings, bShowOptions && bOptionsBeforeFile, "" ) ){
  505. // We're done...
  506. return;
  507. }
  508.  
  509. if( sClassName == "DzFbxExporter" ){
  510. // Selected
  511. oSettings.setBoolValue( "doSelected", false );
  512. // No Hidden
  513. oSettings.setBoolValue( "doVisible", false );
  514. // Figures
  515. oSettings.setBoolValue( "doFigures", true );
  516. // Props
  517. oSettings.setBoolValue( "doProps", true );
  518. // Lights
  519. oSettings.setBoolValue( "doLights", true );
  520. // Cameras
  521. oSettings.setBoolValue( "doCameras", true );
  522. // Animations
  523. oSettings.setBoolValue( "doAnims", false );
  524. // Morphs
  525. oSettings.setBoolValue( "doMorphs", true );
  526.  
  527. // Morph Rules
  528. // Format for rules is "Match1\nAction1\nMatch2\nAction2\nMatch3\nAction3",
  529. // where Match# is a string to search for and Action# is one of Bake|Export|Ignore
  530. // The names of the morphs are in the form: node_name.parameter_name
  531. // The default action is to Bake
  532. // So "FBMHeavy\nExport\nThin\nExport" would export all morphs that have FBMHeavy and all morphs that have Thin in the name
  533. // Using Function to grab the current head morphs in the selection
  534.  
  535. // This is the commented out original line of code that called the CreateMorph() function and exports all of the head controls.
  536. // oSettings.setStringValue( "rules", createMorphRules() );
  537.  
  538. // This is my new custom entry testing that it only exports this one element
  539. oSettings.setStringValue( "rules", "New Faces - Surprised 08 Genesis 8.1 Male\n1" );
  540.  
  541. // Format
  542. // Format for format is "Year# -- Type",
  543. // where Year# is one of 2006|2009|2010|2011|2012|2013|2014 and
  544. // Type is one of Ascii|Binary
  545. oSettings.setStringValue( "format", "FBX 2012 -- Binary" );
  546.  
  547. // Embed Textures
  548. oSettings.setBoolValue( "doEmbed", true );
  549. // Collect Textures To Folder
  550. oSettings.setBoolValue( "doCopyTextures", false );
  551. // Merge Diffuse and Opacity Textures
  552. oSettings.setBoolValue( "doDiffuseOpacity", false );
  553. // Merge Clothing Into Figure Skeleton
  554. oSettings.setBoolValue( "doMergeClothing", true );
  555. // Convert Clothing to Static Geometry
  556. oSettings.setBoolValue( "doStaticClothing", false );
  557. // Allow Degraded Skinning
  558. oSettings.setBoolValue( "degradedSkinning", true );
  559. // Allow Degraded Scaling
  560. oSettings.setBoolValue( "degradedScaling", true );
  561. // SubD Information
  562. oSettings.setBoolValue( "doSubD", false );
  563. // Collapse UV Tiles
  564. oSettings.setBoolValue( "doCollapseUVTiles", false );
  565. } else if( sClassName == "DzDAZCOLLADAExporter" ){
  566. /*
  567. oSettings.setIntValue( "ExportProfile", 0 );
  568. oSettings.setBoolValue( "RemoveUnusedVerts", true );
  569. oSettings.setBoolValue( "IgnoreInvisibleNodes", false );
  570. oSettings.setBoolValue( "BakeScale", false );
  571. oSettings.setBoolValue( "MergeFollowingSkeletons", false );
  572. oSettings.setBoolValue( "SparseMorphs", true );
  573. oSettings.setBoolValue( "WeldGeometry", false );
  574. oSettings.setBoolValue( "UseModifierLists", true );
  575. oSettings.setBoolValue( "CombineMorphs", true );
  576. oSettings.setStringValue( "ImageCopyPath", "" );
  577. oSettings.setBoolValue( "CopyImagesToFolder", false );
  578. oSettings.setBoolValue( "InvertAlphaImage", false );
  579. oSettings.setBoolValue( "CombineAlphaImageIntoDiffuse", false );
  580. oSettings.setStringValue( "CombineAlphaImageIntoDiffuseExt", "png" );
  581. oSettings.setBoolValue( "MergeMaterials", false );
  582. oSettings.setBoolValue( "ExportAnimations", false );
  583. oSettings.setBoolValue( "AnimationIncludesTransformations", false );
  584. oSettings.setBoolValue( "AnimationsIncludeMorphs", false );
  585. */
  586. }
  587.  
  588. // If the version is 4.9.3.22 or newer
  589. if( App.version64 >= 0x0004000900030016 ){
  590. // Define whether or not to show the options after prompting for a file;
  591. // prior to 4.9.3.22 this exporter ignored this option entirely,
  592. // running silent was implied by virtue of being run via script
  593. oSettings.setIntValue( "RunSilent", (bShowOptions && !bOptionsBeforeFile ? 0 : 1) );
  594. }
  595.  
  596. // Debug
  597. //print( oSettings.toJsonString() );
  598.  
  599. // Ensure the path exists
  600. var oDir = new DzDir( sPath );
  601. oDir.mkdir( sPath );
  602.  
  603. // Write the file using the options specified
  604. oExporter.writeFile(
  605. String( "%1/%2.%3" ).arg( sPath ).arg( sBaseName ).arg( sExt ),
  606. oSettings );
  607. //print( oSettings.toJsonString() );
  608.  
  609. // Clean up; don't leak memory
  610. oExporter.deleteLater();
  611. // We didn't find an exporter with the class name we wanted
  612. } else {
  613. // Inform the user
  614. MessageBox.critical( qsTr("An exporter with the class name \"%1\" " +
  615. "could not be found.").arg( sClassName ),
  616. qsTr("Critical Error"), qsTr("&OK") );
  617. }
  618. };
  619.  
  620. // --- END export_fbx_silent ----
  621.  
  622.  
  623. //for( var i = 0, n = s_aSkeletons.length; i < n; i += 1 ){
  624. // heelsFix( s_aSkeletons[i] );
  625. //}
  626.  
  627. exportScene( s_sExporter, s_sExportPath, s_sExportBaseName, s_sExportExt );
  628.  
  629.  
  630. // ----------------------------------------------------------
  631. // ----------------------------------------------------------
  632. // ----------------------------------------------------------
  633. // SAVE maps to file... bump, specular, etc....
  634. // ----------------------------------------------------------
  635.  
  636.  
  637. function label2Variable( sLabel )
  638. {
  639. var sLabelLwr = sLabel.toLowerCase();
  640. var sAlpha ='abcdefghijklmnopqrstuvwxyz0123456789_';
  641. var sResult = '';
  642. for( var i = 0; i < sLabelLwr.length; i += 1 ){
  643. if( sAlpha.search( sLabelLwr[i] ) >= 0 ){
  644. sResult += sLabel[i];
  645. }
  646.  
  647. if( sLabelLwr[i] == ' ' ){
  648. sResult += '_';
  649. }
  650. }
  651.  
  652. if( sResult == "Luminance_cdm^2" ){
  653. sResult = "Luminance_cdm_2";
  654. }
  655.  
  656. return sResult;
  657. };
  658. /*********************************************************************/
  659.  
  660. function fixFilename( sFilename )
  661. {
  662. return sFilename.replace( "&", "(_)" );
  663. };
  664.  
  665. /*********************************************************************/
  666.  
  667. function value2XMLString( oElement, sPropLabel )
  668. {
  669. try {
  670. var oProperty = oElement.findPropertyByLabel( sPropLabel );
  671.  
  672. if( oProperty ){
  673. var sAttrib = label2Variable( sPropLabel );
  674. var sResult = '';
  675. var oTexture;
  676.  
  677. //oElement.getName() == 'Walls' &&
  678. if( sPropLabel == 'Diffuse Texture' ){
  679. //debug( '12zzzzzzzzzzzzzzzzzzzzzzzzzzzzz ' + sPropLabel + ' ' + oProperty.getValue() );
  680. if( oProperty.inherits( "DzImageProperty" ) ){
  681. oTexture = oProperty.getValue();
  682. if( oTexture ){
  683. sResult += ' Diffuse_Color_Map="' + fixFilename( oTexture.getFilename() ) + '"';
  684. }
  685. }
  686. } else {
  687. if( oProperty.inherits( "DzNumericProperty" ) ){
  688. oTexture = oProperty.getMapValue();
  689. if( oTexture ){
  690. sResult = sAttrib + '_Map="' + fixFilename( oTexture.getFilename() ) + '"';
  691. }
  692. }
  693.  
  694. if( oProperty.inherits( "DzColorProperty" ) ){
  695. var clrVal = oProperty.getColorValue();
  696. sResult += ' '+ sAttrib + '="Color ' + clrVal.red + ' ' + clrVal.green + ' ' + clrVal.blue + '"';
  697. } else {
  698. sResult += ' '+ sAttrib + '="'+ oProperty.getValue() + '"';
  699. }
  700. }
  701.  
  702. return( sResult );
  703. }
  704. } catch( error ){
  705. return( '' );
  706. }
  707.  
  708. return( '' );
  709. };
  710.  
  711. /*********************************************************************/
  712.  
  713. function savePropertiesToFile( sExporter, sExportPath, sExportBaseName, sExportExt )
  714. {
  715. var sFile = "%1/%2.xml".arg( sExportPath ).arg( sExportBaseName );
  716.  
  717. var oConfigFile = new DzFile( sFile );
  718. oConfigFile.open( DzFile.WriteOnly );
  719.  
  720. oConfigFile.writeLine( '<materials filename="%1.%2" >'.arg( sExportBaseName ).arg( sExportExt ) );
  721.  
  722. var numI = Scene.getNumNodes();
  723. var numIMat;
  724. var numIShad;
  725. var oNode;
  726. var myTempObj;
  727. var myTempShape;
  728. var myWorkMat;
  729. var myWorkProperty;
  730. // Get the total number of scene nodes
  731.  
  732. var listMat = new Array();
  733. // Iterate over each node
  734. var ii = 0;
  735. for( var i = 0; i < numI; i += 1 ){
  736. // Get the current node
  737. oNode = Scene.getNode( i );
  738. myTempObj = oNode.getObject();
  739. // does it have geometry?
  740. if( myTempObj != null ){
  741. myTempShape = myTempObj.getCurrentShape();
  742. // now digging for the materials!!
  743. numIMat = myTempShape.getNumMaterials();
  744. // iterating aaaagain
  745. for( var j = 0; j < numIMat; j += 1 ){
  746. myWorkMat = myTempShape.getMaterial( j );
  747. //debug( myWorkMat.getName() + ' - ' + myWorkMat.getNumProperties() );
  748. //var allMats = myWorkMat.getAllMaps();
  749. //var numMaps = allMats.length;
  750. var matName = myWorkMat.getName();
  751. var n = listMat.length;
  752. //listMat.pushIfNotExists( myTempObj.getName() + '-' + oNode.getLabel() + '-'+ matName );
  753. listMat.pushIfNotExists( myTempObj.getName() + '-' + matName );
  754. var n1 = listMat.length;
  755. if( n1 > n ){
  756. ii += 1;
  757. //debug( i + '/' + ii + '-' + myTempObj.getName() + '-' + matName );
  758. //debug( i + '/' + ii + '-' + oNode.getLabel() + '-' + matName );
  759. var matText = ' <material object="' + label2Variable( myTempObj.getName() ) + '" label="' + oNode.getLabel() + '" name="' + label2Variable( matName ) + '"';
  760. if( sExportExt == "fbx" ){
  761. matText = ' <material object="' + myTempObj.getName() + '.Shape" label="' + oNode.getLabel() + '" name="' + matName + '"';
  762. }
  763.  
  764. /*
  765. var p = myWorkMat.findPropertyByLabel( 'Base Color' );
  766. if( p ){
  767. matText += ' shaderType="iray"';
  768. } else {
  769. p = myWorkMat.findPropertyByLabel( 'Metal Color' );
  770. if( p )[
  771. matText += ' shaderType="metal"';
  772. } else {
  773. matText += ' shaderType="3delight"';
  774. }
  775. }
  776. */
  777.  
  778. for( var k = 0; k < myWorkMat.getNumProperties(); k += 1 ){
  779. var temp = value2XMLString( myWorkMat, myWorkMat.getProperty( k ).getLabel() );
  780. if( temp != '' ){
  781. matText += ' ' + temp;
  782. }
  783. //debug( i + ' ' + myWorkMat.getProperty( i ).getLabel() + ' - ' + myWorkMat.getProperty( i ).getPath() );
  784. }
  785. matText += '/>';
  786. oConfigFile.writeLine( matText );
  787. }
  788. }
  789. }
  790. //the second iteration is ended above
  791. }
  792. oConfigFile.writeLine( '</materials>' );
  793. oConfigFile.close();
  794. };
  795.  
  796. savePropertiesToFile( s_sExporter, s_sExportPath, s_sExportBaseName, s_sExportExt );
  797.  
  798. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement