Skip to content

Instantly share code, notes, and snippets.

@tedbrownxr
Created December 1, 2021 01:04
Show Gist options
  • Save tedbrownxr/e503e8bb966c5e2af9f8d82ef47f928b to your computer and use it in GitHub Desktop.
Save tedbrownxr/e503e8bb966c5e2af9f8d82ef47f928b to your computer and use it in GitHub Desktop.
Lens Studio: An example of how you can use PlaneTracker in your Next Generation Spectacles project
// -----JS CODE-----
// PLANE TRACKER EXAMPLE
// For Lens Studio on Next Generation Spectacles
// Requires Plane Tracker script: https://gist.github.com/tedbrownxr/64914f814b0d121a9f53f66e5ecf2350
// - Uses Plane Tracker to position an object in the world
// - If the plane is invalid, hides the object and shows the problem with on-screen text
// - Activates on start
// - Tap to set object position
// Ted Brown / November 30, 2021
// @input SceneObject targetObject
// @input Component.Text debugText
script.createEvent("OnStartEvent").bind(function () {
global.planeTracker.start();
});
script.createEvent("UpdateEvent").bind(function () {
if (global.planeTracker.isActive === false) {
return;
}
if (global.planeTracker.isValidSurface === true) {
script.targetObject.enabled = true;
script.targetObject.getTransform().setWorldPosition(global.planeTracker.position);
script.targetObject.getTransform().setWorldRotation(global.planeTracker.rotation);
script.debugText.text = "";
}
else {
script.targetObject.enabled = false;
script.debugText.text = global.planeTracker.status;
}
});
script.createEvent("TapEvent").bind(function () {
if (global.planeTracker.isValidSurface === true) {
global.planeTracker.stop();
script.debugText.text = "";
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment