289 lines
8.8 KiB
Plaintext
289 lines
8.8 KiB
Plaintext
//******************************************************************************
|
|
//
|
|
// 版权所有: 玉溪时光科技有限公司
|
|
// 联系邮箱: q.100@qq.com
|
|
// 开发日期: 2024/04/08
|
|
//
|
|
//******************************************************************************
|
|
|
|
global proc SGPresetsSettings ()
|
|
{
|
|
|
|
if (!`window -ex SuperRiggingEditor`){
|
|
return;
|
|
}
|
|
|
|
if (`window -ex presetsSettingsWin`){
|
|
deleteUI -window presetsSettingsWin;
|
|
}
|
|
|
|
//if(`SGDescriptor -l` == "ZH"){
|
|
|
|
//}
|
|
|
|
string $jsonfile = `SGDescriptor -ti "jointsInfo"`;
|
|
|
|
window -p SuperRiggingEditor -w 310 -h 100 -t "Presets Settings" -s true -tb true presetsSettingsWin;
|
|
formLayout sgPresetsFormLayout;
|
|
textField -tx $jsonfile sgTopologyInfo;
|
|
separator -height 10 -style "in" sgPresetsSeparatorA;
|
|
columnLayout -adj 1 -columnAttach "both" 5 -rowSpacing 2 -columnWidth 150 sgPresetsColumnLayoutA;
|
|
|
|
button -l "Select Head Vertexs" -al "center" -c "SGSelectVertexs 0 head;" ;
|
|
button -l "Save Head Vertexs" -al "center" -c "SGSaveVertexs 0 head;" ;
|
|
|
|
separator -height 10 -style "in";
|
|
button -l "Select Teeth Vertexs" -al "center" -c "SGSelectVertexs 1 teeth;" ;
|
|
button -l "Save Teeth Vertexs" -al "center" -c "SGSaveVertexs 1 teeth;" ;
|
|
|
|
separator -height 10 -style "in";
|
|
button -l "Select EyeLeft Vertexs" -al "center" -c "SGSelectVertexs 3 eyeLeft;" ;
|
|
button -l "Save EyeLeft Vertexs" -al "center" -c "SGSaveVertexs 3 eyeLeft;" ;
|
|
|
|
separator -height 10 -style "in";
|
|
button -l "Select EyeRight Vertexs" -al "center" -c "SGSelectVertexs 4 eyeRight;" ;
|
|
button -l "Save EyeRight Vertexs" -al "center" -c "SGSaveVertexs 4 eyeRight;" ;
|
|
|
|
//separator -height 10 -style "in";
|
|
setParent..;
|
|
|
|
columnLayout -adj 1 -columnAttach "both" 5 -rowSpacing 2 -columnWidth 150 sgPresetsColumnLayoutB;
|
|
//separator -height 10 -style "in";
|
|
|
|
button -l "Select Body Vertexs" -al "center" -c "SGSelectVertexs 50 body;" ;
|
|
button -l "Save Body Vertexs" -al "center" -c "SGSaveVertexs 50 body;" ;
|
|
|
|
separator -height 10 -style "in";
|
|
button -l "Select Neck Vertexs" -al "center" -c "SGSelectVertexs 0 neck;" ;
|
|
button -l "Save Neck Vertexs" -al "center" -c "SGSaveVertexs 0 neck;" ;
|
|
|
|
|
|
separator -height 10 -style "in";
|
|
button -l "Select HeadEye Vertexs" -al "center" -c "SGSelectVertexs 0 headEye;" ;
|
|
button -l "Save HeadEye Vertexs" -al "center" -c "SGSaveVertexs 0 headEye;" ;
|
|
|
|
separator -height 10 -style "in";
|
|
button -l "Select HeadMouth Vertexs" -al "center" -c "SGSelectVertexs 0 headMouth;" ;
|
|
button -l "Save HeadMouth Vertexs" -al "center" -c "SGSaveVertexs 0 headMouth;" ;
|
|
|
|
//separator -height 10 -style "in";
|
|
setParent..;
|
|
|
|
columnLayout -adj 1 -columnAttach "both" 5 -rowSpacing 2 -columnWidth 150 sgPresetsColumnLayoutC;
|
|
separator -height 10 -style "in";
|
|
|
|
button -l "The Closest Ooint Of The Head" -al "center" -c "SGGetClosestPointOnMesh 0;" ;
|
|
button -l "The Closest Ooint Of The Body" -al "center" -c "SGGetClosestPointOnMesh 50" ;
|
|
button -l "The Closest Ooint Of The Teeth" -al "center" -c "SGGetClosestPointOnMesh 1;" ;
|
|
|
|
separator -height 10 -style "in";
|
|
|
|
button -l "Write Joints Default Position" -al "center" -c "SGWriteJointsDefaultPosition;" ;
|
|
|
|
separator -height 10 -style "in";
|
|
setParent..;
|
|
|
|
setParent..;
|
|
|
|
formLayout -e
|
|
|
|
-attachForm sgTopologyInfo "top" 3
|
|
-attachForm sgTopologyInfo "left" 0
|
|
-attachForm sgTopologyInfo "right" 0
|
|
-attachNone sgTopologyInfo "bottom"
|
|
|
|
-attachControl sgPresetsSeparatorA "top" 1 sgTopologyInfo
|
|
-attachForm sgPresetsSeparatorA "left" 0
|
|
-attachForm sgPresetsSeparatorA "right" 0
|
|
-attachNone sgPresetsSeparatorA "bottom"
|
|
|
|
-attachControl sgPresetsColumnLayoutA "top" 1 sgPresetsSeparatorA
|
|
-attachForm sgPresetsColumnLayoutA "left" 0
|
|
-attachPosition sgPresetsColumnLayoutA "right" 0 51
|
|
-attachNone sgPresetsColumnLayoutA "bottom"
|
|
|
|
-attachControl sgPresetsColumnLayoutB "top" 1 sgPresetsSeparatorA
|
|
-attachPosition sgPresetsColumnLayoutB "left" 0 49
|
|
-attachForm sgPresetsColumnLayoutB "right" 0
|
|
-attachNone sgPresetsColumnLayoutB "bottom"
|
|
|
|
-attachControl sgPresetsColumnLayoutC "top" 1 sgPresetsColumnLayoutA
|
|
-attachForm sgPresetsColumnLayoutC "left" 0
|
|
-attachForm sgPresetsColumnLayoutC "right" 0
|
|
-attachNone sgPresetsColumnLayoutC "bottom"
|
|
|
|
sgPresetsFormLayout;
|
|
|
|
showWindow presetsSettingsWin;
|
|
}
|
|
//SGPresetsSettings;
|
|
|
|
global proc SGSelectVertexs (int $meshIndex, string $region)
|
|
{
|
|
string $openfile = `SGDescriptor -ti "vertexsInfo"`;
|
|
string $mesh = `SGGetMeshes -m $meshIndex`;
|
|
int $vertexs[] = `SGReadJson -f $openfile -k $region -t "int"`;
|
|
string $cmd = "select -cl;";
|
|
for($vertex in $vertexs){
|
|
$cmd += "select -add " + $mesh + ".vtx[" + $vertex + "];\n";
|
|
}
|
|
eval($cmd);
|
|
}
|
|
|
|
global proc SGSaveVertexs (int $meshIndex, string $region)
|
|
{
|
|
string $jsonfile = `SGDescriptor -ti "vertexsInfo"`;
|
|
string $mesh = `SGGetMeshes -m $meshIndex`;
|
|
string $sel[] = `ls -sl -fl`;
|
|
int $Indices[];
|
|
for($s in $sel){
|
|
string $buffer[];
|
|
int $numTokens = `tokenize $s "[]" $buffer`;
|
|
string $meshBuffer = $buffer[0];
|
|
if(!`gmatch $meshBuffer ($mesh + "*")`){
|
|
error -n "Model Selection Error...";
|
|
return;
|
|
}
|
|
$Indices[size($Indices)] = $buffer[1];
|
|
}
|
|
SGWriteJson -of $jsonfile -sf $jsonfile -k $region -t "int" $Indices;
|
|
}
|
|
|
|
global proc SGGetClosestPointOnMesh (int $meshIndex)
|
|
{
|
|
string $openfile = `SGDescriptor -ti "jointsInfo"`;
|
|
string $mesh = `SGGetMeshes -m $meshIndex`;
|
|
string $closestPointNode = `createNode closestPointOnMesh`;
|
|
connectAttr -f ($mesh + ".worldMesh[0]") ($closestPointNode + ".inMesh");
|
|
|
|
string $key = "head" ;
|
|
if($meshIndex == 50){
|
|
$key = "body" ;
|
|
}
|
|
string $cmd = "select -cl;";
|
|
string $object[] = `SGReadJson -f $openfile -k $key -t "object"`;
|
|
|
|
for($i=0; $i<size($object); $i++){
|
|
string $jointName[] = `SGReadJson -d $object[$i] -k "joint" -t "string"`;
|
|
string $joint;
|
|
if($meshIndex == 0 || $meshIndex == 1){
|
|
$joint = "DHIhead:" + $jointName[0];
|
|
int $index[] = `SGReadJson -d $object[$i] -k "mesh" -t "int"`;
|
|
if($index[0] == $meshIndex){
|
|
float $pointPosition[] = `xform -q -ws -t $joint`;
|
|
setAttr ($closestPointNode + ".inPosition") $pointPosition[0] $pointPosition[1] $pointPosition[2];
|
|
int $closestVertexIndex = `getAttr ($closestPointNode + ".closestVertexIndex")`;
|
|
$cmd += "select -add " + $mesh + ".vtx[" + $closestVertexIndex + "];\n";
|
|
}
|
|
}else{
|
|
$joint = $jointName[0] + "_drv";
|
|
int $enable[] = `SGReadJson -d $object[$i] -k "enable" -t "bool"`;
|
|
if($enable[0]){
|
|
float $pointPosition[] = `xform -q -ws -t $joint`;
|
|
setAttr ($closestPointNode + ".inPosition") $pointPosition[0] $pointPosition[1] $pointPosition[2];
|
|
int $closestVertexIndex = `getAttr ($closestPointNode + ".closestVertexIndex")`;
|
|
$cmd += "select -add " + $mesh + ".vtx[" + $closestVertexIndex + "];\n";
|
|
}
|
|
}
|
|
}
|
|
delete $closestPointNode;
|
|
eval($cmd);
|
|
}
|
|
|
|
global proc SGWriteJointsDefaultPosition (){
|
|
|
|
string $jsonfile = `SGDescriptor -ti "jointsInfo"`;
|
|
|
|
string $objectBody[] = `SGReadJson -f $jsonfile -k "body" -t "object"`;
|
|
|
|
for($i=0; $i<size($objectBody); $i++){
|
|
string $jointName[] = `SGReadJson -d $objectBody[$i] -k "joint" -t "string"`;
|
|
//string $joint = "DHIhead:"+$jointName[0];
|
|
string $joint = $jointName[0] + "_drv";
|
|
float $pos[] = `xform -q -ws -t $joint`;
|
|
if ($pos[0] < 0) {
|
|
$pos[0] = `ceil(($pos[0] * 10000.0) - 0.5)` / 10000.0;
|
|
} else {
|
|
$pos[0] = `floor(($pos[0] * 10000.0) + 0.5)` / 10000.0;
|
|
}
|
|
if ($pos[1] < 0) {
|
|
$pos[1] = `ceil(($pos[1] * 10000.0) - 0.5)` / 10000.0;
|
|
} else {
|
|
$pos[1] = `floor(($pos[1] * 10000.0) + 0.5)` / 10000.0;
|
|
}
|
|
if ($pos[2] < 0) {
|
|
$pos[2] = `ceil(($pos[2] * 10000.0) - 0.5)` / 10000.0;
|
|
} else {
|
|
$pos[2] = `floor(($pos[2] * 10000.0) + 0.5)` / 10000.0;
|
|
}
|
|
string $data = `SGWriteJson -d $objectBody[$i] -sf "data" -k "translate" -t "double" $pos`;
|
|
$objectBody[$i] = $data;
|
|
}
|
|
SGWriteJson -of $jsonfile -sf $jsonfile -k "body" -t "object" $objectBody;
|
|
|
|
string $objectHead[] = `SGReadJson -f $jsonfile -k "head" -t "object"`;
|
|
for($i=0; $i<size($objectHead); $i++){
|
|
string $jointName[] = `SGReadJson -d $objectHead[$i] -k "joint" -t "string"`;
|
|
string $joint = "DHIhead:"+$jointName[0];
|
|
//string $joint = $jointName[0] + "_drv";
|
|
float $pos[] = `xform -q -ws -t $joint`;
|
|
if ($pos[0] < 0) {
|
|
$pos[0] = `ceil(($pos[0] * 10000.0) - 0.5)` / 10000.0;
|
|
} else {
|
|
$pos[0] = `floor(($pos[0] * 10000.0) + 0.5)` / 10000.0;
|
|
}
|
|
if ($pos[1] < 0) {
|
|
$pos[1] = `ceil(($pos[1] * 10000.0) - 0.5)` / 10000.0;
|
|
} else {
|
|
$pos[1] = `floor(($pos[1] * 10000.0) + 0.5)` / 10000.0;
|
|
}
|
|
if ($pos[2] < 0) {
|
|
$pos[2] = `ceil(($pos[2] * 10000.0) - 0.5)` / 10000.0;
|
|
} else {
|
|
$pos[2] = `floor(($pos[2] * 10000.0) + 0.5)` / 10000.0;
|
|
}
|
|
string $data = `SGWriteJson -d $objectHead[$i] -sf "data" -k "translate" -t "double" $pos`;
|
|
$objectHead[$i] = $data;
|
|
}
|
|
SGWriteJson -of $jsonfile -sf $jsonfile -k "head" -t "object" $objectHead;
|
|
|
|
}
|
|
|
|
|
|
SGPresetsSettings;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|