private String getShortAssetName(String s) { Path sPath = new Path(s); return sPath.getName(); // return s.replaceAll(".*/assets/.*/",""); } // getShortAssetName(String)
private String getShortName(String s) { Path sPath = new Path(s); return sPath.getName(); }
/** * Phase in which parameter values should be extracted from parameters and checked for * consistency and applicability. */ @Override public void validatePhase() throws PipelineException { /* sets up the built-in parameters common to all builders */ validateBuiltInParams(); /* setup the StudioDefinitions version of the UtilContext */ pStudioDefs.setContext(pContext); /* lookup the source images node */ String sourceNodeName = null; VersionID sourceVersionID = null; { Path spath = (Path) getParamValue(aSourceNode); if (spath == null) throw new PipelineException("No " + aSourceNode + " was specified!"); sourceNodeName = spath.toString(); pSourcePrefix = spath.getName(); String sversion = (String) getParamValue(aSourceVersion); if (sversion == null) throw new PipelineException("No " + aSourceVersion + " was specified!"); try { sourceVersionID = new VersionID(sversion); } catch (Exception ex) { throw new PipelineException( "The value supplied for the " + aSourceVersion + " parameter " + "(" + sversion + ") is not a legal node revision number!\n\n" + ex.getMessage()); } try { pSourceVersion = pClient.getCheckedInVersion(sourceNodeName, sourceVersionID); } catch (PipelineException ex) { throw new PipelineException( "The source images node (" + sourceNodeName + " v" + sourceVersionID + ") " + "does not exist!"); } } /* set namer/builder parameters based on the annotations on the source images node */ { boolean validated = false; String projName = null; String taskName = null; String taskType = null; TreeMap<String, BaseAnnotation> annotations = pClient.getAnnotations(sourceNodeName); TreeSet<String> otherPurposes = new TreeSet<String>(); for (String aname : annotations.keySet()) { if (aname.equals("Task") || aname.startsWith("AltTask")) { BaseAnnotation annot = annotations.get(aname); String purpose = lookupPurpose(sourceNodeName, aname, annot); if (purpose == null) { otherPurposes.add("<UNKNWON>"); } else if (purpose.equals(aFocus) || purpose.equals(aEdit) || purpose.equals(aProduct)) { projName = lookupProjectName(sourceNodeName, aname, annot); taskName = lookupTaskName(sourceNodeName, aname, annot); taskType = lookupTaskType(sourceNodeName, aname, annot); validated = true; break; } else { otherPurposes.add(purpose); } } } if (!validated) { StringBuilder buf = new StringBuilder(); buf.append( "Unable to find an valid " + aEdit + ", " + aFocus + " or " + aProduct + " " + "task annotation for the source images node (" + sourceNodeName + " v" + sourceVersionID + ")!"); if (!otherPurposes.isEmpty()) { buf.append( "\n\nHowever, there were task annotations on the source images node for " + "the following unsupported purposes:"); for (String purpose : otherPurposes) buf.append(" " + purpose); } throw new PipelineException(buf.toString()); } if (taskName.length() != 5) throw new PipelineException( "The " + aTaskName + " (" + taskName + ") of the source images " + "node (" + sourceNodeName + " v" + sourceVersionID + ") did not conform to " + "the 2-letter sequence name followed by 3-digit shot number format!"); pProjectName = projName; pSeqName = taskName.substring(0, 2); pShotName = taskName.substring(2, 5); try { pTaskType = TaskType.valueOf(TaskType.class, taskType); } catch (IllegalArgumentException ex) { throw new PipelineException( "The " + DeliverNamer.aTaskType + " (" + taskType + ") of the source images " + "node (" + sourceNodeName + " v" + sourceVersionID + ") was an unknown type " + "by this builder!"); } } /* generate a temporary working area where the approval process will take place and change the util context to use it instead for all future operations */ { String tempView = ("QtDeliver" + "-" + pProjectName + "-" + pSeqName + pShotName + "-" + pSourcePrefix); tempView = tempView.replaceAll(" ", "_"); setContext(new UtilContext(pContext.getAuthor(), tempView, pContext.getToolset())); } /* turn on the DoAnnotations flag for the StageInformation shared by all of the Stages created by this builder since we always want task annotations */ getStageInformation().setDoAnnotations(true); /* initialize internal Project namer */ { pProjectNamer.setParamValue(new ParamMapping(StudioDefinitions.aProjectName), pProjectName); pProjectNamer.generateNames(); } }
@SuppressWarnings("unchecked") @Override public void validatePhase() throws PipelineException { /* the slate and format Nuke script nodes */ String slatePrefix = null; { String script = getStringParamValue(new ParamMapping(aSlateScript), false); Path path = new Path(pProjectNamer.getSlateNukeScriptsParentPath(), script); pSlateNodeName = path.toString(); slatePrefix = path.getName(); pRequiredNodeNames.add(pSlateNodeName); } String formatPrefix = null; { String script = getStringParamValue(new ParamMapping(aFormatScript), false); Path path = new Path(pProjectNamer.getFormatNukeScriptsParentPath(), script); pFormatNodeName = path.toString(); formatPrefix = path.getName(); pRequiredNodeNames.add(pFormatNodeName); } /* the final QuickTime codec settings */ String codecPrefix = null; { String settings = getStringParamValue(new ParamMapping(aCodecSettings), false); Path path = new Path(pProjectNamer.getQtCodecSettingsParentPath(), settings); pCodecNodeName = path.toString(); codecPrefix = path.getName(); pRequiredNodeNames.add(pCodecNodeName); } /* lookup the rest of the parameters */ pDeliveryType = getStringParamValue(new ParamMapping(aDeliveryType)); pDeliverable = getStringParamValue(new ParamMapping(DeliverNamer.aDeliverable), false); pClientVersion = getStringParamValue(new ParamMapping(aClientVersion)); pClientShotName = getStringParamValue(new ParamMapping(aClientShotName)); pLensInfo = getStringParamValue(new ParamMapping(aLensInfo), false); pTakeInfo = getStringParamValue(new ParamMapping(aTakeInfo), false); pNotes = getStringParamValue(new ParamMapping(aNotes)); pSlateHold = getIntegerParamValue(new ParamMapping(aSlateHold), new Range<Integer>(0, null)); /* compute the full frame range with slate holds added */ FrameRange range = pSourceVersion.getPrimarySequence().getFrameRange(); if (range.getBy() != 1) throw new PipelineException( "The source images node (" + pSourceVersion.getName() + " v" + pSourceVersion.getVersionID() + ") must have a frame step increment of (1)!"); pFrameRange = new FrameRange(range.getStart(), range.getEnd() + pSlateHold, 1); /* initialize internal Deliver (Shot) namer */ { pDeliverNamer = new DeliverNamer(pClient, pQueue, getBuilderInformation(), pStudioDefs); pShotNamer = pDeliverNamer; pDeliverNamer.setParamValue(new ParamMapping(StudioDefinitions.aProjectName), pProjectName); pDeliverNamer.setParamValue(new ParamMapping(StudioDefinitions.aSequenceName), pSeqName); pDeliverNamer.setParamValue(new ParamMapping(StudioDefinitions.aShotName), pShotName); pDeliverNamer.setParamValue(new ParamMapping(DeliverNamer.aDeliverable), pDeliverable); pDeliverNamer.setParamValue(new ParamMapping(DeliverNamer.aTaskType), pTaskType.toString()); pDeliverNamer.setParamValue(new ParamMapping(DeliverNamer.aSlatePrefix), slatePrefix); pDeliverNamer.setParamValue(new ParamMapping(DeliverNamer.aFormatPrefix), formatPrefix); pDeliverNamer.setParamValue(new ParamMapping(DeliverNamer.aCodecPrefix), codecPrefix); pDeliverNamer.generateNames(); } }
/** * Construct a {@link SubProcessHeavy SubProcessHeavy} instance which when executed will fulfill * the given action agenda. * * <p> * * @param agenda The agenda to be accomplished by the action. * @param outFile The file to which all STDOUT output is redirected. * @param errFile The file to which all STDERR output is redirected. * @return The SubProcess which will fulfill the agenda. * @throws PipelineException If unable to prepare a SubProcess due to illegal, missing or * imcompatable information in the action agenda or a general failure of the prep method code. */ public SubProcessHeavy prep(ActionAgenda agenda, File outFile, File errFile) throws PipelineException { /* model filenames */ TreeMap<String, Path> modelPaths = new TreeMap<String, Path>(); TreeMap<String, Path> animPaths = new TreeMap<String, Path>(); TreeMap<String, String> nameSpaces = new TreeMap<String, String>(); TreeMap<String, String> reverseNameSpaces = new TreeMap<String, String>(); TreeMap<String, Boolean> usesNameSpace = new TreeMap<String, Boolean>(); TreeMap<String, String> buildTypes = new TreeMap<String, String>(); for (String sname : agenda.getSourceNames()) { if (hasSourceParams(sname)) { FileSeq fseq = agenda.getPrimarySource(sname); String suffix = fseq.getFilePattern().getSuffix(); if (fseq.isSingle() && (suffix != null)) { if (suffix.equals("ma") || suffix.equals("mb")) { Path npath = new Path(sname); String type = getSourceStringParamValue(sname, aSceneType); String nspace = getSourceStringParamValue(sname, aPrefixName); if (nspace == null) { nspace = npath.getName(); } if (type.equals(aModel)) modelPaths.put(sname, new Path(npath.getParentPath(), fseq.getPath(0))); else { animPaths.put(sname, new Path(npath.getParentPath(), fseq.getPath(0))); nspace += "_a"; } boolean useNSpace = false; { Boolean tf = (Boolean) getSourceParamValue(sname, aNameSpace); useNSpace = ((tf != null) && tf); } String buildType = getSourceStringParamValue(sname, aBuildType); if (buildType == null) throw new PipelineException( "The value of the " + aBuildType + " source parameter for node " + "(" + sname + ") was not set!"); buildTypes.put(sname, buildType); nameSpaces.put(sname, nspace); reverseNameSpaces.put(nspace, sname); usesNameSpace.put(sname, useNSpace); } } } } /* the target Maya scene */ Path targetScene = getMayaSceneTargetPath(agenda); String sceneType = getMayaSceneType(agenda); /* create a temporary MEL script file */ File script = createTemp(agenda, "mel"); try { FileWriter out = new FileWriter(script); /* provide parameters as MEL variables */ out.write(genFrameRangeVarsMEL()); /* rename the current scene as the output scene */ out.write( "// SCENE SETUP\n" + "file -rename \"" + targetScene + "\";\n" + "file -type \"" + sceneType + "\";\n\n"); out.write(genUnitsMEL()); writeInitialMEL(agenda, out); /* the model file reference imports */ TreeMap<String, Path> all = new TreeMap<String, Path>(modelPaths); all.putAll(animPaths); for (String sname : all.keySet()) { Path mpath = all.get(sname); String buildType = buildTypes.get(sname); out.write( "// MODEL: " + sname + "\n" + "print \"" + buildType + " Model: " + mpath + "\\n\";\n" + "file\n"); String nspace = nameSpaces.get(sname); boolean useNSpace = usesNameSpace.get(sname); if (buildType.equals(aImport)) { out.write(" -import\n"); if (useNSpace) out.write(" -namespace \"" + nspace + "\"\n"); } else if (buildType.equals(aReference)) { out.write(" -reference\n"); if (useNSpace) out.write(" -namespace \"" + nspace + "\"\n"); else out.write(" -renamingPrefix \"" + nspace + "\"\n"); } else { throw new PipelineException( "Unknown value for the " + aBuildType + " source parameter for node " + "(" + sname + ") encountered!"); } { String fname = mpath.getName(); if (fname.endsWith("ma")) out.write(" -type \"mayaAscii\"\n"); else if (fname.endsWith("mb")) out.write(" -type \"mayaBinary\"\n"); else throw new PipelineException( "Unknown Maya scene format for source file (" + mpath + ")!"); } out.write(" -options \"v=0\"\n" + " \"$WORKING" + mpath + "\";\n\n"); } writeModelMEL(agenda, out); out.write( "global proc string removePrefix(string $name)\n" + "{\n" + " string $toReturn;\n" + " string $buffer[];\n" + " tokenize($name, \"|\", $buffer);\n" + " string $part;\n" + " for ($part in $buffer) {\n" + " string $buffer2[];\n" + " tokenize($part, \":\", $buffer2);\n" + " if ($toReturn == \"\")\n" + " $toReturn += $buffer2[(size($buffer2) -1)];\n" + " else\n" + " $toReturn += \"|\" + $buffer2[(size($buffer2) -1)];\n" + " }\n" + " return $toReturn; \n" + "}\n"); out.write( "global proc string addPrefix(string $name, string $prefix)\n" + "{\n" + " string $toReturn;\n" + " string $buffer[];\n" + " tokenize($name, \"|\", $buffer);\n" + " string $part;\n" + " for ($part in $buffer) {\n" + " if ($toReturn == \"\")\n" + " $toReturn += $prefix + $buffer[(size($buffer) -1)];\n" + " else\n" + " $toReturn += \"|\" + $prefix + $buffer[(size($buffer) -1)];\n" + " }\n" + " return $toReturn;\n" + "}\n"); for (String sname : animPaths.keySet()) { String nspace = nameSpaces.get(sname); String otherNspace = nspace.substring(0, nspace.length() - 2); String modelName = reverseNameSpaces.get(otherNspace); if (modelName != null) { boolean useNSpace = usesNameSpace.get(sname); boolean otherUseNSpace = usesNameSpace.get(modelName); String buildType = buildTypes.get(sname); String otherBuildType = buildTypes.get(modelName); String prefix = generatePrefix(nspace, useNSpace, buildType); String otherPrefix = generatePrefix(otherNspace, otherUseNSpace, otherBuildType); out.write( "{\n" + " string $crvPrefix = \"" + prefix + "\";\n" + " string $objPrefix = \"" + otherPrefix + "\";\n" + " string $obj = $crvPrefix + \"curveInfo\";\n" + " if (`objExists $obj`) {\n" + " int $size = `getAttr -s ($obj + \".cn\")`;\n" + " int $i = 0;\n" + " for ($i = 0; $i < $size; $i++) {\n" + " string $curve = `getAttr ($obj + \".cn[\" + $i + \"]\")`;\n" + " string $attr = `getAttr ($obj + \".an[\" + $i + \"]\")`;\n" + " $curve = addPrefixToName($crvPrefix, $curve);\n" + " $attr = addPrefixToName($objPrefix, $attr);\n" + " print(\"connectAttr -f \" + $curve + \" \" + $attr + \"\\n\");\n" + " connectAttr -f $curve $attr; \n" + " }\n" + " }\n" + " else {\n" + " string $curves[] = `ls -type animCurve ($crvPrefix + \"*\")`;\n" + " string $curve;\n" + " for ($curve in $curves) {\n" + " string $shortName = removePrefix($curve);\n" + " string $buffer[];\n" + " tokenize($shortName, \"_\", $buffer);\n" + " string $attr = $buffer[(size($buffer) -1)];\n" + " string $name = \"\";\n" + " int $length = (size($buffer) -1);\n" + " int $i;\n" + " for ($i = 0; $i < $length; $i++) {\n" + " $name += $buffer[$i];\n" + " if ($i != ($length - 1) )\n" + " $name += \"_\";\n" + " }\n" + " string $channel = addPrefix($name, $objPrefix) + \".\" + $attr;\n" + " print ($curve + \"\\t\" + $channel + \"\\n\");\n" + " if (!`getAttr -l $channel`)\n" + " connectAttr -f ($curve + \".output\") $channel;\n" + " }\n" + " }\n" + "}\n"); } } /* set the time options */ out.write(genPlaybackOptionsMEL()); writeAnimMEL(agenda, out); /* save the file */ out.write( "// SAVE\n" + "print \"Saving Generated Scene: " + targetScene + "\\n\";\n" + "file -save;\n\n"); writeFinalMEL(agenda, out); out.close(); } catch (IOException ex) { throw new PipelineException( "Unable to write temporary MEL script file (" + script + ") for Job " + "(" + agenda.getJobID() + ")!\n" + ex.getMessage()); } /* create the process to run the action */ return createMayaSubProcess(null, script, true, agenda, outFile, errFile); }