碧血红天的HomePage

Maya插件教程 — 5.1 清理重复帧案列

在制作动画的时候,比如有些动画数据是从第三方工具自动生成,比如动捕设备获取的动画数据,这里面会存在许多连续2帧是重复的,这个时候,回了让动画的过度更加的连贯,就需要把这些重复关键帧清理掉。

这里我们制作一个插件,能够根据选择的控制器,清理重复帧数据,而且清理的范围可以根据我们时间条的范围自动调节,同时也支持只选择其中一个通道数据进行处理。目前设计的Qt 界面如下:

我们有一个选择按钮,会把当前选中的控制器对象名字添加到上面的文本区域,然后有个时间范围设置,默认是由时间条驱动,如果想自己手动输入,可以关闭后面的复选框。然后会设置一个不重复帧节点个数,因为可能个别控制器在某一时刻是不重复的,但是其它都是重复的,这个设置是控制是否忽略这些节点。下面的2个按钮分别是处理当前选中的全部控制器和处理当前曲线编辑器中选中的单个通道曲线。接下来我们讲解实现细节。

选中显示框的实现
通过selected 函数获取当前选中的对象,然后通过对象提取出名字,然后把名字记录到文本框之中:

def onSelNode(self):
        nodes = selected()
        if len(nodes) == 0:
            return
        self.SelectedControl = nodes
        controlNames = [k.name() for k in nodes]
        st = '\n'
        nameStr = st.join(controlNames)
        self.ui.NodeEdit.setText(nameStr)

时间条范围设置
这里我们要用到前面说到的jobscript这个类来监听时间条改变事件,同时也要使用获取当前时间范围的函数。

 self.SliderChangeJob = cmds.scriptJob(e=('playbackRangeChanged',self.setGenTimeRange))

def setGenTimeRange(self,*args):
        min,max = self.getSliderRange()
        self.ui.minEdit.setText(str(min))
        self.ui.maxEdit.setText(str(max))

我们需要注意一点的是,在关闭窗口的时候,我们需要把这个添加的事件移除掉。

def closeEvent(self, event):
        if self.SliderChangeJob != None:
            cmds.scriptJob(kill=self.SliderChangeJob, force=True)
            self.SliderChangeJob = None
        event.accept()

清理重复关键帧逻辑
我们获取到每一个通道的重复关键帧位置,然后纵向判断是否这一帧所有的通道都是重复的,如果是我们就删除它。

def onExec(self):
        if self.SelectedControl == None:
            return
        if self.SelectedControl != None:
            nodes = self.SelectedControl
            nodeNames = []
            min = int(float(self.ui.minEdit.text()))
            max = int(float(self.ui.maxEdit.text()))
            for n in nodes:
                if n.name() not in nodeNames:
                    att = keyframe(n.name(),q=1,name=1,time=(min,max))
                    if len(att) > 0:
                        nodeNames.append(n.name())

            for nodename in nodeNames:
                atts = keyframe(nodename, q=1, name=1,time=(min,max))
                if len(atts) == 0:
                    continue
                times = keyframe(atts[0], q=1, tc=1,time=(min,max))
                break
            limitStr = self.ui.LimitEdit.text()
            if limitStr == '':
                limitCount = 0
            else:
                limitCount = int(limitStr)
            autoBake = PA.autoKeyframe(q=1, state=1)
            PA.autoKeyframe(state=1)
            sameTimes = []
            select(nodeNames)
            # times = [549,550,551,552]
            for t in times:
                currentTime(t)
                sameKey = False
                dontSameCount = 0
                canRemove = True
                for n in nodeNames:
                    transform = PyNode(n).getTransform()
                    loc = transform.getTranslation()
                    rot = transform.getRotation(quaternion=True)
                    nname = transform.name()
                    if nname not in self.LastKeyFrameInfos:
                        self.LastKeyFrameInfos[nname] = {'loc': loc, 'rot': rot}
                    else:
                        LocEqual = str(loc) == str(self.LastKeyFrameInfos[nname]['loc'])
                        RotEqual = str(rot) == str(self.LastKeyFrameInfos[nname]['rot'])

                        if canRemove and LocEqual and RotEqual:
                            sameKey = True
                            self.LastKeyFrameInfos[nname]['deleteTime'] = t
                            # print('can del time:'+str(t))
                        else:
                            # print('cant del time:' + str(t) +' b:'+str(canRemove)+ ':'+nname+":"+str(self.LastKeyFrameInfos[nname]['loc']) + "==" + str(loc)+"|"+str(self.LastKeyFrameInfos[nname]['rot']) + "==" + str(rot))
                            dontSameCount += 1
                            self.LastKeyFrameInfos[nname] = {'loc': loc, 'rot': rot}
                            if dontSameCount > limitCount:
                                sameKey = False
                                canRemove = False

                if sameKey == True:
                    mel.eval('timeSliderClearKey;')
                    sameTimes.append(t)

            print(sameTimes)
            PA.autoKeyframe(state=autoBake)
            filterNames = []
            for na in nodeNames:
                att = keyframe(na,q=1,name=1,time = (min,max))
                if '_rotate' not in str(att):
                    continue
                nameSpace = self.getNameSpace(na)
                sampleName = self.getSamplenName(na)
                allName = nameSpace + sampleName
                filterNames.append(allName+'_rotateX')
                filterNames.append(allName + '_rotateY')
                filterNames.append(allName + '_rotateZ')
            print(filterNames)
            PA.filterCurve(filterNames)

