Created
May 21, 2019 06:08
-
-
Save shawwn/106e642ba5d1e4e3a0309a8fbdd9f9b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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