Skip to content

Instantly share code, notes, and snippets.

@magicmikek
Created June 21, 2018 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magicmikek/0444fbd5c146131ad08fbb19875fbc83 to your computer and use it in GitHub Desktop.
Save magicmikek/0444fbd5c146131ad08fbb19875fbc83 to your computer and use it in GitHub Desktop.
self.updateQueue.async {
// Create a plane to visualize the initial position of the detected image.
print(referenceImage.physicalSize.width)
print(referenceImage.physicalSize.height)
let plane = SCNPlane(width: referenceImage.physicalSize.width,
height: referenceImage.physicalSize.height)
let planeNode = SCNNode(geometry: plane)
//planeNode.opacity = 0.25
planeNode.geometry?.firstMaterial?.writesToDepthBuffer = true
planeNode.geometry?.firstMaterial!.colorBufferWriteMask = .alpha
planeNode.renderingOrder = -1
/*
`SCNPlane` is vertically oriented in its local coordinate space, but
`ARImageAnchor` assumes the image is horizontal in its local space, so
rotate the plane to match.
*/
planeNode.eulerAngles.x = -.pi / 2
/*
Image anchors are not tracked after initial detection, so create an
animation that limits the duration for which the plane visualization appears.
*/
//planeNode.runAction(self.imageHighlightAction)
// Add the invisible plane to the scene for occlusion
node.addChildNode(planeNode)
// Create a plane to visualize the initial position of the detected image.
let titleplane = SCNPlane(width: referenceImage.physicalSize.width,
height: referenceImage.physicalSize.height)
titleplane.firstMaterial = self.drawImagesAndText(string: itemTitle, textColor: UIColor.white, fontSize: 40, fontWeight: UIFontWeightBold)
let titleplaneNode = SCNNode(geometry: titleplane)
titleplaneNode.position = SCNVector3Make(titleplaneNode.position.x, titleplaneNode.position.y, titleplaneNode.position.z/*+0.1*Float(referenceImage.physicalSize.height)*/)
titleplaneNode.eulerAngles.x = -.pi / 2
// Add the plane visualization to the scene.
node.addChildNode(titleplaneNode)
// Create a plane to visualize the initial position of the detected image.
let subtitleplane = SCNPlane(width: referenceImage.physicalSize.width,
height: referenceImage.physicalSize.height)
subtitleplane.firstMaterial = self.drawImagesAndText(string: itemSubTitle, textColor: UIColor.white, fontSize: 35, fontWeight: UIFontWeightMedium)
let subtitleplaneNode = SCNNode(geometry: subtitleplane)
subtitleplaneNode.position = SCNVector3Make(subtitleplaneNode.position.x, subtitleplaneNode.position.y, subtitleplaneNode.position.z+0.1*Float(referenceImage.physicalSize.height))
subtitleplaneNode.eulerAngles.x = -.pi / 2
// Add the plane visualization to the scene.
node.addChildNode(subtitleplaneNode)
// Create a plane to visualize the initial position of the detected image.
let descriptionplane = SCNPlane(width: referenceImage.physicalSize.width,
height: referenceImage.physicalSize.height)
descriptionplane.firstMaterial = self.drawImagesAndText(string: itemDescription, textColor: UIColor.white, fontSize: 30, fontWeight: UIFontWeightLight)
let descriptionplaneNode = SCNNode(geometry: descriptionplane)
descriptionplaneNode.position = SCNVector3Make(descriptionplaneNode.position.x, descriptionplaneNode.position.y, descriptionplaneNode.position.z+0.2*Float(referenceImage.physicalSize.height))
descriptionplaneNode.eulerAngles.x = -.pi / 2
// Add the plane visualization to the scene.
node.addChildNode(descriptionplaneNode)
// create a web view
let tvPlane = SCNPlane(width: 0.1,
height: 0.1)
tvPlane.firstMaterial?.diffuse.contents = self.webView
//tvPlane.firstMaterial?.isDoubleSided = true
let tvPlaneNode = SCNNode(geometry: tvPlane)
tvPlaneNode.eulerAngles.x = -.pi / 2
print(tvPlaneNode.renderingOrder)
node.addChildNode(tvPlaneNode)
let tvwaitAction = SCNAction.wait(duration: 2.0)
let tvMoveAction = SCNAction.move(by: SCNVector3(-1.05*Float(referenceImage.physicalSize.width), 0, 0), duration: 1.0)
let tvSequence = SCNAction.sequence([tvwaitAction,tvMoveAction])
tvPlaneNode.runAction(tvSequence)
//animate text in ar
let moveRight = SCNAction.move(by: SCNVector3(1.05*Float(referenceImage.physicalSize.width), 0, 0), duration: 1.0)
let waitAction = SCNAction.wait(duration: 3.0)
let titleSequence = SCNAction.sequence([waitAction,moveRight])
titleplaneNode.runAction(titleSequence)
let subtitleSequence = SCNAction.sequence([waitAction,moveRight])
subtitleplaneNode.runAction(subtitleSequence)
let descriptionSequence = SCNAction.sequence([waitAction,moveRight])
descriptionplaneNode.runAction(descriptionSequence)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment