#!/usr/bin/env python # -*- coding: utf-8 -*- import maya.cmds as cmds from scripts.utils.Core import ( GetMeshes, MetaHumanNormals, RBFDeformer, GetNeckVertices ) def meta_human_normals(): """ 返回MetaHuman模型的法线顶点对应关系 Returns: list: 顶点索引列表,每两个值为一组,分别对应头部和身体的顶点 """ return [ 2805,9, 2806,8, 2807,7, 2808,10, 2809,6, 2810,5, 2811,2, 2812,1, 2813,0, 2814,4, 2815,12, 2816,14, 2817,15, 2818,16, 2819,17, 2820,18, 2821,19, 2822,20, 2823,21, 2824,11, 2873,22, 2876,23, 2965,3, 2997,13, 5876,3818, 5877,30, 5878,31, 5879,32, 5880,29, 5881,28, 5882,26, 5883,24, 5884,25, 5885,27, 5886,34, 5887,35, 5888,36, 5889,37, 5890,38, 5891,39, 5892,40, 5893,41, 5894,42, 5895,33, 5944,43, 5947,44, 11560,16789, 11564,16786, 11567,16795, 11569,16794, 11572,16784, 11575,7645, 11578,22814, 11582,16779, 11585,22833, 11587,22824, 11600,22801, 11795,21578, 11798,21577, 11799,21575, 11802,21573, 11803,21571, 11805,21569, 11807,21566, 11809,21564, 11811,21540, 11899,16775, 11909,16774, 11910,21542, 17607,9206, 17610,9203, 17614,9211, 17617,9207, 17619,9198, 17622,15227, 17626,15170, 17629,9195, 17632,15189, 17635,15180, 17647,15158, 17854,13968, 17856,13966, 17859,13964, 17860,13962, 17863,13960, 17865,13958, 17867,13957, 17869,13955, 17871,13927, 17962,9192, 17968,9186, 17972,13931 ] def get_neck_vertices(): """ 返回颈部顶点列表 Returns: list: 颈部顶点索引列表 """ return [ 70,71,81,85,95,101,103,107,145,192, 236,307,309,321,388,405,415,422,445,497, 499,535,587,594,612,626,631,638,652,689, 692,739,757,777,783,822,851,1147,1377,1510, 1527,1551,1581,1632,1695,1714,1715,1721,1796,1805, 1811,1842,1844,1860,1870,1898,1901,1907,1912,1950, 2006,2032,2043,2058,2099,2106,2111,2119,2143,2158, 2176,2197,2214,2273,2281,2286,2304,2327,2377,2386, 2430,2476,2479,2546,2591,2654,2658,2730,2737,2749, 2790,2887,2891,2892,2893,2894,2895,2896,2901,2905, 2917,2919,2926,2934,2936,2938,2940,2942,2943,2944, 2945,2946,2947,2948,2958,2963,2967,2968,2969,2970, 2972,2978,2981,2984,2986,2988,2989,3020,3025,3027, 3029,3032,3034,3052,3055,3063,3065,3066,3068,3069, 3141,3142,3152,3156,3166,3172,3174,3178,3216,3263, 3307,3378,3380,3392,3459,3476,3486,3493,3516,3568, 3570,3606,3658,3665,3683,3697,3702,3709,3723,3760, 3763,3810,3828,3848,3854,3893,3922,4218,4448,4581, 4598,4622,4652,4703,4766,4785,4786,4792,4867,4876, 4882,4913,4915,4931,4941,4969,4972,4978,4983,5021, 5077,5103,5114,5129,5170,5177,5182,5190,5214,5229, 5247,5268,5285,5344,5352,5357,5375,5398,5448,5457, 5501,5547,5550,5617,5662,5725,5729,5801,5808,5820, 5861,5980,5983,5991,5993,5994,5996,5997,6004,6009, 6016,6074,6087,6096,6172,6186,6196,6200,6209,6213, 6221,6222,6232,6235,6258,6340,6376,6385,6405,6431, 6453,6471,6479,6480,6534,6554,6560,6687,6801,6816, 6840,6856,6861,6882,6894,6903,6906,7027,7079,7084, 7099,7101,7106,7112,7119,7122,7142,7163,7186,7232, 7241,7256,7263,7271,7285,7293,7303,7324,7326,7356, 7358,7362,7376,7381,7627,7648,7656,7806,7816,8020, 8049,8063,8110,8389,8642,8774,8833,8914,8937,8949, 8956,8965,9026,9100,9212,9221,9236,9289,9309,9402, 9407,9409,9414,9415,9452,9458,9462,9468,9498,9587, 9610,9662,9698,9736,9769,9771,9774,9795,9838,9840, 9851,9958,10013,10020,10028,10044,10045,10046,10052,10055, 10065,10066,10068,10071,10095,10098,10105,10108,10131,10134, 10135,10136,10139,10178,10182,10185,10186,10199,10219,10224, 10244,10261,10387,10411,10447,10487,10514,10519,10522,10533, 10540,10587,10605,10610,10613,10625,10646,10655,10688,10732, 10797,10863,10908,10910,10913,10914,10917,10920,10921,10930, 10932,10997,11032,11034,11150,11161,11266,11293,11512,11558, 11609,11630,11651,11668,11675,11693,11755,11761,11768,11813, 11832,12015,12025,12036,12071,12104,12116,12126,12139,12141, 12151,12156,12157,12159,12166,12170,12179,12180,12203,12287, 12325,12332,12352,12378,12400,12424,12433,12434,12490,12506, 12508,12516,12643,12691,12763,12780,12807,12822,12828,12839, 12852,12864,12873,12876,12877,12999,13023,13051,13054,13058, 13074,13076,13082,13089,13094,13099,13121,13142,13161,13206, 13217,13234,13238,13249,13263,13267,13281,13300,13302,13332, 13334,13336,13353,13359,13606,13628,13636,13785,13793,14000, 14027,14044,14090,14369,14623,14752,14811,14892,14917,14928, 14933,14942,15004,15080,15192,15200,15206,15208,15210,15212, 15220,15275,15294,15388,15393,15395,15397,15401,15402,15440, 15446,15450,15454,15483,15580,15601,15653,15688,15727,15761, 15765,15768,15789,15830,15832,15834,15843,15847,15954,16009, 16016,16025,16040,16041,16043,16044,16049,16052,16062,16063, 16065,16067,16092,16095,16102,16105,16129,16130,16132,16133, 16135,16139,16173,16176,16180,16184,16187,16191,16200,16221, 16225,16244,16266,16390,16414,16450,16490,16517,16522,16527, 16538,16544,16557,16593,16609,16617,16621,16630,16656,16665, 16695,16741,16805,16851,16858,16876,16920,16922,16923,16928, 16931,16933,16934,16942,16943,16953,16955,16972,17016,17056, 17058,17064,17088,17095,17186,17196,17303,17330,17341,17432, 17555,17602,17658,17663,17677,17684,17701,17708,17717,17726, 17742,17809,17817,17821,17827,17829,17847,17874,17892,18034, 18047,18182,18197,18199,18201,18227,18237,18304,18308,18359, 18361,18364,18366,18405,18410,18420,18422,18471,18506,18507, 18516,18522,18596,18622,18639,18642,18682,18721,18730,18745, 18825,18893,19005,19207,19208,19247,19251,19322,19324,19325, 19445,19534,19581,19585,19591,19666,19693,19695,19738,19796, 19818,19819,19821,19836,19854,19864,19868,19894,19909,19910, 19914,19915,19916,19917,19929,19936,19939,19948,19952,19957, 19958,19960,19993,20004,20007,20037,20069,20075,20078,20082, 20135,20139,20148,20150,20155,20159,20175,20185,20222,20240, 20267,20352,20391,20392,20411,20415,20440,20444,20525,20564, 20567,20591,20627,20648,20671,20703,20705,20707,20722,20728, 20806,20834,20846,20850,20855,20860,20871,20891,21008,21047, 21060,21195,21210,21212,21214,21240,21250,21317,21321,21372, 21374,21377,21379,21418,21423,21433,21435,21484,21519,21520, 21529,21535,21609,21635,21652,21655,21695,21734,21743,21758, 21838,21906,22018,22220,22221,22260,22264,22335,22337,22338, 22458,22547,22594,22598,22604,22679,22706,22708,22751,22809, 22831,22832,22834,22849,22867,22877,22881,22907,22922,22923, 22927,22928,22929,22930,22942,22949,22952,22961,22965,22970, 22971,22973,23006,23017,23020,23050,23082,23088,23091,23095, 23148,23152,23161,23163,23168,23172,23188,23198,23235,23253, 23280,23365,23404,23405,23424,23428,23453,23457,23538,23577, 23580,23604,23640,23661,23684,23716,23718,23720,23735,23741, 23819,23847,23859,23863,23868,23873,23884,23904,24021 ] def repair_seams(): """ 修复模型接缝 """ # 获取顶点对应关系 vtxs = meta_human_normals() # 获取头部和身体模型 head = GetMeshes(m=0) body = GetMeshes(m=50) # 复制头部模型 head_copy = cmds.duplicate(head, rr=True)[0] # 存储头部顶点索引 head_vtxs = [] count = len(vtxs) // 2 # 处理对应顶点 for i in range(count): h = vtxs[i*2] b = vtxs[i*2+1] head_vtxs.append(h) # 获取身体顶点位置并应用到头部副本 head_vtx = f"{head_copy}.vtx[{h}]" body_vtx = f"{body}.vtx[{b}]" pos = cmds.xform(body_vtx, q=True, ws=True, t=True) cmds.xform(head_vtx, ws=True, t=pos) # 添加颈部顶点 neck_vtxs = get_neck_vertices() head_vtxs.extend(neck_vtxs) # 应用RBF变形器 RBFDeformer( rbf=1, m=[head, head_copy], t=[head], pi=head_vtxs, r=2.25 ) # 清理临时模型 cmds.delete(head_copy) # 如果直接运行此脚本 if __name__ == '__main__': repair_seams()