PortalMask 1.3.2

PortalMask 1.3.2

Max Cobb 维护。



  • Max Cobb

SceneKit-PortalMask

Version License Platform Swift 5.0 Build Status

查看我关于这个 CocoaPod 的 Medium 文章

PortalMask 类在任意矩形框架周围创建一个遮挡框,包括跟踪图像,将跟踪图像或任何静止区域变成查看定义在该区域场景的增强现实入口。这也可以用来制造地面有洞的幻觉。

将此 pod 包含到您的项目中:pod 'PortalMask'

以下示例代码在一个跟踪标记上创建了一个入口,类似于示例 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)
	}
}

还包含用于圆形孔的函数

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

和通过输入坐标的任意多边形。此示例将创建一个三角形入口

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

以下是您可以用这个 Pod 做的一些基本示例

Tracking Portal Example Flappy Bird Example