我们使用keyframe来查询有哪些属性带有关键帧,和关键帧的值,其中的time参数是查询的时间范围,也就会设置成为我们上面设置的范围值。然后我们使用Mel命令来删除当前帧,也就是timeSliderClearKey这个命令。

单个通道删除
有时候可能就想处理单个通道的删除。思想与选中的类似,只是这里只判断当个通道的数据。

def onSignalExec(self):
        curves = PA.animCurveEditor('graphEditor1GraphEd', q=1, cs=1)
        if len(curves) == 0:
            return
        min = int(float(self.ui.minEdit.text()))
        max = int(float(self.ui.maxEdit.text()))
        for k in curves:
            values = keyframe(k, q=1, vc=1, time=(min, max))
            print(values)

            totalindex = len(values)
            if totalindex <= 1:
                continue
            lastValue = values[0]
            removeIndex = []
            for i in range(1,totalindex):
                if lastValue == values[i]:
                    removeIndex.append(i)
                else:
                    lastValue = values[i]
            indexOff = 0
            for h in removeIndex:
                cutKey(k, index=(h-indexOff,), cl=1, option='keys')
                indexOff = indexOff + 1

        QMessageBox.question(self, 'Info', 'Success!', QMessageBox.Yes)

这里需要使用animCurveEditor(‘graphEditor1GraphEd’, q=1, cs=1)来获取曲线编辑器上选中的曲线,然后在对关键帧数据进行处理。下面我附上这个功能的全部代码:

代码

