Skip to content

Instantly share code, notes, and snippets.

@skang2-sc
skang2-sc / WebSocketConnection.ts
Created December 31, 2024 19:30
WebSocketConnection Helper
import Event from "SpectaclesInteractionKit/Utils/Event";
const HOST = "wss://[APP_NAME].herokuapp.com";
export class WebSocketConnection {
private remoteServiceModule: RemoteServiceModule = require("LensStudio:RemoteServiceModule");
private webSocket: WebSocket;
private onMessageEvent = new Event<WebSocketMessageEvent>();
public readonly onMessage = this.onMessageEvent.publicApi();
@skang2-sc
skang2-sc / SampleUsageWebSocket.ts
Created December 31, 2024 19:31
Using WebSocket in Lens Studio.
import { WebSocketConnection } from "./Scripts/WebSocketConnection";
@component
export class SampleUsageWebSocket extends BaseScriptComponent {
private websocket: WebSocketConnection;
onAwake() {
this.websocket = new WebSocketConnection();
this.websocket.onMessage((event) => {
this.receiveAudioFromServer(event);
@skang2-sc
skang2-sc / ToggleImage.ts
Created February 21, 2025 04:21
ToggleImage with Spectacles Interaction Kit
import { PinchButton } from "SpectaclesInteractionKit/Components/UI/PinchButton/PinchButton";
@component
export class ToggleImage extends BaseScriptComponent {
@input
image: Image;
onAwake() {
this.sceneObject
.getComponent(PinchButton.getTypeName())
@skang2-sc
skang2-sc / HeadTrackingSmoothing.ts
Created February 28, 2025 05:46
Adds a OneEuro Filter to Head Tracking
import {
OneEuroFilterQuat,
OneEuroFilterVec3,
} from "./SpectaclesInteractionKit/Utils/OneEuroFilter";
const FILTER_CONFIG = {
frequency: 60,
minCutoff: 2,
beta: 0.015,
dcutoff: 1,
@skang2-sc
skang2-sc / PinholeCameraModel.ts
Created March 5, 2025 06:48
PinholeCameraModel takes the camera intrinsic values from the device camera, and provides helper methods to convert between 2D and 3D coordinates.
/**
* PinholeCameraModel takes the camera intrinsic values from the device camera,
* and provides helper methods to convert between 2D and 3D coordinates.
*/
export class PinholeCameraModel {
public readonly resolution: vec2;
public readonly focalLength: vec2;
public readonly principalPoint: vec2;
constructor(resolution: vec2, focalLength: vec2, principalPoint: vec2) {
@skang2-sc
skang2-sc / CameraCrop.ts
Last active March 19, 2025 21:26
Camera Crop
@component
export class CameraCrop extends BaseScriptComponent {
@input
nonCropImage: Image;
@input
croppedImage: Image;
//Generate this through Asset Browser > Screen Crop Texture
@input
screenCropCameraTexture: Texture;
@skang2-sc
skang2-sc / AudioHelper.ts
Last active April 4, 2025 03:11
Will help you seek to a specific position in your audio component in Lens Studio
@component
export class AudioHelper extends BaseScriptComponent {
// Private property to hold a reference to the AudioComponent
private audioComponent: AudioComponent;
// Called when the script is initialized
onAwake() {
// Retrieve the AudioComponent attached to the same SceneObject
this.audioComponent = this.sceneObject.getComponent("AudioComponent");
// Call the testSeek method to set up a test event
@skang2-sc
skang2-sc / SpeechToText.ts
Created April 28, 2025 16:46
Easy way to use the VoiceML module to get Speech to Text on Spectacles
@component
export class SpeechToText extends BaseScriptComponent {
private voiceMLModule: VoiceMLModule = require("LensStudio:VoiceMLModule");
onAwake() {
let options = VoiceML.ListeningOptions.create();
options.shouldReturnAsrTranscription = true;
options.shouldReturnInterimAsrTranscription = true;
this.voiceMLModule.onListeningEnabled.add(() => {
this.voiceMLModule.startListening(options);