Spectacles 2021 Getting Started
Getting Started
[Spectacles 2021]
Getting Started is a simple project to help you get up and running with your first lens on Spectacles 2021. Tap and hold the touchpad to move the sphere in front of your gaze. Release the touchpad to leave the sphere in place. When you look away from the sphere, an arrow will appear pointing to the sphere. Throughout, the sphere’s local position relative to the camera will print to the UI.
This project shows how to:
- Display text to the screen, including debug logs
- Place an object in space
- Call functions of one script from another script
- Use Behavior Script to fire an event upon looking towards/away from an object
- Implement an arrow guiding the player to look at an offscreen target
Project Download
Please download the project here.
Camera
Your camera should always be set to “Camera Type: Perspective” because we are working in 3D.
In order for an object to stick in space, your lens needs to be tracking the movement of your camera relative to that object. Therefore, you must attach a “Device Tracking” component to the camera and set “Tracking Mode: World.”
In Lens Studio, the z axis of the camera points backwards, behind the camera. To place an object in front of the camera, you must set that object’s local z position relative to the camera to be in the negative direction. For example, the “UI” scene object is parented to the camera, so it is in camera space, and its local position relative to the camera is (0, 0, -20).
Sometimes, the camera pointing backwards confuses me during matrix operations. Therefore, I make a “CameraPivot” scene object parented to the camera, and I point the pivot so its forward points in front of the camera. Please use whatever math or approach works for you.
Lens Controller
The LensController script holds references to the other scripts. It initiates these scripts by calling their “init()” functions, which have been made public via the following code:
script.api.init = init;
The LensController can be a central hub to control initialization, order of operations, and to enable various scripts in your project to talk to each other.
UI Controller
The UIController script holds references to the text components that will display text to the screen. You can use this to display instructions for your player or debug logs for yourself.
Tip: Use “{"widget":"text_area"}” after your variable to expose a multi line string input field in the Inspector.
Orient Object
The OrientObject script shows you how to orient an object relative to the camera. The OrientObject script is actually moving its own scene object so that everything parented to it, in this case a sphere, moves with it.
Tip: To reference variables defined in the Inspector (eg “// @input float lerpSpeed”), you must use “script.lerpSpeed” in your code AND those references must be defined in the Inspector field for your code to run.
To reference variables defined in code (eg “var isHolding = false”), you must simply use “isHolding” in your code - no need to preface the var with “script.”.
OrientObject shows you how to implement Touch and Update events. When you hold the touchpad, Orient Object lerps to be right in front of the camera (the player’s head) at the distance from the player that you set in the Inspector. Lens Studio units are in cm. So “distFromPlayer = 100” means the object will appear 100 cm in front of the camera.
Tip: Note that for the Spectacles 2021, any object closer than 10 cm to the player will not converge correctly and will hurt the player’s eyes or not be visible to them at all.
The OrientObject script function orientObject() also shows you how to both print debug statements to the console and print them to the text components of the UI. Printing debug statementsto the UI is extremely helpful for debugging in the Spectacles 2021, since you cannot access the console while you are testing your lens on the device. To stop printing debug statements to the UI, set “var debug = false” at the top of the script.
Look Arrow
The LookArrow script controls showing, hiding, and pointing the arrow at the target defined in the Inspector. ShowArrow() and hideArrow() are called from behavior scripts that use the angle between your focus direction and the direction from the camera to the target to call custom functions. Behavior script is a great way to easily trigger focus events in your project.
Using .lso To Import This Project Into Another
To import this project into another project, you can export this project as a .lso file:
- In the “Objects” panel, parent everything to one parent “GettingStarted” scene object. A .lso will only export a single scene object. And it will only include the files references by all of that object’s children. To keep your hierarchies intact, collapse the scene objects with children (e.g. tap the arrow beside “Camera” and “OrientObject” so you don’t see their children when you drag those objects beneath the “GettingStarted” parent object).
- In your Resources panel, I like to place everything in one “GettingStarted” folder. This will keep my files for this project in that folder when I import them into another project.
- In the “Objects” panel, Right Mouse Click on the “GettingStarted” parent object and select “Export Object”.
- In the project you’d like to import this .lso file to, click File -> Import and select the .lso file.
Next Step
A next step might be to use the Single Plane Tracking template to place an object in front of you on a surface.
Thankyou so much for sharing this..! Atley Loughridge