scenekit

SceneKit - What orthographicProjection to use for 1:1 points to SceneKit position ratio

旧巷老猫 提交于 2019-12-21 22:04:14
问题 What orthographicProjection does one have to use to be able to make a 2D application in SceneKit with 1:1 SceneKit points to screen points/pixels ratio? Example: I want to position something at (200, 200) on the screen and I want to use a SCNVector with (200, 200, 0) for it. What orthographicProjection do I need for this? 回答1: If you want an orthographic projection where a unit of scene space corresponds to a point of screen space, you need a projection where the left clipping plane is at

Rotate a node using pan gesture in SceneKit iOS

北战南征 提交于 2019-12-21 20:21:53
问题 I am using the below code to rotate a node using the pan gesture. I like to rotate my node only in the y-axis. let translation = gestureRecognize.translation(in: gestureRecognize.view!) let x = Float(translation.x) let y = Float(-translation.y) let anglePan = (sqrt(pow(x,2)+pow(y,2)))*(Float)(Double.pi)/180.0 var rotationVector = SCNVector4() rotationVector.x = 0.0 rotationVector.y = x rotationVector.z = 0.0 rotationVector.w = anglePan node.rotation = rotationVector if(gestureRecognize.state

Can CATransform3D be used to get eye size dimensions in Face Mesh?

给你一囗甜甜゛ 提交于 2019-12-21 16:57:57
问题 I am trying to get width of the eyes and distance of 2 eyes using 3D Face Mesh of ARKit. I have used CATransform3D of ARAnchor ; struct CATransform3D { CGFloat m11, m12, m13, m14; CGFloat m21, m22, m23, m24; CGFloat m31, m32, m33, m34; CGFloat m41, m42, m43, m44; }; Below is my code; func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) { guard let faceAnchor = anchor as? ARFaceAnchor else { return } let leftcaTransform3DValue : CATransform3D = (faceAnchor

How to avoid roll in SceneKit camera controlled by Core Motion?

自作多情 提交于 2019-12-21 12:54:08
问题 I'm setting my SceneKit camera to the current CMDeviceMotion attitude using the CMDeviceMotion extension described in this answer: func deviceDidMove(motion: CMDeviceMotion?, error: NSError?) { if let motion = motion { let orientation = motion.gaze(atOrientation: UIApplication.sharedApplication().statusBarOrientation) cameraNode.orientation = orientation } } This works beautifully, however, I'd like to block the rotation (roll) and only allow the camera to turn around (yaw) and pitch. I tried

Write text on sphere surface SceneKit?

戏子无情 提交于 2019-12-21 12:29:07
问题 I am wondering if there is a way to write text along a surface of a sphere object in SceneKit. I know I put a texture on the surface and achieve this kind of effect if I have an image, but I want to know if I can just add text dynamically somehow over the surface of the sphere. Any idea? EDIT: This works: let layer = CALayer() layer.frame = CGRectMake(0, 0, 100, 100) layer.backgroundColor = UIColor.orangeColor().CGColor var textLayer = CATextLayer() textLayer.frame = layer.bounds textLayer

Xcode 6.1 Swift issue - 'init()' is unavailable: superseded by import of -[NSObject init]

荒凉一梦 提交于 2019-12-21 07:09:14
问题 I have just upgraded my Xcode to 6.1 an am now getting a strange compilation error. 'init()' is unavailable: superseded by import of -[NSObject init] I am subclassing SCNNode and have a optional references to other classes of the same type I am defining. i.e. import UIKit import SceneKit class BayNode: SCNNode { var leftBay:BayNode? var rightBay:BayNode? func addLeftBay() { leftBay = BayNode() // 'init()' is unavailable: superseded by import of -[NSObject init] } } Does anybody know how I can

Convert an image to a SceneKit Node

老子叫甜甜 提交于 2019-12-21 06:05:04
问题 I have a bit-map image: ( However this should work with any arbitrary image ) I want to take my image and make it a 3D SCNNode. I've accomplished that much with this code. That takes each pixel in the image and creates a SCNNode with a SCNBox geometry. static inline SCNNode* NodeFromSprite(const UIImage* image) { SCNNode *node = [SCNNode node]; CFDataRef pixelData = CGDataProviderCopyData(CGImageGetDataProvider(image.CGImage)); const UInt8* data = CFDataGetBytePtr(pixelData); for (int x = 0;

SceneKit: How to detect contact without collision

微笑、不失礼 提交于 2019-12-21 05:37:12
问题 I'm looking for the best way (performace-wise) to detect contact between two objects that do not collide (not bounce off each other) in a SceneKit physics world. I saw that SpriteKit has a contactTestBitMask and a collisionBitMask for physics bodies while SceneKit only has the latter. So there must to be another preferred way to get notified when objects have contact in SceneKit. I guess that calling contactTestBetweenBody:andBody:options: in each frame for each object is not the best way to

How to use multiple cameras for the same scene in Scene Kit

喜欢而已 提交于 2019-12-21 02:46:06
问题 I have 2 SCNViews next to each other and both should show the same scene but through different cameras. It seems to me that Scene Kit uses that node with a camera that is highest in the node hierarchy so I tried something like that leftSceneView.scene?.rootNode.addChildNode(scene.rootNode) rightSceneView.scene?.rootNode.addChildNode(scene.rootNode) leftSceneView.scene?.rootNode.addChildNode(cameraNodeLeft) rightSceneView.scene?.rootNode.addChildNode(cameraNodeRight) but I got the error

Get “up” side of SCNNode from Orientation

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 02:41:32
问题 I have an SCNBox in an SCNScene. Once the scene animates the SCNBox changes is orientation which can be seen by checking its presentationNode.orientation . This value is returned in an SCNVector4. How do I determine which side of the SCNBox is the up facing side from the values returned in the SCNVector4? I have tried to normalize the data and came up with the following data Side 1 = (-x, 0, 0, +x) Side 2 = (0, -x, 0 +y) Side 3 = (-x, +x, -y, y) Side 4 = (x, x, y, y) Side 5 = (-x, 0, +y, 0)