0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

やってみた ~ソフト選択でvtxカラーグラデーション~

0
Last updated at Posted at 2025-12-20

Xで見かけたお題をやってみた。

ソフト選択の内容で、vtXColorを設定したい。 ってやつですね

まずはソフト選択の内容をweight付で取得したいですね。

なんかskinWeightで似たようなことをやってた方が居たような

とかまぁ色々先人の方々の足跡を調べまして・・・なるほど助かりますね。

import maya.cmds as cmds
import maya.OpenMaya as om2

def getSoftSelectionWeights():
        
    sel = om2.MSelectionList()
    softSelection = om2.MRichSelection()
    om2.MGlobal.getRichSelection(softSelection)
    softSelection.getSelection(sel)

    dagPath = om2.MDagPath()
    component = om2.MObject()
    iter = om2.MItSelectionList(sel, om2.MFn.kMeshVertComponent)
    
    weights = {}

    while not iter.isDone():
        iter.getDagPath(dagPath,component)
        dagPath.pop()
        node = dagPath.fullPathName()
        fnComp = om2.MFnSingleIndexedComponent(component)
        for i in range(fnComp.elementCount()):
            weight = 1.0
            if fnComp.hasWeights():
                weight = fnComp.weight(i).influence()
            weights['{}.vtx[{}]'.format(node, fnComp.element(i))] = weight

        next(iter)

    return weights

試してみますと

image.png

取れてそうですね。(しまった長かった)

{'|pSphere1.vtx[160]': 0.0027246475219726562,
 '|pSphere1.vtx[161]': 0.0027246475219726562,
 '|pSphere1.vtx[162]': 0.0027246475219726562,
 '|pSphere1.vtx[163]': 0.0027246475219726562,
 '|pSphere1.vtx[164]': 0.0027246475219726562,
 '|pSphere1.vtx[165]': 0.0027246475219726562,
 '|pSphere1.vtx[166]': 0.0027246475219726562,
 '|pSphere1.vtx[167]': 0.0027246475219726562,
 '|pSphere1.vtx[168]': 0.0027247071266174316,
 '|pSphere1.vtx[169]': 0.0027247071266174316,
 '|pSphere1.vtx[170]': 0.0027247071266174316,
 '|pSphere1.vtx[171]': 0.0027247071266174316,
 '|pSphere1.vtx[172]': 0.0027247071266174316,
 '|pSphere1.vtx[173]': 0.0027247071266174316,
 '|pSphere1.vtx[174]': 0.0027247071266174316,
 '|pSphere1.vtx[175]': 0.0027247071266174316,
 '|pSphere1.vtx[176]': 0.0027247071266174316,
 '|pSphere1.vtx[177]': 0.0027247071266174316,
 '|pSphere1.vtx[178]': 0.0027247071266174316,
 '|pSphere1.vtx[179]': 0.0027247071266174316,
 '|pSphere1.vtx[180]': 0.024963557720184326,
 '|pSphere1.vtx[181]': 0.024963557720184326,
 '|pSphere1.vtx[182]': 0.024963557720184326,
 '|pSphere1.vtx[183]': 0.0249636173248291,
 '|pSphere1.vtx[184]': 0.0249636173248291,
 '|pSphere1.vtx[185]': 0.0249636173248291,
 '|pSphere1.vtx[186]': 0.0249636173248291,
 '|pSphere1.vtx[187]': 0.0249636173248291,
 '|pSphere1.vtx[188]': 0.0249636173248291,
 '|pSphere1.vtx[189]': 0.0249636173248291,
 '|pSphere1.vtx[190]': 0.0249636173248291,
 '|pSphere1.vtx[191]': 0.0249636173248291,
 '|pSphere1.vtx[192]': 0.0249636173248291,
 '|pSphere1.vtx[193]': 0.0249636173248291,
 '|pSphere1.vtx[194]': 0.0249636173248291,
 '|pSphere1.vtx[195]': 0.0249636173248291,
 '|pSphere1.vtx[196]': 0.0249636173248291,
 '|pSphere1.vtx[197]': 0.0249636173248291,
 '|pSphere1.vtx[198]': 0.024963736534118652,
 '|pSphere1.vtx[199]': 0.024963736534118652,
 '|pSphere1.vtx[200]': 0.07311749458312988,
 '|pSphere1.vtx[201]': 0.07311749458312988,
 '|pSphere1.vtx[202]': 0.07311749458312988,
 '|pSphere1.vtx[203]': 0.07311749458312988,
 '|pSphere1.vtx[204]': 0.07311761379241943,
 '|pSphere1.vtx[205]': 0.07311761379241943,
 '|pSphere1.vtx[206]': 0.07311761379241943,
 '|pSphere1.vtx[207]': 0.07311761379241943,
 '|pSphere1.vtx[208]': 0.07311761379241943,
 '|pSphere1.vtx[209]': 0.07311761379241943,
 '|pSphere1.vtx[210]': 0.07311761379241943,
 '|pSphere1.vtx[211]': 0.07311761379241943,
 '|pSphere1.vtx[212]': 0.07311761379241943,
 '|pSphere1.vtx[213]': 0.07311761379241943,
 '|pSphere1.vtx[214]': 0.07311761379241943,
 '|pSphere1.vtx[215]': 0.07311761379241943,
 '|pSphere1.vtx[216]': 0.07311761379241943,
 '|pSphere1.vtx[217]': 0.07311761379241943,
 '|pSphere1.vtx[218]': 0.07311761379241943,
 '|pSphere1.vtx[219]': 0.07311761379241943,
 '|pSphere1.vtx[220]': 0.14946889877319336,
 '|pSphere1.vtx[221]': 0.14946889877319336,
 '|pSphere1.vtx[222]': 0.14946889877319336,
 '|pSphere1.vtx[223]': 0.14946889877319336,
 '|pSphere1.vtx[224]': 0.14946889877319336,
 '|pSphere1.vtx[225]': 0.14946889877319336,
 '|pSphere1.vtx[226]': 0.14946889877319336,
 '|pSphere1.vtx[227]': 0.14946889877319336,
 '|pSphere1.vtx[228]': 0.1494690179824829,
 '|pSphere1.vtx[229]': 0.1494690179824829,
 '|pSphere1.vtx[230]': 0.1494690179824829,
 '|pSphere1.vtx[231]': 0.1494690179824829,
 '|pSphere1.vtx[232]': 0.149469256401062,
 '|pSphere1.vtx[233]': 0.149469256401062,
 '|pSphere1.vtx[234]': 0.149469256401062,
 '|pSphere1.vtx[235]': 0.149469256401062,
 '|pSphere1.vtx[236]': 0.149469256401062,
 '|pSphere1.vtx[237]': 0.149469256401062,
 '|pSphere1.vtx[238]': 0.149469256401062,
 '|pSphere1.vtx[239]': 0.149469256401062,
 '|pSphere1.vtx[240]': 0.25324392318725586,
 '|pSphere1.vtx[241]': 0.25324392318725586,
 '|pSphere1.vtx[242]': 0.25324392318725586,
 '|pSphere1.vtx[243]': 0.25324392318725586,
 '|pSphere1.vtx[244]': 0.25324392318725586,
 '|pSphere1.vtx[245]': 0.25324392318725586,
 '|pSphere1.vtx[246]': 0.25324392318725586,
 '|pSphere1.vtx[247]': 0.25324416160583496,
 '|pSphere1.vtx[248]': 0.25324416160583496,
 '|pSphere1.vtx[249]': 0.25324416160583496,
 '|pSphere1.vtx[250]': 0.25324416160583496,
 '|pSphere1.vtx[251]': 0.25324416160583496,
 '|pSphere1.vtx[252]': 0.2532443404197693,
 '|pSphere1.vtx[253]': 0.2532443404197693,
 '|pSphere1.vtx[254]': 0.2532443404197693,
 '|pSphere1.vtx[255]': 0.2532443404197693,
 '|pSphere1.vtx[256]': 0.2532443404197693,
 '|pSphere1.vtx[257]': 0.2532443404197693,
 '|pSphere1.vtx[258]': 0.2532443404197693,
 '|pSphere1.vtx[259]': 0.2532443404197693,
 '|pSphere1.vtx[260]': 0.3799377679824829,
 '|pSphere1.vtx[261]': 0.3799377679824829,
 '|pSphere1.vtx[262]': 0.3799377679824829,
 '|pSphere1.vtx[263]': 0.3799377679824829,
 '|pSphere1.vtx[264]': 0.3799377679824829,
 '|pSphere1.vtx[265]': 0.3799377679824829,
 '|pSphere1.vtx[266]': 0.3799377679824829,
 '|pSphere1.vtx[267]': 0.3799377679824829,
 '|pSphere1.vtx[268]': 0.379938006401062,
 '|pSphere1.vtx[269]': 0.379938006401062,
 '|pSphere1.vtx[270]': 0.379938006401062,
 '|pSphere1.vtx[271]': 0.379938006401062,
 '|pSphere1.vtx[272]': 0.379938006401062,
 '|pSphere1.vtx[273]': 0.379938006401062,
 '|pSphere1.vtx[274]': 0.379938006401062,
 '|pSphere1.vtx[275]': 0.379938006401062,
 '|pSphere1.vtx[276]': 0.379938006401062,
 '|pSphere1.vtx[277]': 0.379938006401062,
 '|pSphere1.vtx[278]': 0.379938006401062,
 '|pSphere1.vtx[279]': 0.379938006401062,
 '|pSphere1.vtx[280]': 0.5211509466171265,
 '|pSphere1.vtx[281]': 0.5211509466171265,
 '|pSphere1.vtx[282]': 0.5211509466171265,
 '|pSphere1.vtx[283]': 0.5211509466171265,
 '|pSphere1.vtx[284]': 0.5211509466171265,
 '|pSphere1.vtx[285]': 0.5211509466171265,
 '|pSphere1.vtx[286]': 0.5211509466171265,
 '|pSphere1.vtx[287]': 0.5211509466171265,
 '|pSphere1.vtx[288]': 0.5211509466171265,
 '|pSphere1.vtx[289]': 0.5211509466171265,
 '|pSphere1.vtx[290]': 0.5211509466171265,
 '|pSphere1.vtx[291]': 0.5211509466171265,
 '|pSphere1.vtx[292]': 0.5211509466171265,
 '|pSphere1.vtx[293]': 0.5211511850357056,
 '|pSphere1.vtx[294]': 0.5211511850357056,
 '|pSphere1.vtx[295]': 0.5211511850357056,
 '|pSphere1.vtx[296]': 0.5211511850357056,
 '|pSphere1.vtx[297]': 0.5211511850357056,
 '|pSphere1.vtx[298]': 0.5211511850357056,
 '|pSphere1.vtx[299]': 0.5211511850357056,
 '|pSphere1.vtx[300]': 0.6651146411895752,
 '|pSphere1.vtx[301]': 0.6651146411895752,
 '|pSphere1.vtx[302]': 0.6651146411895752,
 '|pSphere1.vtx[303]': 0.6651146411895752,
 '|pSphere1.vtx[304]': 0.6651148200035095,
 '|pSphere1.vtx[305]': 0.6651148200035095,
 '|pSphere1.vtx[306]': 0.6651148200035095,
 '|pSphere1.vtx[307]': 0.6651148200035095,
 '|pSphere1.vtx[308]': 0.6651148200035095,
 '|pSphere1.vtx[309]': 0.6651148200035095,
 '|pSphere1.vtx[310]': 0.6651148200035095,
 '|pSphere1.vtx[311]': 0.6651148200035095,
 '|pSphere1.vtx[312]': 0.6651148200035095,
 '|pSphere1.vtx[313]': 0.6651148200035095,
 '|pSphere1.vtx[314]': 0.6651150584220886,
 '|pSphere1.vtx[315]': 0.6651148200035095,
 '|pSphere1.vtx[316]': 0.6651150584220886,
 '|pSphere1.vtx[317]': 0.6651150584220886,
 '|pSphere1.vtx[318]': 0.6651150584220886,
 '|pSphere1.vtx[319]': 0.6651150584220886,
 '|pSphere1.vtx[320]': 0.7979508638381958,
 '|pSphere1.vtx[321]': 0.7979508638381958,
 '|pSphere1.vtx[322]': 0.7979508638381958,
 '|pSphere1.vtx[323]': 0.7979508638381958,
 '|pSphere1.vtx[324]': 0.7979508638381958,
 '|pSphere1.vtx[325]': 0.7979508638381958,
 '|pSphere1.vtx[326]': 0.7979508638381958,
 '|pSphere1.vtx[327]': 0.7979511022567749,
 '|pSphere1.vtx[328]': 0.7979511022567749,
 '|pSphere1.vtx[329]': 0.7979511022567749,
 '|pSphere1.vtx[330]': 0.7979511022567749,
 '|pSphere1.vtx[331]': 0.7979511022567749,
 '|pSphere1.vtx[332]': 0.7979511022567749,
 '|pSphere1.vtx[333]': 0.7979511022567749,
 '|pSphere1.vtx[334]': 0.7979511022567749,
 '|pSphere1.vtx[335]': 0.7979511022567749,
 '|pSphere1.vtx[336]': 0.7979511022567749,
 '|pSphere1.vtx[337]': 0.7979511022567749,
 '|pSphere1.vtx[338]': 0.7979512810707092,
 '|pSphere1.vtx[339]': 0.7979512810707092,
 '|pSphere1.vtx[340]': 0.9055349826812744,
 '|pSphere1.vtx[341]': 0.9055349826812744,
 '|pSphere1.vtx[342]': 0.9055349826812744,
 '|pSphere1.vtx[343]': 0.9055349826812744,
 '|pSphere1.vtx[344]': 0.9055349826812744,
 '|pSphere1.vtx[345]': 0.9055349826812744,
 '|pSphere1.vtx[346]': 0.9055349826812744,
 '|pSphere1.vtx[347]': 0.9055349826812744,
 '|pSphere1.vtx[348]': 0.9055349826812744,
 '|pSphere1.vtx[349]': 0.9055349826812744,
 '|pSphere1.vtx[350]': 0.9055349826812744,
 '|pSphere1.vtx[351]': 0.9055349826812744,
 '|pSphere1.vtx[352]': 0.9055349826812744,
 '|pSphere1.vtx[353]': 0.9055349826812744,
 '|pSphere1.vtx[354]': 0.9055349826812744,
 '|pSphere1.vtx[355]': 0.9055349826812744,
 '|pSphere1.vtx[356]': 0.9055349826812744,
 '|pSphere1.vtx[357]': 0.9055349826812744,
 '|pSphere1.vtx[358]': 0.9055349826812744,
 '|pSphere1.vtx[359]': 0.9055349826812744,
 '|pSphere1.vtx[360]': 0.9756492972373962,
 '|pSphere1.vtx[361]': 0.9756492972373962,
 '|pSphere1.vtx[362]': 0.9756492972373962,
 '|pSphere1.vtx[363]': 0.9756492972373962,
 '|pSphere1.vtx[364]': 0.9756492972373962,
 '|pSphere1.vtx[365]': 0.9756492972373962,
 '|pSphere1.vtx[366]': 0.9756492972373962,
 '|pSphere1.vtx[367]': 0.9756492972373962,
 '|pSphere1.vtx[368]': 0.9756492972373962,
 '|pSphere1.vtx[369]': 0.9756492972373962,
 '|pSphere1.vtx[370]': 0.9756492972373962,
 '|pSphere1.vtx[371]': 0.9756492972373962,
 '|pSphere1.vtx[372]': 0.9756492972373962,
 '|pSphere1.vtx[373]': 0.9756492972373962,
 '|pSphere1.vtx[374]': 0.9756492972373962,
 '|pSphere1.vtx[375]': 0.9756492972373962,
 '|pSphere1.vtx[376]': 0.9756492972373962,
 '|pSphere1.vtx[377]': 0.9756492972373962,
 '|pSphere1.vtx[378]': 0.9756492972373962,
 '|pSphere1.vtx[379]': 0.9756492972373962,
 '|pSphere1.vtx[381]': 1.0}

