Code Monkey home page Code Monkey logo

ar-ane's Introduction

Adobe AIR + ARKit

ARKit Adobe Air Native Extension for iOS 11.0+ This ANE provides bindings for the ARKit API


Much time, skill and effort has gone into this. Help support the project

paypal


The ANE + Dependencies

N.B. You must use a Mac to build an iOS app using this ANE. Windows is NOT supported.

From the command line cd into /example and run:

bash get_ios_dependencies.sh

This folder, ios_dependencies/device/Frameworks, must be packaged as part of your app when creating the ipa. How this is done will depend on the IDE you are using.
After the ipa is created unzip it and confirm there is a "Frameworks" folder in the root of the .app package.

Getting Started

Firstly, familiarise yourself with the concepts of Apple's ARKit. This ANE is at its core a binding for the ARKit APIs.

Usage

arkit = ARANE.arkit;
if (!arkit.isSupported) {
    trace("ARKIT is NOT Supported on this device");
    return;
}

arkit.view3D.showsStatistics = false;
arkit.view3D.automaticallyUpdatesLighting = true;
arkit.view3D.antialiasingMode = AntialiasingMode.multisampling4X;
arkit.view3D.init();
var config:WorldTrackingConfiguration = new WorldTrackingConfiguration();
config.planeDetection = PlaneDetection.horizontal;
arkit.view3D.session.run(config, [RunOptions.resetTracking, RunOptions.removeExistingAnchors]);

Geometries

The following geometries based on their SCNKit equivalents are available: Box, Sphere, Capsule, Cone, Cylinder, Plane, Pyramid, Torus, Tube

Example

var cone:Cone = new Cone(0, 0.05, 0.1);
var node:Node = new Node(cone);
arkit.view3D.scene.rootNode.addChildNode(node);

Materials

Materials can be supplied as:
ARGB uint
BitmapData
String path to image file

Example

box.firstMaterial.diffuse.contents = ColorARGB.RED;

sphere.firstMaterial.diffuse.contents = "materials/globe.png";

//supply 6 materials for 6 sides of box
box.materials = new <Material>[redMat, greenMat, blueMat, yellowMat, brownMat, whiteMat];

Physics

Example

var box:Box = new Box(0.1, 0.1, 0.1);
box.firstMaterial.diffuse.contents = ColorARGB.ORANGE;
var boxNode:Node = new Node(box);
var boxShape:PhysicsShape = new PhysicsShape(box);
var physicsBody:PhysicsBody = new PhysicsBody(PhysicsBodyType.dynamic, boxShape);
physicsBody.allowsResting = true;

boxNode.physicsBody = physicsBody;
boxNode.position = new Vector3D(0, 0.5, 0);

arkit.view3D.scene.rootNode.addChildNode(boxNode);

Detecting Planes

Example

arkit = ARANE.arkit;
arkit.addEventListener(PlaneDetectedEvent.ON_PLANE_DETECTED, onPlaneDetected);

private function onPlaneDetected(event:PlaneDetectedEvent):void {
    var planeAnchor:PlaneAnchor = event.anchor;
    var node:Node = event.node;
    
    var plane:Box = new Box(planeAnchor.extent.x, planeAnchor.extent.z, 0);
    var gridTexture:String = "materials/grid.png";
    plane.firstMaterial.diffuse.contents = gridTexture;
    
    var planeNode:Node = new Node(plane);
    planeNode.position = new Vector3D(planeAnchor.center.x, 0, planeAnchor.center.z)
    var boxShape:PhysicsShape = new PhysicsShape(plane);
    planeNode.physicsBody = new PhysicsBody(PhysicsBodyType.static, boxShape);
    planeNode.eulerAngles = new Vector3D(-Math.PI / 2, 0, 0);
    node.addChildNode(planeNode);
}

Camera Tracking

Example

arkit = ARANE.arkit;
arkit.addEventListener(CameraTrackingEvent.ON_STATE_CHANGE, onCameraTrackingStateChange);

private function onCameraTrackingStateChange(event:CameraTrackingEvent):void {
    switch (event.state) {
        case TrackingState.notAvailable:
            break;
        case TrackingState.normal:
            break;
        case TrackingState.limited:
            switch (event.reason) {
                case TrackingStateReason.excessiveMotion:
                    break;
                case TrackingStateReason.initializing:
                    break;
                case TrackingStateReason.insufficientFeatures:
                    break;
            }
            break;
    }
}

Detecting Touches

arkit = ARANE.arkit;
arkit.addEventListener(TapEvent.ON_SCENE3D_TAP, onSceneTapped);
private function onSceneTapped(event:TapEvent):void {
    if (event.location) {
        // look for planes
        var arHitTestResult:ARHitTestResult = arkit.view3D.hitTest3D(event.location, [HitTestResultType.existingPlaneUsingExtent]);
        if (arHitTestResult) {
        //plane tapped
        }
        
        var hitTestResult:HitTestResult = arkit.view3D.hitTest(event.location, new HitTestOptions());
        trace("hitTestResult", hitTestResult);
        if (hitTestResult) {
        // node tapped on
        }
    }
}

Running on Simulator

ARKit won't run on the simulator

Running on Device

The example project can be run on the device from IntelliJ using AIR 28.

Issues

The Issues section is for bugs and API requests only.
Use the supplied template or the ticket will be closed.
Paid Premium support is available.

Contributing

If you have knowledge of ARKit contributions are welcome. This includes adding documentation, sample code and Scenekit models.
Likewise, sponsorship or donations will go a long way to pushing the ANE further along.

Prerequisites

You will need:

  • a Mac. Windows is not supported
  • an iOS device with an A9 or later processor
  • IntelliJ IDEA / Flash Builder
  • AIR 28
  • Xcode 9.1 if you wish to edit the iOS source
  • wget on OSX

Task List

  • Planes
    • Horizontal Plane Detection
    • Vertical Plane Detection (iOS 11.3)
    • Plane Updates
    • Plane Removal
    • Apple Sample 'Focus Square'
  • Geometry
    • Box
    • Capsule
    • Cone
    • Cylinder
    • Plane
    • Pyramid
    • Shape (from SVG)
    • Sphere
    • Models
      • from .scn
      • from .dae
    • Text
    • Torus
    • Tube
  • Lighting
  • Materials
    • Colour
    • Image
    • BitmapData
  • Physics
    • Body
    • Collision Events
    • Vehicle
  • Animation
  • Camera
    • Tracking
    • Autofocus (iOS 11.3)
  • Touch
    • Tap
    • Swipe
    • Pinch
    • Long Press
  • Permissions
    • Camera
  • Hit Test
    • Planes
    • Nodes
  • Record AR Scene
    • From Camera (iOS 11.3)

References

ar-ane's People

Contributors

tuarua avatar

Watchers

James Cloos avatar Nikolay Shishenkov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.