Skip to content

Instantly share code, notes, and snippets.

@shawwn
Created May 21, 2019 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawwn/106e642ba5d1e4e3a0309a8fbdd9f9b1 to your computer and use it in GitHub Desktop.
Save shawwn/106e642ba5d1e4e3a0309a8fbdd9f9b1 to your computer and use it in GitHub Desktop.
const SweetieKit = require('std:sweetiekit.node');
THREE = require('../vendor/three/three');
const {
ARSKView,
ARSKViewDelegate,
ARWorldTrackingConfiguration,
SKLabelNode,
SKScene,
ARAnchor,
} = SweetieKit;
async function make(nav, demoVC) {
const view = demoVC.view;
const arView = new ARSKView({ x: 0, y: 0, width: view.frame.width, height: view.frame.height });
const config = new ARWorldTrackingConfiguration();
const chars = [];
const viewDel = new ARSKViewDelegate((view, anchor) => {
const node = new SKLabelNode();
node.text = '@';
chars.push({anchor, node});
return node;
});
const scene = SKScene.sceneWithSize({ width: view.frame.width, height: view.frame.height });
arView.delegate = viewDel;
arView.scene = scene;
scene.touchesEnded = (touches) => {
const camXform = arView.session.currentFrame.camera.transform;
const translation = new THREE.Matrix4().makeTranslation(0,0,-40/1000);
const view = new THREE.Matrix4().fromArray(camXform);
view.multiply(translation);
const anchor = ARAnchor.initWithTransform(view);
arView.session.add(anchor);
};
demoVC.view.addSubview(arView);
nav.pushViewController(demoVC);
arView.presentScene(scene);
arView.viewWillAppear = () => {
arView.session.run(config);
}
}
module.exports = make;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment