0
$\begingroup$

I tried to write a step_falloff node in animation nodes,but i failed,the consoul gave me an error:enter image description here

and my code is:

import bpy
from ... base_types import AnimationNode
from . custom_falloff import CustomFalloff

class StepFalloffNode(bpy.types.Node, AnimationNode):
    bl_idname = "an_StepFalloffNode"
    bl_label = "Step Falloff"
def create(self):
    self.newInput("Integer", "Iterations", "iterations", value = 10)
    self.newInput("Float", "Factor", "factor", value = 1.0)
    self.newInput("Float", "Fallback", "fallback", hide = True).setRange(0, 1)
    self.newOutput("Falloff", "Falloff", "outFalloff")

def execute(self, iterations, factor, fallback):

    strengths = []

    for i in range(iterations):
        fl = factor*i
        strengths.append(fl)

    return stepFalloff(strengths,fallback)

class stepFalloff:
    def __new__(cls, strengths,fallback):
        return CustomFalloff(strengths,fallback)

and i put this code into falloff folder in animationnodes ,how to fix this? anyone has an idea ,thank you!

$\endgroup$

1 Answer 1

1
$\begingroup$

The CustomFalloff expects a FloatList object instead of a normal python list. So you should import the FloatList from data_structures:

from ... data_structures import FloatList

Then in the execute function do something like:

strengths = FloatList(iterations)
for i in range(iterations):
        strengths[i] = factor * i

return stepFalloff(strengths, fallback)

$\endgroup$
1
  • $\begingroup$ Thank Omar Ahmad very much! This code does work correctly! $\endgroup$
    – charis
    Commented Apr 5, 2019 at 3:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .