Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DAZ Studio version 4.12.0.86 filetype DAZ Script
- (function(){
- var s_oFileInfo = new DzFileInfo( getScriptFileName() );
- var s_sToolName = s_oFileInfo.baseName();
- s_oFileInfo.deleteLater();
- var s_aSkeletons = Scene.getSkeletonList();
- var s_oPrimaryNode = Scene.getPrimarySelection();
- var s_oPrimarySkeleton = undefined;
- if( s_oPrimaryNode ){
- if( s_oPrimaryNode.inherits( "DzSkeleton" ) ){
- s_oPrimarySkeleton = s_oPrimaryNode;
- } else if( s_oPrimaryNode.inherits( "DzBone" ) ){
- s_oPrimarySkeleton = s_oPrimaryNode.getSkeleton();
- }
- }
- var s_sExporter = "DzFbxExporter";//"DzDAZCOLLADAExporter"
- var s_sExportExt = "fbx";//"dae"
- // TODO: This should be a preference controlled by the user instead of
- // a hard-coded path on the primary drive of the user's machine; this
- // either needs to be configurable on both sides of the "bridge", or
- // this side needs to store a DzAppSettings with the path used and the
- // other side needs to retrieve the path; either way, both sides need
- // to agree before a change can be pushed to end users
- var s_sExportPath = "C:/TEMP3D";
- if( App.platform() == DzApp.MacOSX ){
- s_sExportPath = "/users/Shared/temp3d";
- }
- var s_sExportBaseName = "DazToMaya";
- /*********************************************************************/
- function getXRot( oSkeleton, sBoneLabel )
- {
- if( !oSkeleton || sBoneLabel.isEmpty() ){
- return undefined;
- }
- var oBone = oSkeleton.findBoneByLabel( sBoneLabel );
- if( !oBone ){
- return undefined;
- }
- var oControl = oBone.getXRotControl();
- var nValue = oControl.getValue();
- //print( ":: get x :: " + sBoneLabel + " :: " + nValue );
- return nValue;
- };
- /*********************************************************************/
- function setXRot( oSkeleton, sBoneLabel, nValue )
- {
- if( !oSkeleton
- || sBoneLabel.isEmpty()
- || nValue == undefined ){
- return;
- }
- //print( ":: set x :: " + sBoneLabel + " :: " + nValue );
- var oBone = oSkeleton.findBoneByLabel( sBoneLabel );
- if( !oBone ){
- return;
- }
- var oControl = oBone.getXRotControl();
- oControl.setValue( nValue );
- };
- // This function will give all the head morphs of selected character
- // and will create the rule to be used in the fbx export.
- /*********************************************************************/
- function createMorphRules(){
- var oNode = Scene.getPrimarySelection();
- if( !oNode ){
- return;
- }
- if( oNode.inherits( "DzBone" ) ){
- oNode = oNode.getSkeleton();
- }
- if( oNode.inherits( "DzSkeleton" ) ){
- oNode = oNode.findBone( "head" );
- }
- if( !oNode ){
- return;
- }
- var oProperty;
- var oPropGroup;
- var oPropTree;
- var oPropOwner;
- var oTgtProperty;
- var oTgtPropGroup;
- var oTgtPropTree;
- var oTgtPropOwner;
- var aProperties = oNode.getPropertyList();
- var morphRule;
- var morphName;
- var morphList=[];
- var morphRule = "";
- for( var i = 0, n = aProperties.length; i < n; i += 1 ){
- oProperty = aProperties[ i ];
- if( !oProperty.getPath().startsWith( "/Pose Controls" ) ){
- continue;
- }
- if( oProperty.isAlias() ){
- oTgtProperty = oProperty.getAliasTarget();
- oTgtPropGroup = oTgtProperty.getGroup();
- oTgtPropTree = oTgtPropGroup.getTree();
- oTgtPropOwner = oTgtPropTree.getOwner();
- morphName =oTgtProperty.name;
- morphList[i]=morphName;
- //oTgtPropOwner.name + "." +
- continue;
- }
- }
- //Remove any nulls or undefined in the array
- morphList = morphList.filter(Boolean);
- for( var i = 0, n = morphList.length; i < n; i += 1 ){
- morphRule = morphRule + morphList[i] + "\n1\n";
- };
- return morphRule = morphRule.substring(0,morphRule.length - 2);
- };
- /*********************************************************************/
- function heelsFix( oSkeleton )
- {
- if( oSkeleton ){
- return;
- }
- //Left
- try { var xRotLeftMetatarsals = getXRot( oSkeleton, "Left Metatarsals" ); } catch( error ){}
- try { var xRotLeftHeel = getXRot( oSkeleton, "Left Heel" ); } catch( error ){}
- try { var xRotLeftFoot = getXRot( oSkeleton, "Left Foot" ); } catch( error ){}
- try { var xRotLeftToes = getXRot( oSkeleton, "Left Toes" ); } catch( error ){}
- try { var xRotLeftBigToe = getXRot( oSkeleton, "Left Big Toe" ); } catch( error ){}
- try { var xRotLeftBigToe2 = getXRot( oSkeleton, "Left Big Toe_2" ); } catch( error ){}
- try { var xRotLeftSmallToe1 = getXRot( oSkeleton, "Left Small Toe 1" ); } catch( error ){}
- try { var xRotLeftSmallToe12 = getXRot( oSkeleton, "Left Small Toe 1_2" ); } catch( error ){}
- try { var xRotLeftSmallToe2 = getXRot( oSkeleton, "Left Small Toe 2" ); } catch( error ){}
- try { var xRotLeftSmallToe22 = getXRot( oSkeleton, "Left Small Toe 2_2" ); } catch( error ){}
- try { var xRotLeftSmallToe3 = getXRot( oSkeleton, "Left Small Toe 3" ); } catch( error ){}
- try { var xRotLeftSmallToe32 = getXRot( oSkeleton, "Left Small Toe 3_2" ); } catch( error ){}
- try { var xRotLeftSmallToe4 = getXRot( oSkeleton, "Left Small Toe 4" ); } catch( error ){}
- try { var xRotLeftSmallToe42 = getXRot( oSkeleton, "Left Small Toe 4_2" ); } catch( error ){}
- //Right
- try { var xRotRightMetatarsals = getXRot( oSkeleton, "Right Metatarsals" ); } catch( error ){}
- try { var xRotRightHeel = getXRot( oSkeleton, "Right Heel" ); } catch( error ){}
- try { var xRotRightFoot = getXRot( oSkeleton, "Right Foot" ); } catch( error ){}
- try { var xRotRightToes = getXRot( oSkeleton, "Right Toes" ); } catch( error ){}
- try { var xRotRightBigToe = getXRot( oSkeleton, "Right Big Toe" ); } catch( error ){}
- try { var xRotRightBigToe2 = getXRot( oSkeleton, "Right Big Toe_2" ); } catch( error ){}
- try { var xRotRightSmallToe1 = getXRot( oSkeleton, "Right Small Toe 1" ); } catch( error ){}
- try { var xRotRightSmallToe12 = getXRot( oSkeleton, "Right Small Toe 1_2" ); } catch( error ){}
- try { var xRotRightSmallToe2 = getXRot( oSkeleton, "Right Small Toe 2" ); } catch( error ){}
- try { var xRotRightSmallToe22 = getXRot( oSkeleton, "Right Small Toe 2_2" ); } catch( error ){}
- try { var xRotRightSmallToe3 = getXRot( oSkeleton, "Right Small Toe 3" ); } catch( error ){}
- try { var xRotRightSmallToe32 = getXRot( oSkeleton, "Right Small Toe 3_2" ); } catch( error ){}
- try { var xRotRightSmallToe4 = getXRot( oSkeleton, "Right Small Toe 4" ); } catch( error ){}
- try { var xRotRightSmallToe42 = getXRot( oSkeleton, "Right Small Toe 4_2" ); } catch( error ){}
- Scene.selectAllNodes( false );
- oSkeleton.select( true );
- var oMgr = MainWindow.getActionMgr();
- var oAction = oMgr.findAction( "DzRestoreFigurePoseAction" );
- if( oAction ){
- oAction.trigger();
- }
- var nZero = 0;
- //Left
- //print( "-----------------------------------------" );
- try { setXRot( oSkeleton, "Left Metatarsals", xRotLeftMetatarsals ); } catch( error ){}
- try { setXRot( "Left Heel", nZero ); } catch( error ){}
- //try { setXRot( oSkeleton, "Left Foot", xRotLeftFoot ); } catch( error ){}
- try { setXRot( oSkeleton, "Left Toes", xRotLeftToes ); } catch( error ){}
- try { setXRot( oSkeleton, "Left Big Toe", xRotLeftBigToe ); } catch( error ){}
- try { setXRot( oSkeleton, "Left Big Toe_2", xRotLeftBigToe2 ); } catch( error ){}
- try { setXRot( oSkeleton, "Left Small Toe 1", xRotLeftSmallToe1 ); } catch( error ){}
- try { setXRot( oSkeleton, "Left Small Toe 1_2", xRotLeftSmallToe12 ); } catch( error ){}
- try { setXRot( oSkeleton, "Left Small Toe 2", xRotLeftSmallToe2 ); } catch( error ){}
- try { setXRot( oSkeleton, "Left Small Toe 2_2", xRotLeftSmallToe22 ); } catch( error ){}
- try { setXRot( oSkeleton, "Left Small Toe 3", xRotLeftSmallToe3 ); } catch( error ){}
- try { setXRot( oSkeleton, "Left Small Toe 3_2", xRotLeftSmallToe32 ); } catch( error ){}
- try { setXRot( oSkeleton, "Left Small Toe 4", xRotLeftSmallToe4 ); } catch( error ){}
- try { setXRot( oSkeleton, "Left Small Toe 4_2", xRotLeftSmallToe42 ); } catch( error ){}
- //Right
- //print( "-----------------------------------------" );
- try { setXRot( oSkeleton, "Right Metatarsals", xRotRightMetatarsals ); } catch( error ){}
- try { setXRot( oSkeleton, "Right Heel", nZero ); } catch( error ){}
- //try { setXRot( oSkeleton, "Right Foot", xRotRightFoot ); } catch( error ){}
- try { setXRot( oSkeleton, "Right Toes", xRotRightToes ); } catch( error ){}
- try { setXRot( oSkeleton, "Right Big Toe", xRotRightBigToe ); } catch( error ){}
- try { setXRot( oSkeleton, "Right Big Toe_2", xRotRightBigToe2 ); } catch( error ){}
- try { setXRot( oSkeleton, "Right Small Toe 1", xRotRightSmallToe1 ); } catch( error ){}
- try { setXRot( oSkeleton, "Right Small Toe 1_2", xRotRightSmallToe12 ); } catch( error ){}
- try { setXRot( oSkeleton, "Right Small Toe 2", xRotRightSmallToe2 ); } catch( error ){}
- try { setXRot( oSkeleton, "Right Small Toe 2_2", xRotRightSmallToe22 ); } catch( error ){}
- try { setXRot( oSkeleton, "Right Small Toe 3", xRotRightSmallToe3 ); } catch( error ){}
- try { setXRot( oSkeleton, "Right Small Toe 3_2", xRotRightSmallToe32 ); } catch( error ){}
- try { setXRot( oSkeleton, "Right Small Toe 4", xRotRightSmallToe4 ); } catch( error ){}
- try { setXRot( oSkeleton, "Right Small Toe 4_2", xRotRightSmallToe42 ); } catch( error ){}
- //print( "-----" );
- };
- // --- START convert_figure_to_props ----
- /**********************************************************************
- The following is derived from a work published as part of the
- Daz Script Documentation. This portion of the script, and/or any
- portion thereof, may only be used in accordance with the
- following license:
- Creative Commons Attribution 3.0 Unported (CC BY 3.0)
- - http://creativecommons.org/licenses/by/3.0
- **********************************************************************/
- // Source: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/nodes/convert_figure_to_props/start
- // - Modified to remove display of messages presented to the user
- function convert2Prop( oSelectedNode )
- {
- // If the selected node is a bone
- if( oSelectedNode.inherits( "DzBone" ) ){
- // Get the skeleton
- oSelectedNode = oSelectedNode.getSkeleton();
- }
- // If we don't have a skeleton
- if( !oSelectedNode.inherits( "DzSkeleton" ) ){
- return;
- }
- // Provide busy feedback to the user
- setBusyCursor();
- // Declare working variables
- var oNode, oParent;
- // Get the number of followers for the skeleton
- var nFollowers = oSelectedNode.getNumFollowSkeletons();
- // Presize an array to collect the converted nodes
- var aProps = new Array( nFollowers );
- // Iterate over the followers; reverse order,
- // the list will change with each conversion
- for( var i = nFollowers - 1; i >= 0; i -= 1 ){
- // Get the 'current' follower
- oNode = oSelectedNode.getFollowSkeleton( i );
- // Get the parent of the follower
- oParent = oNode.getNodeParent();
- // If we have a parent
- if( oParent ){
- // Unparent the follower, in place
- oParent.removeNodeChild( oNode, true );
- }
- // Convert the follower to a prop and collect it
- aProps[ i ] = oSelectedNode.convertFigureToProp( oNode, oNode.name );
- }
- // Create an array helper; to improve speed of resizing the array
- var oArrayHelper = new DzArrayHelper();
- // Get all of the child nodes of the figure
- var aNodes = oSelectedNode.getNodeChildren( true );
- // Iterate over the skeleton nodes
- for( var i = 0; i < aNodes.length; i += 1 ){
- oNode = aNodes[ i ];
- // If the node is not a bone; its some sort of 'prop'
- if( !oNode.inherits( "DzBone" ) ){
- // Get the parent of the node
- oParent = oNode.getNodeParent();
- // If we have a parent
- if( oParent ){
- // Unparent the prop, in place
- oParent.removeNodeChild( oNode, true );
- // Add the prop to the list
- aProps = oArrayHelper.addToArray( aProps, oNode );
- }
- }
- }
- // Convert the figure to a prop
- oSelectedNode = oSelectedNode.convertFigureToProp( oSelectedNode, oSelectedNode.name );
- // Iterate over the props
- for( var i = 0; i < aProps.length; i += 1 ){
- // Get the 'current' prop
- oNode = aProps[ i ];
- // Parent the prop to the figure, in place
- oSelectedNode.addNodeChild( oNode, true );
- }
- // Update the user
- clearBusyCursor();
- };
- // --- END convert_figure_to_props ----
- /*********************************************************************/
- function sceneContainsSkeleton()
- {
- return Scene.getNumSkeletons() > 0;
- };
- /*********************************************************************/
- function sceneContainsHipNode()
- {
- var oNode;
- for( var i = 0, n = Scene.getNumNodes(); i < n; i += 1 ){
- // Get the current node
- oNode = Scene.getNode( i );
- if( oNode.getName().toLowerCase() == "hip" ){
- return true;
- }
- }
- return false;
- };
- // --- START replaceInstance ----
- // Adapted: https://www.daz3d.com/forums/discussion/comment/4940501/#Comment_4940501
- /*********************************************************************/
- function doAction( sClassName )
- {
- var oMgr = MainWindow.getActionMgr();
- var oAction = oMgr.findAction( sClassName );
- if( !oAction ){
- return;
- }
- oAction.trigger();
- };
- /*********************************************************************/
- function replaceInstance( oInstance, oNode )
- {
- var oParent = oInstance.getNodeParent();
- Scene.selectAllNodes( false );
- oInstance.select( true );
- doAction( "DzCopyNodeAction" );
- oInstance.select( false );
- var aNodes = Scene.getNodeList();
- var nNodes = aNodes.length;
- oNode.select( true );
- //doAction( "DzDuplicateNodeHierarchyAction" );
- doAction( "DzDuplicateNodeAction" );
- oNode.select( false );
- aNodes = Scene.getNodeList();
- var oReplacement = aNodes[nNodes];
- if( oParent ){
- oParent.addNodeChild( oReplacement );
- }
- oReplacement.select( true );
- doAction( "DzPasteNodeAction" );
- oReplacement.select( false );
- var oControl = oReplacement.getScaleControl();
- if( oControl.getValue() == 0 ){
- oControl.setValue( 1 );
- }
- oControl = oReplacement.getXScaleControl();
- if( oControl.getValue() == 0 ){
- oControl.setValue( 1 );
- }
- oControl = oReplacement.getYScaleControl();
- if( oControl.getValue() == 0 ){
- oControl.setValue( 1 );
- }
- oControl = oReplacement.getZScaleControl();
- if( oControl.getValue() == 0 ){
- oControl.setValue( 1 );
- }
- Scene.removeNode( oInstance );
- };
- // --- END replaceInstance ----
- /*********************************************************************/
- function replaceInstanceAll()
- {
- var oNode;
- var nNodes = Scene.getNumNodes();
- var aInstances = new Array( nNodes );
- for( var i = 0; i < nNodes; i += 1 ){
- oNode = Scene.getNode( i );
- if( oNode.inherits( "DzInstanceNode" ) ){
- //replace( oNode, oNode.getTarget() );
- //debug( oNode.getLabel() + ":" + oNode.getTarget().getLabel() );
- aInstances[i] = oNode;
- }
- }
- aInstances = aInstances.filter( Boolean );
- if( aInstances.length > 0 ){
- var nResult = MessageBox.question(
- qsTr( "Instances found. They need to be replaced before export. Replace them?" ),
- s_sToolName, qsTr( "&Yes" ), qsTr( "&No" )
- );
- if( nResult == 0 ){
- //debug( "yes" );
- for( var i = 0; i < aInstances.length; i += 1 ){
- oNode = aInstances[i];
- //debug( oNode.getLabel() + ":" + oNode.getTarget().getLabel() );
- try {
- replaceInstance( oNode, oNode.getTarget() );
- }
- catch( error ){}
- }
- }
- }
- };
- replaceInstanceAll();
- if( sceneContainsSkeleton() ){
- if( !sceneContainsHipNode() ){
- var aConvert = Scene.getSkeletonList();
- var nConvert = aConvert.length;
- if( nConvert > 0 ){
- var nResult = MessageBox.question(
- qsTr( "Some objects needs to be converted to props. Convert?\nThis operation is NOT undoable! (save first if needed)" ),
- s_sToolName, qsTr( "&Yes" ), qsTr( "&No" ) );
- if( nResult == 0 ){
- for( var i = 0; i < nConvert; i += 1 ){
- //debug( aConvert[i].getName() );
- try {
- convert2Prop( aConvert[i] )
- } catch( error ){}
- }
- }
- }
- }
- }
- // --- START export_fbx_silent ----
- /**********************************************************************
- The following is derived from a work published as part of the
- Daz Script Documentation. This portion of the script, and/or any
- portion thereof, may only be used in accordance with the
- following license:
- Creative Commons Attribution 3.0 Unported (CC BY 3.0)
- - http://creativecommons.org/licenses/by/3.0
- **********************************************************************/
- // Source: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/file_io/export_fbx_silent/start
- // - Modified to support switching exporters
- // - Other changes for this specific use case
- /*********************************************************************/
- function exportScene( sClassName, sPath, sBaseName, sExt )
- {
- // Get the export manager
- var oExportMgr = App.getExportMgr();
- // Find the exporter
- var oExporter = oExportMgr.findExporterByClassName( sClassName );
- // If the exporter exists
- if( oExporter ){
- // Create a settings object
- var oSettings = new DzFileIOSettings();
- // Define whether or not to show options
- var bShowOptions = false;
- // Define whether or not to show options before prompting for a path;
- // requires 4.9.3.22 or later
- var bOptionsBeforeFile = (bShowOptions && App.version64 >= 0x0004000900030016);
- // Get the options for the exporter
- if( !oExporter.getOptions( oSettings, bShowOptions && bOptionsBeforeFile, "" ) ){
- // We're done...
- return;
- }
- if( sClassName == "DzFbxExporter" ){
- // Selected
- oSettings.setBoolValue( "doSelected", false );
- // No Hidden
- oSettings.setBoolValue( "doVisible", false );
- // Figures
- oSettings.setBoolValue( "doFigures", true );
- // Props
- oSettings.setBoolValue( "doProps", true );
- // Lights
- oSettings.setBoolValue( "doLights", true );
- // Cameras
- oSettings.setBoolValue( "doCameras", true );
- // Animations
- oSettings.setBoolValue( "doAnims", false );
- // Morphs
- oSettings.setBoolValue( "doMorphs", true );
- // Morph Rules
- // Format for rules is "Match1\nAction1\nMatch2\nAction2\nMatch3\nAction3",
- // where Match# is a string to search for and Action# is one of Bake|Export|Ignore
- // The names of the morphs are in the form: node_name.parameter_name
- // The default action is to Bake
- // So "FBMHeavy\nExport\nThin\nExport" would export all morphs that have FBMHeavy and all morphs that have Thin in the name
- // Using Function to grab the current head morphs in the selection
- // This is the commented out original line of code that called the CreateMorph() function and exports all of the head controls.
- // oSettings.setStringValue( "rules", createMorphRules() );
- // This is my new custom entry testing that it only exports this one element
- oSettings.setStringValue( "rules", "New Faces - Surprised 08 Genesis 8.1 Male\n1" );
- // Format
- // Format for format is "Year# -- Type",
- // where Year# is one of 2006|2009|2010|2011|2012|2013|2014 and
- // Type is one of Ascii|Binary
- oSettings.setStringValue( "format", "FBX 2012 -- Binary" );
- // Embed Textures
- oSettings.setBoolValue( "doEmbed", true );
- // Collect Textures To Folder
- oSettings.setBoolValue( "doCopyTextures", false );
- // Merge Diffuse and Opacity Textures
- oSettings.setBoolValue( "doDiffuseOpacity", false );
- // Merge Clothing Into Figure Skeleton
- oSettings.setBoolValue( "doMergeClothing", true );
- // Convert Clothing to Static Geometry
- oSettings.setBoolValue( "doStaticClothing", false );
- // Allow Degraded Skinning
- oSettings.setBoolValue( "degradedSkinning", true );
- // Allow Degraded Scaling
- oSettings.setBoolValue( "degradedScaling", true );
- // SubD Information
- oSettings.setBoolValue( "doSubD", false );
- // Collapse UV Tiles
- oSettings.setBoolValue( "doCollapseUVTiles", false );
- } else if( sClassName == "DzDAZCOLLADAExporter" ){
- /*
- oSettings.setIntValue( "ExportProfile", 0 );
- oSettings.setBoolValue( "RemoveUnusedVerts", true );
- oSettings.setBoolValue( "IgnoreInvisibleNodes", false );
- oSettings.setBoolValue( "BakeScale", false );
- oSettings.setBoolValue( "MergeFollowingSkeletons", false );
- oSettings.setBoolValue( "SparseMorphs", true );
- oSettings.setBoolValue( "WeldGeometry", false );
- oSettings.setBoolValue( "UseModifierLists", true );
- oSettings.setBoolValue( "CombineMorphs", true );
- oSettings.setStringValue( "ImageCopyPath", "" );
- oSettings.setBoolValue( "CopyImagesToFolder", false );
- oSettings.setBoolValue( "InvertAlphaImage", false );
- oSettings.setBoolValue( "CombineAlphaImageIntoDiffuse", false );
- oSettings.setStringValue( "CombineAlphaImageIntoDiffuseExt", "png" );
- oSettings.setBoolValue( "MergeMaterials", false );
- oSettings.setBoolValue( "ExportAnimations", false );
- oSettings.setBoolValue( "AnimationIncludesTransformations", false );
- oSettings.setBoolValue( "AnimationsIncludeMorphs", false );
- */
- }
- // If the version is 4.9.3.22 or newer
- if( App.version64 >= 0x0004000900030016 ){
- // Define whether or not to show the options after prompting for a file;
- // prior to 4.9.3.22 this exporter ignored this option entirely,
- // running silent was implied by virtue of being run via script
- oSettings.setIntValue( "RunSilent", (bShowOptions && !bOptionsBeforeFile ? 0 : 1) );
- }
- // Debug
- //print( oSettings.toJsonString() );
- // Ensure the path exists
- var oDir = new DzDir( sPath );
- oDir.mkdir( sPath );
- // Write the file using the options specified
- oExporter.writeFile(
- String( "%1/%2.%3" ).arg( sPath ).arg( sBaseName ).arg( sExt ),
- oSettings );
- //print( oSettings.toJsonString() );
- // Clean up; don't leak memory
- oExporter.deleteLater();
- // We didn't find an exporter with the class name we wanted
- } else {
- // Inform the user
- MessageBox.critical( qsTr("An exporter with the class name \"%1\" " +
- "could not be found.").arg( sClassName ),
- qsTr("Critical Error"), qsTr("&OK") );
- }
- };
- // --- END export_fbx_silent ----
- //for( var i = 0, n = s_aSkeletons.length; i < n; i += 1 ){
- // heelsFix( s_aSkeletons[i] );
- //}
- exportScene( s_sExporter, s_sExportPath, s_sExportBaseName, s_sExportExt );
- // ----------------------------------------------------------
- // ----------------------------------------------------------
- // ----------------------------------------------------------
- // SAVE maps to file... bump, specular, etc....
- // ----------------------------------------------------------
- function label2Variable( sLabel )
- {
- var sLabelLwr = sLabel.toLowerCase();
- var sAlpha ='abcdefghijklmnopqrstuvwxyz0123456789_';
- var sResult = '';
- for( var i = 0; i < sLabelLwr.length; i += 1 ){
- if( sAlpha.search( sLabelLwr[i] ) >= 0 ){
- sResult += sLabel[i];
- }
- if( sLabelLwr[i] == ' ' ){
- sResult += '_';
- }
- }
- if( sResult == "Luminance_cdm^2" ){
- sResult = "Luminance_cdm_2";
- }
- return sResult;
- };
- /*********************************************************************/
- function fixFilename( sFilename )
- {
- return sFilename.replace( "&", "(_)" );
- };
- /*********************************************************************/
- function value2XMLString( oElement, sPropLabel )
- {
- try {
- var oProperty = oElement.findPropertyByLabel( sPropLabel );
- if( oProperty ){
- var sAttrib = label2Variable( sPropLabel );
- var sResult = '';
- var oTexture;
- //oElement.getName() == 'Walls' &&
- if( sPropLabel == 'Diffuse Texture' ){
- //debug( '12zzzzzzzzzzzzzzzzzzzzzzzzzzzzz ' + sPropLabel + ' ' + oProperty.getValue() );
- if( oProperty.inherits( "DzImageProperty" ) ){
- oTexture = oProperty.getValue();
- if( oTexture ){
- sResult += ' Diffuse_Color_Map="' + fixFilename( oTexture.getFilename() ) + '"';
- }
- }
- } else {
- if( oProperty.inherits( "DzNumericProperty" ) ){
- oTexture = oProperty.getMapValue();
- if( oTexture ){
- sResult = sAttrib + '_Map="' + fixFilename( oTexture.getFilename() ) + '"';
- }
- }
- if( oProperty.inherits( "DzColorProperty" ) ){
- var clrVal = oProperty.getColorValue();
- sResult += ' '+ sAttrib + '="Color ' + clrVal.red + ' ' + clrVal.green + ' ' + clrVal.blue + '"';
- } else {
- sResult += ' '+ sAttrib + '="'+ oProperty.getValue() + '"';
- }
- }
- return( sResult );
- }
- } catch( error ){
- return( '' );
- }
- return( '' );
- };
- /*********************************************************************/
- function savePropertiesToFile( sExporter, sExportPath, sExportBaseName, sExportExt )
- {
- var sFile = "%1/%2.xml".arg( sExportPath ).arg( sExportBaseName );
- var oConfigFile = new DzFile( sFile );
- oConfigFile.open( DzFile.WriteOnly );
- oConfigFile.writeLine( '<materials filename="%1.%2" >'.arg( sExportBaseName ).arg( sExportExt ) );
- var numI = Scene.getNumNodes();
- var numIMat;
- var numIShad;
- var oNode;
- var myTempObj;
- var myTempShape;
- var myWorkMat;
- var myWorkProperty;
- // Get the total number of scene nodes
- var listMat = new Array();
- // Iterate over each node
- var ii = 0;
- for( var i = 0; i < numI; i += 1 ){
- // Get the current node
- oNode = Scene.getNode( i );
- myTempObj = oNode.getObject();
- // does it have geometry?
- if( myTempObj != null ){
- myTempShape = myTempObj.getCurrentShape();
- // now digging for the materials!!
- numIMat = myTempShape.getNumMaterials();
- // iterating aaaagain
- for( var j = 0; j < numIMat; j += 1 ){
- myWorkMat = myTempShape.getMaterial( j );
- //debug( myWorkMat.getName() + ' - ' + myWorkMat.getNumProperties() );
- //var allMats = myWorkMat.getAllMaps();
- //var numMaps = allMats.length;
- var matName = myWorkMat.getName();
- var n = listMat.length;
- //listMat.pushIfNotExists( myTempObj.getName() + '-' + oNode.getLabel() + '-'+ matName );
- listMat.pushIfNotExists( myTempObj.getName() + '-' + matName );
- var n1 = listMat.length;
- if( n1 > n ){
- ii += 1;
- //debug( i + '/' + ii + '-' + myTempObj.getName() + '-' + matName );
- //debug( i + '/' + ii + '-' + oNode.getLabel() + '-' + matName );
- var matText = ' <material object="' + label2Variable( myTempObj.getName() ) + '" label="' + oNode.getLabel() + '" name="' + label2Variable( matName ) + '"';
- if( sExportExt == "fbx" ){
- matText = ' <material object="' + myTempObj.getName() + '.Shape" label="' + oNode.getLabel() + '" name="' + matName + '"';
- }
- /*
- var p = myWorkMat.findPropertyByLabel( 'Base Color' );
- if( p ){
- matText += ' shaderType="iray"';
- } else {
- p = myWorkMat.findPropertyByLabel( 'Metal Color' );
- if( p )[
- matText += ' shaderType="metal"';
- } else {
- matText += ' shaderType="3delight"';
- }
- }
- */
- for( var k = 0; k < myWorkMat.getNumProperties(); k += 1 ){
- var temp = value2XMLString( myWorkMat, myWorkMat.getProperty( k ).getLabel() );
- if( temp != '' ){
- matText += ' ' + temp;
- }
- //debug( i + ' ' + myWorkMat.getProperty( i ).getLabel() + ' - ' + myWorkMat.getProperty( i ).getPath() );
- }
- matText += '/>';
- oConfigFile.writeLine( matText );
- }
- }
- }
- //the second iteration is ended above
- }
- oConfigFile.writeLine( '</materials>' );
- oConfigFile.close();
- };
- savePropertiesToFile( s_sExporter, s_sExportPath, s_sExportBaseName, s_sExportExt );
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement