scenekit

xcode9 / SceneKit - .dae file not loading into SCNScene - returns nil

吃可爱长大的小学妹 提交于 2019-12-02 06:05:07
问题 I'm trying to load a .dae file into SCNScene, using the following code: let solutionScene = SCNScene(named: "art.scnassets/level1.dae") print(solutionScene?.rootNode) // prints nil solutionNode = solutionScene?.rootNode.childNode(withName: "level1", recursively: true) I exported the .dae file from Blender as COLLADA with default settings, contains just a one simple object. When i click on the .dae file in my art.scnassets folder in XCode, it opens without problem and i can see the geometry,

SCNMaterial: can't find init:mdlMaterial:

懵懂的女人 提交于 2019-12-02 05:38:16
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 seem to find the method. I tried in Objective-C and it still doesn't find it. Edit I was already importing

Using AVCaptureDevice as SCNScene background content

試著忘記壹切 提交于 2019-12-02 05:07:50
问题 During the SceneKit: What's New presentation at WWCD2017 (44:19) it was stated that we can now use AVCaptureDevice as background content for SCNScene . Snippet from the presentation: let captureDevice: AVCaptureDevice = ... scene.background.contents = captureDevice However the following code let captureDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back)! scene.background.contents = captureDevice produces an error: [SceneKit] Error: Cannot get pixel buffer

xcode9 / SceneKit - .dae file not loading into SCNScene - returns nil

房东的猫 提交于 2019-12-02 01:01:06
I'm trying to load a .dae file into SCNScene, using the following code: let solutionScene = SCNScene(named: "art.scnassets/level1.dae") print(solutionScene?.rootNode) // prints nil solutionNode = solutionScene?.rootNode.childNode(withName: "level1", recursively: true) I exported the .dae file from Blender as COLLADA with default settings, contains just a one simple object. When i click on the .dae file in my art.scnassets folder in XCode, it opens without problem and i can see the geometry, camera etc. I just can't get it loaded in the SCNScene. Is there anything i missed either on Blender

Subclassing SCNNode

烂漫一生 提交于 2019-12-01 22:58:52
I am importing a simple dae file. I want some of the nodes to be a subclass of SCNNode - MySCNNode. MySCNNode *node = [scnView.scene.rootNode childNodeWithName:@"Box1" recursively:YES]; //additional initialization goes here Tried casting to (MySCNNode *) too. But this is not working. "node" is still an SCNNode. Why? I need to add a few properties and methods to SCNNode. So I subclassed SCNNode. I want the nodes from the scene(imported from a dae) to have the properties and behaviour. The nodes from the scene is always SCNNode. I want it to be of class MySCNNode. I understand needing a subclass

How to extend float3 or any other built-in type to conform to the Codable protocol?

北战南征 提交于 2019-12-01 21:14:01
问题 In trying to serialize an array of float3 objects with the basic JSONEncoder, it's revealed that float3 does not conform to the Codable protocol, so this cannot be done. I tried to write a basic extension as suggested in Encoding and Decoding Custom Types as seen below, but the error 'self' used before all stored properties are initialized is rendered for each of the assignment lines in the init. I assume this is because the compiler is not sure that Float.self is defined prior to the

Rotate SCNNode relative local coordinates

点点圈 提交于 2019-12-01 20:11:44
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? 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)) Have you tried: [node runAction:[SCNAction rotateByX:0 y:1 z:0 duration:5.0]]; //Rotates the node along the y axis for 5 seconds. 来源: https:/

How to extend float3 or any other built-in type to conform to the Codable protocol?

两盒软妹~` 提交于 2019-12-01 20:06:13
In trying to serialize an array of float3 objects with the basic JSONEncoder, it's revealed that float3 does not conform to the Codable protocol, so this cannot be done. I tried to write a basic extension as suggested in Encoding and Decoding Custom Types as seen below, but the error 'self' used before all stored properties are initialized is rendered for each of the assignment lines in the init. I assume this is because the compiler is not sure that Float.self is defined prior to the initialization of float3, but I'm not sure how to resolve this. Further, the end of the init says Return from

scene kit memory management using swift

别等时光非礼了梦想. 提交于 2019-12-01 17:16:59
问题 I'm perplexed as to how I am to free up memory in scene kit using swift. Whenever I create an SCNNode from a collada file, It imports geometry, creates a physics object, and sets a material from a jpg file. This takes up 10 mb of ram when creating a new object for some reason (even though the files sizes are under 300k), but whatever. Whenever it is removed from the parent node, zero ram frees up, and I do not understand why. What code can I use to TRULY remove the object? I can't find any

How to get the real position of a sub node in SceneKit after rotation?

两盒软妹~` 提交于 2019-12-01 16:53:48
问题 I am developing a scene with SceneKit. I have a main node with a subnode: // Main node SCNNode* planet = [SCNNode node]; planet.geometry = [SCNSphere sphereWithRadius:2]; planet.position = SCNVector3Make(0, -3, 5); // sub-node SCNNode* satellite = [SCNNode node]; satellite.geometry = [SCNSphere sphereWithRadius:0.4]; satellite.position = SCNVector3Make(4, 0, 0); [planet addChildNode:satellite]; [scene.rootNode addChildNode:planet]; I use a NSTimer to make some actions and some animations. In