Is there any way to compare two falloffs without evaluating to strengths? Assuming two falloffs are influencing same area?
Falloffs are essentially functions, we can't really compare two functions. What heuristic do you want to employ here?
Hi, I was trying to make a node myself, that stores previous state of falloff. And it does the job. The problem is it always computes because of AN always auto execution. To solve this problem i have a thought to compare two falloffs stored one and current one, if both are same do nothing.
A way to control auto execution would be enough to solve this problem.
Here is my code:
import bpy
from bpy.props import *
from ... events import propertyChanged
from ... base_types import AnimationNode
from .. falloff . mix_falloffs import MixFalloffs
storefalloff = {}
mixModeItems = [
("MAX", "Max", "", "NONE", 0),
("MIN", "Min", "", "NONE", 1)]
class Memoryfalloff(bpy.types.Node, AnimationNode):
bl_idname = "an_Memoryfalloff"
bl_label = "Memory Falloff"
mixMode: EnumProperty(name = "Mix", default = "MAX",
items = mixModeItems, update = AnimationNode.refresh)
def create(self):
self.newInput("Falloff", "Falloff", "falloff")
self.newInput("Integer", "Reset Frame", "resetframe", value = 1, hide = True)
self.newInput("Integer", "Start Frame", "start", value = 1)
self.newInput("Integer", "End Frame", "end", value = 250)
self.newOutput("Falloff", "Falloff", "falloffOut")
def draw(self, layout):
layout.prop(self, "mixMode", text = "")
def execute(self, falloff, resetframe, start, end):
T = bpy.context.scene.frame_current
identifier = self.identifier
if T == resetframe:
storefalloff[identifier] = falloff
storedElement = storefalloff.get(identifier, falloff)
if T >= start and T <= end:
storedElement = MixFalloffs([storedElement, falloff], self.mixMode, default = 1)
storefalloff[identifier] = storedElement
return storedElement
Not sure to be honest. Maybe opt for a statistical approach, do some random sampling and check the equality of the samples.
Did you mean to use random vectors to evaluate falloff and then check for equality?
Can we make a function that only executes on frame changed event?
Yes, or indices depending on falloff types.
If you mean executions that are not bound to the node tree execution, then you may use the @eventHandler("FRAME_CHANGE_POST") decorator for the function you want to execute. See the code for an example of use.
@eventHandler("FRAME_CHANGE_POST") I used this before execute function but it still executing.
Can you show me the code?
Can you show me the code?
import bpy
from bpy.props import *
from ... events import propertyChanged
from ... base_types import AnimationNode
from ... utils.handlers import eventHandler
from .. falloff . mix_falloffs import MixFalloffs
storefalloff = {}
mixModeItems = [
("MAX", "Max", "", "NONE", 0),
("MIN", "Min", "", "NONE", 1)]
class Memoryfalloff(bpy.types.Node, AnimationNode):
bl_idname = "an_Memoryfalloff"
bl_label = "Memory Falloff"
mixMode: EnumProperty(name = "Mix", default = "MAX",
items = mixModeItems, update = AnimationNode.refresh)
def create(self):
self.newInput("Falloff", "Falloff", "falloff")
self.newInput("Integer", "Reset Frame", "resetframe", value = 1, hide = True)
self.newInput("Integer", "Start Frame", "start", value = 1)
self.newInput("Integer", "End Frame", "end", value = 250)
self.newOutput("Falloff", "Falloff", "falloffOut")
def draw(self, layout):
layout.prop(self, "mixMode", text = "")
@eventHandler("FRAME_CHANGE_POST")
def execute(self, falloff, resetframe, start, end):
T = bpy.context.scene.frame_current
identifier = self.identifier
if T == resetframe:
storefalloff[identifier] = falloff
storedElement = storefalloff.get(identifier, falloff)
if T >= start and T <= end:
storedElement = MixFalloffs([storedElement, falloff], self.mixMode, default = 1)
storefalloff[identifier] = storedElement
return storedElement
That't not exactly what I meant. I thought you wanted to execute a function regardless of the execution settings of the node tree. The function where you put the decorator has to have the interface function(scene, depsgraph).
If you meant that you want to execute the node only if the execution was fired due to a frame change, then this is probably not possible.
Thanks for the info Omar, i'll try Statistical approach