Skip to content

Instantly share code, notes, and snippets.

View positlabs's full-sized avatar
🌶️
Focusing

Josh Beckwith positlabs

🌶️
Focusing
View GitHub Profile
@positlabs
positlabs / PlaceObjectOnSurface.js
Last active April 14, 2023 15:05
Object placement for Lens Studio
/*
REQUIRED: Create a ground plane with a collider
so we can hit test against it to place the object on the surface.
*/
/* API */
script.api.enablePlacement = function (bool) { placementEnabled = bool }
script.api.setScreenPoint = function (pt) { screenPoint = pt }
@positlabs
positlabs / Enable4FrontCam.js
Last active April 12, 2023 21:10
Lens studio script to enable an object only on the front camera
//@input SceneObject obj
/** @type {SceneObject} */
var obj = script.obj
script.createEvent('CameraFrontEvent').bind(function(){
if(obj) obj.enabled = true
})
script.createEvent('CameraBackEvent').bind(function(){
if(obj) obj.enabled = false
@positlabs
positlabs / ShadowShader.shader
Created January 20, 2018 00:39
Unity shader for rendering shadows onto a transparent surface. Useful for augmented reality.
Shader "ShadowShader" {
Properties{
_Color("Main Color", Color) = (1,1,1,1)
_MainTex("Base (RGB)", 2D) = "white" {}
_Cutoff("Cutout", Range(0,1)) = 1.0
}
SubShader{
Pass{
Alphatest Greater[_Cutoff] SetTexture[_MainTex]
@positlabs
positlabs / snap-debounce.js
Created March 22, 2023 17:32
Debounce function for Lens Studio. Also provides setTimeout and clearTimeout functions.
/*
Debouncing functions is used for delaying a function call until a certain amount of time has passed.
In the example below, it's used to hide a slider after 3 seconds if the user isn't interacting with it.
*/
/**
* Polyfill for browser function setTimeout
* @param {function} callback - function to trigger after timeout is completed
@positlabs
positlabs / LensStudioDebug.js
Last active January 25, 2023 09:41
Script debugging functions for Lens Studio
/*
Include this script at the top of the scene to enable global commands
Usage:
global.showProps(object)
global.showScene(scene)
global.showSceneObject(sceneObject)
global.showComponent(component)
Original by @robertlugg
https://gist.github.com/robertlugg/a5161200998092ddf69cb7393f7efcc0
@positlabs
positlabs / FrameUpdateMonitor.ts
Created December 16, 2022 15:01
Register a callback for when a video frame is updated
/*
Register a callback for when a video frame is updated
Since video playback generally isn't 60fps, this can be used as a render optimization
new FrameUpdateMonitor(videoElement, callback)
*/
export class FrameUpdateMonitor {
@positlabs
positlabs / backup-github.sh
Last active February 25, 2022 18:45 — forked from rodw/backup-github.sh
A simple script to backup an organization's GitHub repositories, wikis and issues.
#!/bin/bash
# A simple script to backup an organization's GitHub repositories.
# NOTE: if you have more than 100 repositories, you'll need to step thru the list of repos
# returned by GitHub one page at a time, as described at https://gist.github.com/darktim/5582423
GHBU_BACKUP_DIR=${GHBU_BACKUP_DIR-"github-backups"} # where to place the backup files
GHBU_ORG=${GHBU_ORG-"<REPLACE_ME>"} # the GitHub organization whose repos will be backed up
# (if you're backing up a user's repos instead, this should be your GitHub username)
GHBU_UNAME=${GHBU_UNAME-"<REPLACE_ME>"} # the username of a GitHub account (to use with the GitHub API)
@positlabs
positlabs / html2Element.js
Created December 16, 2021 20:52
Converts a string into an html element
/**
* @param {String} HTML representing a single element
* @return {Element}
*/
export function html2Element(html) {
var template = document.createElement('template');
html = html.trim(); // Never return a text node of whitespace as the result
template.innerHTML = html;
return template.content.firstChild;
}
@positlabs
positlabs / screen-plane.js
Created June 20, 2019 12:28
Spark AR script to resize plane to match screen size
/*
Resize plane to match screen size
*/
const Scene = require('Scene')
const camera = Scene.root.find('Camera')
const plane = Scene.root.find('plane0')
plane.width = camera.focalPlane.width
plane.height = camera.focalPlane.height
@positlabs
positlabs / longPress.js
Created September 30, 2021 14:51
Long press for lens studio. WIP
var elapsed = 0
var updateEvent = script.createEvent('UpdateEvent')
updateEvent.enabled = false
updateEvent.bind(function(e){
elapsed += e.getDeltaTime()
if(elapsed > .5){
updateEvent.enabled = false
reset()
}
})