Camera texture sample, drag to select UV?

OK, this effect is just for fun so I don’t feel weird asking for help lol. I want to make an effect, where when the user drags their finger they can select which area of the screen they want on their face (a preview plane appears with this texture while dragging). Two parts to this that confuse me;

  1. for different device sizes how do I adjust the scale on the 2D transform pack so that the camera ratio is correct and doesn’t stretch the width too much or the height?

  2. When the user is dragging I want the sample rectangle (plane) to be visible, then disappear when they lift their finger. I know how to do that! However I don’t know the right patches to hook up in order to plug into the translation aspect of the 2D transform pack. I need it to stay in the bounds of the screen so I don’t get those stretched out “there’s no cam texture here” lines,

Any tips at all are appreciated and patch editor screenshots help immensely, My biggest hurdle is making sure this works for all screens

Hi @alexis,
I’m unsure about what you mean on point number one. About point number two, it’s easy to do with a script, I’m not sure about patches. Here’s a link to the scripting reference, but give me 10m and I’ll make a simple script that detects when the user lifts their finger, I already made something similar for a different use case

1 Like

ah thank you! And I mean keeping the aspect ratio of the camera feed! if it’s just 1:1 it’ll stretch to a square, or an iphonex is much skinnier than an iphone 8. I need the texture of the camera to keep the same ratio as the device screen so it doesn’t look stretched out like this

Screen Shot 2020-09-19 at 5.20.42 PM

I have something working, The numbers just aren’t quite right!

I’m back. Here’s the code, copy paste it to a script and change line 5 with the name of your plane - keep in mind it should be the only plane with that name, otherwise there could be some small errors.

As for the aspect ratio… (DeviceSize) H/W should give you how stretched it is; if say it was twice as high as it is wide it should be a 2, so you if your plane is 1:1 you should stretch the cameraTexture by 2 (tall) and that should look like the normal camera texture.

So in patches:
Take DeviceSize.y/DeviceSize.x -> Swizzle (X1) -> 2DTransform Scale by the output of swizzle.

Keep in mind the code is probably a more complex than it needs to be, I’ve been coding a lot lately and just got accustomed to this style, it includes some basic error checking so that you don’t need to deal with any unhelpful error message from Spark (they give no context :slightly_smiling_face:), instead if there’s an error in the plane name you change in line 5 it will give some info. Reach out if you need more help

Thank you!! I think this will help me immensely with refining

1 Like