在Blender中用程式化生成Animation_Nodes动画01

用如下代码可以自动在Blender中生成AnimationNodes动画。效果如附图。

在Blender中用程式化生成Animation_Nodes动画01

 

    bpy.ops.mesh.primitive_monkey_add(location=(0,4,10))
    msource = bpy.context.object

    if len(mssource.particle_systems) == 0:
        bpy.context.view_layer.objects.active = mssource
        mssource.modifiers.new("part", type='PARTICLE_SYSTEM')
        part = mssource.particle_systems[0]
        
        settings = part.settings
        settings.count=200
        settings.frame_end=120
        settings.lifetime=100
        settings.effector_weights.gravity=0
    
    bpy.data.node_groups.new("NodeTree","an_AnimationNodeTree")
    bpy.data.node_groups['NodeTree'].name='MyNodeTree'
    ng = bpy.data.node_groups['MyNodeTree']    
    
    particleSystemsFromObject = ng.nodes.new("an_ParticleSystemsFromObjectNode")
    particleSystemsFromObject.location=(-600,0)
    particleSystemsFromObject.inputs[0].object=mssource
    
    
    particleSystemParticlesData = ng.nodes.new("an_ParticleSystemParticlesDataNode")
    particleSystemParticlesData.location=(-400,0)

    
    findClosePoints = ng.nodes.new("an_FindClosePointsNode")
    findClosePoints.location=(-200,0)
    
    
    splinesFromEdges = ng.nodes.new("an_SplinesFromEdgesNode")
    splinesFromEdges.location=(100,0)   
    splinesFromEdges.algorithmType='BRANCH'
    
    
    curveObjectOutput= ng.nodes.new("an_CurveObjectOutputNode")
    curveObjectOutput.location=(400,0)  
    curveObjectOutput.inputs[1].isUsed=True
    curveObjectOutput.inputs[2].isUsed=True
    curveObjectOutput.inputs[0].createObject()
    curveObjectOutput.inputs[2].value=0.5
    #add link
    ng.links.new(particleSystemsFromObject.outputs[0],particleSystemParticlesData.inputs[0])
    ng.links.new(particleSystemParticlesData.outputs[0],findClosePoints.inputs[0])
    #ng.links.new(particleSystemParticlesData.outputs[0],combineMesh.inputs[0])
    ng.links.new(findClosePoints.outputs[0],splinesFromEdges.inputs[1])
    ng.links.new(particleSystemParticlesData.outputs[0],splinesFromEdges.inputs[0])
    ng.links.new(splinesFromEdges.outputs[0],curveObjectOutput.inputs[1])

在Blender中用程式化生成Animation_Nodes动画01

 

上一篇:6.属性选择器(重要)


下一篇:架构之:REST和HATEOAS