Last active
March 19, 2025 21:26
-
-
Save skang2-sc/390b1e1de99993de8ef58b7d5dcee197 to your computer and use it in GitHub Desktop.
Camera Crop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@component | |
export class CameraCrop extends BaseScriptComponent { | |
@input | |
nonCropImage: Image; | |
@input | |
croppedImage: Image; | |
//Generate this through Asset Browser > Screen Crop Texture | |
@input | |
screenCropCameraTexture: Texture; | |
private cameraTexture: Texture; | |
private cameraTextureControl: CameraTextureProvider; | |
private cameraModule: CameraModule = require("LensStudio:CameraModule"); | |
onAwake() { | |
//Requesting Camera needs to be done in OnStartEvent | |
this.createEvent("OnStartEvent").bind(() => { | |
// Create a camera request to get the default color camera (i.e. Left vs Right camera) | |
let imageRequest = CameraModule.createCameraRequest(); | |
imageRequest.cameraId = CameraModule.CameraId.Default_Color; | |
// Request the camera and get the camera texture | |
this.cameraTexture = this.cameraModule.requestCamera(imageRequest); | |
//Need to call onNewFrame to start camera streaming remain streaming | |
this.cameraTextureControl = this.cameraTexture | |
.control as CameraTextureProvider; | |
this.cameraTextureControl.onNewFrame.add(() => {}); | |
//Setting crop texture to use the camera texture | |
let screenCropTextureControl = this.screenCropCameraTexture | |
.control as CropTextureProvider; | |
screenCropTextureControl.inputTexture = this.cameraTexture; | |
this.croppedImage.mainPass.baseTex = this.screenCropCameraTexture; | |
// Set the non-cropped image to use the camera texture | |
this.nonCropImage.mainPass.baseTex = this.cameraTexture; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Configure your Screen Crop Texture