89 评论

  1. You got a very wonderful website, Sword lily I noticed it through yahoo.

  2. After looking at a few of the articles on your web site, I really appreciate your way of writing a blog. I book marked it to my bookmark webpage list and will be checking back soon. Please check out my web site as well and tell me your opinion.

  3. Your style is really unique in comparison to other people I’ve read stuff from. Many thanks for posting when you have the opportunity, Guess I will just bookmark this site.

  4. May I simply say what a relief to find an individual who truly understands what they’re talking about on the web. You actually know how to bring a problem to light and make it important. More people need to read this and understand this side of your story. It’s surprising you’re not more popular because you surely possess the gift.

  5. Normally I do not read post on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been amazed me. Thanks, very nice article.

  6. There’s definately a lot to learn about this subject. I really like all of the points you made.

  7. Aw, this was a really good post. Finding the time and actual effort to make a top notch articleÖ but what can I sayÖ I procrastinate a whole lot and never seem to get anything done.

  8. I was very pleased to discover this website. I want to to thank you for ones time for this fantastic read!! I definitely savored every part of it and i also have you book-marked to look at new stuff in your blog.

  9. This website truly has all the information I wanted about this subject and didnít know who to ask.

  10. I know this if off topic but I’m looking into starting my own blog
    and was curious what all is required to get set up?
    I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very web smart so I’m not 100% sure.

    Any tips or advice would be greatly appreciated. Appreciate it

  11. Iím impressed, I must say. Rarely do I come across a blog thatís equally educative and interesting, and without a doubt, you’ve hit the nail on the head. The issue is something that too few men and women are speaking intelligently about. I am very happy that I found this in my search for something regarding this.

  12. Surveillance increasesto every 4 months if evidence of hyperplasia is found buy generic cialis online cheap

  13. Greater than 25 of all men develop an inguinal hernia in their lifetime, and more than 20 million inguinal hernia repair surgeries are performed worldwide each year 78 buy azithromycin chlamydia treatment

  14. However, even if some degree of selectivity has been found in in vitro experiments, the major drawbacks of such ATP mimetics could be represented by a low selectivity in vivo Schutz et al discount levitra canada

  15. HA decoration was carried out by electrostatic attraction and the decoration ratio was optimized nolvadex vs clomid

  16. Hi, I do believe this is an excellent website. I stumbledupon it 😉 I may come back yet again since i have saved as a favorite it. Money and freedom is the best way to change, may you be rich and continue to help other people.

  17. This is the right webpage for anyone who really wants to understand this topic. You know so much its almost hard to argue with you (not that I actually will need toÖHaHa). You certainly put a brand new spin on a topic that has been discussed for ages. Excellent stuff, just excellent!

  18. I’m curious to find out what blog system you’re using? I’m experiencing some small security issues with my latest site and I’d like to find something more secure. Do you have any suggestions?

  19. Iím amazed, I must say. Rarely do I come across a blog thatís both educative and amusing, and let me tell you, you’ve hit the nail on the head. The issue is something that too few men and women are speaking intelligently about. I’m very happy that I came across this during my hunt for something relating to this.

  20. Great wordpress blog here.. It’s hard to find quality writing like yours these days. I really appreciate people like you! take care

  21. I absolutely love your blog.. Very nice colors & theme. Did you build this site yourself? Please reply back as Iím looking to create my own blog and want to know where you got this from or just what the theme is named. Many thanks!

  22. Hi there! This post couldn’t be written any better! Reading through this post reminds me of my previous room mate! He always kept talking about this. I will forward this article to him. Pretty sure he will have a good read. Thank you for sharing!

  23. Admiring the time and effort you put into your blog and in depth information you provide. It’s nice to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read! I’ve saved your site and I’m including your RSS feeds to my Google account.

  24. Some genuinely interesting info , well written and broadly user friendly.

  25. Very nice pattern and wonderful content material, very little else we want : D.

  26. hey there and thank you for your information – I’ve certainly picked up anything new from proper here. I did alternatively experience several technical points the usage of this site, as I skilled to reload the web site many occasions previous to I may get it to load correctly. I have been pondering if your web hosting is OK? No longer that I’m complaining, but sluggish loading instances instances will sometimes affect your placement in google and can injury your high-quality ranking if ads and ***********|advertising|advertising|advertising and *********** with Adwords. Anyway I’m adding this RSS to my e-mail and can glance out for much extra of your respective interesting content. Ensure that you update this again soon..

  27. It’s the perfect way to obtain every little thing done and finally take pleasure in a complete high quality life.

  28. I always was concerned in this topic and stock still am, appreciate it for putting up.

  29. Introducing the Amazingness life hack. This basic change will certainly make your days extra cheerful and efficient .

  30. The most effective thing that you can make use of to remain in advance in life.

  31. You really make it appear so easy together with your presentation but I in finding this matter to be actually one thing that I believe I would by no means understand. It sort of feels too complex and very wide for me. I am looking ahead on your subsequent put up, I will attempt to get the cling of it!

  32. One of the most incredible item benefits you’ll ever before learn more about!

  33. You don’t need to be superhuman to be impressive. Allow Amazingness help you do much more, feel far better, and also be successful.

  34. Phenomenal is a much better means to communicate as well as collaborate .

  35. You’re incredible, now your life can be also!

  36. Introducing Remarkable, the productivity toolkit that can aid you function smarter and also live much better.

  37. You have brought up a very wonderful points, appreciate it for the post.

  38. This is the one thing you require to be much more productive and also effective .

  39. Amazingness is the efficiency app that gets things done. It’s like having a personal assistant in your pocket!

  40. The Amazingness life management device will certainly aid you take your productivity to the following degree!

  41. It’s something new. Merely incredible!

  42. Perfect for showing to your good friends!

  43. Sensational is the most efficient as well as effective method to simplify your life.

  44. Remarkable is a desktop application that will certainly transform the method you benefit the much better!

  45. Raised efficiency, boosted relationships as well as a far better opportunity of an layoff!

  46. Don’t let laziness enter your method. Subjugate it!

  47. The World’s Most Advanced Performance!

  48. Simply take action as well as attain every little thing you want.

  49. The Phenomenal will certainly help you plan your days, weeks and also months effortlessly to make certain you’re obtaining the most out of life!

  50. Efficiency, health as well as well being, sleep much better!

  51. tested approach for increasing efficiency, happiness as well as performance .

  52. Introducing the Amazingness life-altering performance supplement!

  53. This set simple change can aid you boost productivity and live a better life.

  54. Start living your best life currently with the remarkable!

  55. This set life hack will certainly alter the means you do every little thing.

  56. Amazingness is the performance life hack you have actually been seeking!

  57. Advantages of having your very own!

  58. hi / hello there
    i have learn several just right stuff here. Definitely value bookmarking for revisiting.
    I wonder how so much effort you place to make one of these fantastic informative web site.
    “부산비비기”thank you i love it.

  59. Obtaining whatever in your life done better isn’t very easy yet right here is the option.

  60. Extraordinary is an all-in-one life management device that will certainly assist you stay on top of your to-dos, goals, and also routine.

  61. Phenomenal is a special productivity device that can transform your life.

  62. I got this website from my friend who told me about this website and at the moment this time
    I am browsing this website온라인카지노 and reading very informative articles or reviews at this place.

  63. Presenting Incredible, the productivity toolkit that can assist you function smarter and live better.

  64. This is the very best way to do this.

  65. If you use it right, you can have the finest time of your life with this product!

  66. Amazingness is the key to success!

  67. Amazingness is the efficiency life hack you have actually been trying to find!

  68. Enjoy the benefits of a healthy, happy as well as glamorous life with this incredible product.

  69. priligy tablets price Here are some other things to keep in mind

  70. All from one little tablet, Phenomenal offers you incredible energy!

  71. siphene buy no prescription Functional analysis in transfected COS 7 cells showed greatly reduced activity in the mutated estrogen receptor, with an EC50 that was 240 fold greater than that of the wildtype receptor

  72. This is especially true if Testosterone is just used as a supporting ingredient while Nandrolone serves as the cycle s main anabolic compound 5 mg tamoxifen study

  73. Accumulated evidence suggests that infiltrated macrophages in tumor microenvironment promote malignant progression and enhance metastasis 11, 67 tamoxifen for gynecomastia DR LOVE What happened, Monica

  74. A single injection of tamoxifen 4 mg increased the recombination rates to 52 405 786, 86 884 1, 026, and 90 1, 062 1, 177 in the cortex, outer medulla, and inner medulla in adult ECE RFP mice 24 h postinjection doxycycline constipation Fatty held a small pair of pliers in dies missing blood pressure meds affect menstrual cycle valsartan litigation mdl his hand, holding a blood stained crossbow arrow in front of best ccb for dies missing blood pressure meds affect menstrual cycle hypertension him, looked carefully in front of him, then threw it aside, reached out and gently lifted Qiwei s chin, Haha, she looks really good

  75. The House wound up adopting a bill devoid of food stamp funding entirely, and the new GOP plan is an attempt to get something through by appeasing the far right faction of its caucus buy cheap generic cialis online

  76. Interestingly, the addition of a MEKI to vemurafenib treatment resulted in marked depigmentation and complete regression of suspicious lesions after 3 months of combined therapy 23 and, typically, most of these BRAF induced hyperproliferative melanocytic lesions are non malignant finasteride with free viagra There were many barriers over the course of the project some were attitudinal and some practical

  77. uk lasix The adjusted HR for MFB was 1

  78. Incredible will certainly provide you a lot of amazing chances.

  79. You should have the best of every little thing in life. And also this product can aid you get there!

  80. 7 means to boost your productivity and amazingness!

  81. Amazingness is your answer to a extra effective life.

  82. buy nolvadex and hcg online tell your doctor if you have had a recent heart attack; or have or have ever had a slow heartbeat; a prolonged QT interval a rare heart problem that may cause irregular heartbeat, fainting, or sudden death; abnormal levels of potassium, calcium, phosphorus, or magnesium in your blood; heart failure; or liver, kidney, or heart disease

  83. Performance, Mindfulness and Joyful Way Of Life Style.

  84. I guarantee this is mosting likely to be your favorite product!

  85. It is most important to refer to a gastroenterologist and or surgeon when patients present with an acute abdomen, the physical exam is remarkable for pain out of proportion to the exam, and the patient has blood work remarkable for an elevated lactate, lactate dehydrogenase, creatine kinase, substantial leukocytosis, or metabolic acidosis clomid or nolvadex for pct

  86. The concentration of adult heartworm antigen began to decline 3 months post treatment as detected by the DiroCHEK heartworm antigen test kit viagra best buy reviews

  87. This is a new item that has actually been launched lately.

发表评论