From 293cdfd3162ae5aa2fbadd27a83049df8725fc14 Mon Sep 17 00:00:00 2001 From: Krunal Gediya <46007562+kgediya@users.noreply.github.com> Date: Tue, 11 Jan 2022 23:39:58 +0530 Subject: [PATCH] Create getGalleryMediaAspectRatio.js * Used to fetch aspect ratio of gallery media files useful for scaling etc. * Also fires a pulse on media change which can be used for various animations, transitions, events, triggers etc. --- getGalleryMediaAspectRatio.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 getGalleryMediaAspectRatio.js diff --git a/getGalleryMediaAspectRatio.js b/getGalleryMediaAspectRatio.js new file mode 100644 index 0000000..031b790 --- /dev/null +++ b/getGalleryMediaAspectRatio.js @@ -0,0 +1,28 @@ +/** + * Written by KrazyyKrunal + * https://www.facebook.com/sparkarhub/portfolios/ig/krazyykrunal/ + */ +const Scene = require('Scene'); +export const Diagnostics = require('Diagnostics'); +const Textures = require('Textures'); +const Patches = require('Patches'); +const Reactive = require('Reactive'); +(async function () { + + //Get the galleryTexture +const galleryTex = await Textures.findFirst('galleryTexture0'); + +//Calculate Aspect ratio +var aspectRatio = galleryTex.width.div(galleryTex.height) + +//Send the value to patch editor +Patches.inputs.setScalar('aspectRatio',aspectRatio) + +//This will ensure whenever the media is changed it will send the updated value to the patch editor +//also it will fire a pulse whenever the media is changed +galleryTex.onMediaChange.subscribe(function(){ + Diagnostics.log('Event Fired') + Patches.inputs.setScalar('aspectRatio',aspectRatio) + Patches.inputs.setPulse('mediaChanged',Reactive.once()) +}) +})();