How can I add a 2dView having text in the ARkit iOS scene

How can I add 2dView with text to the ARKit iOS scene. How can I add this view at the top of the node, which will not rotate when the node rotates.enter image description here

+8
source share
2 answers

You can add SCNPlaneand use it SCNLookAtConstraintso that the plane always looks at the camera.

You can create a custom material and set its material properties :

  • Color (UIColor or CGColor), defining a constant color on the surface of materials Number (

  • An image (UIImage or CGImage) that defines the texture displayed on the surface of materials.

  • (CALayer)
  • (SKTexture, MDLTexture, MTLTexture GLKTextureInfo)
  • SpriteKit (SKScene)

CoreAnimation SpriteKit,

SceneKit , (, UIView)


SpriteKit:

  • SpriteKit:

:.

let skScene = SKScene(size: CGSize(width: 200, height: 200))
skScene.backgroundColor = UIColor.clear

let rectangle = SKShapeNode(rect: CGRect(x: 0, y: 0, width: 200, height: 200), cornerRadius: 10)
rectangle.fillColor = #colorLiteral(red: 0.807843148708344, green: 0.0274509806185961, blue: 0.333333343267441, alpha: 1.0)
rectangle.strokeColor = #colorLiteral(red: 0.439215689897537, green: 0.0117647061124444, blue: 0.192156866192818, alpha: 1.0)
rectangle.lineWidth = 5
rectangle.alpha = 0.4
let labelNode = SKLabelNode(text: "Hello World")
labelNode.fontSize = 20
labelNode.fontName = "San Fransisco"
labelNode.position = CGPoint(x:100,y:100)
skScene.addChild(rectangle)
skScene.addChild(labelNode)
  1. .

.

let plane = SCNPlane(width: 20, height: 20)
let material = SCNMaterial()
material.isDoubleSided = true
material.diffuse.contents = skScene
plane.materials = [material]
let node = SCNNode(geometry: plane)
scene.rootNode.addChildNode(node)

.

labelNode.run(SKAction.repeatForever(SKAction.rotate(byAngle: .pi, duration: 2)))

enter image description here

+17
0

All Articles