scenekit

SceneKit shader not working

空扰寡人 提交于 2019-12-13 06:59:53
问题 I'm trying to work with shaders in SceneKit on iOS 8. Here is my code: let sphere = SCNSphere(radius: 6) sphere.segmentCount = 100 sphere.firstMaterial?.diffuse.contents = UIImage(named: "noise.png") sphere.firstMaterial?.diffuse.wrapS = SCNWrapMode.Repeat sphere.firstMaterial?.diffuse.wrapT = SCNWrapMode.Repeat sphere.firstMaterial?.reflective.contents = UIImage(named: "envmap3") sphere.firstMaterial?.fresnelExponent = 1.3 let sphereNode = SCNNode(geometry: sphere) sphereNode.position =

Creating a subclass of a SCNNode

删除回忆录丶 提交于 2019-12-13 05:55:52
问题 I'm loading a node from a .dae file with the following code: func newNode() -> SCNNode { var node = SCNNode() let scene = SCNScene(named: "circle.dae") var nodeArray = scene!.rootNode.childNodes for childNode in nodeArray { node.addChildNode(childNode as! SCNNode) } return node } I would now like to add some properties and methods to this specific node so that when I load it in a scene it gets a random color that I can then modify whenever I want. I had done something similar with a subclass

ARKit image detection, add image

北慕城南 提交于 2019-12-13 05:11:46
问题 I'm using ARKit 1.5 (beta) for image detection. Once I detect my image I would like to then place a AR scene image using the plane detected. How can this be done? My code so far which detects the image (which is in my assets folder): /// - Tag: ARImageAnchor-Visualizing func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) { guard let imageAnchor = anchor as? ARImageAnchor else { return } let referenceImage = imageAnchor.referenceImage updateQueue.async { //

In SceneKit SCNAction hangs when called from completion handler of RunAction

纵然是瞬间 提交于 2019-12-13 04:27:38
问题 Calling an SCNAction from the completion handler of RunAction seems to hang SceneKit. A touch event or rotating the device seems to unblock the hang. To reproduce: 1) Take the default SceneKit project you get on startup with the rotating spaceship. 2) Replace the animation code: ship.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 2, 0, 1))); with: ship.RunAction(SCNAction.RotateBy(0, 2, 0, durationInSeconds: 3.0f), delegate { Console.WriteLine("DONE ROTATE"); ship.RunAction

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

ARKIT : SKVideoNode continue playing while node is out of scene, pause is not working

断了今生、忘了曾经 提交于 2019-12-13 03:46:54
问题 I am implementing a demo project using SceneKit and ARKit where i keep camera on some picture and play video from url. Everything works fine but i could not be able to stop previous video and it starts another video. Previous video plays on background. It happens sometimes when i switch image. My implementation is : @IBOutlet var sceneView: ARSCNView! var videosNames = [String]() var player = AVPlayer() var videoNode = SKVideoNode() In viewDidload, sceneView.delegate = self // Create a

How to access specific child node Scenekit

ε祈祈猫儿з 提交于 2019-12-13 03:15:09
问题 So in my application, you can think that it is similar to blackjack. There is a deck of 52 cards, and you reuse the same design on the back of the card, but it has different card faces such as Ace Spade, 2 Diamond and etc. So in my Scenekit, I created a scene to specifically design 1 card. I will then duplicate it in my main scene 52 times. I also uniquely identify each individual parent node with a specific name such as Card1, Card2, Card3 and etc. In my View Controller, I do the act of

Reduce Application Lag while using shadows in SceneKit

不打扰是莪最后的温柔 提交于 2019-12-13 02:15:50
问题 I am working on a 3D map in SceneKit. When I enable the Cast Shadow Property of a directional light in SceneKit, the shadows appear, but the application becomes very slow. How do I reduce the lag while still maintaining shadows in the scene? 回答1: Use Fake Shadows (shadows generated and baked as a texture in 3D authoring tool) rather than True Shadow Map . To apply fake shadows as a texture for 3D plane use PNG file format with premultiplied alpha channel ( RGB * A ). It helps you get rid of

SCNNode.flattenedClone() does not reduce draw calls

独自空忆成欢 提交于 2019-12-12 19:13:36
问题 I'm trying to optimize my SceneKit app by reducing draw calls. From the Apple Documentation, and many WWDC talks, combining many child nodes into a single node via flattenedClone() should reduce draw calls, but I am unable to reduce draw calls by utilizing this method. I have attached a simple example SceneKit app that demonstrates how flattenedClone is not reducing draw calls. When the app starts, 5 objects are displayed, and you can see 5 draw calls. (well, 6 actually if you interact with

Controlling an object orbiting a sphere

纵饮孤独 提交于 2019-12-12 16:04:45
问题 I want to let the user control an object moving over the surface of a static sphere. Using two buttons to rotate the direction of the object clockwise and anti-clockwise as it constantly moves forward similar to asteroids. In scene kit there are three different orientation properties for an SCNNode and I really don't know where to start. I understand how to execute everything except the rotation around the sphere. 回答1: You're looking for a parameterization of the surface of the sphere. You