scnnode

ARKit - How to contain SCNText within another SCNNode (speech bubble)

耗尽温柔 提交于 2019-12-21 06:23:06
问题 I am trying to create a quote generator with simple text within a speech bubble in ARKit. I can show the speech bubble with text, but the text always starts in the middle and overflows outside of the speech bubble. Any help getting it align in the top left of the speech bubble and wrapping within the speech bubble would be appreciated. Result Classes class SpeechBubbleNode: SCNNode { private let textNode = TextNode() var string: String? { didSet { textNode.string = string } } override init()

Tube Physics Body acting like SCNCylinder, but how to make it act like SCNTube?

≡放荡痞女 提交于 2019-12-20 02:56:12
问题 I am trying to make a tube and its physics body like so in SceneKit. let BoxGeometry = SCNTube(innerRadius: 5, outerRadius: 12.5, height: 4) Box = SCNNode(geometry: BoxGeometry) Box.pivot = SCNMatrix4MakeRotation(Float(M_PI_2/8), 0, 1, 0) Box.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.Static, shape: nil) Box.physicsBody?.mass = 5 Box.categoryBitMask = colorCategory scene.rootNode.addChildNode(Box) However, when another object falls onto this object it does not pass through the

Rotate SCNNode relative local coordinates

别等时光非礼了梦想. 提交于 2019-12-20 01:14:27
问题 I'm trying to rotate a node by SCNAction , but it rotates relative to parent’s coordinate space. Is it possible to rotate a node relative local's coordinate system? 回答1: Sure. You can obtain parent's space coordinates for rotation axis with convertVector method. For example, this action will do 180 degrees rotation around local x-axis: SCNAction.rotate(by: .pi, around: node.convertVector(SCNVector3(1, 0, 0), to: node.parent), duration: TimeInterval(5)) 回答2: Have you tried: [node runAction:

removing SCNNode does not free memory before creating new SCNNode

孤人 提交于 2019-12-19 08:11:49
问题 I am building an app that uses Scenekit to display a scene based on information returned from a data base. I have created a custom class with a class func that creates a SCNNode containing everything that needs to be drawn and returns it to my SCNView. Before calling this function I remove any existing nodes. Everything works great until I need to call it a second time. After removing the old SCNNode The memory is not deallocated before creating the new one. Is there a standard way of

SCNBox different colour or texture on each face

时光毁灭记忆、已成空白 提交于 2019-12-17 17:42:08
问题 I'm new to iOS development and I've got myself stumped. I am trying to render a cube using SceneKit that has a different colour for each face. This is what I've got so far: func sceneSetup() { // 1 let scene = SCNScene() // 2 let BoxGeometry = SCNBox(width: 0.9, height: 0.9, length: 0.9, chamferRadius: 0.0) BoxGeometry.firstMaterial?.diffuse.contents = UIColor.redColor() let cube = SCNNode(geometry: BoxGeometry) cube.position = SCNVector3(x: 0, y: 0, z: -1) scene.rootNode.addChildNode(cube) /

SCNBox different colour or texture on each face

浪子不回头ぞ 提交于 2019-12-17 17:42:08
问题 I'm new to iOS development and I've got myself stumped. I am trying to render a cube using SceneKit that has a different colour for each face. This is what I've got so far: func sceneSetup() { // 1 let scene = SCNScene() // 2 let BoxGeometry = SCNBox(width: 0.9, height: 0.9, length: 0.9, chamferRadius: 0.0) BoxGeometry.firstMaterial?.diffuse.contents = UIColor.redColor() let cube = SCNNode(geometry: BoxGeometry) cube.position = SCNVector3(x: 0, y: 0, z: -1) scene.rootNode.addChildNode(cube) /

How to create a SCNNode from a .usdz?

耗尽温柔 提交于 2019-12-13 15:27:15
问题 I have downloaded the .usdz models provided by Apple: https://developer.apple.com/arkit/gallery/ But now, I want to create a SCNNode with one of these models, so I am doing this to obtain the node: guard let urlPath = Bundle.main.url(forResource: "retrotv", withExtension: "usdz") else { return } let mdlAsset = MDLAsset(url: urlPath) let modelRootNode = SCNScene(mdlAsset: mdlAsset).rootNode Then I add it to the scene and the result is this: Why does it have no textures? I have the downloaded

Get the direction arrow toward the SCNNode once that node is not visible in ARCamera

本秂侑毒 提交于 2019-12-13 12:41:18
问题 If ARCamera moving left, right, up or down and if that node becomes invisible in ARCamera. I want to indicate the arrow that you need to move camera up/down/right/left. 回答1: if let pointOfView = sceneView.pointOfView{ let isMaybeVisible = sceneView.isNode((displayNode.presentation), insideFrustumOf: pointOfView) if isMaybeVisible{ if arrowVisible{ arrow.removeFromParentNode() } }else{ if !arrowVisible{ sceneView.pointOfView?.addChildNode(arrow) } } } isNode(_:insideFrustumOf:) here checks if

SCNAction to change color of node works once, then never again

走远了吗. 提交于 2019-12-13 03:49:45
问题 Still getting my bearings with Swift, be gentle ;-) I have set up an action to change the color of a node, which I call every few seconds. It works like a charm on the first call, but after that the color remains the same. My code: let duration: TimeInterval = 3 var myRed = 255 var myGreen = 0 var myBlue = 0 var voltage: UInt32 = 0 { willSet(newV) { } didSet { myGreen = Int.random(in: 0...255) let act1 = SCNAction.customAction(duration: duration, action: { (node, elapsedTime) in let

Get vector in SCNNode environment from touch location swift

倖福魔咒の 提交于 2019-12-12 04:14:17
问题 I have the position and orientation of my camera, the CGPoint touch location on the screen, I need the line (preferably vector) in the direction that I touched on the screen in my 3d SCNNode environment, how can I get this? A code snippet would be very helpful. 回答1: You can use the SCNSceneRenderer.unprojectPoint(_:) method for this. This method, which is implemented by SCNView , takes the coordinates of your point as a SCNVector3 . Set the first two elements in the coordinate space of your