Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yearofthewhopper/71da10b7b5f1a7ee448371514e58e0c4 to your computer and use it in GitHub Desktop.
Save yearofthewhopper/71da10b7b5f1a7ee448371514e58e0c4 to your computer and use it in GitHub Desktop.
//// I adapted this very slightly from the sparkar docs to use with world template as is https://sparkar.facebook.com/ar-studio/learn/tutorials/scripting?utm_campaign=welcome_screen_learn_more&utm_medium=learn&utm_offering=spark-ar&utm_product=spark-ar&utm_source=product#scaling-the-boombox-with-pinch-gestures
const Scene = require('Scene');
const TouchGestures = require('TouchGestures');
const sceneRoot = Scene.root;
Promise.all([
sceneRoot.findFirst('planeTracker0'),
sceneRoot.findFirst('dragHere')
])
.then(function (objects) {
const planeTracker = objects[0];
const placer = objects[1];
TouchGestures.onPan().subscribe(function (gesture) {
planeTracker.trackPoint(gesture.location, gesture.state);
});
const placerTransform = placer.transform;
TouchGestures.onPinch().subscribeWithSnapshot({
'lastScaleX': placerTransform.scaleX,
'lastScaleY': placerTransform.scaleY,
'lastScaleZ': placerTransform.scaleZ
}, function (gesture, snapshot) {
placerTransform.scaleX = gesture.scale.mul(snapshot.lastScaleX);
placerTransform.scaleY = gesture.scale.mul(snapshot.lastScaleY);
placerTransform.scaleZ = gesture.scale.mul(snapshot.lastScaleZ);
});
TouchGestures.onRotate().subscribeWithSnapshot({
'lastRotationY': placerTransform.rotationY,
}, function (gesture, snapshot) {
const correctRotation = gesture.rotation.mul(-1);
placerTransform.rotationY = correctRotation.add(snapshot.lastRotationY);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment