天道酬勤,学无止境

scnnode

Xcode 7 SceneKit 对象的位置属性在移动时不更新?(Xcode 7 SceneKit object's position property does not update when moved?)

问题 所以我正在制作一个游戏,在那个游戏中,你将使用 DPad 在场景中移动你的球。 我使用的是 Xcode 7 Beta 5,尽管 beta 4 中存在同样的问题。这是测试视图控制器的代码: class TestController: UIViewController,DPadDelegate { @IBOutlet var scnView:SCNView! @IBOutlet var dpad:DPad! var timer:NSTimer? var update:NSTimer? var colors = [UIColor.blueColor(),UIColor.redColor(),UIColor.whiteColor(),UIColor.yellowColor(),UIColor.cyanColor(),UIColor.orangeColor(),UIColor.magentaColor(),UIColor.purpleColor()] var player:SCNNode! var camera:SCNNode = SCNNode() var i = 0 override func viewDidLoad() { super.viewDidLoad() NSTimer.scheduledTimerWithTimeInterval(2, target: self

2021-11-29 21:29:15    分类:技术分享    xcode   camera   scenekit   scnnode   xcode7-beta5

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

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 center. Instead it sits appearing to be levitating in air. It is acting like the physics body is a complete

2021-11-25 23:20:29    分类:问答    swift   scenekit   scnnode

Xcode 7 SceneKit object's position property does not update when moved?

So I'm making a game and in said game, you will use a DPad to move your ball around the scene. I'm using Xcode 7 Beta 5 though the same problem existed in beta 4. Here is the code of a test view controller: class TestController: UIViewController,DPadDelegate { @IBOutlet var scnView:SCNView! @IBOutlet var dpad:DPad! var timer:NSTimer? var update:NSTimer? var colors = [UIColor.blueColor(),UIColor.redColor(),UIColor.whiteColor(),UIColor.yellowColor(),UIColor.cyanColor(),UIColor.orangeColor(),UIColor.magentaColor(),UIColor.purpleColor()] var player:SCNNode! var camera:SCNNode = SCNNode() var i = 0

2021-11-21 03:13:19    分类:问答    xcode   camera   scenekit   scnnode   xcode7-beta5

cameranode随着iOS设备移动而旋转(cameranode rotate as iOS device moving)

问题 这是 360 度视频播放器项目。 我一个cameranode(添加SCNNode )为根节点,该cameranode被放于中心(0,0,0) SCNSphere ,它可以通过现在播放视频。 现在我必须使用devicemotion。 我需要在设备移动时旋转相机。 不只是旋转某个角度。 (不仅仅是设备移动,当我拿着设备时,我的移动视为设备移动。因为我发现如果我使用deviceMotion.attitude.roll ,cameranode 只在设备移动时移动,而不是当我用设备) 当设备位于(x1,y1,z1)位置时,cameranode会随着设备移动而旋转,当设备再次位于(x1,y1,z1)位置时,视图应该和我们上次离开的一样. 这是我所做的: if (self.motionManager.gyroAvailable) { self.motionManager.gyroUpdateInterval = 1.0/60.0; [self.motionManager startGyroUpdatesToQueue:self.queue withHandler:^(CMGyroData *gyroData, NSError *error){ if (error) { [self.motionManager stopGyroUpdates]; NSLog(@"Gyroscope

2021-11-20 10:53:53    分类:技术分享    ios   scenekit   cmmotionmanager   scnnode

SceneKit 获取旋转后的节点位置(SceneKit get node position after rotation)

问题 例如,我有两个SCNNode s,其中SCNBox几何形状一个接一个地增加x位置属性: SCNBox(width: 0, height: 0, length: 0.02, chamferRadius: 0) 然后我想使用带有SCNVector4 rotation属性旋转第一个,但是当旋转发生时,我希望我的第二个节点跟随第一个节点并根据第一个节点的旋转改变它的位置。 我在网上找到了这个解决方案,并试图打印节点的position 、 worldPosition和presentation.position但它们都是相同的值。 有人可以帮我找出旋转后如何获得节点的位置吗? 回答1 节点在旋转时的位置不会改变。 也许您可以考虑使用物理机制(例如SCNPhysicsHingeJoint连接节点? 我发现这个例子可能对你的场景有用: http://lepetit-prince.net/ios/?p=3540 另一个例子: http://appleengine.hatenablog.com/entry/2017/08/17/154852

2021-11-15 04:18:19    分类:技术分享    ios   swift   rotation   scenekit   scnnode

cameranode rotate as iOS device moving

It's 360 degree video player project. I add a cameranode(SCNNode) to a rootnode, the cameranode was put at the center(0,0,0) of the SCNSphere, It can play video by now. Now I have to use devicemotion. I need to rotate the camera when device moves. Not just rotate a certain angle. (Not just device move, When I'm holding a device, my moving regard as the device moving. because I found if I use deviceMotion.attitude.roll, the cameranode only moves when device moves by itself, not when I circle around with device) When device is located in (x1,y1,z1) position, the cameranode would rotate as the

2021-11-15 02:33:01    分类:问答    ios   scenekit   cmmotionmanager   scnnode

SceneKit get node position after rotation

For example I have two SCNNodes with SCNBox geometry positioned one after another increasing x position property: SCNBox(width: 0, height: 0, length: 0.02, chamferRadius: 0) Then I want to rotate the first one using rotation property with SCNVector4, but when rotation happens I want my second node to follow the first one and change its position according rotation of the first one. I found this solution on the web and tried to print node's position, worldPosition and presentation.position but they are all the same value. Can someone help me to find out how can I obtain node's position after

2021-11-11 04:10:54    分类:问答    ios   swift   rotation   scenekit   scnnode

SceneKit:在父级内部垂直居中缩放 SCNNode?(SceneKit: vertically center scaled SCNNode inside parent?)

问题 目标是缩放 SCNNode 并将其垂直居中在其父级内。 但是,缩放 SCNNode 不会影响其边界框,并且无法计算缩放后的高度。 如果没有准确的高度,您如何将节点垂直居中放置在其父节点内? 要说明使用缩放高度的问题,请参阅附件 Tiki.dae。 资产的原始高度(如边界框所示)为 324.36。 但是,如果将 Y 比例设置为 0.01,则高度不会变为 ~3.24。 它变得小于 3,您可以通过将其舒适地安装在高度为 3(半径为 1.5)的球体中来证明这一点。 下面的代码试图将缩放节点置于其父节点内,但它不起作用。 注意:参考节点是 WWDC 2015 fox 演示中的 fox/panda 参考节点。 // Create reference node let referenceNode = SCNReferenceNode(URL: referenceURL) referenceNode?.load() // Scale reference node let scale = Float(3) referenceNode?.scale = SCNVector3(x: scale, y: scale, z: scale) // Create geometry for sphere let sphereGeometry = SCNSphere(radius: (gridSphere

2021-11-10 14:29:26    分类:技术分享    ios   scenekit   scnnode

如何快速创建 SCNNode 数组(How to create an array of SCNNode in swift)

问题 我想创建一个基金来创建一个节点数组。 我的声明如下: func createSphereNode () { var spheres = [SCNNode()] let sphereGeometry = SCNSphere(radius: 2.5) let sphereMaterial = SCNMaterial() sphereMaterial.diffuse.contents = UIColor.greenColor() sphereGeometry.materials = [sphereMaterial] for var i=0;i<15;i++ { let gravityFields = SCNPhysicsField.radialGravityField() gravityFields .strength = 0 spheres[i] = SCNNode(geometry: sphereGeometry) spheres[i].position = SCNVector3(x: Float(-15 + (6 * i)), y: 1.5, z: 0) spheres[i].physicsField = gravityFields let shape = SCNPhysicsShape(geometry: sphereGeometry, options: nil) let

2021-11-09 16:35:21    分类:技术分享    arrays   swift   scenekit   scnnode

How to create an array of SCNNode in swift

I want to create a fund to create an array of nodes. My declaration is as follows: func createSphereNode () { var spheres = [SCNNode()] let sphereGeometry = SCNSphere(radius: 2.5) let sphereMaterial = SCNMaterial() sphereMaterial.diffuse.contents = UIColor.greenColor() sphereGeometry.materials = [sphereMaterial] for var i=0;i<15;i++ { let gravityFields = SCNPhysicsField.radialGravityField() gravityFields .strength = 0 spheres[i] = SCNNode(geometry: sphereGeometry) spheres[i].position = SCNVector3(x: Float(-15 + (6 * i)), y: 1.5, z: 0) spheres[i].physicsField = gravityFields let shape =

2021-11-06 02:38:55    分类:问答    arrays   swift   scenekit   scnnode