instructions

ARKit series of articles directory

Ray Wenderlich’s ARKit by Tutorials is a summary of his reading notes

The book has three free chapters on how to make a portal app: Chapter 7, chapter 8 and Chapter 9, which I have fully translated, and here is a summary and reflection of the following three chapters:

  • Create a portal App in ARKit: Ready to go
  • Create a portal App in ARKit: Add objects
  • Create a space-time gate App in ARKit: Textures and lighting

First: Get Ready to Start

Mainly about the initial preparation, the start of ARSession, plane detection,debug options

Part two: Adding objects

To add an anchor point to the center of the screen

var viewCenter: CGPoint {
  let viewBounds = view.bounds
  return CGPoint(x: viewBounds.width / 2.0, y: viewBounds.height / 2.0)}/ / 1
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  / / 2
  if lethit = sceneView? .hitTest(viewCenter, types: [.existingPlaneUsingExtent]).first {/ / 3sceneView? .session.add(anchor:ARAnchor.init(transform: hit.worldTransform))      
  }
}
Copy the code

With a hit test, you know if the center of the screen is aligned to a plane

This allows you to click on the screen to add 3D objects when you are aligned with the plane

Part three: Materials and lighting

It mainly discusses the actual use of a lot of materials and textures, including wrapT and wrapS, such as Wrapping mode

And the use of lights

The most interesting part of this chapter is how to make the door invisible from the outside (only the frame can be seen from the outside), but everything can be seen from the inside. Here’s the effect:

This is amazing: a layer of almost transparent geometry is placed on the outside of the wall (SCNBox transparency = 0.000001), and the renderingOrder of the outer layer is controlled so that it renders before the inner object

func makeOuterSurfaceNode(width: CGFloat, height: CGFloat, length: CGFloat) -> SCNNode {
  / / 1
  let outerSurface = SCNBox(width: width,
                            height: height,
                            length: length,
                            chamferRadius: 0)

  / / 2outerSurface.firstMaterial? .diffuse.contents =UIColor.white outerSurface.firstMaterial? .transparency =0.000001

  / / 3
  let outerSurfaceNode = SCNNode(geometry: outerSurface)
  outerSurfaceNode.renderingOrder = 10
  return outerSurfaceNode
}
Copy the code

Explanation of code:

  1. Create an outerSurface scene cube geometry object with the same dimensions as the floor and ceiling.
  2. Add visible content to the diffuse properties of the cube object to render it out. Set Transparency to a very low value so that the object is hidden from view.
  3. Create an SCNNode object from the outerSurface geometry. Set the renderingOrder of the node to 10. The larger the render order value of a node, the later it will be rendered. In order to make the floor and ceiling invisible from outside the portal, you will need to render the internal ceiling and floor nodes in a rendering order much larger than 10.

Since the production process of the Spacegate app has been officially released as a free chapter, I have translated it all. This article only lists the key points, if necessary, please read the original or translation closely.

Since the release of ARKit, there have been a lot of demos on the Internet like spacegate, but many people only showed the video effects, not the code. I believe that most people like me, although the overall feeling is not difficult, but still do not understand how to achieve the effect of the outside can not see the wall, this book finally helps us to solve the mystery.

Part two Reading notes end!