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

Added Expressions Presets and functions #465

Open
wants to merge 4 commits into
base: expressions
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/Expressions/presets/clamp.fexpr
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ description=Clamp value to upper and lower.
highlighters="clamp(x, lower, upper)"
id=graphics.friction.clamp
title=Clamp
version=1
version=1
13 changes: 13 additions & 0 deletions src/core/Expressions/presets/copyX.fexpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[General]
author=@pgilfernandez
bindings="x = x"
categories=
definitions=
description="It copies the value from it's X parameter. There is a proportion value that allow a proportional final Y value"
highlighters=
id=graphics.friction.copyX
license=
script="proportion = 1; // Change this value if need a proportional Y\nreturn x * proportion"
title=Copy X
url=
version=1
13 changes: 13 additions & 0 deletions src/core/Expressions/presets/copyY.fexpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[General]
author=@pgilfernandez
bindings="y = y"
categories=
definitions=
description="It copies the value from it's Y parameter. There is a proportion value that allow a proportional final X value"
highlighters=
id=graphics.friction.copyY
license=
script="proportion = 1; // Change this value if need a proportional X\nreturn y * proportion"
title=Copy Y
url=
version=1
13 changes: 13 additions & 0 deletions src/core/Expressions/presets/followPathX.fexpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[General]
author=@pgilfernandez
bindings="complete = properties.complete;\nframe = $frame;\noffsetX = path.transform.translation.x;\noffsetY = path.transform.translation.y;\n"
categories=
definitions=
description="To be applied to X parameter. Simulates the effect 'follow path' and allows accessing to 'translate' values for the 'complete' parameter. It needs to manually add the path vector points to the 'Script' in order to work"
highlighters=
id=graphics.friction.followPathX
license=
script="var path = [\n [[0.0, 0.0], [524.965, 17.3065], [346.131, 398.051], [623.036, 565.347]],\n [[623.036, 565.347], [899.941, 732.644], [1381.64, 449.97], [1214.34, 124.03]],\n [[1214.34, 124.03], [1047.05, -201.91], [623.036, 23.0754], [686.493, 314.402]],\n [[686.493, 314.402], [749.95, 605.729], [1468.17, 969.167], [1667.2, 297.096]]\n];\n\nvar numSegments = path.length;\n\nvar t_global = clamp(complete * numSegments, 0, numSegments); \n\nvar segmentIndex = Math.floor(t_global);\nsegmentIndex = clamp(segmentIndex, 0, numSegments - 1);\n\nvar t_local = t_global - segmentIndex;\n\nvar P0 = path[segmentIndex][0];\nvar P1 = path[segmentIndex][1];\nvar P2 = path[segmentIndex][2];\nvar P3 = path[segmentIndex][3];\n\nvar x = Math.pow(1 - t_local, 3) * P0[0] +\n 3 * Math.pow(1 - t_local, 2) * t_local * P1[0] +\n 3 * (1 - t_local) * Math.pow(t_local, 2) * P2[0] +\n Math.pow(t_local, 3) * P3[0];\n\nvar y = Math.pow(1 - t_local, 3) * P0[1] +\n 3 * Math.pow(1 - t_local, 2) * t_local * P1[1] +\n 3 * (1 - t_local) * Math.pow(t_local, 2) * P2[1] +\n Math.pow(t_local, 3) * P3[1];\n\nreturn x + offsetX;"
title=Follow path Y
url=
version=1
13 changes: 13 additions & 0 deletions src/core/Expressions/presets/followPathY.fexpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[General]
author=@pgilfernandez
bindings="complete = properties.complete;\nframe = $frame;\noffsetX = path.transform.translation.x;\noffsetY = path.transform.translation.y;\n"
categories=
definitions=
description="To be applied to Y parameter. Simulates the effect 'follow path' and allows accessing to 'translate' values for the 'complete' parameter. It needs to manually add the path vector points to the 'Script' in order to work"
highlighters=
id=graphics.friction.followPathY
license=
script="var path = [\n [[0.0, 0.0], [524.965, 17.3065], [346.131, 398.051], [623.036, 565.347]],\n [[623.036, 565.347], [899.941, 732.644], [1381.64, 449.97], [1214.34, 124.03]],\n [[1214.34, 124.03], [1047.05, -201.91], [623.036, 23.0754], [686.493, 314.402]],\n [[686.493, 314.402], [749.95, 605.729], [1468.17, 969.167], [1667.2, 297.096]]\n];\n\nvar numSegments = path.length;\n\nvar t_global = clamp(complete * numSegments, 0, numSegments); \n\nvar segmentIndex = Math.floor(t_global);\nsegmentIndex = clamp(segmentIndex, 0, numSegments - 1);\n\nvar t_local = t_global - segmentIndex;\n\nvar P0 = path[segmentIndex][0];\nvar P1 = path[segmentIndex][1];\nvar P2 = path[segmentIndex][2];\nvar P3 = path[segmentIndex][3];\n\nvar x = Math.pow(1 - t_local, 3) * P0[0] +\n 3 * Math.pow(1 - t_local, 2) * t_local * P1[0] +\n 3 * (1 - t_local) * Math.pow(t_local, 2) * P2[0] +\n Math.pow(t_local, 3) * P3[0];\n\nvar y = Math.pow(1 - t_local, 3) * P0[1] +\n 3 * Math.pow(1 - t_local, 2) * t_local * P1[1] +\n 3 * (1 - t_local) * Math.pow(t_local, 2) * P2[1] +\n Math.pow(t_local, 3) * P3[1];\n\nreturn y + offsetY;"
title=Follow path Y
url=
version=1
13 changes: 13 additions & 0 deletions src/core/Expressions/presets/generateNoise.fexpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[General]
author=@pgilfernandez
bindings=
categories=
definitions="function generateNoise(t, scale = 1, strength = 1, phase = 0, detail = 1) {\n // Fixed permutation for consistency\n const permutation = Array.from({ length: 256 }, (_, i) => i).concat(Array.from({ length: 256 }, (_, i) => i));\n \n function fade(t) {\n return t * t * t * (t * (t * 6 - 15) + 10);\n }\n\n function lerp(a, b, t) {\n return a + t * (b - a);\n }\n\n function grad(hash, x) {\n const h = hash & 15;\n const gradient = 1 + (h & 7); // Gradient range between 1 and 8\n return (h & 8 ? -gradient : gradient) * x;\n }\n\n function perlinNoise(x) {\n const X = Math.floor(x) & 255;\n x -= Math.floor(x);\n const u = fade(x);\n\n const a = permutation[X];\n const b = permutation[X + 1];\n\n return lerp(grad(a, x), grad(b, x - 1), u);\n }\n\n let amplitude = strength;\n let frequency = scale;\n let total = 0;\n\n for (let i = 0; i < detail; i++) {\n total += perlinNoise((t + phase) * frequency) * amplitude;\n frequency *= 2; // Double frequency for each octave\n amplitude /= 2; // Halve amplitude for each octave\n }\n return total;\n}\n"
description="Generates random noise to the base value, it will generate smooth variation along time"
highlighters="generateNoise(t, scale, strength, phase, detail)"
id=graphics.friction.generateNoise
license=
script=
title=Generate Noise
url=
version=1
13 changes: 13 additions & 0 deletions src/core/Expressions/presets/orbitX.fexpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[General]
author=@pgilfernandez
bindings="centerX = properties.x;\nframe = $frame;\nradius = properties.radius;"
categories=
definitions=
description="To be applied to X parameter. It simulates the orbit around an origin with 'translate' X and Y parameters. It could be connected to custom properties to allow easier controll of both expressions"
highlighters=
id=graphics.friction.orbitX
license=
script="speed = 150; // frames\ndirection = 1; // 1 clockwise, -1 counter clockwise\noffset = 0;\ncircleOverTimeX = Math.sin( (frame/speed) * 2 * Math.PI * direction + (offset * (Math.PI / 180)) ) * radius; \nreturn centerX + circleOverTimeX;"
title=Orbit X
url=
version=1
13 changes: 13 additions & 0 deletions src/core/Expressions/presets/orbitY.fexpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[General]
author=@pgilfernandez
bindings="centerY = properties.y;\nframe = $frame;\nradius = properties.radius;\n"
categories=
definitions=
description="To be applied to Y parameter. It simulates the orbit around an origin with 'translate' X and Y parameters. It could be connected to custom properties to allow easier controll of both expressions"
highlighters=
id=graphics.friction.orbitY
license=
script="speed = 150; // frames\ndirection = 1; // 1 clockwise, -1 counter clockwise\noffset = 0;\ncircleOverTimeY = -Math.cos( (frame/speed) * 2 * Math.PI * direction + (offset * (Math.PI / 180)) ) * radius;\nreturn centerY + circleOverTimeY;"
title=Orbit Y
url=
version=1
13 changes: 13 additions & 0 deletions src/core/Expressions/presets/oscillation.fexpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[General]
author=@pgilfernandez
bindings=
categories=
definitions="function oscillation(origin, time, frequency, amplitude, shift) {\n var correctedShift = ((shift % (2 * Math.PI)) + (2 * Math.PI)) % (2 * Math.PI);\n var val = Math.cos((correctedShift + time) * frequency) * amplitude;\n return origin + val;\n}"
description="It creates a oscillation movement like a wave"
highlighters="oscillation(origin, time, frequency, amplitude, shift)"
id=graphics.friction.oscillation
license=
script=
title=Oscillation
url=
version=1
13 changes: 13 additions & 0 deletions src/core/Expressions/presets/rotation.fexpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[General]
author=@pgilfernandez
bindings="fps = $scene.fps;\nframe = $frame;\nvalue = $value;"
categories=
definitions=
description="It rotates the object on a constant speed controlled by FPS"
highlighters=
id=graphics.friction.rotation
license=
script="time = frame / fps;\nspeed = 100;\ndirection = 1; // clockwise = 1, counterclockwise = -1\noffset = value; // instead of controlling if with $value\n // you can use any float number\nreturn (time * speed + offset) % 360 * direction;"
title=Rotation
url=
version=1
13 changes: 13 additions & 0 deletions src/core/Expressions/presets/time.fexpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[General]
author=@@pgilfernandez
bindings="frame =$frame;\nfps =$scene.fps;"
categories=
definitions=
description="It animates the parameter based on the frame number and the frames per second of the scene."
highlighters=
id=graphics.friction.time
license=
script="time = frame / fps;\nreturn time"
title=Time
url=
version=1
13 changes: 13 additions & 0 deletions src/core/Expressions/presets/trackObject.fexpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[General]
author=@pgilfernandez
bindings="objectPos = transform.translation;\npivotPos = transform.pivot;\noffsetAngle = $value;\ntargetPos = circle.transform.translation;\n"
categories=
definitions=
description="It looks at another object, it is meant to be applied to a 'rotation' parameter"
highlighters=
id=graphics.friction.trackObject
license=
script="var realObjectPosX = objectPos[0] + pivotPos[0];\nvar realObjectPosY = objectPos[1] + pivotPos[1];\nvar realTargetPosX = targetPos[0];\nvar realTargetPosY = targetPos[1];\n\nvar deltaX = realTargetPosX - realObjectPosX;\nvar deltaY = realTargetPosY - realObjectPosY;\n\nvar angleRad = Math.atan2(deltaY, deltaX);\nvar angleDeg = angleRad * (180 / Math.PI);\n\nreturn angleDeg + offsetAngle;\n"
title=Track object
url=
version=1
13 changes: 13 additions & 0 deletions src/core/Expressions/presets/wave.fexpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[General]
author=@pgilfernandez
bindings="fps = $scene.fps;\nframe = $frame;\nwidth = $scene.width;\n"
categories=
definitions=
description="It creates a wave function that can be used to animate objects"
highlighters=@Invalid()
id=graphics.friction.wave
license=
script="origin = width/2;\ntime = frame / fps;\nfrequency = 400;\namplitude = 300;\nshift = 0;\nreturn oscillation(origin, time, frequency, amplitude, shift)"
title=Wave
url=
version=1
13 changes: 13 additions & 0 deletions src/core/Expressions/presets/wiggle.fexpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[General]
author=@pgilfernandez
bindings="fps = $scene.fps;\nframe = $frame;\nvalue = $value;\n"
categories=
definitions=
description="Similar to AE Wiggle, it creates random variation of the initial value of the parameter"
highlighters=
id=graphics.friction.wiggle
license=
script="// value is used to set an origin from where the noise will start\ntime = frame / fps;\nscale = 0.6;\nstrength = 20;\nphase = 5; // use different values to randomize the init\ndetail = 4;\nnoise = generateNoise(time, scale, strength, phase, detail);\nreturn value + noise"
title=Wiggle
url=
version=1