// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // Description: // This script exports selected objects or the current scene // to an Alembic file by AbcExport command. // // // Procedure Name: // syncOptionVars // // Description: // Synchronize option values with the argument list. // // Input Arguments: // version - The version of the argument list. // // args - A list of arguments to invoke AbcExport. // // Return Value: // None. // proc syncOptionVars(string $version, string $args[]) { int $versionNum = $version; string $cacheTimeRange[] = stringToStringArray($args[1], ":"); string $start[] = stringToStringArray($args[2], ":"); string $end[] = stringToStringArray($args[3], ":"); string $evaluateEvery[] = stringToStringArray($args[4], ":"); string $enableSample[] = stringToStringArray($args[5], ":"); string $lowFrameRelativeSample[] = stringToStringArray($args[6], ":"); string $highFrameRelativeSample[] = stringToStringArray($args[7], ":"); int $enablePreRoll = $args[8]; float $preRollStartFrame = $args[9]; string $attr = $args[10]; string $attrPrefix = $args[11]; int $verbose = $args[12]; int $noNormals = $args[13]; int $renderableOnly = $args[14]; int $stripNamespaces = $args[15]; int $uvWrite = $args[16]; int $wholeFrameGeo = $args[17]; int $worldSpace = $args[18]; int $writeVisibility = $args[19]; string $perFrameCallbackMel = $args[20]; string $postJobCallbackMel = $args[21]; string $perFrameCallbackPython = $args[22]; string $postJobCallbackPython = $args[23]; optionVar -clearArray Alembic_exportCacheTimeRanges; optionVar -clearArray Alembic_exportStarts; optionVar -clearArray Alembic_exportEnds; optionVar -clearArray Alembic_exportEvaluateEverys; optionVar -clearArray Alembic_exportEnableFrameRelativeSamples; optionVar -clearArray Alembic_exportLowFrameRelativeSamples; optionVar -clearArray Alembic_exportHighFrameRelativeSamples; int $tmpRangeMode, $tmpEnableSample; float $tmpStart, $tmpEnd, $tmpEvaluateEvery, $tmpLowSample, $tmpHighSample; int $i; for ($i = 0; $i < size($cacheTimeRange); $i++) { $tmpRangeMode = $cacheTimeRange[$i]; $tmpStart = $start[$i]; $tmpEnd = $end[$i]; $tmpEvaluateEvery = $evaluateEvery[$i]; $tmpEnableSample = $enableSample[$i]; $tmpLowSample = $lowFrameRelativeSample[$i]; $tmpHighSample = $highFrameRelativeSample[$i]; optionVar -intValueAppend Alembic_exportCacheTimeRanges $tmpRangeMode; optionVar -floatValueAppend Alembic_exportStarts $tmpStart; optionVar -floatValueAppend Alembic_exportEnds $tmpEnd; optionVar -floatValueAppend Alembic_exportEvaluateEverys $tmpEvaluateEvery; optionVar -intValueAppend Alembic_exportEnableFrameRelativeSamples $tmpEnableSample; optionVar -floatValueAppend Alembic_exportLowFrameRelativeSamples $tmpLowSample; optionVar -floatValueAppend Alembic_exportHighFrameRelativeSamples $tmpHighSample; } optionVar -intValue Alembic_exportEnablePreRoll $enablePreRoll; optionVar -floatValue Alembic_exportPreRollStartFrame $preRollStartFrame; optionVar -stringValue Alembic_exportAttr $attr; optionVar -stringValue Alembic_exportAttrPrefix $attrPrefix; optionVar -intValue Alembic_exportVerbose $verbose; optionVar -intValue Alembic_exportNoNormals $noNormals; optionVar -intValue Alembic_exportRenderableOnly $renderableOnly; optionVar -intValue Alembic_exportStripNamespaces $stripNamespaces; optionVar -intValue Alembic_exportUVWrite $uvWrite; optionVar -intValue Alembic_exportWholeFrameGeo $wholeFrameGeo; optionVar -intValue Alembic_exportWorldSpace $worldSpace; optionVar -intValue Alembic_exportWriteVisibility $writeVisibility; optionVar -stringValue Alembic_exportPerFrameCallbackMel $perFrameCallbackMel; optionVar -stringValue Alembic_exportPostJobCallbackMel $postJobCallbackMel; optionVar -stringValue Alembic_exportPerFrameCallbackPython $perFrameCallbackPython; optionVar -stringValue Alembic_exportPostJobCallbackPython $postJobCallbackPython; if ($versionNum >= 2) { int $filterEulerRotations = $args[24]; optionVar -intValue Alembic_exportFilterEulerRotations $filterEulerRotations; } if ($versionNum >= 3) { int $writeColorSets = $args[25]; int $writeFaceSets = $args[26]; optionVar -intValue Alembic_exportWriteColorSets $writeColorSets; optionVar -intValue Alembic_exportWriteFaceSets $writeFaceSets; } if ($versionNum >= 4) { int $dataFormat = $args[27]; optionVar -intValue Alembic_exportDataFormat $dataFormat; } if ($versionNum >= 5) { float $preRollStep = $args[28]; optionVar -floatValue Alembic_exportPreRollStep $preRollStep; } if ($versionNum >= 6) { int $writeCreases = $args[29]; optionVar -intValue Alembic_exportWriteCreases $writeCreases; } if ($versionNum >= 7) { int $writeUVSets = $args[30]; optionVar -intValue Alembic_exportWriteUVSets $writeUVSets; } } proc int containsWhiteSpace(string $str) { if (size(`match " " $str`) > 0) { return 1; } else { return 0; } } // // Procedure Name: // doAlembicExportArgList // // Description: // Execute AbcExport command based on the argument list. // // Input Arguments: // version - The version of the argument list. // // args - A list of arguments to invoke AbcExport. // // Return Value: // None. // global proc doAlembicExportArgList(string $version, string $args[]) { if (!`exists captureAlembicExportOptionVars`) { eval("source \"performAlembicExport.mel\""); } // back up the current option values so that we can restore // them later if the dialog is cancelled int $exportAll = $args[0]; string $optionVarsBackup[] = captureAlembicExportOptionVars($version, $exportAll); // synchronize the option values with the argument list syncOptionVars($version, $args); // prepare filter and starting dir for file dialog string $filter = (uiRes("m_doAlembicExportArgList.kAlembic")) + " (*.abc);;" + (uiRes("m_doAlembicExportArgList.kAllFiles")) + " (*.*)"; if (size(`workspace -fileRuleEntry alembicCache`) == 0) { workspace -fileRule "alembicCache" "cache/alembic"; workspace -saveWorkspace; } string $workspace = `workspace -fileRuleEntry alembicCache`; $workspace = `workspace -expandName $workspace`; sysFile -makeDir $workspace; global string $gAlembicExportLastDirectory; global string $gAlembicExportLastWorkspace; string $startingDir = $gAlembicExportLastDirectory; if (size($startingDir) == 0 || $gAlembicExportLastWorkspace != `workspace -q -rootDirectory`) { $startingDir = $workspace; } // choose a file to export string $result[]; if ($exportAll) { $result = `fileDialog2 -returnFilter 1 -fileFilter $filter -caption (uiRes("m_doAlembicExportArgList.kExportAll2")) -startingDirectory $startingDir -fileMode 0 -okCaption (uiRes("m_doAlembicExportArgList.kExportAll3")) -optionsUICreate "Alembic_exportFileOptionsUICreate" -optionsUIInit "Alembic_exportFileOptionsUIInit" -optionsUICommit "Alembic_exportAllFileOptionsUICommit" `; } else { $result = `fileDialog2 -returnFilter 1 -fileFilter $filter -caption (uiRes("m_doAlembicExportArgList.kExportSelection2")) -startingDirectory $startingDir -fileMode 0 -okCaption (uiRes("m_doAlembicExportArgList.kExportSelection3")) -optionsUICreate "Alembic_exportFileOptionsUICreate" -optionsUIInit "Alembic_exportFileOptionsUIInit" -optionsUICommit "Alembic_exportSelectionFileOptionsUICommit" `; } if (size($result) == 0 || size($result[0]) == 0) { // cancelled // Restore optionVars to the state before this procedure is called // syncOptionVars($version, $optionVarsBackup); return; } // Save the last directory $gAlembicExportLastDirectory = dirname($result[0]); $gAlembicExportLastWorkspace = `workspace -q -rootDirectory`; // parameters int $cacheTimeRanges[] = `optionVar -q Alembic_exportCacheTimeRanges`; float $startFrames[] = `optionVar -q Alembic_exportStarts`; float $endFrames[] = `optionVar -q Alembic_exportEnds`; float $evaluateEvery[] = `optionVar -q Alembic_exportEvaluateEverys`; int $enableSample[] = `optionVar -q Alembic_exportEnableFrameRelativeSamples`; float $lowFrameRelativeSamples[] = `optionVar -q Alembic_exportLowFrameRelativeSamples`; float $highFrameRelativeSamples[]= `optionVar -q Alembic_exportHighFrameRelativeSamples`; int $enablePreRoll = `optionVar -q Alembic_exportEnablePreRoll`; float $preRollStartFrame = `optionVar -q Alembic_exportPreRollStartFrame`; float $preRollStep = `optionVar -q Alembic_exportPreRollStep`; string $attr = `optionVar -q Alembic_exportAttr`; string $attrPrefix = `optionVar -q Alembic_exportAttrPrefix`; int $verbose = `optionVar -q Alembic_exportVerbose`; int $noNormals = `optionVar -q Alembic_exportNoNormals`; int $renderableOnly = `optionVar -q Alembic_exportRenderableOnly`; int $stripNamespaces = `optionVar -q Alembic_exportStripNamespaces`; int $uvWrite = `optionVar -q Alembic_exportUVWrite`; int $writeColorSets = `optionVar -q Alembic_exportWriteColorSets`; int $writeFaceSets = `optionVar -q Alembic_exportWriteFaceSets`; int $wholeFrameGeo = `optionVar -q Alembic_exportWholeFrameGeo`; int $worldSpace = `optionVar -q Alembic_exportWorldSpace`; int $writeVisibility = `optionVar -q Alembic_exportWriteVisibility`; int $filterEulerRotations = `optionVar -q Alembic_exportFilterEulerRotations`; int $writeCreases = `optionVar -q Alembic_exportWriteCreases`; int $writeUVSets = `optionVar -q Alembic_exportWriteUVSets`; int $dataFormat = `optionVar -q Alembic_exportDataFormat`; string $perFrameCallbackMel = `optionVar -q Alembic_exportPerFrameCallbackMel`; string $postJobCallbackMel = `optionVar -q Alembic_exportPostJobCallbackMel`; string $perFrameCallbackPython = `optionVar -q Alembic_exportPerFrameCallbackPython`; string $postJobCallbackPython = `optionVar -q Alembic_exportPostJobCallbackPython`; // build AbcExport command string $command = "AbcExport "; string $job; int $i; float $firstCacheFrame = 1; for ($i = 0; $i < size($cacheTimeRanges); $i++) { float $startEnd[]; if ($cacheTimeRanges[$i] != 3) { $startEnd = Alembic_getStartEndFrames($cacheTimeRanges[$i]); } else { $startEnd[0] = $startFrames[$i]; $startEnd[1] = $endFrames[$i]; } if ($i == 0) { $firstCacheFrame = $startEnd[0]; } $job += ("-frameRange " + $startEnd[0] + " " + $startEnd[1] + " "); if ($evaluateEvery[$i] != 1) { if ($evaluateEvery[$i] <= 0) { error (uiRes("m_doAlembicExportArgList.kInvalidEvaluateEvery")); return; } $job += ("-step " + $evaluateEvery[$i] + " "); } if ($enableSample[$i]) { if ($lowFrameRelativeSamples[$i] > 0 || $lowFrameRelativeSamples[$i] < -$evaluateEvery[$i]) { error (uiRes("m_doAlembicExportArgList.kInvalidLowFrameRelativeSample")); return; } if ($highFrameRelativeSamples[$i] < 0 || $highFrameRelativeSamples[$i] > $evaluateEvery[$i]) { error (uiRes("m_doAlembicExportArgList.kInvalidHighFrameRelativeSample")); return; } $job += "-frameRelativeSample "; $job += $lowFrameRelativeSamples[$i]; $job += " -frameRelativeSample 0 -frameRelativeSample "; $job += $highFrameRelativeSamples[$i]; $job += " "; } } if ($enablePreRoll) { // Check arguments. if ($preRollStep <= 0) { error (uiRes("m_doAlembicExportArgList.kInvalidPreRollStep")); return; } if ($preRollStartFrame >= $firstCacheFrame) { error (uiRes("m_doAlembicExportArgList.kInvalidPreRollStartFrame")); return; } // Compute the pre-roll end frame. float $preRollEndFrame = Alembic_getPrerollEndFrame($preRollStartFrame, $firstCacheFrame, $preRollStep); string $preRollFlags = ("-frameRange " + $preRollStartFrame + " " + $preRollEndFrame + " -step " + $preRollStep + " -preRoll "); $job = $preRollFlags + $job; } string $attrArray[], $attrPrefixArray[]; tokenize $attr "," $attrArray; tokenize $attrPrefix "," $attrPrefixArray; for ($i = 0; $i < size($attrArray); $i++) { if (size($attrArray[$i]) > 0) { $job += "-attr "; $job += formValidObjectName($attrArray[$i]); $job += " "; } } for ($i = 0; $i < size($attrPrefixArray); $i++) { if (size($attrPrefixArray[$i]) > 0) { $job += "-attrPrefix "; $job += formValidObjectName($attrPrefixArray[$i]); $job += " "; } } if ($verbose) { $command += "-verbose "; } if ($noNormals) { $job += "-noNormals "; } if ($renderableOnly) { $job += "-ro "; } if ($stripNamespaces) { $job += "-stripNamespaces "; } if ($uvWrite) { $job += "-uvWrite "; } if ($writeColorSets) { $job += "-writeColorSets "; } if ($writeFaceSets) { $job += "-writeFaceSets "; } if ($wholeFrameGeo) { $job += "-wholeFrameGeo "; } if ($worldSpace) { $job += "-worldSpace "; } if ($writeVisibility) { $job += "-writeVisibility "; } if ($filterEulerRotations) { $job += "-eulerFilter "; } if($writeCreases){ $job += "-autoSubd "; } if($writeUVSets){ $job += "-writeUVSets "; } if ($dataFormat == 1) { $job += "-dataFormat hdf "; } else if ($dataFormat == 2) { $job += "-dataFormat ogawa "; } if (size($perFrameCallbackMel) > 0) { if (containsWhiteSpace($perFrameCallbackMel)) { $perFrameCallbackMel = "\"" + encodeString($perFrameCallbackMel) + "\""; } $job += ("-melPerFrameCallback " + encodeString($perFrameCallbackMel) + " "); } if (size($postJobCallbackMel) > 0) { if (containsWhiteSpace($postJobCallbackMel)) { $postJobCallbackMel = "\"" + encodeString($postJobCallbackMel) + "\""; } $job += ("-melPostJobCallback " + encodeString($postJobCallbackMel) + " "); } if (size($perFrameCallbackPython) > 0) { if (containsWhiteSpace($perFrameCallbackPython)) { $perFrameCallbackPython = "\"" + encodeString($perFrameCallbackPython) + "\""; } $job += ("-pythonPerFrameCallback " + encodeString($perFrameCallbackPython) + " "); } if (size($postJobCallbackPython) > 0) { if (containsWhiteSpace($postJobCallbackPython)) { $postJobCallbackPython = "\"" + encodeString($postJobCallbackPython) + "\""; } $job += ("-pythonPostJobCallback " + encodeString($postJobCallbackPython) + " "); } if (!$exportAll) { string $selections[] = `ls -selection -long`; string $selection; for ($selection in $selections) { $job += "-root " + $selection + " "; } } string $file = $result[0]; if (containsWhiteSpace($file)) { $file = "\"" + $file + "\""; } $command += ("-j \"" + $job + "-file " + encodeString($file) + "\""); // execute command if (!`pluginInfo -q -loaded AbcExport`) { error (uiRes("m_doAlembicExportArgList.kAbcExportNotLoaded")); return; } evalEcho($command); }