scenekit

Subclassing SCNScene and SceneKit Editor

拈花ヽ惹草 提交于 2019-12-02 13:16:12
I have SCNScene subclass with a camera setup, that I want to use in all the subclasses. let scene01 = TheSubclassScene() let scene02 = TheSubclassScene(named:"art.scnassets/testScene.scn")! self.sceneArray.addObject(scene01) self.sceneArray.addObject(scene02) I want to change the scenes at runtime. This works when I create the scene in code but not with a scene from the SceneKit Editor. So scene01 is working but scene02 isn't. In the debugger I can see the two scenes in the array. One is of type SCNSceneSubclass but the other is of type SCNScene. Is there any way to get this working? Update:

How do I change location of pivot point in SceneKit

风格不统一 提交于 2019-12-02 12:59:59
问题 I'm trying to move pivot point to the center of an object so it rotates around its center. How can I do this? I see no option in Xcode editor for doing this. I tried changing the pivot point programmatically: // create a new scene let scene = SCNScene(named: "art.scnassets/Heart.scn")! // change pivot point scene.rootNode.pivot = SCNMatrix4MakeTranslation(0.5, 0.5, 0.5) But it doesn't work either, the object still rotates around its old pivot point. 回答1: The heart is (probably) not the root

Drag object on XZ plane

可紊 提交于 2019-12-02 12:43:28
问题 I am working on an augmented reality app and I would like to be able to drag an object in the space. The problem with the solutions I find here in SO, the ones that suggest using projectPoint / unprojectPoint , is that they produce movement along the XY plane. I was trying to use the fingers movement on the screen as an offset for x and z coordinates of the node. The problem is that there is a lot of stuff to take in consideration (camera's position, node's position, node's rotation, etc..)

Node group's position is reset at the start of SCNNode.runAction

风格不统一 提交于 2019-12-02 12:36:57
I have some code that rotates several SCNNodes around the x axis when the screen is tapped like so: func handleTap(gestureRecognize: UIGestureRecognizer) { let sceneView = self.view as SCNView let slice = self.cubes[0...8] let container = SCNNode() for node: SCNNode in slice { container.addChildNode(node) } sceneView.scene!.rootNode.addChildNode(container) container.runAction(SCNAction.rotateByX(CGFloat(M_PI / 2), y: 0.0, z: 0.0, duration: 1), completionHandler: { () -> Void in println("complete") }) } The issue that I'm running into is that every time this function is called, the nodes seem

Applying simple Physics to a .scn object in SceneKit XCODE SWIFT

半城伤御伤魂 提交于 2019-12-02 11:07:49
Hey Below I have a normal sphere that I created just to test if my in game scene/world has physics. So I simply put the ball in the scene/world and it is perfect. It is affected by the gravity. So then I try to do the exact same thing to the .scn file. I give it physics the same as the test sphere that falls down do to gravity. but the man doesn't move. The gravity is set to -9.8 to simulate regular gravity Code: //----Test-Circle-here-------------------- var sphere1: SCNNode! let sphereGeometry = SCNSphere(radius: 10.5) let sphereMaterial = SCNMaterial() let collisionCapsuleRadius = CGFloat(0

App Crashs on Touch of the screen Scenekit with a overlayskscene Xcode Swift

别来无恙 提交于 2019-12-02 10:17:53
Hey ok what is the best way to recognize touch for a HUD on a scene kit 3D game on a Overlayskscene. because i have a button called "AButton" but when ever i touch the Button or the screen the game crashes after hours of search I'm guessing the problem is the touchbegin on the scene kit don't exactly get along. But then how do i make it so that when a user touches a button on the HUD it doesn't crash the system and it actually works. can you look at my code and rewrite it. do i use touches begin or do i us hit test or something else (I never have used hit test before)? handleTap:]:

Creating path using CGMutablePath creates line to wrong CGPoint

丶灬走出姿态 提交于 2019-12-02 09:19:32
I was planning to display information of AR object in screen with arrow in 2D. So I used projectPoint to get corresponding position of object in screen. I have this function to return convert 3D position of node to 2D and CGPoint to display info text in. func getPoint(sceneView: ARSCNView) -> (CGPoint, CGPoint){ let projectedPoint = sceneView.projectPoint(node.worldPosition) return (point, CGPoint(x: CGFloat(projectedPoint.x), y: CGFloat(projectedPoint.y)) ) } and this to draw line using SpriteKit : let (f,s) = parts[3].getPoint(sceneView: sceneView) line.removeFromParent() let path =

SCNMaterial: can't find init:mdlMaterial:

人盡茶涼 提交于 2019-12-02 08:38:23
问题 I'm trying to add a bump map to a material and since apparently there is no way to do it with a plain SCNMaterial, I just tried to use a MDLMaterial instead, and then convert it to a SCNMaterial. There is a method in the Apple documentation for this: convenience init(MDLMaterial mdlMaterial: MDLMaterial) But I keep getting an error: /Users/ramy/Documents/Swift/Space Shooter/Space Shooter/Util.swift:50:26: Incorrect argument label in call (have 'MDLMaterial:', expected 'coder:') It doesn't

Drag object on XZ plane

北城以北 提交于 2019-12-02 07:13:48
I am working on an augmented reality app and I would like to be able to drag an object in the space. The problem with the solutions I find here in SO, the ones that suggest using projectPoint / unprojectPoint , is that they produce movement along the XY plane. I was trying to use the fingers movement on the screen as an offset for x and z coordinates of the node. The problem is that there is a lot of stuff to take in consideration (camera's position, node's position, node's rotation, etc..) Is there a simpler way of doing this? first you need to create floor or very large plane few meters (i

SceneKit SCNPhysicsBody get notified of resting

痴心易碎 提交于 2019-12-02 06:24:59
SceneKit Is there a way to get notified when dynamicBody is in resting State ? I want to remove dynamicBody when it finished to fall to the ground and stopped moving completely - I presume that I will have quite large amount of those so I would like to use something event based rather than looping through all the bodies and checking their velocities ? Hal Mueller You could use Key-Value Observation on the isResting property. See Is key-value observation (KVO) available in Swift? . Or you could use the SCNPhysicsContact and SCNPhysicsContactDelegate to detect collisions with the floor, and use