olive icon indicating copy to clipboard operation
olive copied to clipboard

[NODES] Simple math operations in numeric input fields

Open prokoudine opened this issue 6 years ago • 6 comments

It's quite useful to have basic math operations in numeric input fields in cases when you know exactly by how much you want to change a value.

Here is how it works e.g. in GIMP:

  1. Place the cursor after the last number in the numeric input field
  2. Type +231, or -7643, or *3, or /28
  3. Press Tab to compute
  4. The original value in the input field then gets replaced with the computed value

prokoudine avatar Feb 10 '19 12:02 prokoudine

Blender has a great way of doing this, also allows other variable's to be used, (such as frame). In order to tell Blender that a user wants a scripted driver a # is used.

Such an expression could be: #sin(frame).

I can straight away think of a few very useful variables: frame frame number of clip sframe frame number of sequence length length of clip which effect is on

With frame & length a user could easily make a ken burns effect for example, which dynamically responds to editing. Only issue I can see is how to deal with transitions? frame would have to start from beginning of transition, not clip.

alcomposer avatar Feb 10 '19 13:02 alcomposer

@alcomposer Yeah, I left it out for simplicity's sake, but yes — GIMP does that sort of thing too (e.g. 1000px + 2cm, or 700+2%), and it's useful indeed. 'frame', 'sframe', and 'length' look good to me :)

prokoudine avatar Feb 10 '19 14:02 prokoudine

Some more I can think of are height, width and their s- prefixed versions, for doing operations that might depend on clip/sequence dimensions.

However, one should think, how this would work (or not) with keyframes? And would it be animatable? (ex: compute #sin(frame) every frame)

capezotte avatar Feb 10 '19 14:02 capezotte

@oc1024 obviously this is a long term idea. If you check out Blender, yes #sin(frame) would be calculated for every frame.)

If this was to work with keyframes then there would need to be another keyword: keyframe. The keyframe keyword would allow a user to feed the keyframed value into the field. Something like:

#keyframe+sin(frame) would add a wobble to the keyframed animation.

alcomposer avatar Feb 10 '19 14:02 alcomposer

I think it would be convenient to do the simplest mathematical operations to change the time on the timeline when the video is being edited. Just as implemented in a blender VSE.

dma3000 avatar Feb 17 '19 19:02 dma3000

This is where GLSL may be better as a scripting language because of its context of computing per frame pixel. While sin, cos, and tan may be interesting for some scenarios. Easing functions that handle tweening may be much easier to understand and implement than hard core inline math. This is the way that CSS went after having hardcore math in Flash. In the end most artistic types just weren't that handy with calculating computation. Easing functions were easier to understand...

frink avatar Mar 04 '19 06:03 frink