use python script change joint weight isn't update in viewport



  • hi,everyone

    I write a python script for smooth joint weight,just a simple test.
    This script works correctly,i can see weight change real time,but joint effect isn't change,polygon isn't change with weight smooth(when i move polygon and 'ctrl z',it work).I try to add "c4d.EventAdd" and "Message(c4d.MSG_UPDATE)",but no effect.
    Could you give me some suggestions?this is my code.Thank you very much!


    import c4d
    from c4d import utils
    
    pcount = op.GetPointCount()
    WeightTag = op.GetFirstTag()
    
    def GetPointWeight():
        pweightandjoint = {}
        for pindex in xrange(0,pcount):
            pweight = WeightTag.GetWeight(0,pindex)
            pweightandjoint.setdefault(pindex,pweight)
    
        return pweightandjoint
    
    
    def GetNeighborPoint():
        n = utils.Neighbor()
        n.Init(op)
        np = dict()
        for index in xrange(0,pcount):
            polys = n.GetPointPolys(index)
            for p in polys:
                poly = op.GetPolygon(p)
                if index == poly.a:
                    np.setdefault(index,set()).add(poly.b)
                    np[index].add(poly.d)
                elif index == poly.b:
                    np.setdefault(index,set()).add(poly.a)
                    np[index].add(poly.c)
                elif index == poly.c:
                    np.setdefault(index,set()).add(poly.b)
                    np[index].add(poly.d if poly.c != poly.d else poly.a)
                elif index == poly.d:
                    np.setdefault(index,set()).add(poly.c if poly.c != poly.d else poly.b)
                    np[index].add(poly.a)
    
            np[index]=list(np[index])
    
        return np
    
    
    def main():
        nearpoint = GetNeighborPoint()
        pointweight = GetPointWeight()
        weight = 0
        for index in xrange(0,pcount):
            length = len(nearpoint[index])
            for pnt in xrange(0,length):
                weight += pointweight[nearpoint[index][pnt]]
    
            weight += pointweight[index]
            length += 1
            WeightTag.SetWeight(0,index,weight/length)
            weight = 0
    
        op.Message(c4d.MSG_UPDATE)
        c4d.EventAdd()
    
    
    if __name__=='__main__':
        main()
    
    -------------------------------------------


  • 0_1537327488644_QQ截图20180919112348.png1_1537327488644_QQ截图20180919112424.png



  • CAWeightTag.WeightDirty() use this☺



  • @chuanzhen wow!thank you very much!可以给我解答一下C4D里面的带dirty这类函数是什么意思么?一直不太明白(Could you explain to me the meaning of this function?)



  • dirty 一般是记录操作的更改,例如你想检测发生的变化后,从而执行某些操作,就是检测dirty,这是我的理解,更准确的回答可以让maxon SDK团队人回答你,或者观看文档
    (Answer translation:dirty is usually a change in the record operation. For example, if you want to detect the change that has occurred, and then perform some operations, it is to detect dirty. This is my understanding. A more accurate answer can let the maxon SDK team answer you or watch the document.)


  • Global Moderator

    Hi,

    not much to contribute here, yet.

    But I have a few requests:
    I hope you don't mind, I restored the first two posts, so others will have a chance to follow the discussion and can make use of the answer in future. I'd say, please, do only delete posts, if these are really redundant, otherwise rather leave it.

    To be honest (and please bear my ignorance) I'm not completely sure about the language being used in your last posts, I hope I'm not insulting anyone, suspecting it to be Chinese. While we are fine with people discussing in their native language, we'd like to kindly ask you to provide us with some sort of translation in such cases. In the end this forum is all about sharing information with an international community.

    Please also consider using the tagging system to categorize your threads (as I did here now), it will help us to keep this forum tidy.

    A more accurate answer can let the maxon SDK team answer you or watch the document.

    Can you maybe rephrase the question or provide some more details, we are not sure, on what to provide more details or a more accurate answer.

    Cheers,
    Andreas



  • @a_block i'm sorry but i didn't want delete posts,i just write some error and hope to rewrite(i didn't see 'edit' at that time).
    I will use english or give annotation next time ,Thank you for this wonderful community.


  • Global Moderator

    @mike No need to apologize, we are all new here. No worries. Especially during the starting phase of this new forum, we try to point even at small issues, hoping it will lead to a cleaner forum in future.