Giter Site home page Giter Site logo

maxxfrazer / scenekit-portalmask Goto Github PK

View Code? Open in Web Editor NEW
70.0 4.0 5.0 4.4 MB

Clean class to create a portal in SceneKit for use in ARKit.

License: MIT License

Ruby 15.74% Swift 78.05% Shell 6.20%
arkit portal augmented-reality scenekit swift ios arkit-plugin cocoapods pods

scenekit-portalmask's Introduction

SceneKit-PortalMask

Version License Platform Swift 5.0 Build Status

See my Medium post about this CocoaPod

This class PortalMask creates an occluding box around any rectangular frame, including a tracking image, which turns the tracking image or any static area into an Augmented Reality portal into a scene you can define inside that area that can be seen by looking through the defined portal. This can also be used to have the illusion of a hole in the ground.

Include this pod in your project: pod 'PortalMask'

The following example code creates a portal ontop of a tracking marker, similar to the example gif.

func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
	if let imageAnchor = anchor as? ARImageAnchor {
		let nodeRotated = SCNNode()
		nodeRotated.eulerAngles.x = -.pi / 2
		// the next 2 lines add the portal
		let portal = PortalMask(frameSize: imageAnchor.referenceImage.physicalSize)
		nodeRotated.addChildNode(portal)

		// the next 4 lines add a cube inside the image area
		let width = imageAnchor.referenceImage.physicalSize.width
		let boxNode = SCNNode(geometry: SCNBox(width: width, height: width, length: width, chamferRadius: 0))
		boxNode.position.z = -boxNode.width
		nodeRotated.addChildNode(boxNode)

		node.addChild(nodeRotated)
	}
}

Also contains functions for circular holes:

let portal = PortalMask(radius: imageAnchor.referenceImage.physicalSize.width)

And any other polygon by feeding coordinates. This example will make a triangular portal:

let portal = PortalMask(path: [CGPoint(x: 1, y: -1), CGPoint(x: 0, y: 1), CGPoint(x: -1, y: -1)])

Here's some basic examples of what you can do with this Pod:

Tracking Portal Example Flappy Bird Example

scenekit-portalmask's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.