んで、これを基にvtxColor設定をしてあげればいいですね。

これかなー?

import maya.cmds as cmds
import maya.OpenMaya as om2

def getSoftSelectionWeights():
        
    sel = om2.MSelectionList()
    softSelection = om2.MRichSelection()
    om2.MGlobal.getRichSelection(softSelection)
    softSelection.getSelection(sel)

    dagPath = om2.MDagPath()
    component = om2.MObject()
    iter = om2.MItSelectionList(sel, om2.MFn.kMeshVertComponent)
    
    weights = {}

    while not iter.isDone():
        iter.getDagPath(dagPath,component)
        dagPath.pop()
        node = dagPath.fullPathName()
        fnComp = om2.MFnSingleIndexedComponent(component)
        for i in range(fnComp.elementCount()):
            weight = 1.0
            if fnComp.hasWeights():
                weight = fnComp.weight(i).influence()
            weights['{}.vtx[{}]'.format(node, fnComp.element(i))] = weight

        next(iter)

    return weights

weightVtx = getSoftSelectionWeights()
for vtx in list(weightVtx.keys()):	
    cmds.polyColorPerVertex(vtx,rgb =[1 * weightVtx[vtx],0,0])

では再び。

これで実行するとー
image.png

できて・・・るかな?
image.png

雑感

image.png

  • ちゃんとツール化するなら、この辺のオプションの挙動をちゃんと確認しなきゃなー
  • softSelection取れるとなると、なんかほかにも使えそうなきはしますねぇ

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?