Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support expressions plugins/bundle #433

Merged
merged 3 commits into from
Jan 31, 2025
Merged

Support expressions plugins/bundle #433

merged 3 commits into from
Jan 31, 2025

Conversation

rodlie
Copy link
Member

@rodlie rodlie commented Jan 26, 2025

Support extending the default selection of JS functions in Qt, currently only supports functions bundled with Friction ('clamp'), but can easily be modified to scan a user defined directory.

Added 'clamp' as an example:

Screenshot 2025-01-26 at 22 14 00

@pgilfernandez

Support extending the default JS functions.

Added 'clamp' as an example.
@rodlie rodlie added enhancement New feature or request expressions labels Jan 26, 2025
@pgilfernandez
Copy link

Great news! I love it!
Tomorrow I will test it with some of the functions I ported and used successfully

cheers

@rodlie
Copy link
Member Author

rodlie commented Jan 27, 2025

How to make a new function

Add a target for the editor (autocomplete):

src/core/Expressions/functions/myfunc.conf

target="myfunc(x, some_other_var)"

Add the function:

src/core/Expressions/functions/myfunc.js

function myfunc(...) {
...
}

Add the files to the resource file (manually or through Qt Creator):

src/core/coreresources.qrc

<qresource prefix="/expressions">
...
        <file alias="myfunc.conf">Expressions/functions/myfunc.conf</file>
        <file alias="myfunc.js">Expressions/functions/myfunc.js</file>
...
</qresource>

And finally make sure it's loaded at startup:

src/core/appsupport.cpp:1127

functions << "myfunc";

That's it, any user can now use that function.

@rodlie
Copy link
Member Author

rodlie commented Jan 27, 2025

Great news! I love it! Tomorrow I will test it with some of the functions I ported and used successfully

It's basic, but works for adding missing functions. I kept it simple so we can include this in 1.0 instead of waiting for 1.1. We will of course expand/improve on this in 1.1

@pgilfernandez
Copy link

OK, I get it, I'll try.

Do you think it would be possible to include the "...can easily be modified to scan a user defined directory" option for v1.0? if not it would stay as something for just devs that are able to compile Friction by themselves, right?

@rodlie
Copy link
Member Author

rodlie commented Jan 27, 2025

OK, I get it, I'll try.

Do you think it would be possible to include the "...can easily be modified to scan a user defined directory" option for v1.0? if not it would stay as something for just devs that are able to compile Friction by themselves, right?

The initial idea was to add support for missing user requested functions like clamp, I can of course add support for loading from a folder (will add later today).

My only concern is that too many functions may add a performance penalty when the JS code is evaluated.

@rodlie rodlie added this to the 1.0.0 milestone Jan 27, 2025
@rodlie
Copy link
Member Author

rodlie commented Jan 27, 2025

Ok, latest commit adds support for external functions.

Search paths:

  • friction-bin/plugins/expressions/
  • friction-bin/../share/friction/plugins/expressions/
  • $HOME/Library/Preferences/friction/Expressions/ (macOS)
  • $HOME/.config/friction/Expressions (Linux)
  • Don't remember paths for Win

@rodlie rodlie changed the title Support expressions presets/bundle Support expressions plugins/bundle Jan 27, 2025
@pgilfernandez
Copy link

Did you test it?
I can't make it to work, I mean, clamp works out of the box but I could not be able to add an user function by placing myfuncion.js in $HOME/Library/Preferences/friction/Expressions/...

Any idea? may I be doing anything wrong?

Thanks

@rodlie
Copy link
Member Author

rodlie commented Jan 27, 2025

You need a .conf file.

@rodlie
Copy link
Member Author

rodlie commented Jan 27, 2025

$ tree Expressions/
Expressions/
|-- funky.conf
`-- funky.js

1 directory, 2 files
$ cat Expressions/funky.conf 
target="funky(x)"
$ cat Expressions/funky.js   
function funky(number) {
    return number + Math.random();
}

btw, you can use sub-folders, Friction should go through all folders in search path.

@rodlie
Copy link
Member Author

rodlie commented Jan 27, 2025

Added a new repo for misc expressions: https://github.com/friction2d/friction-expressions

@pgilfernandez
Copy link

Great, I got it working!

I'll play with some more expressions to have some for v1.0 (I'll PR them to the new repo) 😄

@pgilfernandez
Copy link

And I guess we will need to extend the "Expressions" Documentation section 😉

@rodlie
Copy link
Member Author

rodlie commented Jan 27, 2025

I can make a plugin manager ("Friction Store") for expressions and shaders for v1.1.

Can probably reuse what I did for Natron: https://github.com/rodlie/NatronPluginManager

@rodlie rodlie merged commit 5c6fd25 into main Jan 31, 2025
6 checks passed
@rodlie rodlie deleted the expr-presets branch January 31, 2025 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants