Created
November 27, 2024 02:25
-
-
Save ChuckieChen945/89a95ba61d36cfd3a51b7488cc67b598 to your computer and use it in GitHub Desktop.
未完成的Maya根据硬边自动拆分UV的脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TODO:用PyMEL重写 https://github.com/LumaPictures/pymel | |
// 硬边拆UV | |
// 获取当前选择的物体 | |
string $selection[] = `ls -sl`; | |
if (size($selection) == 0) { | |
warning "没有选择任何物体,请选择一个物体。"; | |
} else { | |
for ($obj in $selection) { | |
// 90度以下为硬边 | |
polySoftEdge -a 90 -ch 1 $obj; | |
// TODO:将折痕转化为硬边,然后取消折痕 | |
// 基于摄影机创建UV | |
polyProjection -type Planar -md p -constructionHistory 1 ($obj + ".f[*]"); | |
// 初始化硬边标志 | |
int $hasHardEdges = 0; | |
// 获取物体的所有边 | |
string $edges[] = `polyListComponentConversion -toEdge $obj`; | |
// 检查每条边是否为硬边 | |
for ($edge in $edges) { | |
// 获取边的软硬信息 | |
string $edgeInfo[] = `polyInfo -edgeToVertex $edge`; | |
// 如果 polyInfo 输出信息包含 "hard",则该边为硬边 | |
if (`gmatch $edgeInfo[0] "*Hard*"`) { | |
$hasHardEdges = 1; | |
break; | |
} | |
} | |
// 根据是否有硬边执行不同操作 | |
if ($hasHardEdges) { | |
polyUVHardEdgesAutoSeams 1; | |
u3dUnfold -ite 1 -p 0 -bi 1 -tf 1 -ms 4096 -rs 2 $edges; | |
texOrientShells; | |
u3dLayout -res 256 -scl 1 -rmn 0 -rmx 360 -rst 90 -spc 0.00390625 -mar 0.001953125 -box 0 1 0 1 $edges; | |
} else { | |
// 自动接缝 效果不好,弃用 | |
// u3dAutoSeam -s 0.5 -p 1; | |
} | |
} | |
} | |
// TODO:输出时检查对象 | |
// 清历史,冻结 | |
// TODO:检查UV | |
// 是否超界,是否重叠 | |
// TODO: 高低模自动重命名,导出以供烘焙 | |
// 获取每个边的夹角。弃用 | |
// // 获取当前选择的对象 | |
// string $selection[] = `ls -sl`; | |
// if (size($selection) == 0) { | |
// warning "没有选择任何对象,请选择一个对象。"; | |
// } else { | |
// for ($obj in $selection) { | |
// // 获取该物体的所有边集合并存储为数组 | |
// string $allEdges[] = `polyListComponentConversion -toEdge $obj`; | |
// // 展开边集合为单独的边列表 | |
// string $edges[] = `filterExpand -sm 32 $allEdges`; | |
// // 检查是否成功获取边 | |
// if (size($edges) == 0) { | |
// warning ("未找到边:" + $obj + "\n"); | |
// } else { | |
// // 遍历每条边并输出边的名称 | |
// for ($edge in $edges) { | |
// // 获取这条边的两个顶点 | |
// string $edgeVertices[] = `polyEdgeVertex -q $edge`; | |
// // 获取边的两个顶点法线 | |
// float $normal1[], $normal2[]; | |
// polyNormalPerVertex -q -xyz $edgeVertices[0] $normal1; | |
// polyNormalPerVertex -q -xyz $edgeVertices[1] $normal2; | |
// // 计算法线向量的夹角 | |
// float $dotProduct = $normal1[0] * $normal2[0] + $normal1[1] * $normal2[1] + $normal1[2] * $normal2[2]; | |
// float $mag1 = `mag <<$normal1[0], $normal1[1], $normal1[2]>>`; | |
// float $mag2 = `mag <<$normal2[0], $normal2[1], $normal2[2]>>`; | |
// float $cosAngle = $dotProduct / ($mag1 * $mag2); | |
// float $angle = rad_to_deg(acos($cosAngle)); | |
// // 输出边的角度 | |
// print ($edge + " 的角度为: " + $angle + " 度\n"); | |
// } | |
// } | |
// } | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment