2017-01-04 8 views
0

私はBlenderには新しくPythonには新しく、レイヤー1には "BallB"という名前のボールがあります。Pythonを使ってBlender 2.78aでキーフレームを作るには?

今、私は、BlenderでPythonを使って簡単なバブリングアニメーションを作成したいのですが、キーフレームを作ることができません。これは私が多くを試してみましたが、多くのエラーを得た...私が見つけたすべてのスニペットが動作しませんでしたし、私のスクリプトはオールウェイズ

RuntimeError: Operator bpy.ops.anim.change ... expected an timeline/animation area to be activated

と、より多くのようなPythonの-エラーでクラッシュしたレイヤ2

に起こるはず。

私には誰かのヒントがありますか?

私はそう、私は;-)

マイコードを私に進み、すべてのヒントのために非常に感謝していブレンダーでスクリプトアニメーションを学ぶしたいと思います:

import bpy, math, random 

d   = 4 
anz   = 100 
frameAnz = 10 

scene = bpy.context.scene 
scene.frame_start = 1 
scene.frame_end = 100 


for anz in range (0,anz): 

    ball = bpy.data.objects["ballB"] 

    tball = ball.copy() 
    xpos = -1 * (d/2) + random.randint(0,(d-1)) 
    xpos += random.random() 
    ypos = -1 * (d/2) + random.randint(0,(d-1)) 
    ypos += random.random() 
    zpos = random.randint(0,(d-1)) 
    zpos += random.random() 



    bn = str(anz).zfill(5) 
    bn = "zz_Ball-" + bn 

    tball.name = bn 
    tball.location = (xpos, ypos, zpos) 
    sz = random.uniform(0.015,0.09) 


    tball.scale = (sz,sz,sz) 

    #tball.nodes["Emission"].inputs[1].default_value = 200 
    tball.select = False 
    scene.objects.link(tball) 
    #print ("done!") 

obj = bpy.context 

for actFrame in range(1,frameAnz): 
    # scene = bpy.context.scene 
# scene.keyframe_insert(data_path="gravity", frame = actFrame) 


    for ob in scene.objects: 

     ploc = ob.location 
     #print (ploc) 
     xpos = ploc[0] 
     ypos = ploc[1] 
     zpos = ploc[2] 

     zpos = zpos + random.random() 
     ob.location = (xpos, ypos, zpos) 
     #ypos = ball.location[1] 
     #zpos = ball.location]2] 

     #zpos = zpos - random.random() 

     #ball.location = (xpoy, ypos, zpos) 
     #obj.keyframe_insert_menu('Location') 
     #bpy.context.scene.frame_set(0) 
    #scene = bpy.context.scene 
    #scene.keyframe_insert(data_path="Location", frame=actFrame) 

は、実際にはそうなります

enter image description here

答えて

0

obj.keyframe_insert()を使用したい場合は、indexパラメータを使用して、1つの位置の値だけをキーフレームすることができます。

最初のオブジェクトをコピーするということは、新しいオブジェクトが同じアニメーションデータを使用して、それらが一致して動いていることを意味します。新しいオブジェクトを作成し、同じメッシュデータを使用することができます。

オブジェクトlayersプロパティは、オブジェクトが表示される場所を指定する20個のブール値の配列です。オブジェクトをシーンに追加すると、アクティブなレイヤーに表示されるように設定されます。シーン。

import bpy, random 

d   = 4 
anz   = 100 
frameAnz = 20 
scene = bpy.context.scene 
scene.frame_start = 1 
scene.frame_end = 100 
ball = bpy.data.objects["ballB"] 

for anz in range (0,anz): 
    xpos = -1 * (d/2) + random.randint(0,(d-1)) 
    xpos += random.random() 
    ypos = -1 * (d/2) + random.randint(0,(d-1)) 
    ypos += random.random() 
    zpos = random.randint(0,(d-1)) 
    zpos += random.random() 

    bn = str(anz).zfill(5) 
    bn = "zz_Ball-" + bn 

    tball = bpy.data.objects.new(bn, ball.data) 
    tball.location = (xpos, ypos, zpos) 
    sz = random.uniform(0.015,0.09) 
    tball.scale = (sz,sz,sz) 

    tball.select = False 
    scene.objects.link(tball) 
    tball.layers = [False,True] + [False]*18 

for actFrame in range(1,frameAnz): 
    for ob in scene.objects: 
     ob.location.z += random.random() 
     ob.keyframe_insert(data_path='location', index=2, frame=actFrame) 
+0

ありがとう、@Sambler - これは、Blenderでのアニメーションの理解を向上させます。 昨日私の最初の解決策を見つけました: http://blender.stackexchange.com/questions/70456/how-to-make-keyframes-in-blender-2-78a-using-python/70478#70478 私は、魅力的なBlenderとPythonに関する最後の質問ではないと確信しています;-) – Atari800XL

関連する問題