1 Star 0 Fork 0

weijer/VertexAnimationTextureMaya

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
VertexAnimationTextureMaya.mel 10.98 KB
一键复制 编辑 原始数据 按行查看 历史
salt-k2t 提交于 2021-12-19 13:27 . Drag and drop install (#4)
// ***************************************************************************
// INSTALL MODULE
// ***************************************************************************
//
// DESCRIPTION:
// Add the module which is located in the same directory as the .mel file
// into the first available MAYA_MODULE_PATH directory. It doesn't matter
// where on disk the module lives as the script will make sure the path in
// the .mod file links to the correct place. There are some basic sanity
// checks in place to make sure the script doesn't error out. This includes
// Maya version compatibility with the module. Permissions of the directories
// files have to be written to and incorrectly formatted module files.
//
// REQUIRES:
// - Template .mod file ( replace regular file path with <PATH> )
// - Maya module ( scripts/icons/plug-ins etc directories )
//
// USAGE:
// source <MEL_FILE>;
//
// AUTHORS:
// Robert Joosten - rwm.joosten@gmail.com
//
// LICENSE:
// MIT
//
// VERSIONS:
// 1.0.0 - Aug 23, 2018 - Initial Release.
// 1.0.1 - Sep 17, 2018 - Allow for use in paths that contain a space.
// 1.0.2 - Oct 03, 2018 - Fix path error installing on UNIX.
// 1.0.3 - Jun 04, 2021 - Python 2/3 compatibility
//
// ***************************************************************************
proc string[] getModulePathsFromEnvironment()
{
// get all of the paths in the MAYA_MODULE_PATH variable and split them
// into a string array.
string $paths[];
string $separator = (`about -nt`) ? ";" : ":";
tokenize(getenv("MAYA_MODULE_PATH"), $separator, $paths);
return $paths;
}
// ***************************************************************************
proc string findModuleFileInPath(string $path)
{
// get the first module file found in the directory.
string $files[] = `getFileList -folder $path -filespec "*.mod"`;
return $files[0];
}
proc string findModuleFileInModulePath(string $moduleFile, string $modulePaths[])
{
// loop module paths
for( $path in $modulePaths )
{
// find moduleFile in path
string $files[] = `getFileList -folder $path -filespec $moduleFile`;
if ($files[0] != "")
return $path;
}
// declare empty output
string $empty;
return $empty;
}
// ***************************************************************************
proc string[] readModuleFile(string $path)
{
// read the module file and return each line as a string part of a string
// array.
string $lines[];
$fileId = `fopen $path "r"`;
string $data = `fread $fileId $data`;
tokenize($data, "\n", $lines);
return $lines;
}
// ***************************************************************************
proc string getConditionValue(string $line)
{
// get the condition value by splitting the string on the : character and
// returning the second section of the partition.
string $partitions[];
tokenize($line, ":", $partitions);
return $partitions[1];
}
// ***************************************************************************
proc string[] parseModuleLine(string $line)
{
// declare output variable
string $output[];
// declare default output
string $mayaVersion;
string $language;
string $platform;
// make sure its a module line by checking if the line starts with a +
// or -.
if (startsWith($line, "+") == 0 && startsWith($line, "-") == 0)
return $output;
// get partitions
string $partitions[];
tokenize($line, " ", $partitions);
// get partitions length
$length = size($partitions);
// loop partitions in reverse
for( $i=1; $i<$length+1; ++$i )
{
// get reverse index
int $index = $length - $i;
string $part = $partitions[$index];
// extract conditions
if (startsWith($part, "MAYAVERSION") == 1)
{
$mayaVersion = getConditionValue($part);
stringArrayRemoveAtIndex($index, $partitions);
}
else if (startsWith($part, "LANGUAGE") == 1)
{
$language = getConditionValue($part);
stringArrayRemoveAtIndex($index, $partitions);
}
else if (startsWith($part, "PLATFORM") == 1)
{
$platform = getConditionValue($part);
stringArrayRemoveAtIndex($index, $partitions);
}
}
// set output
$output[0] = $partitions[0];
$output[1] = $partitions[1];
$output[2] = $partitions[2];
$output[3] = $partitions[3];
$output[4] = $mayaVersion;
$output[5] = $language;
$output[6] = $platform;
return $output;
}
// ***************************************************************************
proc string[] findModuleMatch(string $lines[])
{
// get maya data
string $mayaVersion = `about -version`;
string $language = `about -uiLanguage`;
string $platform = `about -operatingSystem`;
// process module to see if its suitable for the current version of Maya.
for($line in $lines)
{
// get line data
string $lineData[] = parseModuleLine($line);
// validate line data
if ($lineData[0] == "")
continue;
// validate maya version
if ($lineData[4] != "" && $lineData[4] != $mayaVersion)
continue;
// validate language
if ($lineData[5] != "" && $lineData[5] != $language)
continue;
// validate platform
if ($lineData[6] != "" && $lineData[6] != $platform)
continue;
// return match
return $lineData;
}
// declare empty output
string $empty[];
return $empty;
}
// ***************************************************************************
proc loadModuleExtended(string $moduleFile, string $path)
{
// get separator
string $separator = "/";
// load module
loadModule -load $moduleFile;
// add scripts path to system path, for some reason after loading the
// module we are still not able to import the scripts even though the
// path is available in the MAYA_SCRIPT_PATH.
string $scriptPath = $path + $separator + "scripts";
python("import sys; sys.path.append('" + $scriptPath + "')");
// see if a userSetup.py is present in the script folder. If this is the
// case execute that file.
string $userSetup = $scriptPath + $separator + "userSetup.py";
if (`filetest -e $userSetup` == 1)
python("import six; import __main__; six.exec_(open('" + $userSetup + "').read(), __main__.__dict__ )");
}
// ***************************************************************************
global proc installModule()
{
// get path from mel file
string $melWhatIs = `whatIs "installModule"`;
string $melWhatIsPath = `match ": (.*)" $melWhatIs`;
int $melSize = `size $melWhatIsPath`;
string $melPath = `substring $melWhatIsPath 3 ($melSize-3)`;
string $path = dirname($melPath);
// get separator
string $separator = "/";
// find installed module
string $modules[] = `moduleInfo -listModules`;
// get module paths from the environment and choose the first one if this
// variable is not overwritten the .mod file will be written to this path.
string $modulePaths[] = getModulePathsFromEnvironment();
string $modulePathDefault;
// find module in current directory
string $moduleFileBase = findModuleFileInPath($path);
// validate module
if ($moduleFileBase == "")
error("\nNo template module file found in " + $path);
// find full module path
string $moduleFile = $path + $separator + $moduleFileBase;
// read module content
string $moduleContent[] = readModuleFile($moduleFile);
// find module match
string $moduleMatch[] = findModuleMatch($moduleContent);
string $moduleName = $moduleMatch[1];
string $moduleVersion = $moduleMatch[2];
// validate module content
if ($moduleName == "")
error("\nNo valid module information found matching the current version/language/platform of Maya in " + $moduleFile);
// check if module already exists
if (stringArrayContains($moduleName, $modules) == 1)
{
string $moduleVersionExisting = `moduleInfo -moduleName $moduleName -version`;
string $existingPath = `moduleInfo -moduleName $moduleName -path`;
if ($moduleVersion == $moduleVersionExisting && $path ==$existingPath)
{
print("The " + $moduleName + " module, version " + $moduleVersion + " at " + $path + " is already installed!");
return;
}
// find existing module path
$modulePathDefault = findModuleFileInModulePath($moduleFileBase, $modulePaths);
}
// get existing module path to the front of the list
if ($modulePathDefault != "")
{
int $index = stringArrayFind($modulePathDefault, 0, $modulePaths);
stringArrayRemoveAtIndex($index, $modulePaths);
stringArrayInsertAtIndex(0, $modulePaths, $modulePathDefault);
}
// loop module paths
for($modulePath in $modulePaths)
{
// only allow default path to be written if it exists
if ($modulePathDefault != "" && $modulePathDefault != $modulePath)
continue;
// create dir in case it doesn't exist
sysFile -makeDir $modulePath;
// construct module path
string $outputPath = $modulePath + $separator + $moduleFileBase;
// write module file
$fileId = `fopen $outputPath "w"`;
// if the default path exists error if the file cannot be written
// this means the module has been installed by hand in a directory
// that is not writable without administrator permissions. The error
// will ask the user to copy the script by hand.
if ($fileId == 0 && $modulePathDefault == $modulePath)
error("\nThe " + $moduleName + " module, version " + $moduleVersion + " could not be updated as the current path it is installed in is not writable.\nPlease overwrite the " + $moduleFileBase + " file in " + $modulePath + ".");
else if ($fileId == 0)
continue;
// write lines
print("Content:\n");
for($line in $moduleContent){
string $processedLine = `substitute "<PATH>" $line $path`;
print(" " + $processedLine + "\n");
fprint $fileId ($processedLine + "\n");
}
// print output
print("Output:\n");
print(" " + $outputPath + "\n");
// close output path
fclose $fileId;
// load module
loadModuleExtended($outputPath, $path);
return;
}
// throw error as module has not been installed
error("\nThe " + $moduleName + " module, version " + $moduleVersion + " could not be installed as non of the module paths were writable.");
}
// process
installModule();
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/weijer/VertexAnimationTextureMaya.git
git@gitee.com:weijer/VertexAnimationTextureMaya.git
weijer
VertexAnimationTextureMaya
VertexAnimationTextureMaya
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385