碧血红天的HomePage

Maya插件教程 — 5.2 批量写关键帧

我们平常在单帧操作的频率很大。但是有时候,我们想把自己的关键帧数据导入到编辑器中,这时候对关键帧的批量写入就是非常必要的。否则整个过程就会因为大量的导入变的很慢。

比如我们存在如下一个Json格式的文件,里面描述了一根骨骼的关键帧数据:

#D:/keyframe.json
{
    "FPS":24,
    "KeyTime":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],
    "Name":"joint1",
    "Channels":{
        "translateX":[0,0,0,1,20,1,2,1,2,6,7,2,3,5,6],
        "translateY":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
        "translateZ":[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5],
        "rotateX":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
        "rolateY":[10,20,30,40,50,60,70,80,90,0,10,20,30,40,50],
        "rotateZ":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    }
}

现在我们首先解析这个文件,拿到帧率,关键帧和通道的关键帧值。在Python中直接引入json这个模块来解析Json数据。

import json

with open("D:/keyframe.json") as json_file:
    data = json.load(json_file)
    print(data)

接下来我们需要使用费Pymel库来批量操作关键帧:

import maya.api.OpenMaya as om
import maya.api.OpenMayaAnim as oma

现在我们写一个批量写入关键帧的函数:

def getNode(nodeName):
    selectionList = om.MSelectionList()
    selectionList.add(nodeName)
    dependNode = selectionList.getDependNode(0)
    return dependNode

def AddKeysForNode(channels,nodepath,frames,fps):
    MfNode = getNode(nodepath)
    node = PyNode(nodepath)
    node.setRotationOrder(1,True)
    unitMap = {'60': 11, '30': 8, '24': 6}
    times = om.MTimeArray()
    for frame in frames:
        times.append(om.MTime(frame,unit=unitMap[str(fps)]))
    for k in channels:
        frameValues = om.MDoubleArray(channels[k])
        plug = node.findPlug(node.attribute(k), True)
        animCurveNode = oma.MFnAnimCurve()
        animCurveNode.create(plug, 1)
        animCurveNode.addKeys(times,frameValues)

我们把上面解析出Json数据调用次即可:

AddKeyForNode(data['Channels'],data['Name'],data[KeyTime],data['FPS'])

134 评论

  1. Greetings! Very useful advice within this article! It is the little changes that will make the greatest changes. Thanks a lot for sharing!

  2. I blog often and I truly appreciate your information. This great article has really peaked my interest. I am going to bookmark your site and keep checking for new information about once a week. I opted in for your RSS feed as well.

  3. Aw, this was a really nice post. Taking the time and actual effort to create a very good articleÖ but what can I sayÖ I put things off a whole lot and never manage to get anything done.

  4. Very nice write-up. I definitely love this website. Keep it up!

  5. Veery nice article, just what I wanted to find.

    my homepage … agen slot online

  6. hi opp ggeis 2022 ert go fi

  7. You’re so interesting! I do not suppose I’ve truly read through something like this before. So great to find another person with some original thoughts on this issue. Really.. thanks for starting this up. This web site is something that’s needed on the internet, someone with some originality!

  8. Great post. I am facing a couple of these problems.

  9. Hi there friends, its impressive piece of writing about teachingand fully
    defined, keep it up all the time.

  10. You’re so cool! I don’t suppose I’ve read a single thing like that before. So nice to discover somebody with genuine thoughts on this subject. Seriously.. thank you for starting this up. This website is something that is required on the web, someone with a little originality!

  11. Hi! I just would like to offer you a big thumbs up for your excellent info you have right here on this post. I’ll be returning to your site for more soon.

  12. I wanted to thank you for this excellent read!! I certainly loved every little bit of it. I have got you book-marked to check out new things you postÖ

  13. May I simply say what a comfort to find somebody that truly understands what they’re discussing on the internet. You actually understand how to bring an issue to light and make it important. More people should look at this and understand this side of your story. It’s surprising you aren’t more popular because you definitely have the gift.

  14. May I simply say what a comfort to uncover a person that truly knows what they’re talking about on the internet. You actually understand how to bring a problem to light and make it important. A lot more people ought to look at this and understand this side of the story. I was surprised you’re not more popular given that you surely possess the gift.

  15. Good day! I just wish to give you a huge thumbs up for the great information you have right here on this post. I’ll be coming back to your site for more soon.

  16. This is the right blog for anyone who hopes to find out about this topic. You understand a whole lot its almost tough to argue with you (not that I actually will need toÖHaHa). You definitely put a new spin on a subject which has been written about for ages. Wonderful stuff, just wonderful!

  17. Very nice post. I definitely appreciate this website. Continue the good work!

  18. Hi, I do believe this is a great site. I stumbledupon it 😉 I’m going to return once again since i have bookmarked it. Money and freedom is the best way to change, may you be rich and continue to guide other people.

  19. Very interesting info !Perfect just what I was searching for! “The whole point of getting things done is knowing what to leave undone.” by Lady Reading.

  20. Good info. Lucky me I discovered your website by accident (stumbleupon). I’ve bookmarked it for later!

  21. priligy pill 5 mm b, 200 Ојm d, e, 100 Ојm f, g, 50 Ојm i, k and 20 Ојm h, l, m, n, j and insets in j

  22. Good web site you have got here.. Itís difficult to find high-quality writing like yours nowadays. I truly appreciate people like you! Take care!!

  23. Everything is very open with a really clear explanation of the challenges. It was really informative. Your website is useful. Thank you for sharing!

  24. I am glad to be one of many visitors on this outstanding internet site (:, regards for posting.

  25. Appreciate it for this marvellous post, I am glad I detected this internet site on yahoo.

  26. Enjoyed looking at this, very good stuff, appreciate it. “What the United States does best is to understand itself. What it does worst is understand others.” by Carlos Fuentes.

  27. I am now not certain where you are getting your info, but good topic. I needs to spend some time finding out much more or understanding more. Thank you for wonderful information I was in search of this information for my mission.

  28. Very interesting info !Perfect just what I was looking for!

  29. Magnificent web site. Lots of helpful info here. I am sending it to several buddies ans additionally sharing in delicious. And naturally, thank you in your effort!

  30. The normality of the distribution of the variables was evaluated using the Shapiro Wilk test buy generic cialis online safely The indictment was brought by the Jinan prosecutorГў s office, Xinhua said, signaling the eastern Chinese city will host the trial

  31. I really like your writing style, wonderful information, thanks for posting :D. “The superfluous is very necessary.” by Francois Marie Arouet Voltaire.

  32. Sweet blog! I found it while surfing around on Yahoo News. Do you have any tips on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Cheers

  33. A lot of whatever you point out is astonishingly legitimate and that makes me wonder why I hadn’t looked at this in this light previously. This piece really did switch the light on for me personally as far as this particular subject matter goes. Nonetheless there is actually just one point I am not necessarily too comfortable with and whilst I attempt to reconcile that with the central idea of your issue, allow me observe exactly what all the rest of your subscribers have to say.Nicely done.

  34. Woah! I’m really digging the template/theme of this
    blog. It’s simple, yet effective. A lot of times it’s
    hard to get that “perfect balance” between superb usability and visual appeal.
    I must say that you’ve done a excellent job with this.

    Also, the blog loads super fast for me on Chrome.

    Outstanding Blog!

  35. Productivity, Mindfulness and also Joyful Way Of Life Layout.

  36. The World’s Most Advanced Productivity!

  37. Your life will never coincide after this!

  38. Just how? Amazingness will alter just how you come close to life and also make everyday an experience.

  39. Thanks for this post, I am a big fan of this web site would like to continue updated.

  40. Get one year free plus approximately 40 off your very first registration!

  41. When you can’t discover a treatment to your medical ailment, say farewell to difficult days and nights.

  42. Once as well as for all with this remarkable item, all of your issues will be solved!

  43. The best part of living a amazing life is that you’re extra focused as well as calm .

  44. Incredible is an all-in-one time management toolkit that can assist you obtain even more carried out in less time.

  45. Amazingness is a way of living that shoots one’s capacity to do wonders.

  46. Just how? Amazingness can aid you live an remarkable life by offering you with the tools to be much more productive and also obtain more performed in much less time.

  47. Discover just how to obtain even more out of life with this one basic change!

  48. Breathing in and out several times a day enhances your life exceptionally.

  49. Psychological quality as well as focus to make sure that you can get whatever done better than ever!

  50. You’re impressive, currently your life can be as well!

  51. Introducing Remarkable, the productivity toolkit that can help you function smarter as well as live much better.

  52. This is something that every home and also business requirements.

  53. Remarkable is a unique efficiency tool that will certainly assist you obtain even more carried out in much less time.

  54. Get the outcomes you desire with much less effort, incredibly simple.

  55. It’s time to experience an phenomenal degree of high quality and efficiency in a way you never ever assumed possible.

  56. Get the results you want with much less initiative, super simple.

  57. Amazingness is a productivity booster that will certainly transform your life for the better!

  58. One of the most functional word in the dictionary!

  59. The Amazingness lets you obtain even more performed in much less time, without all the anxiety.

  60. Introducing the Amazingness life-altering efficiency supplement!

  61. Subscribe now and also get going on your trip today!

  62. Amazing is a exclusive formula for assisting you complete extra and also really feel much better about your life.

  63. I was suggested this website by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my trouble. You’re incredible! Thanks!

  64. Amazingness is the productivity life hack you’ve been seeking!

  65. This fantastic life changing service is what you have actually been awaiting!

  66. The most remarkable item ever before created!

  67. tried and tested method for boosting performance, happiness and also efficiency .

  68. You will be surprised just how effortlessly you can get your work done when using this.

  69. For those that are experienced in producing fantastic material by themselves!

  70. I will make your life a lot easier, you won’t know just how to thank me.

  71. You will certainly never ever have to worry about obtaining anything done again.

  72. You’re incredible, currently your life can be too!

  73. That’s right, it’s a software that permits you to be a lot more effective.

  74. Make every little thing better with the Amazingness program.

  75. web this is very good, I like, material that is too amazing and, unique, continue to work if you believe eat certainly can, me comet with hope able help you ask for permission okay totosoju

  76. This is a new product that has actually been launched just recently.

  77. For those that are experienced in developing wonderful web content on their own!

  78. viagra online 150mg buy online viagra viagra coupon online

  79. viagra price india viagra uk pharmacy buy discount viagra online

  80. cialis canadian pharmacy buy cialis using paypal viagra cialis from germany

  81. generic tadalafil in us cialis 200 mg price sildenafil citrate & tadalafil tablets

  82. cialis vs viagra reddit cialis discussion forum cialis daily vs regular cialis

  83. web this is too good, I like, material that is too fantastic and, unique, continue to work unless you sure eat certainly can, me comet with hope able support you ask for permission okay totosoju

  84. web this is very good, I like, material that is very fantastic and, unique, continue to work except you sure eat certainly can, me comet with hope can support you ask for permission okay totosoju

  85. mexican pharmacy rohypnol lloyds pharmacy nolvadex cvs pharmacy florida oxycodone

  86. Produced hectic people that wish to be much more successful as well as productive .

  87. web this is too good, I like, material that is absolutely awesome and, unique, continue to work if you believe eat certainly can, me comet together hope can support you ask for permission okay totopanen

  88. Offering you the remarkable benefits of Incredible!

  89. Amazingness all-in-one, single resource option.

  90. Incredible is an all-in-one life management device that will make your life simpler than ever.

  91. finasteride online canadian pharmacy canadian pharmacy voltaren gel generic propecia pharmacy

  92. Sensational is the one stop buy whatever performance!

  93. Brain fitness instructor that operates in 10 minutes a day.

  94. drugs from canada legal cheapest pharmacy for provigil nolvadex online pharmacy

  95. pharmacy store canadian pharmacy uk delivery nizoral shampoo cvs pharmacy

  96. rx express pharmacy hurley ms Tadapox indomethacin pharmacy

  97. The one-of-a-kind functions of this item makes it easy to use, much faster, and much more efficient.

  98. Hi! Would you mind if I share your blog with my myspace
    group? There’s a lot of people that I think would really enjoy your content.
    Please let me know. Cheers

    my web blog: Knt 777

  99. web site this is too good, I like, material that is very fantastic and, unique, continue to work unless you sure eat certainly can, me comet together hope can support you ask for permission okay totopanen

  100. When I initially commented I clicked the “Notify me when new comments are added” checkbox and now each time
    a comment is added I get three emails with the same comment.
    Is there any way you can remove me from that
    service? Thank you!

  101. When using this, you will be shocked how easily you can obtain your job done.

  102. 27 Parenteral administration of balanced non alkalizing fluids with calcium gluconate often speeds recovery viagra trial pack Cooper LB, Mentz RJ, Gallup D, Lala A, DeVore AD, Vader JM, AbouEzzeddine OF, Bart BA, Anstrom KJ, Hernandez AF, Felker GM

  103. online canadian pharmacy viagra viagra brand name in india where can i purchase viagra

  104. cheapest generic viagra prices viagra no prescription viagra 50mg online india

  105. sildenafil 50 mg online uk generic viagra 50 can i buy viagra online in usa

  106. Of these early alterations in coagulation in response to chemotherapy, only the prolongation of PT is an independent predictor for chemotherapy induced thrombosis buy zithromax for chlamydia for humans

  107. what is cialis tadalafil 20 mg used for cialis france can you take cialis in the morning and viagra at night

  108. viagra 25 mg buy online viagra generic viagra generic viagra

  109. price of viagra 100mg in canada sildenafil 100mg paypal viagra canada no prescription

  110. tadalista vs cialis J Natl Compr Canc Netw 7 535 541, 2009

  111. cheap viagra india online viagra in india real female viagra

  112. buying cialis without a prescription peptide liquid tadalafil vikalis 20mg tadalafil

  113. cialis 2.5 mg cialis cheaper order online cialis with dapoxetine

  114. It is administered at 800mg orally every day buy lasix without prescription

  115. marley drugs tadalafil cheapest tadalafil tablets viagra cialis on line parmacy

  116. The Tg hsp70l hFKRP L276I IRES eGFP zebrafish were pulsed for 1 hour with heat shock at 38 C at 1 dpf, and analyzed at 2, 3, 4, and 5 dpf priligy buy

  117. cialis purchase tadalafil sales apomorphine and tadalafil

  118. tadalafil citrate dosage bodybuilding ordering cialis in canada cialis pills

  119. tried and tested method for increasing joy, efficiency and also efficiency .

  120. the cost of tadalafil in belize cheap genieric cialis voucher cialis index

  121. sildenafil 5 mg viagraonlineusa viagra 50mg price in india online

  122. what does cialis look like buy tadalafil online no prescription tadalafil generic 20 mg ebay

  123. viagra online rx pharmacy cheapest sildenafil australia sildenafil online pharmacy india

  124. See your performance rise and also simplify even the most complicated job.

  125. A couple of simple ideas and tricks will certainly make you fantastic!

  126. how to save money on cialis cialis black reviews how long before sex should i take cialis

  127. Sensational is the perfect productivity device that can assist you get even more done in much less time!

发表评论