Skip to content

Instantly share code, notes, and snippets.

@koji
Last active January 12, 2021 04:03
Show Gist options
  • Save koji/8e5f8ac4aa4bc753266594d99117827e to your computer and use it in GitHub Desktop.
Save koji/8e5f8ac4aa4bc753266594d99117827e to your computer and use it in GitHub Desktop.
Native UI Picker for SparkAR Studio
const Scene = require("Scene");
const NativeUI = require("NativeUI");
const Textures = require("Textures");
const Materials = require("Materials");
(async function () {
const button1 = await Textures.findFirst("texture0");
const button2 = await Textures.findFirst("texture1");
const button3 = await Textures.findFirst("texture2");
const mat1 = await Materials.findFirst("bgMaterial1");
const mat2 = await Materials.findFirst("bgMaterial2");
const mat3 = await Materials.findFirst("bgMaterial3");
const bg = await Scene.root.findFirst("background");
const config = {
selectedIndex: 0,
items: [
{ image_texture: button1 },
{ image_texture: button2 },
{ image_texture: button3 },
],
mats: [{ material: mat1 }, { material: mat2 }, { material: mat3 }],
};
const picker = NativeUI.picker;
picker.configure(config);
picker.visible = true;
picker.selectedIndex.monitor().subscribe((val) => {
bg.material = config.mats[val.newValue].material;
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment