Swiftpack.co -  maxxfrazer/SceneKit-PortalMask as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
maxxfrazer/SceneKit-PortalMask
Clean class to create a portal in SceneKit for use in ARKit.
.package(url: "https://github.com/maxxfrazer/SceneKit-PortalMask.git", from: "v1.3.2")

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

GitHub

link
Stars: 53
Last commit: 1 year ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

Added Swift PM
2 years ago

No code updates, only restructure and supporting Swift Package Manager

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics