Skip to content

Instantly share code, notes, and snippets.


Andreas Jakl andijakl

View GitHub Profile
andijakl / EnvironmentalLight.cs
Created Jun 4, 2020
Snippet of the EnvironmentalLight code of Google ARCore for Unity
View EnvironmentalLight.cs
LightEstimate estimate = Frame.LightEstimate;
// Updates directional light
DirectionalLight.transform.rotation = estimate.DirectionalLightRotation;
DirectionalLight.color = estimate.DirectionalLightColor;
// Set ambient probe
RenderSettings.ambientMode = AmbientMode.Skybox;
RenderSettings.ambientProbe = estimate.AmbientProbe;
// Set reflection probe (if activated)
RenderSettings.defaultReflectionMode = DefaultReflectionMode.Custom;
RenderSettings.customReflection = estimate.ReflectionProbe;
andijakl / AnchorPositioning.js
Last active Aug 30, 2019
Complete AnchorPositioning.js script that creates an AR anchor in Amazon Sumerian, based on the upcoming scripting API.
View AnchorPositioning.js
// Import Sumerian scripts
import * as s from 'module://sumerian-common/api';
import * as si from 'module://sumerian-common/internal';
export default class AnchorPositioning extends s.Action {
static get PROPERTIES() {
return {
// Optional property to set the owner of the AR anchor
anchorEntity: {
andijakl / AnchorPositioning.js
Created Aug 8, 2019
Subscribing to the event StartPlaceMode to enable the Augmented Reality placement mode functionality.
View AnchorPositioning.js
// Listen for the world event "StartPlaceWorld". This will be sent
// by another component in the scene when the placement mode should
// be active. When that event is received, this script sets placeMode to true,
// which actually allows this script to react to touch events.
this.startPlaceWorldEvent ='StartPlaceWorld');
this.startPlaceWorldEvent.listen(ctx, data => this.placeMode.set(true));
andijakl / AnchorPositioning.js
Last active Aug 8, 2019
Call-back when the AR system of the device (ARCore / ARKit) sends the anchor ID to our scene, so that we can link it to the entity.
View AnchorPositioning.js
// Anchor registration callback. Sets the anchor ID of the entity's
// ArAnchorComponent. The engine's ArSystem will automatically update
// the world position and orientation of entities with a valid anchor ID.
registerAnchorCallback(anchorId) {
if (anchorId) {
this.internalAnchorEntity.getComponent('ArAnchorComponent').anchorId = anchorId;
console.log("Registered AR anchor: " + anchorId);
console.log("Quit place mode and sent WorldPlaced event");
andijakl / AnchorPositioning.js
Last active Aug 8, 2019
Call-back from the hit test: register an AR anchor at this position through Amazon Sumerian's ArSystem.
View AnchorPositioning.js
// Hit test callback. If the hit test was successful (i.e., detected a
// point in the real world), registers an anchor with that point.
hitTestCallback(anchorTransform) {
if (anchorTransform) {
console.log("Transform from hit test: " + anchorTransform + ". Registering anchor...");
this.arSystem.registerAnchor(anchorTransform, (anchorId) => this.registerAnchorCallback(anchorId));
} else {
console.log("No transform received from hit test");
andijakl / AnchorPositioning.js
Created Aug 8, 2019
Remove the event listener for the touch event in Amazon Sumerian.
View AnchorPositioning.js
// Cleanup. When this script stops, also remove the event listeners.
// This is especially important here, as Sumerian doesn't always reliably
// clean up all the runtime-registrations when you repeatedly start the scene.
() => {
console.log("Removing touch event listener.");
this.internalWorld.sumerianRunner.renderer.domElement.removeEventListener('touchend', performHitTestCallback);
// For testing on the PC with a mouse
//this.internalWorld.sumerianRunner.renderer.domElement.removeEventListener('mouseup', performHitTestCallback);
andijakl / AnchorPositioning.js
Created Aug 8, 2019
Adding the touchend event listener through the HTML DOM within Amazon Sumerian.
View AnchorPositioning.js
// Add an event listener for touch events anywhere on the screen.
// Note: the MouseUpAction of Sumerian doesn't provide the coordinates
// -> use the HTML DOM event directly. This is accessible through
// the Renderer.
this.internalWorld.sumerianRunner.renderer.domElement.addEventListener('touchend', performHitTestCallback);
// Phones use touch events. To also develop / test on a PC (or on
// a mobile device with a mouse attached), you can also register for
// mouse events.
//this.internalWorld.sumerianRunner.renderer.domElement.addEventListener('mouseup', performHitTestCallback);
andijakl / AnchorPositioning.js
Created Aug 8, 2019
Registering the hit test call back. Stores it in a variable to allow removing the event listener later, and using an arrow function to preserver this.
View AnchorPositioning.js
// Listeners and Callbacks
// -------------------------------------------------------------------
// First, create a variable that stores an arrow function to the
// performHitTest method of this class. This method takes care of
// starting the hit test in the native AR system.
// We need this as an arrow function to have access to "this" in
// the class scope. Creating this function in a variable allows
// to remove the event listener once the scene closes.
var performHitTestCallback = (evt) => this.performHitTest(evt);
andijakl / AnchorPositioning.js
Created Aug 8, 2019
Callback after the user taps the screen. Performs a hit test using Amazon Sumerian's ArSystem, which forwards the request to the device-native AR subsystem (ARCore / ARKit).
View AnchorPositioning.js
// Touch handler.
// As the first step, performs a hit test at the currrent screen location.
performHitTest(evt) {
// Check if this script is currently in an active place mode.
// That is triggered when another component in the scene sent the
// StartPlaceWorld event.
if (!this.placeMode.get()) {
// Currently not place mode - don't proceed!
console.log("Not in place mode - not proceeding");
andijakl / AnchorPositioning.js
Created Jul 29, 2019
Get a reference to the Amazon Sumerian engine internal version of the World.
View AnchorPositioning.js
// World reference
// -------------------------------------------------------------------
// The world is essentially the loaded scene. It allows interacting
// with the scene contents and reading / setting several properties
// of it.
const publicWorld =;
// Same as before, we actually need the more powerful internal world
// class, not the "normal" one.
this.internalWorld = si.World.forPublicWorld(publicWorld);
You can’t perform that action at this time.